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

Side by Side Diff: o3d/gpu_plugin/np_utils/np_dispatcher.h

Issue 196032: Replaced BaseNPObject with DefaultNPObject because...... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 | « o3d/gpu_plugin/np_utils/np_class_unittest.cc ('k') | o3d/gpu_plugin/np_utils/np_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef O3D_GPU_PLUGIN_NP_UTILS_NP_DISPATCHER_H_ 5 #ifndef O3D_GPU_PLUGIN_NP_UTILS_NP_DISPATCHER_H_
6 #define O3D_GPU_PLUGIN_NP_UTILS_NP_DISPATCHER_H_ 6 #define O3D_GPU_PLUGIN_NP_UTILS_NP_DISPATCHER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "o3d/gpu_plugin/np_utils/np_utils.h" 10 #include "o3d/gpu_plugin/np_utils/np_utils.h"
11 #include "third_party/npapi/bindings/npapi.h" 11 #include "third_party/npapi/bindings/npapi.h"
12 #include "third_party/npapi/bindings/npruntime.h" 12 #include "third_party/npapi/bindings/npruntime.h"
13 13
14 // These macros are used to make dispatcher chains. See the comment for the 14 // Dispatchers make regular member functions available as NPObject methods.
15 // DispatchedNPObject class. 15 // Usage:
16 //
17 // class MyNPObject : public DefaultNPObject<NPObject> {
18 // public:
19 // int MyMethod(bool a, float b);
20 // NP_UTILS_BEGIN_DISPATCHER_CHAIN(MyNPObject, DispatchedNPObject)
21 // NP_UTILS_DISPATCHER(MyMethod, int(bool, float))
22 // NP_UTILS_END_DISPATCHER_CHAIN
23 // };
24 //
25 // Multiple member functions may be listed in the dispatcher chain. Inheritance
26 // is supported. The following types are supported as return types and parameter
27 // types:
28 // * bool
29 // * int
30 // * float
31 // * double
32 // * std::string
33 // * NPObject*
34 //
35
36 // These macros are used to make dispatcher chains.
16 #define NP_UTILS_NP_UTILS_DISPATCHER_JOIN2(a, b) a ## b 37 #define NP_UTILS_NP_UTILS_DISPATCHER_JOIN2(a, b) a ## b
17 #define NP_UTILS_DISPATCHER_JOIN(a, b) NP_UTILS_NP_UTILS_DISPATCHER_JOIN2(a, b) 38 #define NP_UTILS_DISPATCHER_JOIN(a, b) NP_UTILS_NP_UTILS_DISPATCHER_JOIN2(a, b)
18 #define NP_UTILS_DISPATCHER_UNIQUE \ 39 #define NP_UTILS_DISPATCHER_UNIQUE \
19 NP_UTILS_DISPATCHER_JOIN(dispatcher, __LINE__) 40 NP_UTILS_DISPATCHER_JOIN(dispatcher, __LINE__)
20 41
21 #define NP_UTILS_BEGIN_DISPATCHER_CHAIN(Class, BaseClass) \ 42 #define NP_UTILS_BEGIN_DISPATCHER_CHAIN(Class, BaseClass) \
22 static BaseNPDispatcher* GetStaticDispatcherChain() { \ 43 static BaseNPDispatcher* GetDispatcherChain() { \
23 typedef Class ThisClass; \ 44 typedef Class ThisClass; \
24 BaseNPDispatcher* top_dispatcher = BaseClass::GetStaticDispatcherChain(); \ 45 BaseNPDispatcher* top_dispatcher = BaseClass::GetDispatcherChain(); \
25 46
26 #define NP_UTILS_DISPATCHER(name, Signature) \ 47 #define NP_UTILS_DISPATCHER(name, Signature) \
27 static NPDispatcher<ThisClass, Signature> \ 48 static NPDispatcher<ThisClass, Signature> \
28 NP_UTILS_DISPATCHER_UNIQUE( \ 49 NP_UTILS_DISPATCHER_UNIQUE( \
29 top_dispatcher, \ 50 top_dispatcher, \
30 #name, \ 51 #name, \
31 &ThisClass::name); \ 52 &ThisClass::name); \
32 top_dispatcher = &NP_UTILS_DISPATCHER_UNIQUE; \ 53 top_dispatcher = &NP_UTILS_DISPATCHER_UNIQUE; \
33 54
34 #define NP_UTILS_END_DISPATCHER_CHAIN \ 55 #define NP_UTILS_END_DISPATCHER_CHAIN \
35 return top_dispatcher; \ 56 return top_dispatcher; \
36 } \ 57 } \
37 virtual BaseNPDispatcher* GetDynamicDispatcherChain() { \ 58 bool HasMethod(NPIdentifier name) { \
38 static BaseNPDispatcher* top_dispatcher = GetStaticDispatcherChain(); \ 59 return DispatcherHasMethodHelper(GetDispatcherChain(), this, name); \
39 return top_dispatcher; \ 60 } \
61 bool Invoke(NPIdentifier name, \
62 const NPVariant* args, \
63 uint32_t num_args, \
64 NPVariant* result) { \
65 return DispatcherInvokeHelper(GetDispatcherChain(), \
66 this, \
67 name, \
68 args, \
69 num_args, \
70 result); \
71 } \
72 bool Enumerate(NPIdentifier** names, uint32_t* num_names) { \
73 return DispatcherEnumerateHelper(GetDispatcherChain(), \
74 this, \
75 names, \
76 num_names); \
40 } \ 77 } \
41 78
42 namespace o3d { 79 namespace o3d {
43 namespace gpu_plugin { 80 namespace gpu_plugin {
44 81
45 class BaseNPDispatcher { 82 class BaseNPDispatcher {
46 public: 83 public:
47 explicit BaseNPDispatcher(BaseNPDispatcher* next, const NPUTF8* name) 84 BaseNPDispatcher(BaseNPDispatcher* next, const NPUTF8* name);
48 : next_(next) {
49 // Convert first character to lower case if it is the ASCII range.
50 // TODO(apatrick): do this correctly for non-ASCII characters.
51 std::string java_script_style_name(name);
52 if (isupper(java_script_style_name[0])) {
53 java_script_style_name[0] = tolower(java_script_style_name[0]);
54 }
55 85
56 name_ = NPBrowser::get()->GetStringIdentifier( 86 virtual ~BaseNPDispatcher();
57 java_script_style_name.c_str());
58 }
59
60 virtual ~BaseNPDispatcher() {
61 }
62 87
63 BaseNPDispatcher* next() const { 88 BaseNPDispatcher* next() const {
64 return next_; 89 return next_;
65 } 90 }
66 91
67 NPIdentifier name() const { 92 NPIdentifier name() const {
68 return name_; 93 return name_;
69 } 94 }
70 95
71 virtual int num_args() const = 0; 96 virtual int num_args() const = 0;
72 97
73 virtual bool Invoke(NPObject* object, 98 virtual bool Invoke(NPObject* object,
74 const NPVariant* args, 99 const NPVariant* args,
75 uint32_t num_args, 100 uint32_t num_args,
76 NPVariant* result) = 0; 101 NPVariant* result) = 0;
77 102
78 private: 103 private:
79 BaseNPDispatcher* next_; 104 BaseNPDispatcher* next_;
80 NPIdentifier name_; 105 NPIdentifier name_;
81 DISALLOW_COPY_AND_ASSIGN(BaseNPDispatcher); 106 DISALLOW_COPY_AND_ASSIGN(BaseNPDispatcher);
82 }; 107 };
83 108
109 bool DispatcherHasMethodHelper(BaseNPDispatcher* chain,
110 NPObject* object,
111 NPIdentifier name);
112
113 bool DispatcherInvokeHelper(BaseNPDispatcher* chain,
114 NPObject* object,
115 NPIdentifier name,
116 const NPVariant* args,
117 uint32_t num_args,
118 NPVariant* result);
119
120 bool DispatcherEnumerateHelper(BaseNPDispatcher* chain,
121 NPObject* object,
122 NPIdentifier** names,
123 uint32_t* num_names);
124
84 // This class should never be instantiated. It is always specialized. Attempting 125 // This class should never be instantiated. It is always specialized. Attempting
85 // to instantiate it results in a compilation error. This might mean an 126 // to instantiate it results in a compilation error. This might mean an
86 // attempt to instantiate a dispatcher with more parameters than have been 127 // attempt to instantiate a dispatcher with more parameters than have been
87 // specialized for. See the specialization code below. 128 // specialized for. See the specialization code below.
88 template <typename NPObjectType, typename FunctionType> 129 template <typename NPObjectType, typename FunctionType>
89 struct NPDispatcher { 130 struct NPDispatcher {
90 }; 131 };
91 132
92 #define TO_NPVARIANT(index) \ 133 #define TO_NPVARIANT(index) \
93 T##index n##index; \ 134 T##index n##index; \
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 216
176 #include "o3d/gpu_plugin/np_utils/np_dispatcher_specializations.h" // NOLINT 217 #include "o3d/gpu_plugin/np_utils/np_dispatcher_specializations.h" // NOLINT
177 218
178 219
179 #undef TO_NPVARIANT 220 #undef TO_NPVARIANT
180 221
181 } // namespace gpu_plugin 222 } // namespace gpu_plugin
182 } // namespace o3d 223 } // namespace o3d
183 224
184 #endif // O3D_GPU_PLUGIN_NP_UTILS_NP_DISPATCHER_H_ 225 #endif // O3D_GPU_PLUGIN_NP_UTILS_NP_DISPATCHER_H_
OLDNEW
« no previous file with comments | « o3d/gpu_plugin/np_utils/np_class_unittest.cc ('k') | o3d/gpu_plugin/np_utils/np_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698