| 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, METHOD4) | 9 // #define MYAPI_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3) |
| 10 // METHOD0(Method1) | 10 // METHOD0(Method1) |
| 11 // METHOD3(Method2, int, String, Value) | |
| 12 // METHOD1(Method3, int) | 11 // METHOD1(Method3, int) |
| 13 // (snippet above should be multiline macro, add trailing backslashes) | 12 // (snippet above should be multiline macro, add trailing backslashes) |
| 14 // | 13 // |
| 15 // DEFINE_RPC_CLASS(MyApi, MYAPI_STRUCT) | 14 // DEFINE_RPC_CLASS(MyApi, MYAPI_STRUCT) |
| 16 // | 15 // |
| 17 // The snippet above will generate three classes: MyApi, MyApiStub and | 16 // The snippet above will generate three classes: MyApi, MyApiStub and |
| 18 // MyApiDispatch. | 17 // MyApiDispatch. |
| 19 // | 18 // |
| 20 // 1. For each method defined in the marco MyApi will have a | 19 // 1. For each method defined in the marco MyApi will have a |
| 21 // pure virtual function generated, so that MyApi would look like: | 20 // pure virtual function generated, so that MyApi would look like: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 46 // MyApi* real_object; | 45 // MyApi* real_object; |
| 47 // MyApiDispatch::Dispatch(real_object, raw_string_call_generated_by_stub); | 46 // MyApiDispatch::Dispatch(real_object, raw_string_call_generated_by_stub); |
| 48 // | 47 // |
| 49 // will make corresponding calls to the real object. | 48 // will make corresponding calls to the real object. |
| 50 | 49 |
| 51 #ifndef WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_H_ | 50 #ifndef WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_H_ |
| 52 #define WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_H_ | 51 #define WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_H_ |
| 53 | 52 |
| 54 #include <string> | 53 #include <string> |
| 55 | 54 |
| 55 // Do not remove this one although it is not used. |
| 56 #include <wtf/OwnPtr.h> | 56 #include <wtf/OwnPtr.h> |
| 57 | 57 |
| 58 #include "base/basictypes.h" | 58 #include "base/basictypes.h" |
| 59 #include "base/logging.h" | 59 #include "base/string_util.h" |
| 60 #include "base/values.h" | 60 #include "webkit/glue/glue_util.h" |
| 61 | 61 |
| 62 namespace WebCore { | 62 namespace WebCore { |
| 63 class String; | 63 class String; |
| 64 } | 64 } |
| 65 | 65 |
| 66 using WebCore::String; | 66 using WebCore::String; |
| 67 | 67 |
| 68 /////////////////////////////////////////////////////// | 68 /////////////////////////////////////////////////////// |
| 69 // RPC dispatch macro | 69 // RPC dispatch macro |
| 70 | 70 |
| 71 template<typename T> | 71 template<typename T> |
| 72 struct RpcTypeTrait { | 72 struct RpcTypeTrait { |
| 73 typedef T ApiType; | 73 typedef T ApiType; |
| 74 typedef T DispatchType; | 74 }; |
| 75 static const DispatchType& Pass(const DispatchType& t) { | 75 |
| 76 return t; | 76 template<> |
| 77 struct RpcTypeTrait<bool> { |
| 78 typedef bool ApiType; |
| 79 static bool Parse(const std::string& t) { |
| 80 int i; |
| 81 bool success = StringToInt(t, &i); |
| 82 ASSERT(success); |
| 83 return i; |
| 84 } |
| 85 static std::string ToString(bool b) { |
| 86 return IntToString(b ? 1 : 0); |
| 77 } | 87 } |
| 78 }; | 88 }; |
| 79 | 89 |
| 80 template<> | 90 template<> |
| 81 struct RpcTypeTrait<Value> { | 91 struct RpcTypeTrait<int> { |
| 82 typedef const Value& ApiType; | 92 typedef int ApiType; |
| 83 typedef Value* DispatchType; | 93 static int Parse(const std::string& t) { |
| 84 static const Value& Pass(Value* t) { | 94 int i; |
| 85 return *t; | 95 bool success = StringToInt(t, &i); |
| 96 ASSERT(success); |
| 97 return i; |
| 98 } |
| 99 static std::string ToString(int i) { |
| 100 return IntToString(i); |
| 86 } | 101 } |
| 87 }; | 102 }; |
| 88 | 103 |
| 89 template<> | 104 template<> |
| 90 struct RpcTypeTrait<String> { | 105 struct RpcTypeTrait<String> { |
| 91 typedef const String& ApiType; | 106 typedef const String& ApiType; |
| 92 typedef String DispatchType; | 107 static String Parse(const std::string& t) { |
| 93 static const DispatchType& Pass(const DispatchType& t) { | 108 return webkit_glue::StdStringToString(t); |
| 94 return t; | 109 } |
| 110 static std::string ToString(const String& t) { |
| 111 return webkit_glue::StringToStdString(t); |
| 95 } | 112 } |
| 96 }; | 113 }; |
| 97 | 114 |
| 98 template<> | 115 template<> |
| 99 struct RpcTypeTrait<std::string> { | 116 struct RpcTypeTrait<std::string> { |
| 100 typedef const std::string& ApiType; | 117 typedef const std::string& ApiType; |
| 101 typedef std::string DispatchType; | 118 static std::string Parse(const std::string& s) { |
| 102 static const DispatchType& Pass(const DispatchType& t) { | 119 return s; |
| 103 return t; | 120 } |
| 121 static std::string ToString(const std::string& s) { |
| 122 return s; |
| 104 } | 123 } |
| 105 }; | 124 }; |
| 106 | 125 |
| 107 /////////////////////////////////////////////////////// | 126 /////////////////////////////////////////////////////// |
| 108 // RPC Api method declarations | 127 // RPC Api method declarations |
| 109 | 128 |
| 110 #define TOOLS_RPC_API_METHOD0(Method) \ | 129 #define TOOLS_RPC_API_METHOD0(Method) \ |
| 111 virtual void Method() = 0; | 130 virtual void Method() = 0; |
| 112 | 131 |
| 113 #define TOOLS_RPC_API_METHOD1(Method, T1) \ | 132 #define TOOLS_RPC_API_METHOD1(Method, T1) \ |
| 114 virtual void Method(RpcTypeTrait<T1>::ApiType t1) = 0; | 133 virtual void Method(RpcTypeTrait<T1>::ApiType t1) = 0; |
| 115 | 134 |
| 116 #define TOOLS_RPC_API_METHOD2(Method, T1, T2) \ | 135 #define TOOLS_RPC_API_METHOD2(Method, T1, T2) \ |
| 117 virtual void Method(RpcTypeTrait<T1>::ApiType t1, \ | 136 virtual void Method(RpcTypeTrait<T1>::ApiType t1, \ |
| 118 RpcTypeTrait<T2>::ApiType t2) = 0; | 137 RpcTypeTrait<T2>::ApiType t2) = 0; |
| 119 | 138 |
| 120 #define TOOLS_RPC_API_METHOD3(Method, T1, T2, T3) \ | 139 #define TOOLS_RPC_API_METHOD3(Method, T1, T2, T3) \ |
| 121 virtual void Method(RpcTypeTrait<T1>::ApiType t1, \ | 140 virtual void Method(RpcTypeTrait<T1>::ApiType t1, \ |
| 122 RpcTypeTrait<T2>::ApiType t2, \ | 141 RpcTypeTrait<T2>::ApiType t2, \ |
| 123 RpcTypeTrait<T3>::ApiType t3) = 0; | 142 RpcTypeTrait<T3>::ApiType t3) = 0; |
| 124 | 143 |
| 125 #define TOOLS_RPC_API_METHOD4(Method, T1, T2, T3, T4) \ | |
| 126 virtual void Method(RpcTypeTrait<T1>::ApiType t1, \ | |
| 127 RpcTypeTrait<T2>::ApiType t2, \ | |
| 128 RpcTypeTrait<T3>::ApiType t3, \ | |
| 129 RpcTypeTrait<T4>::ApiType t4) = 0; | |
| 130 | |
| 131 /////////////////////////////////////////////////////// | 144 /////////////////////////////////////////////////////// |
| 132 // RPC stub method implementations | 145 // RPC stub method implementations |
| 133 | 146 |
| 134 #define TOOLS_RPC_STUB_METHOD0(Method) \ | 147 #define TOOLS_RPC_STUB_METHOD0(Method) \ |
| 135 virtual void Method() { \ | 148 virtual void Method() { \ |
| 136 InvokeAsync(class_name, #Method); \ | 149 this->delegate_->SendRpcMessage(class_name, #Method); \ |
| 137 } | 150 } |
| 138 | 151 |
| 139 #define TOOLS_RPC_STUB_METHOD1(Method, T1) \ | 152 #define TOOLS_RPC_STUB_METHOD1(Method, T1) \ |
| 140 virtual void Method(RpcTypeTrait<T1>::ApiType t1) { \ | 153 virtual void Method(RpcTypeTrait<T1>::ApiType t1) { \ |
| 141 InvokeAsync(class_name, #Method, &t1); \ | 154 this->delegate_->SendRpcMessage( \ |
| 155 class_name, \ |
| 156 #Method, \ |
| 157 RpcTypeTrait<T1>::ToString(t1)); \ |
| 142 } | 158 } |
| 143 | 159 |
| 144 #define TOOLS_RPC_STUB_METHOD2(Method, T1, T2) \ | 160 #define TOOLS_RPC_STUB_METHOD2(Method, T1, T2) \ |
| 145 virtual void Method(RpcTypeTrait<T1>::ApiType t1, \ | 161 virtual void Method(RpcTypeTrait<T1>::ApiType t1, \ |
| 146 RpcTypeTrait<T2>::ApiType t2) { \ | 162 RpcTypeTrait<T2>::ApiType t2) { \ |
| 147 InvokeAsync(class_name, #Method, &t1, &t2); \ | 163 this->delegate_->SendRpcMessage( \ |
| 164 class_name, \ |
| 165 #Method, \ |
| 166 RpcTypeTrait<T1>::ToString(t1), \ |
| 167 RpcTypeTrait<T2>::ToString(t2)); \ |
| 148 } | 168 } |
| 149 | 169 |
| 150 #define TOOLS_RPC_STUB_METHOD3(Method, T1, T2, T3) \ | 170 #define TOOLS_RPC_STUB_METHOD3(Method, T1, T2, T3) \ |
| 151 virtual void Method(RpcTypeTrait<T1>::ApiType t1, \ | 171 virtual void Method(RpcTypeTrait<T1>::ApiType t1, \ |
| 152 RpcTypeTrait<T2>::ApiType t2, \ | 172 RpcTypeTrait<T2>::ApiType t2, \ |
| 153 RpcTypeTrait<T3>::ApiType t3) { \ | 173 RpcTypeTrait<T3>::ApiType t3) { \ |
| 154 InvokeAsync(class_name, #Method, &t1, &t2, &t3); \ | 174 this->delegate_->SendRpcMessage( \ |
| 155 } | 175 class_name, \ |
| 156 | 176 #Method, \ |
| 157 #define TOOLS_RPC_STUB_METHOD4(Method, T1, T2, T3, T4) \ | 177 RpcTypeTrait<T1>::ToString(t1), \ |
| 158 virtual void Method(RpcTypeTrait<T1>::ApiType t1, \ | 178 RpcTypeTrait<T2>::ToString(t2), \ |
| 159 RpcTypeTrait<T2>::ApiType t2, \ | 179 RpcTypeTrait<T3>::ToString(t3)); \ |
| 160 RpcTypeTrait<T3>::ApiType t3, \ | |
| 161 RpcTypeTrait<T4>::ApiType t4) { \ | |
| 162 InvokeAsync(class_name, #Method, &t1, &t2, &t3, &t4); \ | |
| 163 } | 180 } |
| 164 | 181 |
| 165 /////////////////////////////////////////////////////// | 182 /////////////////////////////////////////////////////// |
| 166 // RPC dispatch method implementations | 183 // RPC dispatch method implementations |
| 167 | 184 |
| 168 #define TOOLS_RPC_DISPATCH0(Method) \ | 185 #define TOOLS_RPC_DISPATCH0(Method) \ |
| 169 if (method_name == #Method) { \ | 186 if (method_name == #Method) { \ |
| 170 delegate->Method(); \ | 187 delegate->Method(); \ |
| 171 return true; \ | 188 return true; \ |
| 172 } | 189 } |
| 173 | 190 |
| 174 #define TOOLS_RPC_DISPATCH1(Method, T1) \ | 191 #define TOOLS_RPC_DISPATCH1(Method, T1) \ |
| 175 if (method_name == #Method) { \ | 192 if (method_name == #Method) { \ |
| 176 RpcTypeTrait<T1>::DispatchType t1; \ | 193 delegate->Method(RpcTypeTrait<T1>::Parse(p1)); \ |
| 177 DevToolsRpc::GetListValue(message, 0, &t1); \ | |
| 178 delegate->Method( \ | |
| 179 RpcTypeTrait<T1>::Pass(t1)); \ | |
| 180 return true; \ | 194 return true; \ |
| 181 } | 195 } |
| 182 | 196 |
| 183 #define TOOLS_RPC_DISPATCH2(Method, T1, T2) \ | 197 #define TOOLS_RPC_DISPATCH2(Method, T1, T2) \ |
| 184 if (method_name == #Method) { \ | 198 if (method_name == #Method) { \ |
| 185 RpcTypeTrait<T1>::DispatchType t1; \ | |
| 186 RpcTypeTrait<T2>::DispatchType t2; \ | |
| 187 DevToolsRpc::GetListValue(message, 0, &t1); \ | |
| 188 DevToolsRpc::GetListValue(message, 1, &t2); \ | |
| 189 delegate->Method( \ | 199 delegate->Method( \ |
| 190 RpcTypeTrait<T1>::Pass(t1), \ | 200 RpcTypeTrait<T1>::Parse(p1), \ |
| 191 RpcTypeTrait<T2>::Pass(t2) \ | 201 RpcTypeTrait<T2>::Parse(p2) \ |
| 192 ); \ | 202 ); \ |
| 193 return true; \ | 203 return true; \ |
| 194 } | 204 } |
| 195 | 205 |
| 196 #define TOOLS_RPC_DISPATCH3(Method, T1, T2, T3) \ | 206 #define TOOLS_RPC_DISPATCH3(Method, T1, T2, T3) \ |
| 197 if (method_name == #Method) { \ | 207 if (method_name == #Method) { \ |
| 198 RpcTypeTrait<T1>::DispatchType t1; \ | |
| 199 RpcTypeTrait<T2>::DispatchType t2; \ | |
| 200 RpcTypeTrait<T3>::DispatchType t3; \ | |
| 201 DevToolsRpc::GetListValue(message, 0, &t1); \ | |
| 202 DevToolsRpc::GetListValue(message, 1, &t2); \ | |
| 203 DevToolsRpc::GetListValue(message, 2, &t3); \ | |
| 204 delegate->Method( \ | 208 delegate->Method( \ |
| 205 RpcTypeTrait<T1>::Pass(t1), \ | 209 RpcTypeTrait<T1>::Parse(p1), \ |
| 206 RpcTypeTrait<T2>::Pass(t2), \ | 210 RpcTypeTrait<T2>::Parse(p2), \ |
| 207 RpcTypeTrait<T3>::Pass(t3) \ | 211 RpcTypeTrait<T3>::Parse(p3) \ |
| 208 ); \ | |
| 209 return true; \ | |
| 210 } | |
| 211 | |
| 212 #define TOOLS_RPC_DISPATCH4(Method, T1, T2, T3, T4) \ | |
| 213 if (method_name == #Method) { \ | |
| 214 RpcTypeTrait<T1>::DispatchType t1; \ | |
| 215 RpcTypeTrait<T2>::DispatchType t2; \ | |
| 216 RpcTypeTrait<T3>::DispatchType t3; \ | |
| 217 RpcTypeTrait<T4>::DispatchType t4; \ | |
| 218 DevToolsRpc::GetListValue(message, 0, &t1); \ | |
| 219 DevToolsRpc::GetListValue(message, 1, &t2); \ | |
| 220 DevToolsRpc::GetListValue(message, 2, &t3); \ | |
| 221 DevToolsRpc::GetListValue(message, 3, &t4); \ | |
| 222 delegate->Method( \ | |
| 223 RpcTypeTrait<T1>::Pass(t1), \ | |
| 224 RpcTypeTrait<T2>::Pass(t2), \ | |
| 225 RpcTypeTrait<T3>::Pass(t3), \ | |
| 226 RpcTypeTrait<T4>::Pass(t4) \ | |
| 227 ); \ | 212 ); \ |
| 228 return true; \ | 213 return true; \ |
| 229 } | 214 } |
| 230 | 215 |
| 231 #define TOOLS_END_RPC_DISPATCH() \ | 216 #define TOOLS_END_RPC_DISPATCH() \ |
| 232 } | 217 } |
| 233 | 218 |
| 234 // This macro defines three classes: Class with the Api, ClassStub that is | 219 // This macro defines three classes: Class with the Api, ClassStub that is |
| 235 // serializing method calls and ClassDispatch that is capable of dispatching | 220 // serializing method calls and ClassDispatch that is capable of dispatching |
| 236 // the serialized message into its delegate. | 221 // the serialized message into its delegate. |
| 237 #define DEFINE_RPC_CLASS(Class, STRUCT) \ | 222 #define DEFINE_RPC_CLASS(Class, STRUCT) \ |
| 238 class Class {\ | 223 class Class {\ |
| 239 public: \ | 224 public: \ |
| 240 Class() { \ | 225 Class() { \ |
| 241 class_name = #Class; \ | 226 class_name = #Class; \ |
| 242 } \ | 227 } \ |
| 243 ~Class() {} \ | 228 ~Class() {} \ |
| 244 \ | 229 \ |
| 245 STRUCT( \ | 230 STRUCT( \ |
| 246 TOOLS_RPC_API_METHOD0, \ | 231 TOOLS_RPC_API_METHOD0, \ |
| 247 TOOLS_RPC_API_METHOD1, \ | 232 TOOLS_RPC_API_METHOD1, \ |
| 248 TOOLS_RPC_API_METHOD2, \ | 233 TOOLS_RPC_API_METHOD2, \ |
| 249 TOOLS_RPC_API_METHOD3, \ | 234 TOOLS_RPC_API_METHOD3) \ |
| 250 TOOLS_RPC_API_METHOD4) \ | |
| 251 std::string class_name; \ | 235 std::string class_name; \ |
| 252 private: \ | 236 private: \ |
| 253 DISALLOW_COPY_AND_ASSIGN(Class); \ | 237 DISALLOW_COPY_AND_ASSIGN(Class); \ |
| 254 }; \ | 238 }; \ |
| 255 \ | 239 \ |
| 256 class Class##Stub : public Class, public DevToolsRpc { \ | 240 class Class##Stub : public Class, public DevToolsRpc { \ |
| 257 public: \ | 241 public: \ |
| 258 explicit Class##Stub(Delegate* delegate) : DevToolsRpc(delegate) {} \ | 242 explicit Class##Stub(Delegate* delegate) : DevToolsRpc(delegate) {} \ |
| 259 virtual ~Class##Stub() {} \ | 243 virtual ~Class##Stub() {} \ |
| 260 typedef Class CLASS; \ | 244 typedef Class CLASS; \ |
| 261 STRUCT( \ | 245 STRUCT( \ |
| 262 TOOLS_RPC_STUB_METHOD0, \ | 246 TOOLS_RPC_STUB_METHOD0, \ |
| 263 TOOLS_RPC_STUB_METHOD1, \ | 247 TOOLS_RPC_STUB_METHOD1, \ |
| 264 TOOLS_RPC_STUB_METHOD2, \ | 248 TOOLS_RPC_STUB_METHOD2, \ |
| 265 TOOLS_RPC_STUB_METHOD3, \ | 249 TOOLS_RPC_STUB_METHOD3) \ |
| 266 TOOLS_RPC_STUB_METHOD4) \ | |
| 267 private: \ | 250 private: \ |
| 268 DISALLOW_COPY_AND_ASSIGN(Class##Stub); \ | 251 DISALLOW_COPY_AND_ASSIGN(Class##Stub); \ |
| 269 }; \ | 252 }; \ |
| 270 \ | 253 \ |
| 271 class Class##Dispatch { \ | 254 class Class##Dispatch { \ |
| 272 public: \ | 255 public: \ |
| 273 Class##Dispatch() {} \ | 256 Class##Dispatch() {} \ |
| 274 virtual ~Class##Dispatch() {} \ | 257 virtual ~Class##Dispatch() {} \ |
| 275 \ | 258 \ |
| 276 static bool Dispatch(Class* delegate, \ | 259 static bool Dispatch(Class* delegate, \ |
| 277 const std::string& class_name, \ | 260 const std::string& class_name, \ |
| 278 const std::string& method_name, \ | 261 const std::string& method_name, \ |
| 279 const std::string& raw_msg) { \ | 262 const std::string& p1, \ |
| 280 OwnPtr<ListValue> message( \ | 263 const std::string& p2, \ |
| 281 static_cast<ListValue*>(DevToolsRpc::ParseMessage(raw_msg))); \ | 264 const std::string& p3) { \ |
| 282 return Dispatch(delegate, class_name, method_name, *message.get()); \ | |
| 283 } \ | |
| 284 \ | |
| 285 static bool Dispatch(Class* delegate, \ | |
| 286 const std::string& class_name, \ | |
| 287 const std::string& method_name, \ | |
| 288 const ListValue& message) { \ | |
| 289 if (class_name != #Class) { \ | 265 if (class_name != #Class) { \ |
| 290 return false; \ | 266 return false; \ |
| 291 } \ | 267 } \ |
| 292 typedef Class CLASS; \ | 268 typedef Class CLASS; \ |
| 293 STRUCT( \ | 269 STRUCT( \ |
| 294 TOOLS_RPC_DISPATCH0, \ | 270 TOOLS_RPC_DISPATCH0, \ |
| 295 TOOLS_RPC_DISPATCH1, \ | 271 TOOLS_RPC_DISPATCH1, \ |
| 296 TOOLS_RPC_DISPATCH2, \ | 272 TOOLS_RPC_DISPATCH2, \ |
| 297 TOOLS_RPC_DISPATCH3, \ | 273 TOOLS_RPC_DISPATCH3) \ |
| 298 TOOLS_RPC_DISPATCH4) \ | |
| 299 return false; \ | 274 return false; \ |
| 300 } \ | 275 } \ |
| 301 private: \ | 276 private: \ |
| 302 DISALLOW_COPY_AND_ASSIGN(Class##Dispatch); \ | 277 DISALLOW_COPY_AND_ASSIGN(Class##Dispatch); \ |
| 303 }; | 278 }; |
| 304 | 279 |
| 305 /////////////////////////////////////////////////////// | 280 /////////////////////////////////////////////////////// |
| 306 // RPC base class | 281 // RPC base class |
| 307 class DevToolsRpc { | 282 class DevToolsRpc { |
| 308 public: | 283 public: |
| 309 class Delegate { | 284 class Delegate { |
| 310 public: | 285 public: |
| 311 Delegate() {} | 286 Delegate() {} |
| 312 virtual ~Delegate() {} | 287 virtual ~Delegate() {} |
| 313 virtual void SendRpcMessage(const std::string& class_name, | 288 virtual void SendRpcMessage(const std::string& class_name, |
| 314 const std::string& method_name, | 289 const std::string& method_name, |
| 315 const std::string& raw_msg) = 0; | 290 const std::string& p1 = "", |
| 291 const std::string& p2 = "", |
| 292 const std::string& p3 = "") = 0; |
| 316 private: | 293 private: |
| 317 DISALLOW_COPY_AND_ASSIGN(Delegate); | 294 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 318 }; | 295 }; |
| 319 | 296 |
| 320 explicit DevToolsRpc(Delegate* delegate); | 297 explicit DevToolsRpc(Delegate* delegate) |
| 321 virtual ~DevToolsRpc(); | 298 : delegate_(delegate) {} |
| 322 | 299 virtual ~DevToolsRpc() {}; |
| 323 void InvokeAsync( | |
| 324 const std::string& class_name, | |
| 325 const std::string& method_name) { | |
| 326 ListValue message; | |
| 327 SendValueMessage(class_name, method_name, message); | |
| 328 } | |
| 329 | |
| 330 template<typename T1> | |
| 331 void InvokeAsync( | |
| 332 const std::string& class_name, | |
| 333 const std::string& method_name, | |
| 334 T1 t1) { | |
| 335 ListValue message; | |
| 336 message.Append(CreateValue(t1)); | |
| 337 SendValueMessage(class_name, method_name, message); | |
| 338 } | |
| 339 | |
| 340 template<typename T1, typename T2> | |
| 341 void InvokeAsync( | |
| 342 const std::string& class_name, | |
| 343 const std::string& method_name, | |
| 344 T1 t1, T2 t2) { | |
| 345 ListValue message; | |
| 346 message.Append(CreateValue(t1)); | |
| 347 message.Append(CreateValue(t2)); | |
| 348 SendValueMessage(class_name, method_name, message); | |
| 349 } | |
| 350 | |
| 351 template<typename T1, typename T2, typename T3> | |
| 352 void InvokeAsync( | |
| 353 const std::string& class_name, | |
| 354 const std::string& method_name, | |
| 355 T1 t1, T2 t2, T3 t3) { | |
| 356 ListValue message; | |
| 357 message.Append(CreateValue(t1)); | |
| 358 message.Append(CreateValue(t2)); | |
| 359 message.Append(CreateValue(t3)); | |
| 360 SendValueMessage(class_name, method_name, message); | |
| 361 } | |
| 362 | |
| 363 template<typename T1, typename T2, typename T3, typename T4> | |
| 364 void InvokeAsync( | |
| 365 const std::string& class_name, | |
| 366 const std::string& method_name, | |
| 367 T1 t1, T2 t2, T3 t3, T4 t4) { | |
| 368 ListValue message; | |
| 369 message.Append(CreateValue(t1)); | |
| 370 message.Append(CreateValue(t2)); | |
| 371 message.Append(CreateValue(t3)); | |
| 372 message.Append(CreateValue(t4)); | |
| 373 SendValueMessage(class_name, method_name, message); | |
| 374 } | |
| 375 | |
| 376 static Value* ParseMessage(const std::string& raw_msg); | |
| 377 static std::string Serialize(const Value& value); | |
| 378 static void GetListValue(const ListValue& message, int index, bool* value); | |
| 379 static void GetListValue(const ListValue& message, int index, int* value); | |
| 380 static void GetListValue( | |
| 381 const ListValue& message, | |
| 382 int index, | |
| 383 String* value); | |
| 384 static void GetListValue( | |
| 385 const ListValue& message, | |
| 386 int index, | |
| 387 std::string* value); | |
| 388 static void GetListValue(const ListValue& message, int index, Value** value); | |
| 389 | 300 |
| 390 protected: | 301 protected: |
| 391 // Primarily for unit testing. | 302 Delegate* delegate_; |
| 392 void set_delegate(Delegate* delegate) { this->delegate_ = delegate; } | |
| 393 | |
| 394 private: | 303 private: |
| 395 // Value adapters for supported Rpc types. | |
| 396 static Value* CreateValue(const String* value); | |
| 397 static Value* CreateValue(const std::string* value); | |
| 398 static Value* CreateValue(int* value); | |
| 399 static Value* CreateValue(bool* value); | |
| 400 static Value* CreateValue(const Value* value); | |
| 401 | |
| 402 void SendValueMessage(const std::string& class_name, | |
| 403 const std::string& method_name, | |
| 404 const Value& value); | |
| 405 | |
| 406 Delegate* delegate_; | |
| 407 DISALLOW_COPY_AND_ASSIGN(DevToolsRpc); | 304 DISALLOW_COPY_AND_ASSIGN(DevToolsRpc); |
| 408 }; | 305 }; |
| 409 | 306 |
| 410 #endif // WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_H_ | 307 #endif // WEBKIT_GLUE_DEVTOOLS_DEVTOOLS_RPC_H_ |
| OLD | NEW |