OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // DevTools RPC subsystem is a simple string serialization-based rpc | 5 // DevTools RPC subsystem is a simple string serialization-based rpc |
6 // implementation. The client is responsible for defining the Rpc-enabled | 6 // implementation. The client is responsible for defining the Rpc-enabled |
7 // interface in terms of its macros: | 7 // interface in terms of its macros: |
8 // | 8 // |
9 // #define MYAPI_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3) | 9 // #define MYAPI_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3) |
10 // METHOD0(Method1) | 10 // METHOD0(Method1) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // calls to the underlying MyApi methods: | 43 // calls to the underlying MyApi methods: |
44 // | 44 // |
45 // MyApi* real_object; | 45 // MyApi* real_object; |
46 // MyApiDispatch::Dispatch(real_object, raw_string_call_generated_by_stub); | 46 // MyApiDispatch::Dispatch(real_object, raw_string_call_generated_by_stub); |
47 // | 47 // |
48 // will make corresponding calls to the real object. | 48 // will make corresponding calls to the real object. |
49 | 49 |
50 #ifndef WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_H_ | 50 #ifndef WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_H_ |
51 #define WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_H_ | 51 #define WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_H_ |
52 | 52 |
53 #include <string> | 53 #include "PlatformString.h" |
54 | 54 |
55 // Do not remove this one although it is not used. | 55 // TODO(darin): Remove these dependencies on Chromium base/. |
56 #include <wtf/OwnPtr.h> | |
57 | |
58 #include "base/basictypes.h" | 56 #include "base/basictypes.h" |
59 #include "base/compiler_specific.h" | 57 #include "base/compiler_specific.h" |
60 #include "base/string_util.h" | |
61 #include "webkit/glue/glue_util.h" | |
62 | 58 |
63 namespace WebCore { | 59 namespace WebCore { |
64 class String; | 60 class String; |
65 } | 61 } |
66 | 62 |
67 using WebCore::String; | 63 using WebCore::String; |
68 | 64 |
69 /////////////////////////////////////////////////////// | 65 /////////////////////////////////////////////////////// |
70 // RPC dispatch macro | 66 // RPC dispatch macro |
71 | 67 |
72 template<typename T> | 68 template<typename T> |
73 struct RpcTypeTrait { | 69 struct RpcTypeTrait { |
74 typedef T ApiType; | 70 typedef T ApiType; |
75 }; | 71 }; |
76 | 72 |
77 template<> | 73 template<> |
78 struct RpcTypeTrait<bool> { | 74 struct RpcTypeTrait<bool> { |
79 typedef bool ApiType; | 75 typedef bool ApiType; |
80 static bool Parse(const std::string& t) { | 76 static bool Parse(const WebCore::String& t) { |
81 int i; | 77 ALLOW_UNUSED bool success; |
82 ALLOW_UNUSED bool success = StringToInt(t, &i); | 78 int i = t.toIntStrict(&success); |
83 ASSERT(success); | 79 ASSERT(success); |
84 return i; | 80 return i; |
85 } | 81 } |
86 static std::string ToString(bool b) { | 82 static WebCore::String ToString(bool b) { |
87 return IntToString(b ? 1 : 0); | 83 return WebCore::String::number(b ? 1 : 0); |
88 } | 84 } |
89 }; | 85 }; |
90 | 86 |
91 template<> | 87 template<> |
92 struct RpcTypeTrait<int> { | 88 struct RpcTypeTrait<int> { |
93 typedef int ApiType; | 89 typedef int ApiType; |
94 static int Parse(const std::string& t) { | 90 static int Parse(const WebCore::String& t) { |
95 int i; | 91 ALLOW_UNUSED bool success; |
96 ALLOW_UNUSED bool success = StringToInt(t, &i); | 92 int i = t.toIntStrict(&success); |
97 ASSERT(success); | 93 ASSERT(success); |
98 return i; | 94 return i; |
99 } | 95 } |
100 static std::string ToString(int i) { | 96 static WebCore::String ToString(int i) { |
101 return IntToString(i); | 97 return WebCore::String::number(i); |
102 } | 98 } |
103 }; | 99 }; |
104 | 100 |
105 template<> | 101 template<> |
106 struct RpcTypeTrait<String> { | 102 struct RpcTypeTrait<String> { |
107 typedef const String& ApiType; | 103 typedef const String& ApiType; |
108 static String Parse(const std::string& t) { | 104 static String Parse(const WebCore::String& t) { |
109 return webkit_glue::StdStringToString(t); | 105 return t; |
110 } | 106 } |
111 static std::string ToString(const String& t) { | 107 static WebCore::String ToString(const String& t) { |
112 return webkit_glue::StringToStdString(t); | 108 return t; |
113 } | |
114 }; | |
115 | |
116 template<> | |
117 struct RpcTypeTrait<std::string> { | |
118 typedef const std::string& ApiType; | |
119 static std::string Parse(const std::string& s) { | |
120 return s; | |
121 } | |
122 static std::string ToString(const std::string& s) { | |
123 return s; | |
124 } | 109 } |
125 }; | 110 }; |
126 | 111 |
127 /////////////////////////////////////////////////////// | 112 /////////////////////////////////////////////////////// |
128 // RPC Api method declarations | 113 // RPC Api method declarations |
129 | 114 |
130 #define TOOLS_RPC_API_METHOD0(Method) \ | 115 #define TOOLS_RPC_API_METHOD0(Method) \ |
131 virtual void Method() = 0; | 116 virtual void Method() = 0; |
132 | 117 |
133 #define TOOLS_RPC_API_METHOD1(Method, T1) \ | 118 #define TOOLS_RPC_API_METHOD1(Method, T1) \ |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 Class() { \ | 211 Class() { \ |
227 class_name = #Class; \ | 212 class_name = #Class; \ |
228 } \ | 213 } \ |
229 ~Class() {} \ | 214 ~Class() {} \ |
230 \ | 215 \ |
231 STRUCT( \ | 216 STRUCT( \ |
232 TOOLS_RPC_API_METHOD0, \ | 217 TOOLS_RPC_API_METHOD0, \ |
233 TOOLS_RPC_API_METHOD1, \ | 218 TOOLS_RPC_API_METHOD1, \ |
234 TOOLS_RPC_API_METHOD2, \ | 219 TOOLS_RPC_API_METHOD2, \ |
235 TOOLS_RPC_API_METHOD3) \ | 220 TOOLS_RPC_API_METHOD3) \ |
236 std::string class_name; \ | 221 WebCore::String class_name; \ |
237 private: \ | 222 private: \ |
238 DISALLOW_COPY_AND_ASSIGN(Class); \ | 223 DISALLOW_COPY_AND_ASSIGN(Class); \ |
239 }; \ | 224 }; \ |
240 \ | 225 \ |
241 class Class##Stub : public Class, public DevToolsRpc { \ | 226 class Class##Stub : public Class, public DevToolsRpc { \ |
242 public: \ | 227 public: \ |
243 explicit Class##Stub(Delegate* delegate) : DevToolsRpc(delegate) {} \ | 228 explicit Class##Stub(Delegate* delegate) : DevToolsRpc(delegate) {} \ |
244 virtual ~Class##Stub() {} \ | 229 virtual ~Class##Stub() {} \ |
245 typedef Class CLASS; \ | 230 typedef Class CLASS; \ |
246 STRUCT( \ | 231 STRUCT( \ |
247 TOOLS_RPC_STUB_METHOD0, \ | 232 TOOLS_RPC_STUB_METHOD0, \ |
248 TOOLS_RPC_STUB_METHOD1, \ | 233 TOOLS_RPC_STUB_METHOD1, \ |
249 TOOLS_RPC_STUB_METHOD2, \ | 234 TOOLS_RPC_STUB_METHOD2, \ |
250 TOOLS_RPC_STUB_METHOD3) \ | 235 TOOLS_RPC_STUB_METHOD3) \ |
251 private: \ | 236 private: \ |
252 DISALLOW_COPY_AND_ASSIGN(Class##Stub); \ | 237 DISALLOW_COPY_AND_ASSIGN(Class##Stub); \ |
253 }; \ | 238 }; \ |
254 \ | 239 \ |
255 class Class##Dispatch { \ | 240 class Class##Dispatch { \ |
256 public: \ | 241 public: \ |
257 Class##Dispatch() {} \ | 242 Class##Dispatch() {} \ |
258 virtual ~Class##Dispatch() {} \ | 243 virtual ~Class##Dispatch() {} \ |
259 \ | 244 \ |
260 static bool Dispatch(Class* delegate, \ | 245 static bool Dispatch(Class* delegate, \ |
261 const std::string& class_name, \ | 246 const WebCore::String& class_name, \ |
262 const std::string& method_name, \ | 247 const WebCore::String& method_name, \ |
263 const std::string& p1, \ | 248 const WebCore::String& p1, \ |
264 const std::string& p2, \ | 249 const WebCore::String& p2, \ |
265 const std::string& p3) { \ | 250 const WebCore::String& p3) { \ |
266 if (class_name != #Class) { \ | 251 if (class_name != #Class) { \ |
267 return false; \ | 252 return false; \ |
268 } \ | 253 } \ |
269 typedef Class CLASS; \ | 254 typedef Class CLASS; \ |
270 STRUCT( \ | 255 STRUCT( \ |
271 TOOLS_RPC_DISPATCH0, \ | 256 TOOLS_RPC_DISPATCH0, \ |
272 TOOLS_RPC_DISPATCH1, \ | 257 TOOLS_RPC_DISPATCH1, \ |
273 TOOLS_RPC_DISPATCH2, \ | 258 TOOLS_RPC_DISPATCH2, \ |
274 TOOLS_RPC_DISPATCH3) \ | 259 TOOLS_RPC_DISPATCH3) \ |
275 return false; \ | 260 return false; \ |
276 } \ | 261 } \ |
277 private: \ | 262 private: \ |
278 DISALLOW_COPY_AND_ASSIGN(Class##Dispatch); \ | 263 DISALLOW_COPY_AND_ASSIGN(Class##Dispatch); \ |
279 }; | 264 }; |
280 | 265 |
281 /////////////////////////////////////////////////////// | 266 /////////////////////////////////////////////////////// |
282 // RPC base class | 267 // RPC base class |
283 class DevToolsRpc { | 268 class DevToolsRpc { |
284 public: | 269 public: |
285 class Delegate { | 270 class Delegate { |
286 public: | 271 public: |
287 Delegate() {} | 272 Delegate() {} |
288 virtual ~Delegate() {} | 273 virtual ~Delegate() {} |
289 virtual void SendRpcMessage(const std::string& class_name, | 274 virtual void SendRpcMessage(const WebCore::String& class_name, |
290 const std::string& method_name, | 275 const WebCore::String& method_name, |
291 const std::string& p1 = "", | 276 const WebCore::String& p1 = "", |
292 const std::string& p2 = "", | 277 const WebCore::String& p2 = "", |
293 const std::string& p3 = "") = 0; | 278 const WebCore::String& p3 = "") = 0; |
294 private: | 279 private: |
295 DISALLOW_COPY_AND_ASSIGN(Delegate); | 280 DISALLOW_COPY_AND_ASSIGN(Delegate); |
296 }; | 281 }; |
297 | 282 |
298 explicit DevToolsRpc(Delegate* delegate) | 283 explicit DevToolsRpc(Delegate* delegate) |
299 : delegate_(delegate) {} | 284 : delegate_(delegate) {} |
300 virtual ~DevToolsRpc() {}; | 285 virtual ~DevToolsRpc() {}; |
301 | 286 |
302 protected: | 287 protected: |
303 Delegate* delegate_; | 288 Delegate* delegate_; |
304 private: | 289 private: |
305 DISALLOW_COPY_AND_ASSIGN(DevToolsRpc); | 290 DISALLOW_COPY_AND_ASSIGN(DevToolsRpc); |
306 }; | 291 }; |
307 | 292 |
308 #endif // WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_H_ | 293 #endif // WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_H_ |
OLD | NEW |