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

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: simplify Created 5 years 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
(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 #include "ipc/ipc_message_utils_impl.h"
9
10 namespace IPC {
11
12 template <uint32_t Id, const char* Name, typename... Ins>
13 CommonAsyncMessage<Id, Name, base::Tuple<Ins...>, base::Tuple<>>::
14 CommonAsyncMessage(int32_t routing_id, const Ins&... ins)
15 : Message(routing_id, ID, PRIORITY_NORMAL) {
16 Schema::Write(this, base::MakeRefTuple(ins...));
17 }
18
19 template <uint32_t Id, const char* Name, typename... Ins>
20 bool CommonAsyncMessage<Id, Name, base::Tuple<Ins...>, base::Tuple<>>::Read(
21 const Message* msg,
22 Param* p) {
23 return Schema::Read(msg, p);
24 }
25
26 template <uint32_t Id, const char* Name, typename... Ins>
27 void CommonAsyncMessage<Id, Name, base::Tuple<Ins...>, base::Tuple<>>::Log(
28 std::string* name,
29 const Message* msg,
30 std::string* l) {
31 if (name)
32 *name = Name;
33 if (!msg || !l)
34 return;
35 Param p;
36 if (Schema::Read(msg, &p))
37 LogParam(p, l);
38 }
39
40 template <uint32_t Id, const char* Name, typename... Ins, typename... Outs>
41 CommonSyncMessage<Id, Name, base::Tuple<Ins...>, base::Tuple<Outs...>>::
42 CommonSyncMessage(int32_t routing_id, const Ins&... ins, Outs*... outs)
43 : SyncMessage(
44 routing_id,
45 ID,
46 PRIORITY_NORMAL,
47 new ParamDeserializer<ReplyParam>(base::MakeRefTuple(*outs...))) {
48 Schema::Write(this, base::MakeRefTuple(ins...));
49 }
50
51 template <uint32_t Id, const char* Name, typename... Ins, typename... Outs>
52 bool CommonSyncMessage<Id, Name, base::Tuple<Ins...>, base::Tuple<Outs...>>::
53 ReadSendParam(const Message* msg, SendParam* p) {
54 return Schema::ReadSendParam(msg, p);
55 }
56
57 template <uint32_t Id, const char* Name, typename... Ins, typename... Outs>
58 bool CommonSyncMessage<Id, Name, base::Tuple<Ins...>, base::Tuple<Outs...>>::
59 ReadReplyParam(const Message* msg,
60 typename base::TupleTypes<ReplyParam>::ValueTuple* p) {
61 return Schema::ReadReplyParam(msg, p);
62 }
63
64 template <uint32_t Id, const char* Name, typename... Ins, typename... Outs>
65 void CommonSyncMessage<Id, Name, base::Tuple<Ins...>, base::Tuple<Outs...>>::
66 Log(std::string* name, const Message* msg, std::string* l) {
67 if (name)
68 *name = Name;
69 if (!msg || !l)
70 return;
71 if (msg->is_sync()) {
72 typename base::TupleTypes<SendParam>::ValueTuple p;
73 if (Schema::ReadSendParam(msg, &p))
74 LogParam(p, l);
75 AddOutputParamsToLog(msg, l);
76 } else {
77 typename base::TupleTypes<ReplyParam>::ValueTuple p;
78 if (Schema::ReadReplyParam(msg, &p))
79 LogParam(p, l);
80 }
81 }
82
83 } // namespace IPC
84
85 #endif // IPC_IPC_MESSAGE_TEMPLATES_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698