summaryrefslogtreecommitdiffstats
path: root/ipc/ipc_message_utils.h
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-26 21:27:30 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-26 21:27:30 +0000
commit1d4ecf498386569dfb438f7536b573213bbcaaba (patch)
tree2f05a90aa931e14aac6f9acee38ba471b5e55ea4 /ipc/ipc_message_utils.h
parent80f6c7266b94973ce98e96ff743507a750dd7ae0 (diff)
downloadchromium_src-1d4ecf498386569dfb438f7536b573213bbcaaba.zip
chromium_src-1d4ecf498386569dfb438f7536b573213bbcaaba.tar.gz
chromium_src-1d4ecf498386569dfb438f7536b573213bbcaaba.tar.bz2
Add support for exporting IPC messages from component DLLs.
This removes MessageWithTuple and MessageWithReply since it is not easy to export a class that inherits from a template specialization. The functionality of those classes are split now between new classes, MessageSchema and SyncMessageSchema, and being declared inline via macros. The key point is that we want to avoid inlining the constructor and Read functions for messages. That avoids code bloat since those functions contain all of the parameter serialization and deserialization code. Those are the functions that we really want to have contained with component DLLs. To export IPC messages from a DLL, it is necessary to #define IPC_MESSAGE_EXPORT above message declarations. You can see this in action here: http://codereview.chromium.org/7687005/diff/41012/ppapi/proxy/ppapi_messages.h Review URL: http://codereview.chromium.org/7768001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98491 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_message_utils.h')
-rw-r--r--ipc/ipc_message_utils.h162
1 files changed, 17 insertions, 145 deletions
diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h
index ae7490c..9da9eba4 100644
--- a/ipc/ipc_message_utils.h
+++ b/ipc/ipc_message_utils.h
@@ -944,136 +944,13 @@ struct ParamTraits< Tuple5<A, B, C, D, E> > {
// Used for asynchronous messages.
template <class ParamType>
-class MessageWithTuple : public Message {
+class MessageSchema {
public:
typedef ParamType Param;
typedef typename TupleTypes<ParamType>::ParamTuple RefParam;
- // The constructor and the Read() method's templated implementations are in
- // ipc_message_utils_impl.h. The subclass constructor and Log() methods call
- // the templated versions of these and make sure there are instantiations in
- // those translation units.
- MessageWithTuple(int32 routing_id, uint32 type, const RefParam& p);
-
+ static void Write(Message* msg, const RefParam& p) IPC_MSG_NOINLINE;
static bool Read(const Message* msg, Param* p) IPC_MSG_NOINLINE;
-
- // Generic dispatcher. Should cover most cases.
- template<class T, class S, class Method>
- static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) {
- Param p;
- if (Read(msg, &p)) {
- DispatchToMethod(obj, func, p);
- return true;
- }
- return false;
- }
-
- // The following dispatchers exist for the case where the callback function
- // needs the message as well. They assume that "Param" is a type of Tuple
- // (except the one arg case, as there is no Tuple1).
- template<class T, class S, typename TA>
- static bool Dispatch(const Message* msg, T* obj, S* sender,
- void (T::*func)(const Message&, TA)) {
- Param p;
- if (Read(msg, &p)) {
- (obj->*func)(*msg, p.a);
- return true;
- }
- return false;
- }
-
- 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)) {
- Param p;
- if (Read(msg, &p)) {
- (obj->*func)(*msg, p.a, p.b);
- return true;
- }
- return false;
- }
-
- 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)) {
- Param p;
- if (Read(msg, &p)) {
- (obj->*func)(*msg, p.a, p.b, p.c);
- return true;
- }
- return false;
- }
-
- 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)) {
- Param p;
- if (Read(msg, &p)) {
- (obj->*func)(*msg, p.a, p.b, p.c, p.d);
- return true;
- }
- return false;
- }
-
- 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)) {
- Param p;
- if (Read(msg, &p)) {
- (obj->*func)(*msg, p.a, p.b, p.c, p.d, p.e);
- return true;
- }
- return false;
- }
-
- // Functions used to do manual unpacking. Only used by the automation code,
- // these should go away once that code uses SyncChannel.
- template<typename TA, typename TB>
- static bool Read(const IPC::Message* msg, TA* a, TB* b) {
- ParamType params;
- if (!Read(msg, &params))
- return false;
- *a = params.a;
- *b = params.b;
- return true;
- }
-
- template<typename TA, typename TB, typename TC>
- static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c) {
- ParamType params;
- if (!Read(msg, &params))
- return false;
- *a = params.a;
- *b = params.b;
- *c = params.c;
- return true;
- }
-
- template<typename TA, typename TB, typename TC, typename TD>
- static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d) {
- ParamType params;
- if (!Read(msg, &params))
- return false;
- *a = params.a;
- *b = params.b;
- *c = params.c;
- *d = params.d;
- return true;
- }
-
- 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) {
- ParamType params;
- if (!Read(msg, &params))
- return false;
- *a = params.a;
- *b = params.b;
- *c = params.c;
- *d = params.d;
- *e = params.e;
- return true;
- }
};
// defined in ipc_logging.cc
@@ -1139,57 +1016,52 @@ class ParamDeserializer : public MessageReplyDeserializer {
// Used for synchronous messages.
template <class SendParamType, class ReplyParamType>
-class MessageWithReply : public SyncMessage {
+class SyncMessageSchema {
public:
typedef SendParamType SendParam;
typedef typename TupleTypes<SendParam>::ParamTuple RefSendParam;
typedef ReplyParamType ReplyParam;
- MessageWithReply(int32 routing_id, uint32 type,
- const RefSendParam& send, const ReplyParam& reply);
+ static void Write(Message* msg, const RefSendParam& send) IPC_MSG_NOINLINE;
static bool ReadSendParam(const Message* msg, SendParam* p) IPC_MSG_NOINLINE;
static bool ReadReplyParam(
const Message* msg,
typename TupleTypes<ReplyParam>::ValueTuple* p) IPC_MSG_NOINLINE;
template<class T, class S, class Method>
- static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) {
- SendParam send_params;
- Message* reply = GenerateReply(msg);
- bool error;
- if (ReadSendParam(msg, &send_params)) {
+ static bool DispatchWithSendParams(bool ok, const SendParam& send_params,
+ const Message* msg, T* obj, S* sender,
+ Method func) {
+ Message* reply = SyncMessage::GenerateReply(msg);
+ if (ok) {
typename TupleTypes<ReplyParam>::ValueTuple reply_params;
DispatchToMethod(obj, func, send_params, &reply_params);
WriteParam(reply, reply_params);
- error = false;
LogReplyParamsToMessage(reply_params, msg);
} else {
NOTREACHED() << "Error deserializing message " << msg->type();
reply->set_reply_error();
- error = true;
}
-
sender->Send(reply);
- return !error;
+ return ok;
}
template<class T, class Method>
- static bool DispatchDelayReply(const Message* msg, T* obj, Method func) {
- SendParam send_params;
- Message* reply = GenerateReply(msg);
- bool error;
- if (ReadSendParam(msg, &send_params)) {
+ static bool DispatchDelayReplyWithSendParams(bool ok,
+ const SendParam& send_params,
+ const Message* msg, T* obj,
+ Method func) {
+ Message* reply = SyncMessage::GenerateReply(msg);
+ if (ok) {
Tuple1<Message&> t = MakeRefTuple(*reply);
ConnectMessageAndReply(msg, reply);
DispatchToMethod(obj, func, send_params, &t);
- error = false;
} else {
NOTREACHED() << "Error deserializing message " << msg->type();
reply->set_reply_error();
obj->Send(reply);
- error = true;
}
- return !error;
+ return ok;
}
template<typename TA>