| Index: webkit/glue/devtools/devtools_rpc.h
|
| ===================================================================
|
| --- webkit/glue/devtools/devtools_rpc.h (revision 24604)
|
| +++ webkit/glue/devtools/devtools_rpc.h (working copy)
|
| @@ -6,9 +6,8 @@
|
| // implementation. The client is responsible for defining the Rpc-enabled
|
| // interface in terms of its macros:
|
| //
|
| -// #define MYAPI_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3, METHOD4)
|
| +// #define MYAPI_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3)
|
| // METHOD0(Method1)
|
| -// METHOD3(Method2, int, String, Value)
|
| // METHOD1(Method3, int)
|
| // (snippet above should be multiline macro, add trailing backslashes)
|
| //
|
| @@ -53,11 +52,12 @@
|
|
|
| #include <string>
|
|
|
| +// Do not remove this one although it is not used.
|
| #include <wtf/OwnPtr.h>
|
|
|
| #include "base/basictypes.h"
|
| -#include "base/logging.h"
|
| -#include "base/values.h"
|
| +#include "base/string_util.h"
|
| +#include "webkit/glue/glue_util.h"
|
|
|
| namespace WebCore {
|
| class String;
|
| @@ -71,37 +71,56 @@
|
| template<typename T>
|
| struct RpcTypeTrait {
|
| typedef T ApiType;
|
| - typedef T DispatchType;
|
| - static const DispatchType& Pass(const DispatchType& t) {
|
| - return t;
|
| +};
|
| +
|
| +template<>
|
| +struct RpcTypeTrait<bool> {
|
| + typedef bool ApiType;
|
| + static bool Parse(const std::string& t) {
|
| + int i;
|
| + bool success = StringToInt(t, &i);
|
| + ASSERT(success);
|
| + return i;
|
| }
|
| + static std::string ToString(bool b) {
|
| + return IntToString(b ? 1 : 0);
|
| + }
|
| };
|
|
|
| template<>
|
| -struct RpcTypeTrait<Value> {
|
| - typedef const Value& ApiType;
|
| - typedef Value* DispatchType;
|
| - static const Value& Pass(Value* t) {
|
| - return *t;
|
| +struct RpcTypeTrait<int> {
|
| + typedef int ApiType;
|
| + static int Parse(const std::string& t) {
|
| + int i;
|
| + bool success = StringToInt(t, &i);
|
| + ASSERT(success);
|
| + return i;
|
| }
|
| + static std::string ToString(int i) {
|
| + return IntToString(i);
|
| + }
|
| };
|
|
|
| template<>
|
| struct RpcTypeTrait<String> {
|
| typedef const String& ApiType;
|
| - typedef String DispatchType;
|
| - static const DispatchType& Pass(const DispatchType& t) {
|
| - return t;
|
| + static String Parse(const std::string& t) {
|
| + return webkit_glue::StdStringToString(t);
|
| }
|
| + static std::string ToString(const String& t) {
|
| + return webkit_glue::StringToStdString(t);
|
| + }
|
| };
|
|
|
| template<>
|
| struct RpcTypeTrait<std::string> {
|
| typedef const std::string& ApiType;
|
| - typedef std::string DispatchType;
|
| - static const DispatchType& Pass(const DispatchType& t) {
|
| - return t;
|
| + static std::string Parse(const std::string& s) {
|
| + return s;
|
| }
|
| + static std::string ToString(const std::string& s) {
|
| + return s;
|
| + }
|
| };
|
|
|
| ///////////////////////////////////////////////////////
|
| @@ -122,46 +141,44 @@
|
| RpcTypeTrait<T2>::ApiType t2, \
|
| RpcTypeTrait<T3>::ApiType t3) = 0;
|
|
|
| -#define TOOLS_RPC_API_METHOD4(Method, T1, T2, T3, T4) \
|
| - virtual void Method(RpcTypeTrait<T1>::ApiType t1, \
|
| - RpcTypeTrait<T2>::ApiType t2, \
|
| - RpcTypeTrait<T3>::ApiType t3, \
|
| - RpcTypeTrait<T4>::ApiType t4) = 0;
|
| -
|
| ///////////////////////////////////////////////////////
|
| // RPC stub method implementations
|
|
|
| #define TOOLS_RPC_STUB_METHOD0(Method) \
|
| virtual void Method() { \
|
| - InvokeAsync(class_name, #Method); \
|
| + this->delegate_->SendRpcMessage(class_name, #Method); \
|
| }
|
|
|
| #define TOOLS_RPC_STUB_METHOD1(Method, T1) \
|
| virtual void Method(RpcTypeTrait<T1>::ApiType t1) { \
|
| - InvokeAsync(class_name, #Method, &t1); \
|
| + this->delegate_->SendRpcMessage( \
|
| + class_name, \
|
| + #Method, \
|
| + RpcTypeTrait<T1>::ToString(t1)); \
|
| }
|
|
|
| #define TOOLS_RPC_STUB_METHOD2(Method, T1, T2) \
|
| virtual void Method(RpcTypeTrait<T1>::ApiType t1, \
|
| RpcTypeTrait<T2>::ApiType t2) { \
|
| - InvokeAsync(class_name, #Method, &t1, &t2); \
|
| + this->delegate_->SendRpcMessage( \
|
| + class_name, \
|
| + #Method, \
|
| + RpcTypeTrait<T1>::ToString(t1), \
|
| + RpcTypeTrait<T2>::ToString(t2)); \
|
| }
|
|
|
| #define TOOLS_RPC_STUB_METHOD3(Method, T1, T2, T3) \
|
| virtual void Method(RpcTypeTrait<T1>::ApiType t1, \
|
| RpcTypeTrait<T2>::ApiType t2, \
|
| RpcTypeTrait<T3>::ApiType t3) { \
|
| - InvokeAsync(class_name, #Method, &t1, &t2, &t3); \
|
| + this->delegate_->SendRpcMessage( \
|
| + class_name, \
|
| + #Method, \
|
| + RpcTypeTrait<T1>::ToString(t1), \
|
| + RpcTypeTrait<T2>::ToString(t2), \
|
| + RpcTypeTrait<T3>::ToString(t3)); \
|
| }
|
|
|
| -#define TOOLS_RPC_STUB_METHOD4(Method, T1, T2, T3, T4) \
|
| - virtual void Method(RpcTypeTrait<T1>::ApiType t1, \
|
| - RpcTypeTrait<T2>::ApiType t2, \
|
| - RpcTypeTrait<T3>::ApiType t3, \
|
| - RpcTypeTrait<T4>::ApiType t4) { \
|
| - InvokeAsync(class_name, #Method, &t1, &t2, &t3, &t4); \
|
| - }
|
| -
|
| ///////////////////////////////////////////////////////
|
| // RPC dispatch method implementations
|
|
|
| @@ -173,61 +190,29 @@
|
|
|
| #define TOOLS_RPC_DISPATCH1(Method, T1) \
|
| if (method_name == #Method) { \
|
| - RpcTypeTrait<T1>::DispatchType t1; \
|
| - DevToolsRpc::GetListValue(message, 0, &t1); \
|
| - delegate->Method( \
|
| - RpcTypeTrait<T1>::Pass(t1)); \
|
| + delegate->Method(RpcTypeTrait<T1>::Parse(p1)); \
|
| return true; \
|
| }
|
|
|
| #define TOOLS_RPC_DISPATCH2(Method, T1, T2) \
|
| if (method_name == #Method) { \
|
| - RpcTypeTrait<T1>::DispatchType t1; \
|
| - RpcTypeTrait<T2>::DispatchType t2; \
|
| - DevToolsRpc::GetListValue(message, 0, &t1); \
|
| - DevToolsRpc::GetListValue(message, 1, &t2); \
|
| delegate->Method( \
|
| - RpcTypeTrait<T1>::Pass(t1), \
|
| - RpcTypeTrait<T2>::Pass(t2) \
|
| + RpcTypeTrait<T1>::Parse(p1), \
|
| + RpcTypeTrait<T2>::Parse(p2) \
|
| ); \
|
| return true; \
|
| }
|
|
|
| #define TOOLS_RPC_DISPATCH3(Method, T1, T2, T3) \
|
| if (method_name == #Method) { \
|
| - RpcTypeTrait<T1>::DispatchType t1; \
|
| - RpcTypeTrait<T2>::DispatchType t2; \
|
| - RpcTypeTrait<T3>::DispatchType t3; \
|
| - DevToolsRpc::GetListValue(message, 0, &t1); \
|
| - DevToolsRpc::GetListValue(message, 1, &t2); \
|
| - DevToolsRpc::GetListValue(message, 2, &t3); \
|
| delegate->Method( \
|
| - RpcTypeTrait<T1>::Pass(t1), \
|
| - RpcTypeTrait<T2>::Pass(t2), \
|
| - RpcTypeTrait<T3>::Pass(t3) \
|
| + RpcTypeTrait<T1>::Parse(p1), \
|
| + RpcTypeTrait<T2>::Parse(p2), \
|
| + RpcTypeTrait<T3>::Parse(p3) \
|
| ); \
|
| return true; \
|
| }
|
|
|
| -#define TOOLS_RPC_DISPATCH4(Method, T1, T2, T3, T4) \
|
| -if (method_name == #Method) { \
|
| - RpcTypeTrait<T1>::DispatchType t1; \
|
| - RpcTypeTrait<T2>::DispatchType t2; \
|
| - RpcTypeTrait<T3>::DispatchType t3; \
|
| - RpcTypeTrait<T4>::DispatchType t4; \
|
| - DevToolsRpc::GetListValue(message, 0, &t1); \
|
| - DevToolsRpc::GetListValue(message, 1, &t2); \
|
| - DevToolsRpc::GetListValue(message, 2, &t3); \
|
| - DevToolsRpc::GetListValue(message, 3, &t4); \
|
| - delegate->Method( \
|
| - RpcTypeTrait<T1>::Pass(t1), \
|
| - RpcTypeTrait<T2>::Pass(t2), \
|
| - RpcTypeTrait<T3>::Pass(t3), \
|
| - RpcTypeTrait<T4>::Pass(t4) \
|
| - ); \
|
| - return true; \
|
| -}
|
| -
|
| #define TOOLS_END_RPC_DISPATCH() \
|
| }
|
|
|
| @@ -246,8 +231,7 @@
|
| TOOLS_RPC_API_METHOD0, \
|
| TOOLS_RPC_API_METHOD1, \
|
| TOOLS_RPC_API_METHOD2, \
|
| - TOOLS_RPC_API_METHOD3, \
|
| - TOOLS_RPC_API_METHOD4) \
|
| + TOOLS_RPC_API_METHOD3) \
|
| std::string class_name; \
|
| private: \
|
| DISALLOW_COPY_AND_ASSIGN(Class); \
|
| @@ -262,8 +246,7 @@
|
| TOOLS_RPC_STUB_METHOD0, \
|
| TOOLS_RPC_STUB_METHOD1, \
|
| TOOLS_RPC_STUB_METHOD2, \
|
| - TOOLS_RPC_STUB_METHOD3, \
|
| - TOOLS_RPC_STUB_METHOD4) \
|
| + TOOLS_RPC_STUB_METHOD3) \
|
| private: \
|
| DISALLOW_COPY_AND_ASSIGN(Class##Stub); \
|
| }; \
|
| @@ -276,16 +259,9 @@
|
| static bool Dispatch(Class* delegate, \
|
| const std::string& class_name, \
|
| const std::string& method_name, \
|
| - const std::string& raw_msg) { \
|
| - OwnPtr<ListValue> message( \
|
| - static_cast<ListValue*>(DevToolsRpc::ParseMessage(raw_msg))); \
|
| - return Dispatch(delegate, class_name, method_name, *message.get()); \
|
| - } \
|
| - \
|
| - static bool Dispatch(Class* delegate, \
|
| - const std::string& class_name, \
|
| - const std::string& method_name, \
|
| - const ListValue& message) { \
|
| + const std::string& p1, \
|
| + const std::string& p2, \
|
| + const std::string& p3) { \
|
| if (class_name != #Class) { \
|
| return false; \
|
| } \
|
| @@ -294,8 +270,7 @@
|
| TOOLS_RPC_DISPATCH0, \
|
| TOOLS_RPC_DISPATCH1, \
|
| TOOLS_RPC_DISPATCH2, \
|
| - TOOLS_RPC_DISPATCH3, \
|
| - TOOLS_RPC_DISPATCH4) \
|
| + TOOLS_RPC_DISPATCH3) \
|
| return false; \
|
| } \
|
| private: \
|
| @@ -312,98 +287,20 @@
|
| virtual ~Delegate() {}
|
| virtual void SendRpcMessage(const std::string& class_name,
|
| const std::string& method_name,
|
| - const std::string& raw_msg) = 0;
|
| + const std::string& p1 = "",
|
| + const std::string& p2 = "",
|
| + const std::string& p3 = "") = 0;
|
| private:
|
| DISALLOW_COPY_AND_ASSIGN(Delegate);
|
| };
|
|
|
| - explicit DevToolsRpc(Delegate* delegate);
|
| - virtual ~DevToolsRpc();
|
| + explicit DevToolsRpc(Delegate* delegate)
|
| + : delegate_(delegate) {}
|
| + virtual ~DevToolsRpc() {};
|
|
|
| - void InvokeAsync(
|
| - const std::string& class_name,
|
| - const std::string& method_name) {
|
| - ListValue message;
|
| - SendValueMessage(class_name, method_name, message);
|
| - }
|
| -
|
| - template<typename T1>
|
| - void InvokeAsync(
|
| - const std::string& class_name,
|
| - const std::string& method_name,
|
| - T1 t1) {
|
| - ListValue message;
|
| - message.Append(CreateValue(t1));
|
| - SendValueMessage(class_name, method_name, message);
|
| - }
|
| -
|
| - template<typename T1, typename T2>
|
| - void InvokeAsync(
|
| - const std::string& class_name,
|
| - const std::string& method_name,
|
| - T1 t1, T2 t2) {
|
| - ListValue message;
|
| - message.Append(CreateValue(t1));
|
| - message.Append(CreateValue(t2));
|
| - SendValueMessage(class_name, method_name, message);
|
| - }
|
| -
|
| - template<typename T1, typename T2, typename T3>
|
| - void InvokeAsync(
|
| - const std::string& class_name,
|
| - const std::string& method_name,
|
| - T1 t1, T2 t2, T3 t3) {
|
| - ListValue message;
|
| - message.Append(CreateValue(t1));
|
| - message.Append(CreateValue(t2));
|
| - message.Append(CreateValue(t3));
|
| - SendValueMessage(class_name, method_name, message);
|
| - }
|
| -
|
| - template<typename T1, typename T2, typename T3, typename T4>
|
| - void InvokeAsync(
|
| - const std::string& class_name,
|
| - const std::string& method_name,
|
| - T1 t1, T2 t2, T3 t3, T4 t4) {
|
| - ListValue message;
|
| - message.Append(CreateValue(t1));
|
| - message.Append(CreateValue(t2));
|
| - message.Append(CreateValue(t3));
|
| - message.Append(CreateValue(t4));
|
| - SendValueMessage(class_name, method_name, message);
|
| - }
|
| -
|
| - static Value* ParseMessage(const std::string& raw_msg);
|
| - static std::string Serialize(const Value& value);
|
| - static void GetListValue(const ListValue& message, int index, bool* value);
|
| - static void GetListValue(const ListValue& message, int index, int* value);
|
| - static void GetListValue(
|
| - const ListValue& message,
|
| - int index,
|
| - String* value);
|
| - static void GetListValue(
|
| - const ListValue& message,
|
| - int index,
|
| - std::string* value);
|
| - static void GetListValue(const ListValue& message, int index, Value** value);
|
| -
|
| protected:
|
| - // Primarily for unit testing.
|
| - void set_delegate(Delegate* delegate) { this->delegate_ = delegate; }
|
| -
|
| - private:
|
| - // Value adapters for supported Rpc types.
|
| - static Value* CreateValue(const String* value);
|
| - static Value* CreateValue(const std::string* value);
|
| - static Value* CreateValue(int* value);
|
| - static Value* CreateValue(bool* value);
|
| - static Value* CreateValue(const Value* value);
|
| -
|
| - void SendValueMessage(const std::string& class_name,
|
| - const std::string& method_name,
|
| - const Value& value);
|
| -
|
| Delegate* delegate_;
|
| + private:
|
| DISALLOW_COPY_AND_ASSIGN(DevToolsRpc);
|
| };
|
|
|
|
|