Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Side by Side Diff: ppapi/thunk/enter.h

Issue 6905088: New thunk system for Pepper proxy and implementation (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/shared_impl/tracker_base.cc ('k') | ppapi/thunk/ppb_graphics_2d_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef PPAPI_THUNK_ENTER_H_
6 #define PPAPI_THUNK_ENTER_H_
7
8 #include "base/basictypes.h"
9 #include "ppapi/c/pp_resource.h"
10 #include "ppapi/proxy/interface_id.h"
11 #include "ppapi/shared_impl/function_group_base.h"
12 #include "ppapi/shared_impl/resource_object_base.h"
13 #include "ppapi/shared_impl/tracker_base.h"
14
15 namespace ppapi {
16 namespace thunk {
17
18 // EnterHost* helper objects: These objects wrap a call from the C PPAPI into
19 // the internal implementation. They make sure the lock is acquired and will
20 // automatically set up some stuff for you.
21 //
22 // You should always check whether the enter succeeded before using the object.
23 // If this fails, then the instance or resource ID supplied was invalid.
24 //
25 // The |report_error| arguments to the constructor should indicate if errors
26 // should be logged to the console. If the calling function expects that the
27 // input values are correct (the normal case), this should be set to true. In
28 // some case like |IsFoo(PP_Resource)| the caller is quersioning whether their
29 // handle is this type, and we don't want to report an error if it's not.
30 //
31 // Standalone functions: EnterHostFunction
32 // Automatically gets the implementation for the function API for the
33 // supplied PP_Instance.
34 //
35 // Resource member functions: EnterHostResource
36 // Automatically interprets the given PP_Resource as a resource ID and sets
37 // up the resource object for you.
38
39 template<typename FunctionsT>
40 class EnterFunction {
41 public:
42 EnterFunction(PP_Instance instance, bool report_error)
43 : functions_(NULL) {
44 shared_impl::FunctionGroupBase* base =
45 shared_impl::TrackerBase::Get()->GetFunctionAPI(
46 instance, FunctionsT::interface_id);
47 if (base)
48 functions_ = base->GetAs<FunctionsT>();
49 // TODO(brettw) check error and if report_error is set, do something.
50 }
51 ~EnterFunction() {}
52
53 bool succeeded() const { return !!functions_; }
54 bool failed() const { return !functions_; }
55
56 FunctionsT* functions() { return functions_; }
57
58 private:
59 FunctionsT* functions_;
60
61 DISALLOW_COPY_AND_ASSIGN(EnterFunction);
62 };
63
64 template<typename ResourceT>
65 class EnterResource {
66 public:
67 EnterResource(PP_Resource resource, bool report_error)
68 : object_(NULL) {
69 shared_impl::ResourceObjectBase* base =
70 shared_impl::TrackerBase::Get()->GetResourceAPI(resource);
71 if (base)
72 object_ = base->GetAs<ResourceT>();
73 // TODO(brettw) check error and if report_error is set, do something.
74 }
75 ~EnterResource() {}
76
77 bool succeeded() const { return !!object_; }
78 bool failed() const { return !object_; }
79
80 ResourceT* object() { return object_; }
81
82 private:
83 ResourceT* object_;
84
85 DISALLOW_COPY_AND_ASSIGN(EnterResource);
86 };
87
88 } // namespace thunk
89 } // namespace ppapi
90
91 #endif // PPAPI_THUNK_ENTER_H_
OLDNEW
« no previous file with comments | « ppapi/shared_impl/tracker_base.cc ('k') | ppapi/thunk/ppb_graphics_2d_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698