Index: ipc/ipc_message_macros.h |
=================================================================== |
--- ipc/ipc_message_macros.h (revision 98434) |
+++ ipc/ipc_message_macros.h (working copy) |
@@ -194,6 +194,11 @@ |
#define IPC_STRUCT_MEMBER(type, name) type name; |
#define IPC_STRUCT_END() }; |
+// Override this to force message classes to be exported. |
+#ifndef IPC_MESSAGE_EXPORT |
+#define IPC_MESSAGE_EXPORT |
+#endif |
+ |
// Message macros collect specific numbers of arguments and funnel them into |
// the common message generation macro. These should never be redefined. |
#define IPC_MESSAGE_CONTROL0(msg_class) \ |
@@ -412,6 +417,174 @@ |
#define IPC_SYNC_MESSAGE_ROUTED5_4(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out, type4_out) \ |
IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 4, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out, type3_out, type4_out)) |
+// The following macros define the common set of methods provided by ASYNC |
+// message classes. |
+#define IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
+ template<class T, class S, class Method> \ |
+ static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) { \ |
+ Schema::Param p; \ |
+ if (Read(msg, &p)) { \ |
+ DispatchToMethod(obj, func, p); \ |
+ return true; \ |
+ } \ |
+ return false; \ |
+ } |
+#define IPC_ASYNC_MESSAGE_METHODS_1 \ |
+ IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
+ template<class T, class S, typename TA> \ |
+ static bool Dispatch(const Message* msg, T* obj, S* sender, \ |
+ void (T::*func)(const Message&, TA)) { \ |
+ Schema::Param p; \ |
+ if (Read(msg, &p)) { \ |
+ (obj->*func)(*msg, p.a); \ |
+ return true; \ |
+ } \ |
+ return false; \ |
+ } |
+#define IPC_ASYNC_MESSAGE_METHODS_2 \ |
+ IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
+ template<class T, class S, typename TA, typename TB> \ |
+ static bool Dispatch(const Message* msg, T* obj, S* sender, \ |
+ void (T::*func)(const Message&, TA, TB)) { \ |
+ Schema::Param p; \ |
+ if (Read(msg, &p)) { \ |
+ (obj->*func)(*msg, p.a, p.b); \ |
+ return true; \ |
+ } \ |
+ return false; \ |
+ } \ |
+ template<typename TA, typename TB> \ |
+ static bool Read(const IPC::Message* msg, TA* a, TB* b) { \ |
+ Schema::Param p; \ |
+ if (!Read(msg, &p)) \ |
+ return false; \ |
+ *a = p.a; \ |
+ *b = p.b; \ |
+ return true; \ |
+ } |
+#define IPC_ASYNC_MESSAGE_METHODS_3 \ |
+ IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
+ template<class T, class S, typename TA, typename TB, typename TC> \ |
+ static bool Dispatch(const Message* msg, T* obj, S* sender, \ |
+ void (T::*func)(const Message&, TA, TB, TC)) { \ |
+ Schema::Param p; \ |
+ if (Read(msg, &p)) { \ |
+ (obj->*func)(*msg, p.a, p.b, p.c); \ |
+ return true; \ |
+ } \ |
+ return false; \ |
+ } \ |
+ template<typename TA, typename TB, typename TC> \ |
+ static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c) { \ |
+ Schema::Param p; \ |
+ if (!Read(msg, &p)) \ |
+ return false; \ |
+ *a = p.a; \ |
+ *b = p.b; \ |
+ *c = p.c; \ |
+ return true; \ |
+ } |
+#define IPC_ASYNC_MESSAGE_METHODS_4 \ |
+ IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
+ template<class T, class S, typename TA, typename TB, typename TC, \ |
+ typename TD> \ |
+ static bool Dispatch(const Message* msg, T* obj, S* sender, \ |
+ void (T::*func)(const Message&, TA, TB, TC, TD)) { \ |
+ Schema::Param p; \ |
+ if (Read(msg, &p)) { \ |
+ (obj->*func)(*msg, p.a, p.b, p.c, p.d); \ |
+ return true; \ |
+ } \ |
+ return false; \ |
+ } \ |
+ template<typename TA, typename TB, typename TC, typename TD> \ |
+ static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d) { \ |
+ Schema::Param p; \ |
+ if (!Read(msg, &p)) \ |
+ return false; \ |
+ *a = p.a; \ |
+ *b = p.b; \ |
+ *c = p.c; \ |
+ *d = p.d; \ |
+ return true; \ |
+ } |
+#define IPC_ASYNC_MESSAGE_METHODS_5 \ |
+ IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
+ template<class T, class S, typename TA, typename TB, typename TC, \ |
+ typename TD, typename TE> \ |
+ static bool Dispatch(const Message* msg, T* obj, S* sender, \ |
+ void (T::*func)(const Message&, TA, TB, TC, TD, TE)) { \ |
+ Schema::Param p; \ |
+ if (Read(msg, &p)) { \ |
+ (obj->*func)(*msg, p.a, p.b, p.c, p.d, p.e); \ |
+ return true; \ |
+ } \ |
+ return false; \ |
+ } \ |
+ template<typename TA, typename TB, typename TC, typename TD, typename TE> \ |
+ static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d, \ |
+ TE* e) { \ |
+ Schema::Param p; \ |
+ if (!Read(msg, &p)) \ |
+ return false; \ |
+ *a = p.a; \ |
+ *b = p.b; \ |
+ *c = p.c; \ |
+ *d = p.d; \ |
+ *e = p.e; \ |
+ return true; \ |
+ } |
+ |
+// The following macros define the common set of methods provided by SYNC |
+// message classes. |
+#define IPC_SYNC_MESSAGE_METHODS_GENERIC \ |
+ template<class T, class S, class Method> \ |
+ static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) { \ |
+ Schema::SendParam send_params; \ |
+ bool ok = ReadSendParam(msg, &send_params); \ |
+ return Schema::DispatchWithSendParams(ok, send_params, msg, obj, sender, \ |
+ func); \ |
+ } \ |
+ template<class T, class Method> \ |
+ static bool DispatchDelayReply(const Message* msg, T* obj, Method func) { \ |
+ Schema::SendParam send_params; \ |
+ bool ok = ReadSendParam(msg, &send_params); \ |
+ return Schema::DispatchDelayReplyWithSendParams(ok, send_params, msg, \ |
+ obj, func); \ |
+ } |
+#define IPC_SYNC_MESSAGE_METHODS_0 \ |
+ IPC_SYNC_MESSAGE_METHODS_GENERIC |
+#define IPC_SYNC_MESSAGE_METHODS_1 \ |
+ IPC_SYNC_MESSAGE_METHODS_GENERIC \ |
+ template<typename TA> \ |
+ static void WriteReplyParams(Message* reply, TA a) { \ |
+ Schema::WriteReplyParams(reply, a); \ |
+ } |
+#define IPC_SYNC_MESSAGE_METHODS_2 \ |
+ IPC_SYNC_MESSAGE_METHODS_GENERIC \ |
+ template<typename TA, typename TB> \ |
+ static void WriteReplyParams(Message* reply, TA a, TB b) { \ |
+ Schema::WriteReplyParams(reply, a, b); \ |
+ } |
+#define IPC_SYNC_MESSAGE_METHODS_3 \ |
+ IPC_SYNC_MESSAGE_METHODS_GENERIC \ |
+ template<typename TA, typename TB, typename TC> \ |
+ static void WriteReplyParams(Message* reply, TA a, TB b, TC c) { \ |
+ Schema::WriteReplyParams(reply, a, b, c); \ |
+ } |
+#define IPC_SYNC_MESSAGE_METHODS_4 \ |
+ IPC_SYNC_MESSAGE_METHODS_GENERIC \ |
+ template<typename TA, typename TB, typename TC, typename TD> \ |
+ static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d) { \ |
+ Schema::WriteReplyParams(reply, a, b, c, d); \ |
+ } |
+#define IPC_SYNC_MESSAGE_METHODS_5 \ |
+ IPC_SYNC_MESSAGE_METHODS_GENERIC \ |
+ template<typename TA, typename TB, typename TC, typename TD, typename TE> \ |
+ static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d, TE e) { \ |
+ Schema::WriteReplyParams(reply, a, b, c, d, e); \ |
+ } |
+ |
// Common message macro which dispatches into one of the 6 (sync x kind) |
// routines. There is a way that these 6 cases can be lumped together, |
// but the macros get very complicated in that case. |
@@ -424,6 +597,7 @@ |
#define IPC_EMPTY_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
class msg_class : public IPC::Message { \ |
public: \ |
+ typedef IPC::Message Schema; \ |
enum { ID = IPC_MESSAGE_ID() }; \ |
msg_class() : IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) {} \ |
}; |
@@ -431,50 +605,66 @@ |
#define IPC_EMPTY_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
class msg_class : public IPC::Message { \ |
public: \ |
+ typedef IPC::Message Schema; \ |
enum { ID = IPC_MESSAGE_ID() }; \ |
msg_class(int32 routing_id) \ |
: IPC::Message(routing_id, ID, PRIORITY_NORMAL) {} \ |
}; |
#define IPC_ASYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
- class msg_class : \ |
- public IPC::MessageWithTuple<IPC_TUPLE_IN_##in_cnt in_list> { \ |
+ class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \ |
public: \ |
+ typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \ |
+ typedef Schema::Param Param; \ |
enum { ID = IPC_MESSAGE_ID() }; \ |
msg_class(IPC_TYPE_IN_##in_cnt in_list); \ |
virtual ~msg_class(); \ |
+ static bool Read(const Message* msg, Schema::Param* p); \ |
static void Log(std::string* name, const Message* msg, std::string* l); \ |
+ IPC_ASYNC_MESSAGE_METHODS_##in_cnt \ |
}; |
#define IPC_ASYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
- class msg_class : \ |
- public IPC::MessageWithTuple<IPC_TUPLE_IN_##in_cnt in_list> { \ |
+ class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \ |
public: \ |
+ typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \ |
+ typedef Schema::Param Param; \ |
enum { ID = IPC_MESSAGE_ID() }; \ |
msg_class(int32 routing_id IPC_COMMA_##in_cnt \ |
IPC_TYPE_IN_##in_cnt in_list); \ |
virtual ~msg_class(); \ |
+ static bool Read(const Message* msg, Schema::Param* p); \ |
static void Log(std::string* name, const Message* msg, std::string* l); \ |
+ IPC_ASYNC_MESSAGE_METHODS_##in_cnt \ |
}; |
#define IPC_SYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
- class msg_class : \ |
- public IPC::MessageWithReply<IPC_TUPLE_IN_##in_cnt in_list, \ |
- IPC_TUPLE_OUT_##out_cnt out_list> { \ |
+ class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \ |
public: \ |
+ typedef IPC::SyncMessageSchema<IPC_TUPLE_IN_##in_cnt in_list, \ |
+ IPC_TUPLE_OUT_##out_cnt out_list> Schema; \ |
+ typedef Schema::ReplyParam ReplyParam; \ |
+ typedef Schema::SendParam SendParam; \ |
enum { ID = IPC_MESSAGE_ID() }; \ |
msg_class(IPC_TYPE_IN_##in_cnt in_list \ |
IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \ |
IPC_TYPE_OUT_##out_cnt out_list); \ |
virtual ~msg_class(); \ |
+ static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \ |
+ static bool ReadReplyParam( \ |
+ const Message* msg, \ |
+ TupleTypes<ReplyParam>::ValueTuple* p); \ |
static void Log(std::string* name, const Message* msg, std::string* l); \ |
+ IPC_SYNC_MESSAGE_METHODS_##out_cnt \ |
}; |
#define IPC_SYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
- class msg_class : \ |
- public IPC::MessageWithReply<IPC_TUPLE_IN_##in_cnt in_list, \ |
- IPC_TUPLE_OUT_##out_cnt out_list> { \ |
+ class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \ |
public: \ |
+ typedef IPC::SyncMessageSchema<IPC_TUPLE_IN_##in_cnt in_list, \ |
+ IPC_TUPLE_OUT_##out_cnt out_list> Schema; \ |
+ typedef Schema::ReplyParam ReplyParam; \ |
+ typedef Schema::SendParam SendParam; \ |
enum { ID = IPC_MESSAGE_ID() }; \ |
msg_class(int32 routing_id \ |
IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \ |
@@ -482,7 +672,12 @@ |
IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \ |
IPC_TYPE_OUT_##out_cnt out_list); \ |
virtual ~msg_class(); \ |
+ static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \ |
+ static bool ReadReplyParam( \ |
+ const Message* msg, \ |
+ TupleTypes<ReplyParam>::ValueTuple* p); \ |
static void Log(std::string* name, const Message* msg, std::string* l); \ |
+ IPC_SYNC_MESSAGE_METHODS_##out_cnt \ |
}; |
#if defined(IPC_MESSAGE_IMPL) |
@@ -501,30 +696,42 @@ |
#define IPC_ASYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list) : \ |
- IPC::MessageWithTuple<IPC_TUPLE_IN_##in_cnt in_list> \ |
- (MSG_ROUTING_CONTROL, ID, IPC_NAME_IN_##in_cnt in_list) \ |
- {} \ |
- msg_class::~msg_class() {} |
+ IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) { \ |
+ Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \ |
+ } \ |
+ msg_class::~msg_class() {} \ |
+ bool msg_class::Read(const Message* msg, Schema::Param* p) { \ |
+ return Schema::Read(msg, p); \ |
+ } |
#define IPC_ASYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
msg_class::msg_class(int32 routing_id IPC_COMMA_##in_cnt \ |
IPC_TYPE_IN_##in_cnt in_list) : \ |
- IPC::MessageWithTuple<IPC_TUPLE_IN_##in_cnt in_list> \ |
- (routing_id, ID, IPC_NAME_IN_##in_cnt in_list) \ |
- {} \ |
- msg_class::~msg_class() {} |
+ IPC::Message(routing_id, ID, PRIORITY_NORMAL) { \ |
+ Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \ |
+ } \ |
+ msg_class::~msg_class() {} \ |
+ bool msg_class::Read(const Message* msg, Schema::Param* p) { \ |
+ return Schema::Read(msg, p); \ |
+ } |
#define IPC_SYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list \ |
IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \ |
IPC_TYPE_OUT_##out_cnt out_list) : \ |
- IPC::MessageWithReply<IPC_TUPLE_IN_##in_cnt in_list, \ |
- IPC_TUPLE_OUT_##out_cnt out_list> \ |
- (MSG_ROUTING_CONTROL, ID, \ |
- IPC_NAME_IN_##in_cnt in_list, \ |
- IPC_NAME_OUT_##out_cnt out_list) \ |
- {} \ |
- msg_class::~msg_class() {} |
+ IPC::SyncMessage(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL, \ |
+ new IPC::ParamDeserializer<Schema::ReplyParam>( \ |
+ IPC_NAME_OUT_##out_cnt out_list)) { \ |
+ Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \ |
+ } \ |
+ msg_class::~msg_class() {} \ |
+ bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \ |
+ return Schema::ReadSendParam(msg, p); \ |
+ } \ |
+ bool msg_class::ReadReplyParam(const Message* msg, \ |
+ TupleTypes<ReplyParam>::ValueTuple* p) { \ |
+ return Schema::ReadReplyParam(msg, p); \ |
+ } |
#define IPC_SYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
msg_class::msg_class(int32 routing_id \ |
@@ -532,13 +739,19 @@ |
IPC_TYPE_IN_##in_cnt in_list \ |
IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \ |
IPC_TYPE_OUT_##out_cnt out_list) : \ |
- IPC::MessageWithReply<IPC_TUPLE_IN_##in_cnt in_list, \ |
- IPC_TUPLE_OUT_##out_cnt out_list> \ |
- (routing_id, ID, \ |
- IPC_NAME_IN_##in_cnt in_list, \ |
- IPC_NAME_OUT_##out_cnt out_list) \ |
- {} \ |
- msg_class::~msg_class() {} |
+ IPC::SyncMessage(routing_id, ID, PRIORITY_NORMAL, \ |
+ new IPC::ParamDeserializer<Schema::ReplyParam>( \ |
+ IPC_NAME_OUT_##out_cnt out_list)) { \ |
+ Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \ |
+ } \ |
+ msg_class::~msg_class() {} \ |
+ bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \ |
+ return Schema::ReadSendParam(msg, p); \ |
+ } \ |
+ bool msg_class::ReadReplyParam(const Message* msg, \ |
+ TupleTypes<ReplyParam>::ValueTuple* p) { \ |
+ return Schema::ReadReplyParam(msg, p); \ |
+ } |
#define IPC_EMPTY_MESSAGE_LOG(msg_class) |
@@ -550,8 +763,8 @@ |
*name = #msg_class; \ |
if (!msg || !l) \ |
return; \ |
- Param p; \ |
- if (Read(msg, &p)) \ |
+ Schema::Param p; \ |
+ if (Schema::Read(msg, &p)) \ |
IPC::LogParam(p, l); \ |
} |
@@ -564,13 +777,13 @@ |
if (!msg || !l) \ |
return; \ |
if (msg->is_sync()) { \ |
- TupleTypes<SendParam>::ValueTuple p; \ |
- if (ReadSendParam(msg, &p)) \ |
+ TupleTypes<Schema::SendParam>::ValueTuple p; \ |
+ if (Schema::ReadSendParam(msg, &p)) \ |
IPC::LogParam(p, l); \ |
AddOutputParamsToLog(msg, l); \ |
} else { \ |
- TupleTypes<ReplyParam>::ValueTuple p; \ |
- if (ReadReplyParam(msg, &p)) \ |
+ TupleTypes<Schema::ReplyParam>::ValueTuple p; \ |
+ if (Schema::ReadReplyParam(msg, &p)) \ |
IPC::LogParam(p, l); \ |
} \ |
} |
@@ -722,7 +935,8 @@ |
#define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \ |
case msg_class::ID: \ |
- msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, &member_func); \ |
+ msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, \ |
+ &member_func); \ |
break; |
#define IPC_MESSAGE_HANDLER(msg_class, member_func) \ |
@@ -730,7 +944,8 @@ |
#define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \ |
case msg_class::ID: \ |
- msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, &member_func); \ |
+ msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, \ |
+ &member_func); \ |
break; |
#define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \ |