Chromium Code Reviews| 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 <type_traits> | 10 #include <type_traits> |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 const Tuple& tuple, | 35 const Tuple& tuple, |
| 36 base::IndexSequence<Ns...>) { | 36 base::IndexSequence<Ns...>) { |
| 37 // TODO(mdempsky): Apply UnwrapTraits like base::DispatchToMethod? | 37 // TODO(mdempsky): Apply UnwrapTraits like base::DispatchToMethod? |
| 38 (obj->*method)(parameter, base::get<Ns>(tuple)...); | 38 (obj->*method)(parameter, base::get<Ns>(tuple)...); |
| 39 } | 39 } |
| 40 | 40 |
| 41 // The following function is for async IPCs which have a dispatcher with an | 41 // The following function is for async IPCs which have a dispatcher with an |
| 42 // extra parameter specified using IPC_BEGIN_MESSAGE_MAP_WITH_PARAM. | 42 // extra parameter specified using IPC_BEGIN_MESSAGE_MAP_WITH_PARAM. |
| 43 template <typename ObjT, typename P, typename... Args, typename... Ts> | 43 template <typename ObjT, typename P, typename... Args, typename... Ts> |
| 44 typename std::enable_if<sizeof...(Args) == sizeof...(Ts)>::type | 44 typename std::enable_if<sizeof...(Args) == sizeof...(Ts)>::type |
| 45 DispatchToMethod(ObjT* obj, | 45 DispatchToMethod(ObjT* obj, |
|
danakj
2016/03/03 21:01:40
Or use this?
| |
| 46 void (ObjT::*method)(P*, Args...), | 46 void (ObjT::*method)(P*, Args...), |
| 47 P* parameter, | 47 P* parameter, |
| 48 const base::Tuple<Ts...>& tuple) { | 48 const base::Tuple<Ts...>& tuple) { |
| 49 DispatchToMethodImpl(obj, method, parameter, tuple, | 49 DispatchToMethodImpl(obj, method, parameter, tuple, |
| 50 base::MakeIndexSequence<sizeof...(Ts)>()); | 50 base::MakeIndexSequence<sizeof...(Ts)>()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 enum class MessageKind { | 53 enum class MessageKind { |
| 54 CONTROL, | 54 CONTROL, |
| 55 ROUTED, | 55 ROUTED, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 static bool Dispatch(const Message* msg, | 159 static bool Dispatch(const Message* msg, |
| 160 T* obj, | 160 T* obj, |
| 161 S* sender, | 161 S* sender, |
| 162 P* parameter, | 162 P* parameter, |
| 163 Method func) { | 163 Method func) { |
| 164 SendParam send_params; | 164 SendParam send_params; |
| 165 bool ok = ReadSendParam(msg, &send_params); | 165 bool ok = ReadSendParam(msg, &send_params); |
| 166 Message* reply = SyncMessage::GenerateReply(msg); | 166 Message* reply = SyncMessage::GenerateReply(msg); |
| 167 if (ok) { | 167 if (ok) { |
| 168 ReplyParam reply_params; | 168 ReplyParam reply_params; |
| 169 base::DispatchToMethod(obj, func, send_params, &reply_params); | 169 base::DispatchToMethod(obj, func, parameter, send_params, &reply_params); |
| 170 WriteParam(reply, reply_params); | 170 WriteParam(reply, reply_params); |
| 171 LogReplyParamsToMessage(reply_params, msg); | 171 LogReplyParamsToMessage(reply_params, msg); |
| 172 } else { | 172 } else { |
| 173 NOTREACHED() << "Error deserializing message " << msg->type(); | 173 NOTREACHED() << "Error deserializing message " << msg->type(); |
| 174 reply->set_reply_error(); | 174 reply->set_reply_error(); |
| 175 } | 175 } |
| 176 sender->Send(reply); | 176 sender->Send(reply); |
| 177 return ok; | 177 return ok; |
| 178 } | 178 } |
| 179 | 179 |
| 180 template <class T, class P, class Method> | 180 template <class T, class P, class Method> |
| 181 static bool DispatchDelayReply(const Message* msg, | 181 static bool DispatchDelayReply(const Message* msg, |
| 182 T* obj, | 182 T* obj, |
| 183 P* parameter, | 183 P* parameter, |
| 184 Method func) { | 184 Method func) { |
| 185 SendParam send_params; | 185 SendParam send_params; |
| 186 bool ok = ReadSendParam(msg, &send_params); | 186 bool ok = ReadSendParam(msg, &send_params); |
| 187 Message* reply = SyncMessage::GenerateReply(msg); | 187 Message* reply = SyncMessage::GenerateReply(msg); |
| 188 if (ok) { | 188 if (ok) { |
| 189 base::Tuple<Message&> t = base::MakeRefTuple(*reply); | 189 base::Tuple<Message&> t = base::MakeRefTuple(*reply); |
| 190 ConnectMessageAndReply(msg, reply); | 190 ConnectMessageAndReply(msg, reply); |
| 191 base::DispatchToMethod(obj, func, send_params, &t); | 191 base::DispatchToMethod(obj, func, parameter, send_params, &t); |
| 192 } else { | 192 } else { |
| 193 NOTREACHED() << "Error deserializing message " << msg->type(); | 193 NOTREACHED() << "Error deserializing message " << msg->type(); |
| 194 reply->set_reply_error(); | 194 reply->set_reply_error(); |
| 195 obj->Send(reply); | 195 obj->Send(reply); |
| 196 } | 196 } |
| 197 return ok; | 197 return ok; |
| 198 } | 198 } |
| 199 | 199 |
| 200 private: | 200 private: |
| 201 MessageT(Routing routing, const Ins&... ins, Outs*... outs); | 201 MessageT(Routing routing, const Ins&... ins, Outs*... outs); |
| 202 }; | 202 }; |
| 203 | 203 |
| 204 } // namespace IPC | 204 } // namespace IPC |
| 205 | 205 |
| 206 #if defined(IPC_MESSAGE_IMPL) | 206 #if defined(IPC_MESSAGE_IMPL) |
| 207 #include "ipc/ipc_message_templates_impl.h" | 207 #include "ipc/ipc_message_templates_impl.h" |
| 208 #endif | 208 #endif |
| 209 | 209 |
| 210 #endif // IPC_IPC_MESSAGE_TEMPLATES_H_ | 210 #endif // IPC_IPC_MESSAGE_TEMPLATES_H_ |
| OLD | NEW |