Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: ipc/ipc_message_templates.h

Issue 1770013002: Replace base::Tuple in //ipc with std::tuple (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/tuple.h" 13 #include "base/tuple.h"
Tom Sepez 2016/03/07 19:05:02 ditto and ditto
tzik 2016/03/08 03:32:59 Added <tuple>. Let me leave "base/tuple.h" here.
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "ipc/ipc_message.h" 15 #include "ipc/ipc_message.h"
16 #include "ipc/ipc_message_utils.h" 16 #include "ipc/ipc_message_utils.h"
17 17
18 namespace IPC { 18 namespace IPC {
19 19
20 // This function is for all the async IPCs that don't pass an extra parameter 20 // This function is for all the async IPCs that don't pass an extra parameter
21 // using IPC_BEGIN_MESSAGE_MAP_WITH_PARAM. 21 // using IPC_BEGIN_MESSAGE_MAP_WITH_PARAM.
22 template <typename ObjT, typename Method, typename P, typename Tuple> 22 template <typename ObjT, typename Method, typename P, typename Tuple>
23 void DispatchToMethod(ObjT* obj, Method method, P*, const Tuple& tuple) { 23 void DispatchToMethod(ObjT* obj, Method method, P*, const Tuple& tuple) {
24 base::DispatchToMethod(obj, method, tuple); 24 base::DispatchToMethod(obj, method, tuple);
25 } 25 }
26 26
27 template <typename ObjT, 27 template <typename ObjT,
28 typename Method, 28 typename Method,
29 typename P, 29 typename P,
30 typename Tuple, 30 typename Tuple,
31 size_t... Ns> 31 size_t... Ns>
32 void DispatchToMethodImpl(ObjT* obj, 32 void DispatchToMethodImpl(ObjT* obj,
33 Method method, 33 Method method,
34 P* parameter, 34 P* parameter,
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, std::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,
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 std::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,
56 }; 56 };
57 57
58 // Routing is a helper struct so MessageT's private common constructor has a 58 // Routing is a helper struct so MessageT's private common constructor has a
(...skipping 18 matching lines...) Expand all
77 77
78 // MessageT is the common template used for all user-defined message types. 78 // MessageT is the common template used for all user-defined message types.
79 // It's intended to be used via the macros defined in ipc_message_macros.h. 79 // It's intended to be used via the macros defined in ipc_message_macros.h.
80 template <typename Meta, 80 template <typename Meta,
81 typename InTuple = typename Meta::InTuple, 81 typename InTuple = typename Meta::InTuple,
82 typename OutTuple = typename Meta::OutTuple> 82 typename OutTuple = typename Meta::OutTuple>
83 class MessageT; 83 class MessageT;
84 84
85 // Asynchronous message partial specialization. 85 // Asynchronous message partial specialization.
86 template <typename Meta, typename... Ins> 86 template <typename Meta, typename... Ins>
87 class MessageT<Meta, base::Tuple<Ins...>, void> : public Message { 87 class MessageT<Meta, std::tuple<Ins...>, void> : public Message {
88 public: 88 public:
89 using Param = base::Tuple<Ins...>; 89 using Param = std::tuple<Ins...>;
90 enum { ID = Meta::ID }; 90 enum { ID = Meta::ID };
91 91
92 // TODO(mdempsky): Remove. Uses of MyMessage::Schema::Param can be replaced 92 // TODO(mdempsky): Remove. Uses of MyMessage::Schema::Param can be replaced
93 // with just MyMessage::Param. 93 // with just MyMessage::Param.
94 using Schema = MessageT; 94 using Schema = MessageT;
95 95
96 IPC_MESSAGET_SFINAE(Meta::kKind == MessageKind::CONTROL) 96 IPC_MESSAGET_SFINAE(Meta::kKind == MessageKind::CONTROL)
97 MessageT(const Ins&... ins) : MessageT(Routing(MSG_ROUTING_CONTROL), ins...) { 97 MessageT(const Ins&... ins) : MessageT(Routing(MSG_ROUTING_CONTROL), ins...) {
98 DCHECK(Meta::kKind == MessageKind::CONTROL) << Meta::kName; 98 DCHECK(Meta::kKind == MessageKind::CONTROL) << Meta::kName;
99 } 99 }
(...skipping 20 matching lines...) Expand all
120 } 120 }
121 return false; 121 return false;
122 } 122 }
123 123
124 private: 124 private:
125 MessageT(Routing routing, const Ins&... ins); 125 MessageT(Routing routing, const Ins&... ins);
126 }; 126 };
127 127
128 // Synchronous message partial specialization. 128 // Synchronous message partial specialization.
129 template <typename Meta, typename... Ins, typename... Outs> 129 template <typename Meta, typename... Ins, typename... Outs>
130 class MessageT<Meta, base::Tuple<Ins...>, base::Tuple<Outs...>> 130 class MessageT<Meta, std::tuple<Ins...>, std::tuple<Outs...>>
131 : public SyncMessage { 131 : public SyncMessage {
132 public: 132 public:
133 using SendParam = base::Tuple<Ins...>; 133 using SendParam = std::tuple<Ins...>;
134 using ReplyParam = base::Tuple<Outs...>; 134 using ReplyParam = std::tuple<Outs...>;
135 enum { ID = Meta::ID }; 135 enum { ID = Meta::ID };
136 136
137 // TODO(mdempsky): Remove. Uses of MyMessage::Schema::{Send,Reply}Param can 137 // TODO(mdempsky): Remove. Uses of MyMessage::Schema::{Send,Reply}Param can
138 // be replaced with just MyMessage::{Send,Reply}Param. 138 // be replaced with just MyMessage::{Send,Reply}Param.
139 using Schema = MessageT; 139 using Schema = MessageT;
140 140
141 IPC_MESSAGET_SFINAE(Meta::kKind == MessageKind::CONTROL) 141 IPC_MESSAGET_SFINAE(Meta::kKind == MessageKind::CONTROL)
142 MessageT(const Ins&... ins, Outs*... outs) 142 MessageT(const Ins&... ins, Outs*... outs)
143 : MessageT(Routing(MSG_ROUTING_CONTROL), ins..., outs...) { 143 : MessageT(Routing(MSG_ROUTING_CONTROL), ins..., outs...) {
144 DCHECK(Meta::kKind == MessageKind::CONTROL) << Meta::kName; 144 DCHECK(Meta::kKind == MessageKind::CONTROL) << Meta::kName;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 std::tuple<Message&> t = std::tie(*reply);
190 ConnectMessageAndReply(msg, reply); 190 ConnectMessageAndReply(msg, reply);
191 base::DispatchToMethod(obj, func, send_params, &t); 191 base::DispatchToMethod(obj, func, 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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698