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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ipc/ipc_message_templates_impl.h
diff --git a/ipc/ipc_message_templates_impl.h b/ipc/ipc_message_templates_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..df0ecf6703c0edd52eafae032e3a86f8d0771938
--- /dev/null
+++ b/ipc/ipc_message_templates_impl.h
@@ -0,0 +1,85 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef IPC_IPC_MESSAGE_TEMPLATES_IMPL_H_
+#define IPC_IPC_MESSAGE_TEMPLATES_IMPL_H_
+
+#include "ipc/ipc_message_utils_impl.h"
+
+namespace IPC {
+
+template <uint32_t Id, const char* Name, typename... Ins>
+CommonAsyncMessage<Id, Name, base::Tuple<Ins...>, base::Tuple<>>::
+ CommonAsyncMessage(int32_t routing_id, const Ins&... ins)
+ : Message(routing_id, ID, PRIORITY_NORMAL) {
+ Schema::Write(this, base::MakeRefTuple(ins...));
+}
+
+template <uint32_t Id, const char* Name, typename... Ins>
+bool CommonAsyncMessage<Id, Name, base::Tuple<Ins...>, base::Tuple<>>::Read(
+ const Message* msg,
+ Param* p) {
+ return Schema::Read(msg, p);
+}
+
+template <uint32_t Id, const char* Name, typename... Ins>
+void CommonAsyncMessage<Id, Name, base::Tuple<Ins...>, base::Tuple<>>::Log(
+ std::string* name,
+ const Message* msg,
+ std::string* l) {
+ if (name)
+ *name = Name;
+ if (!msg || !l)
+ return;
+ Param p;
+ if (Schema::Read(msg, &p))
+ LogParam(p, l);
+}
+
+template <uint32_t Id, const char* Name, typename... Ins, typename... Outs>
+CommonSyncMessage<Id, Name, base::Tuple<Ins...>, base::Tuple<Outs...>>::
+ CommonSyncMessage(int32_t routing_id, const Ins&... ins, Outs*... outs)
+ : SyncMessage(
+ routing_id,
+ ID,
+ PRIORITY_NORMAL,
+ new ParamDeserializer<ReplyParam>(base::MakeRefTuple(*outs...))) {
+ Schema::Write(this, base::MakeRefTuple(ins...));
+}
+
+template <uint32_t Id, const char* Name, typename... Ins, typename... Outs>
+bool CommonSyncMessage<Id, Name, base::Tuple<Ins...>, base::Tuple<Outs...>>::
+ ReadSendParam(const Message* msg, SendParam* p) {
+ return Schema::ReadSendParam(msg, p);
+}
+
+template <uint32_t Id, const char* Name, typename... Ins, typename... Outs>
+bool CommonSyncMessage<Id, Name, base::Tuple<Ins...>, base::Tuple<Outs...>>::
+ ReadReplyParam(const Message* msg,
+ typename base::TupleTypes<ReplyParam>::ValueTuple* p) {
+ return Schema::ReadReplyParam(msg, p);
+}
+
+template <uint32_t Id, const char* Name, typename... Ins, typename... Outs>
+void CommonSyncMessage<Id, Name, base::Tuple<Ins...>, base::Tuple<Outs...>>::
+ Log(std::string* name, const Message* msg, std::string* l) {
+ if (name)
+ *name = Name;
+ if (!msg || !l)
+ return;
+ if (msg->is_sync()) {
+ typename base::TupleTypes<SendParam>::ValueTuple p;
+ if (Schema::ReadSendParam(msg, &p))
+ LogParam(p, l);
+ AddOutputParamsToLog(msg, l);
+ } else {
+ typename base::TupleTypes<ReplyParam>::ValueTuple p;
+ if (Schema::ReadReplyParam(msg, &p))
+ LogParam(p, l);
+ }
+}
+
+} // namespace IPC
+
+#endif // IPC_IPC_MESSAGE_TEMPLATES_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698