OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 IPC_IPC_MESSAGE_TEMPLATES_H_ | 5 #ifndef IPC_IPC_MESSAGE_TEMPLATES_H_ |
6 #define IPC_IPC_MESSAGE_TEMPLATES_H_ | 6 #define IPC_IPC_MESSAGE_TEMPLATES_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 static bool ReadSendParam(const Message* msg, SendParam* p); | 156 static bool ReadSendParam(const Message* msg, SendParam* p); |
157 static bool ReadReplyParam(const Message* msg, ReplyParam* p); | 157 static bool ReadReplyParam(const Message* msg, ReplyParam* p); |
158 static void WriteReplyParams(Message* reply, const Outs&... outs); | 158 static void WriteReplyParams(Message* reply, const Outs&... outs); |
159 static void Log(std::string* name, const Message* msg, std::string* l); | 159 static void Log(std::string* name, const Message* msg, std::string* l); |
160 | 160 |
161 template <class T, class S, class P, class Method> | 161 template <class T, class S, class P, class Method> |
162 static bool Dispatch(const Message* msg, | 162 static bool Dispatch(const Message* msg, |
163 T* obj, | 163 T* obj, |
164 S* sender, | 164 S* sender, |
165 P* parameter, | 165 P* /* parameter */, |
166 Method func) { | 166 Method func) { |
167 TRACE_EVENT0("ipc", Meta::kName); | 167 TRACE_EVENT0("ipc", Meta::kName); |
168 SendParam send_params; | 168 SendParam send_params; |
169 bool ok = ReadSendParam(msg, &send_params); | 169 bool ok = ReadSendParam(msg, &send_params); |
170 Message* reply = SyncMessage::GenerateReply(msg); | 170 Message* reply = SyncMessage::GenerateReply(msg); |
171 if (ok) { | 171 if (ok) { |
172 ReplyParam reply_params; | 172 ReplyParam reply_params; |
173 base::DispatchToMethod(obj, func, send_params, &reply_params); | 173 base::DispatchToMethod(obj, func, send_params, &reply_params); |
174 WriteParam(reply, reply_params); | 174 WriteParam(reply, reply_params); |
175 LogReplyParamsToMessage(reply_params, msg); | 175 LogReplyParamsToMessage(reply_params, msg); |
176 } else { | 176 } else { |
177 NOTREACHED() << "Error deserializing message " << msg->type(); | 177 NOTREACHED() << "Error deserializing message " << msg->type(); |
178 reply->set_reply_error(); | 178 reply->set_reply_error(); |
179 } | 179 } |
180 sender->Send(reply); | 180 sender->Send(reply); |
181 return ok; | 181 return ok; |
182 } | 182 } |
183 | 183 |
184 template <class T, class P, class Method> | 184 template <class T, class P, class Method> |
185 static bool DispatchDelayReply(const Message* msg, | 185 static bool DispatchDelayReply(const Message* msg, |
186 T* obj, | 186 T* obj, |
187 P* parameter, | 187 P* /* parameter */, |
188 Method func) { | 188 Method func) { |
189 TRACE_EVENT0("ipc", Meta::kName); | 189 TRACE_EVENT0("ipc", Meta::kName); |
190 SendParam send_params; | 190 SendParam send_params; |
191 bool ok = ReadSendParam(msg, &send_params); | 191 bool ok = ReadSendParam(msg, &send_params); |
192 Message* reply = SyncMessage::GenerateReply(msg); | 192 Message* reply = SyncMessage::GenerateReply(msg); |
193 if (ok) { | 193 if (ok) { |
194 std::tuple<Message&> t = std::tie(*reply); | 194 std::tuple<Message&> t = std::tie(*reply); |
195 ConnectMessageAndReply(msg, reply); | 195 ConnectMessageAndReply(msg, reply); |
196 base::DispatchToMethod(obj, func, send_params, &t); | 196 base::DispatchToMethod(obj, func, send_params, &t); |
197 } else { | 197 } else { |
198 NOTREACHED() << "Error deserializing message " << msg->type(); | 198 NOTREACHED() << "Error deserializing message " << msg->type(); |
199 reply->set_reply_error(); | 199 reply->set_reply_error(); |
200 obj->Send(reply); | 200 obj->Send(reply); |
201 } | 201 } |
202 return ok; | 202 return ok; |
203 } | 203 } |
204 | 204 |
| 205 template <class T, class P, class Method> |
| 206 static bool DispatchWithParamDelayReply(const Message* msg, |
| 207 T* obj, |
| 208 P* parameter, |
| 209 Method func) { |
| 210 TRACE_EVENT0("ipc", Meta::kName); |
| 211 SendParam send_params; |
| 212 bool ok = ReadSendParam(msg, &send_params); |
| 213 Message* reply = SyncMessage::GenerateReply(msg); |
| 214 if (ok) { |
| 215 std::tuple<Message&> t = std::tie(*reply); |
| 216 ConnectMessageAndReply(msg, reply); |
| 217 std::tuple<P*> parameter_tuple(parameter); |
| 218 auto concat_params = std::tuple_cat(parameter_tuple, send_params); |
| 219 base::DispatchToMethod(obj, func, concat_params, &t); |
| 220 } else { |
| 221 NOTREACHED() << "Error deserializing message " << msg->type(); |
| 222 reply->set_reply_error(); |
| 223 obj->Send(reply); |
| 224 } |
| 225 return ok; |
| 226 } |
| 227 |
205 private: | 228 private: |
206 MessageT(Routing routing, const Ins&... ins, Outs*... outs); | 229 MessageT(Routing routing, const Ins&... ins, Outs*... outs); |
207 }; | 230 }; |
208 | 231 |
209 } // namespace IPC | 232 } // namespace IPC |
210 | 233 |
211 #if defined(IPC_MESSAGE_IMPL) | 234 #if defined(IPC_MESSAGE_IMPL) |
212 #include "ipc/ipc_message_templates_impl.h" | 235 #include "ipc/ipc_message_templates_impl.h" |
213 #endif | 236 #endif |
214 | 237 |
215 #endif // IPC_IPC_MESSAGE_TEMPLATES_H_ | 238 #endif // IPC_IPC_MESSAGE_TEMPLATES_H_ |
OLD | NEW |