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

Side by Side Diff: ipc/ipc_message_templates_impl.h

Issue 1532053002: use variadic macros/templates in IPC message implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move for real Created 4 years, 10 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
« no previous file with comments | « ipc/ipc_message_templates.h ('k') | ipc/ipc_message_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef IPC_IPC_MESSAGE_TEMPLATES_IMPL_H_
6 #define IPC_IPC_MESSAGE_TEMPLATES_IMPL_H_
7
8 namespace IPC {
9
10 template <typename... Ts>
11 class ParamDeserializer : public MessageReplyDeserializer {
12 public:
13 explicit ParamDeserializer(const base::Tuple<Ts&...>& out) : out_(out) {}
14
15 bool SerializeOutputParameters(const IPC::Message& msg,
16 base::PickleIterator iter) override {
17 return ReadParam(&msg, &iter, &out_);
18 }
19
20 base::Tuple<Ts&...> out_;
21 };
22
23 template <typename Meta, typename... Ins>
24 MessageT<Meta, base::Tuple<Ins...>, void>::MessageT(Routing routing,
25 const Ins&... ins)
26 : Message(routing.id, ID, PRIORITY_NORMAL) {
27 WriteParam(this, base::MakeRefTuple(ins...));
28 }
29
30 template <typename Meta, typename... Ins>
31 bool MessageT<Meta, base::Tuple<Ins...>, void>::Read(const Message* msg,
32 Param* p) {
33 base::PickleIterator iter(*msg);
34 return ReadParam(msg, &iter, p);
35 }
36
37 template <typename Meta, typename... Ins>
38 void MessageT<Meta, base::Tuple<Ins...>, void>::Log(std::string* name,
39 const Message* msg,
40 std::string* l) {
41 if (name)
42 *name = Meta::kName;
43 if (!msg || !l)
44 return;
45 Param p;
46 if (Read(msg, &p))
47 LogParam(p, l);
48 }
49
50 template <typename Meta, typename... Ins, typename... Outs>
51 MessageT<Meta, base::Tuple<Ins...>, base::Tuple<Outs...>>::MessageT(
52 Routing routing,
53 const Ins&... ins,
54 Outs*... outs)
55 : SyncMessage(
56 routing.id,
57 ID,
58 PRIORITY_NORMAL,
59 new ParamDeserializer<Outs...>(base::MakeRefTuple(*outs...))) {
60 WriteParam(this, base::MakeRefTuple(ins...));
61 }
62
63 template <typename Meta, typename... Ins, typename... Outs>
64 bool MessageT<Meta, base::Tuple<Ins...>, base::Tuple<Outs...>>::ReadSendParam(
65 const Message* msg,
66 SendParam* p) {
67 base::PickleIterator iter = SyncMessage::GetDataIterator(msg);
68 return ReadParam(msg, &iter, p);
69 }
70
71 template <typename Meta, typename... Ins, typename... Outs>
72 bool MessageT<Meta, base::Tuple<Ins...>, base::Tuple<Outs...>>::ReadReplyParam(
73 const Message* msg,
74 ReplyParam* p) {
75 base::PickleIterator iter = SyncMessage::GetDataIterator(msg);
76 return ReadParam(msg, &iter, p);
77 }
78
79 template <typename Meta, typename... Ins, typename... Outs>
80 void MessageT<Meta,
81 base::Tuple<Ins...>,
82 base::Tuple<Outs...>>::WriteReplyParams(Message* reply,
83 const Outs&... outs) {
84 WriteParam(reply, base::MakeRefTuple(outs...));
85 }
86
87 template <typename Meta, typename... Ins, typename... Outs>
88 void MessageT<Meta, base::Tuple<Ins...>, base::Tuple<Outs...>>::Log(
89 std::string* name,
90 const Message* msg,
91 std::string* l) {
92 if (name)
93 *name = Meta::kName;
94 if (!msg || !l)
95 return;
96 if (msg->is_sync()) {
97 SendParam p;
98 if (ReadSendParam(msg, &p))
99 LogParam(p, l);
100 AddOutputParamsToLog(msg, l);
101 } else {
102 ReplyParam p;
103 if (ReadReplyParam(msg, &p))
104 LogParam(p, l);
105 }
106 }
107
108 } // namespace IPC
109
110 #endif // IPC_IPC_MESSAGE_TEMPLATES_IMPL_H_
OLDNEW
« no previous file with comments | « ipc/ipc_message_templates.h ('k') | ipc/ipc_message_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698