| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_COMMON_IPC_MESSAGE_UTILS_H_ | 5 #ifndef CHROME_COMMON_IPC_MESSAGE_UTILS_H_ |
| 6 #define CHROME_COMMON_IPC_MESSAGE_UTILS_H_ | 6 #define CHROME_COMMON_IPC_MESSAGE_UTILS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 | 1054 |
| 1055 | 1055 |
| 1056 //----------------------------------------------------------------------------- | 1056 //----------------------------------------------------------------------------- |
| 1057 // Generic message subclasses | 1057 // Generic message subclasses |
| 1058 | 1058 |
| 1059 // Used for asynchronous messages. | 1059 // Used for asynchronous messages. |
| 1060 template <class ParamType> | 1060 template <class ParamType> |
| 1061 class MessageWithTuple : public Message { | 1061 class MessageWithTuple : public Message { |
| 1062 public: | 1062 public: |
| 1063 typedef ParamType Param; | 1063 typedef ParamType Param; |
| 1064 typedef typename ParamType::ParamTuple RefParam; |
| 1064 | 1065 |
| 1065 MessageWithTuple(int32 routing_id, uint16 type, const Param& p) | 1066 MessageWithTuple(int32 routing_id, uint16 type, const RefParam& p) |
| 1066 : Message(routing_id, type, PRIORITY_NORMAL) { | 1067 : Message(routing_id, type, PRIORITY_NORMAL) { |
| 1067 WriteParam(this, p); | 1068 WriteParam(this, p); |
| 1068 } | 1069 } |
| 1069 | 1070 |
| 1070 static bool Read(const Message* msg, Param* p) { | 1071 static bool Read(const Message* msg, Param* p) { |
| 1071 void* iter = NULL; | 1072 void* iter = NULL; |
| 1072 bool rv = ReadParam(msg, &iter, p); | 1073 bool rv = ReadParam(msg, &iter, p); |
| 1073 DCHECK(rv) << "Error deserializing message " << msg->type(); | 1074 DCHECK(rv) << "Error deserializing message " << msg->type(); |
| 1074 return rv; | 1075 return rv; |
| 1075 } | 1076 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1086 } | 1087 } |
| 1087 | 1088 |
| 1088 // The following dispatchers exist for the case where the callback function | 1089 // The following dispatchers exist for the case where the callback function |
| 1089 // needs the message as well. They assume that "Param" is a type of Tuple | 1090 // needs the message as well. They assume that "Param" is a type of Tuple |
| 1090 // (except the one arg case, as there is no Tuple1). | 1091 // (except the one arg case, as there is no Tuple1). |
| 1091 template<class T, typename TA> | 1092 template<class T, typename TA> |
| 1092 static bool Dispatch(const Message* msg, T* obj, | 1093 static bool Dispatch(const Message* msg, T* obj, |
| 1093 void (T::*func)(const Message&, TA)) { | 1094 void (T::*func)(const Message&, TA)) { |
| 1094 Param p; | 1095 Param p; |
| 1095 if (Read(msg, &p)) { | 1096 if (Read(msg, &p)) { |
| 1096 (obj->*func)(*msg, p); | 1097 (obj->*func)(*msg, p.a); |
| 1097 return true; | 1098 return true; |
| 1098 } | 1099 } |
| 1099 return false; | 1100 return false; |
| 1100 } | 1101 } |
| 1101 | 1102 |
| 1102 template<class T, typename TA, typename TB> | 1103 template<class T, typename TA, typename TB> |
| 1103 static bool Dispatch(const Message* msg, T* obj, | 1104 static bool Dispatch(const Message* msg, T* obj, |
| 1104 void (T::*func)(const Message&, TA, TB)) { | 1105 void (T::*func)(const Message&, TA, TB)) { |
| 1105 Param p; | 1106 Param p; |
| 1106 if (Read(msg, &p)) { | 1107 if (Read(msg, &p)) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 | 1216 |
| 1216 // defined in ipc_logging.cc | 1217 // defined in ipc_logging.cc |
| 1217 void GenerateLogData(const std::wstring& channel, const Message& message, | 1218 void GenerateLogData(const std::wstring& channel, const Message& message, |
| 1218 LogData* data); | 1219 LogData* data); |
| 1219 | 1220 |
| 1220 // Used for synchronous messages. | 1221 // Used for synchronous messages. |
| 1221 template <class SendParamType, class ReplyParamType> | 1222 template <class SendParamType, class ReplyParamType> |
| 1222 class MessageWithReply : public SyncMessage { | 1223 class MessageWithReply : public SyncMessage { |
| 1223 public: | 1224 public: |
| 1224 typedef SendParamType SendParam; | 1225 typedef SendParamType SendParam; |
| 1226 typedef typename SendParam::ParamTuple RefSendParam; |
| 1225 typedef ReplyParamType ReplyParam; | 1227 typedef ReplyParamType ReplyParam; |
| 1226 | 1228 |
| 1227 MessageWithReply(int32 routing_id, uint16 type, | 1229 MessageWithReply(int32 routing_id, uint16 type, |
| 1228 const SendParam& send, const ReplyParam& reply) | 1230 const RefSendParam& send, const ReplyParam& reply) |
| 1229 : SyncMessage(routing_id, type, PRIORITY_NORMAL, | 1231 : SyncMessage(routing_id, type, PRIORITY_NORMAL, |
| 1230 new ParamDeserializer<ReplyParam>(reply)) { | 1232 new ParamDeserializer<ReplyParam>(reply)) { |
| 1231 WriteParam(this, send); | 1233 WriteParam(this, send); |
| 1232 } | 1234 } |
| 1233 | 1235 |
| 1234 static void Log(const Message* msg, std::wstring* l) { | 1236 static void Log(const Message* msg, std::wstring* l) { |
| 1235 if (msg->is_sync()) { | 1237 if (msg->is_sync()) { |
| 1236 SendParam p; | 1238 SendParam p; |
| 1237 void* iter = SyncMessage::GetDataIterator(msg); | 1239 void* iter = SyncMessage::GetDataIterator(msg); |
| 1238 if (ReadParam(msg, &iter, &p)) | 1240 if (ReadParam(msg, &iter, &p)) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 ReplyParam p(a, b, c, d, e); | 1345 ReplyParam p(a, b, c, d, e); |
| 1344 WriteParam(reply, p); | 1346 WriteParam(reply, p); |
| 1345 } | 1347 } |
| 1346 }; | 1348 }; |
| 1347 | 1349 |
| 1348 //----------------------------------------------------------------------------- | 1350 //----------------------------------------------------------------------------- |
| 1349 | 1351 |
| 1350 } // namespace IPC | 1352 } // namespace IPC |
| 1351 | 1353 |
| 1352 #endif // CHROME_COMMON_IPC_MESSAGE_UTILS_H_ | 1354 #endif // CHROME_COMMON_IPC_MESSAGE_UTILS_H_ |
| OLD | NEW |