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

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
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 // TODO(brettw) auto-deduce the interface ID from the FunctionsT, or
43 // implement GetFunctionAPI in such a way that no ID is necessary at this
44 // level (could have a templatized Get function on TrackerBase that does
45 // this internally).
piman 2011/05/06 17:00:09 Remove TODO since it's done
46 EnterFunction(PP_Instance instance, bool report_error)
piman 2011/05/06 17:00:09 You could make report_error a template parameter.
47 : functions_(NULL) {
48 shared_impl::FunctionGroupBase* base =
49 shared_impl::TrackerBase::Get()->GetFunctionAPI(
50 instance, FunctionsT::interface_id);
51 if (base)
52 functions_ = base->GetAs<FunctionsT>();
53 // TODO(brettw) check error and if report_error is set, do something.
54 }
55 ~EnterFunction() {}
56
57 bool succeeded() const { return !!functions_; }
58 bool failed() const { return !functions_; }
59
60 FunctionsT* functions() { return functions_; }
61
62 private:
63 FunctionsT* functions_;
64
65 DISALLOW_COPY_AND_ASSIGN(EnterFunction);
66 };
67
68 template<typename ResourceT>
69 class EnterResource {
70 public:
71 EnterResource(PP_Resource resource, bool report_error)
72 : object_(NULL) {
73 shared_impl::ResourceObjectBase* base =
74 shared_impl::TrackerBase::Get()->GetResourceAPI(resource);
75 if (base)
76 object_ = base->GetAs<ResourceT>();
77 // TODO(brettw) check error and if report_error is set, do something.
78 }
79 ~EnterResource() {}
80
81 bool succeeded() const { return !!object_; }
82 bool failed() const { return !object_; }
83
84 ResourceT* object() { return object_; }
85
86 private:
87 ResourceT* object_;
88
89 DISALLOW_COPY_AND_ASSIGN(EnterResource);
90 };
91
92 } // namespace thunk
93 } // namespace ppapi
94
95 #endif // PPAPI_THUNK_ENTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698