blob: 2cab6fb258b8bee137e835ab45f2bcbd6258cbee [file] [log] [blame]
[email protected]7de84042012-02-21 16:04:501// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]6476c72c2011-02-11 18:46:195// Defining IPC Messages
initial.commit09911bf2008-07-26 23:55:296//
[email protected]6476c72c2011-02-11 18:46:197// Your IPC messages will be defined by macros inside of an XXX_messages.h
8// header file. Most of the time, the system can automatically generate all
9// of messaging mechanism from these definitions, but sometimes some manual
10// coding is required. In these cases, you will also have an XXX_messages.cc
philipjb3b3f8e2015-08-12 08:30:0111// implementation file as well.
[email protected]6476c72c2011-02-11 18:46:1912//
13// The senders of your messages will include your XXX_messages.h file to
14// get the full set of definitions they need to send your messages.
15//
16// Each XXX_messages.h file must be registered with the IPC system. This
17// requires adding two things:
[email protected]f9509812012-10-23 23:03:3518// - An XXXMsgStart value to the IPCMessageStart enum in ipc_message_start.h
[email protected]6476c72c2011-02-11 18:46:1919// - An inclusion of XXX_messages.h file in a message generator .h file
20//
21// The XXXMsgStart value is an enumeration that ensures uniqueness for
22// each different message file. Later, you will use this inside your
[email protected]e86a2552011-11-11 00:21:0223// XXX_messages.h file before invoking message declaration macros:
[email protected]6476c72c2011-02-11 18:46:1924// #define IPC_MESSAGE_START XXXMsgStart
25// ( ... your macro invocations go here ... )
26//
27// Message Generator Files
28//
29// A message generator .h header file pulls in all other message-declaring
30// headers for a given component. It is included by a message generator
31// .cc file, which is where all the generated code will wind up. Typically,
[email protected]d7a5e3e2011-03-12 16:28:3632// you will use an existing generator (e.g. common_message_generator.cc
33// in /chrome/common), but there are circumstances where you may add a
34// new one.
[email protected]6476c72c2011-02-11 18:46:1935//
philipjb3b3f8e2015-08-12 08:30:0136// In the rare circumstances where you can't re-use an existing file,
[email protected]6476c72c2011-02-11 18:46:1937// your YYY_message_generator.cc file for a component YYY would contain
38// the following code:
39// // Get basic type definitions.
[email protected]21fa3a12010-12-08 23:34:1640// #define IPC_MESSAGE_IMPL
[email protected]6476c72c2011-02-11 18:46:1941// #include "path/to/YYY_message_generator.h"
42// // Generate constructors.
43// #include "ipc/struct_constructor_macros.h"
44// #include "path/to/YYY_message_generator.h"
45// // Generate destructors.
46// #include "ipc/struct_destructor_macros.h"
47// #include "path/to/YYY_message_generator.h"
[email protected]6476c72c2011-02-11 18:46:1948// // Generate param traits write methods.
49// #include "ipc/param_traits_write_macros.h"
[email protected]d7a5e3e2011-03-12 16:28:3650// namespace IPC {
[email protected]6476c72c2011-02-11 18:46:1951// #include "path/to/YYY_message_generator.h"
[email protected]d7a5e3e2011-03-12 16:28:3652// } // namespace IPC
[email protected]6476c72c2011-02-11 18:46:1953// // Generate param traits read methods.
54// #include "ipc/param_traits_read_macros.h"
[email protected]d7a5e3e2011-03-12 16:28:3655// namespace IPC {
[email protected]6476c72c2011-02-11 18:46:1956// #include "path/to/YYY_message_generator.h"
[email protected]d7a5e3e2011-03-12 16:28:3657// } // namespace IPC
[email protected]6476c72c2011-02-11 18:46:1958// // Generate param traits log methods.
59// #include "ipc/param_traits_log_macros.h"
[email protected]d7a5e3e2011-03-12 16:28:3660// namespace IPC {
[email protected]6476c72c2011-02-11 18:46:1961// #include "path/to/YYY_message_generator.h"
62// } // namespace IPC
initial.commit09911bf2008-07-26 23:55:2963//
[email protected]6476c72c2011-02-11 18:46:1964// In cases where manual generation is required, in your XXX_messages.cc
65// file, put the following after all the includes for param types:
66// #define IPC_MESSAGE_IMPL
67// #include "XXX_messages.h"
68// (... implementation of traits not auto-generated ...)
69//
70// Multiple Inclusion
71//
72// The XXX_messages.h file will be multiply-included by the
73// YYY_message_generator.cc file, so your XXX_messages file can't be
74// guarded in the usual manner. Ideally, there will be no need for any
philipjb3b3f8e2015-08-12 08:30:0175// inclusion guard, since the XXX_messages.h file should consist solely
[email protected]6476c72c2011-02-11 18:46:1976// of inclusions of other headers (which are self-guarding) and IPC
77// macros (which are multiply evaluating).
78//
[email protected]01c86ec2012-07-11 19:01:4379// Note that #pragma once cannot be used here; doing so would mark the whole
[email protected]6476c72c2011-02-11 18:46:1980// file as being singly-included. Since your XXX_messages.h file is only
81// partially-guarded, care must be taken to ensure that it is only included
82// by other .cc files (and the YYY_message_generator.h file). Including an
83// XXX_messages.h file in some other .h file may result in duplicate
84// declarations and a compilation failure.
85//
86// Type Declarations
87//
88// It is generally a bad idea to have type definitions in a XXX_messages.h
89// file; most likely the typedef will then be used in the message, as opposed
philipjb3b3f8e2015-08-12 08:30:0190// to the struct itself. Later, an IPC message dispatcher will need to call
[email protected]6476c72c2011-02-11 18:46:1991// a function taking that type, and that function is declared in some other
92// header. Thus, in order to get the type definition, the other header
93// would have to include the XXX_messages.h file, violating the rule above
94// about not including XXX_messages.h file in other .h files.
95//
96// One approach here is to move these type definitions to another (guarded)
97// .h file and include this second .h in your XXX_messages.h file. This
98// is still less than ideal, because the dispatched function would have to
99// redeclare the typedef or include this second header. This may be
100// reasonable in a few cases.
101//
102// Failing all of the above, then you will want to bracket the smallest
103// possible section of your XXX_messages.h file containing these types
104// with an include guard macro. Be aware that providing an incomplete
105// class type declaration to avoid pulling in a long chain of headers is
106// acceptable when your XXX_messages.h header is being included by the
107// message sending caller's code, but not when the YYY_message_generator.c
philipjb3b3f8e2015-08-12 08:30:01108// is building the messages. In addition, due to the multiple inclusion
[email protected]6476c72c2011-02-11 18:46:19109// restriction, these type ought to be guarded. Follow a convention like:
110// #ifndef SOME_GUARD_MACRO
111// #define SOME_GUARD_MACRO
112// class some_class; // One incomplete class declaration
113// class_some_other_class; // Another incomplete class declaration
114// #endif // SOME_GUARD_MACRO
115// #ifdef IPC_MESSAGE_IMPL
[email protected]c13849c2014-06-18 17:32:42116// #include "path/to/some_class.h" // Full class declaration
117// #include "path/to/some_other_class.h" // Full class declaration
[email protected]6476c72c2011-02-11 18:46:19118// #endif // IPC_MESSAGE_IMPL
119// (.. IPC macros using some_class and some_other_class ...)
120//
121// Macro Invocations
122//
123// You will use IPC message macro invocations for three things:
124// - New struct definitions for IPC
125// - Registering existing struct and enum definitions with IPC
126// - Defining the messages themselves
127//
128// New structs are defined with IPC_STRUCT_BEGIN(), IPC_STRUCT_MEMBER(),
129// IPC_STRUCT_END() family of macros. These cause the XXX_messages.h
130// to proclaim equivalent struct declarations for use by callers, as well
131// as later registering the type with the message generation. Note that
132// IPC_STRUCT_MEMBER() is only permitted inside matching calls to
[email protected]dedd0a92013-06-04 07:20:32133// IPC_STRUCT_BEGIN() / IPC_STRUCT_END(). There is also an
134// IPC_STRUCT_BEGIN_WITH_PARENT(), which behaves like IPC_STRUCT_BEGIN(),
philipjb3b3f8e2015-08-12 08:30:01135// but also accommodates structs that inherit from other structs.
[email protected]6476c72c2011-02-11 18:46:19136//
137// Externally-defined structs are registered with IPC_STRUCT_TRAITS_BEGIN(),
138// IPC_STRUCT_TRAITS_MEMBER(), and IPC_STRUCT_TRAITS_END() macros. These
[email protected]94dc971d2011-03-05 19:08:32139// cause registration of the types with message generation only.
140// There's also IPC_STRUCT_TRAITS_PARENT, which is used to register a parent
141// class (whose own traits are already defined). Note that
142// IPC_STRUCT_TRAITS_MEMBER() and IPC_STRUCT_TRAITS_PARENT are only permitted
[email protected]e503a122011-03-17 18:20:52143// inside matching calls to IPC_STRUCT_TRAITS_BEGIN() /
144// IPC_STRUCT_TRAITS_END().
[email protected]6476c72c2011-02-11 18:46:19145//
[email protected]dedd0a92013-06-04 07:20:32146// Enum types are registered with a single IPC_ENUM_TRAITS_VALIDATE() macro.
147// There is no need to enumerate each value to the IPC mechanism. Instead,
148// pass an expression in terms of the parameter |value| to provide
149// range-checking. For convenience, the IPC_ENUM_TRAITS() is provided which
150// performs no checking, passing everything including out-of-range values.
151// Its use is discouraged. The IPC_ENUM_TRAITS_MAX_VALUE() macro can be used
152// for the typical case where the enum must be in the range 0..maxvalue
153// inclusive. The IPC_ENUM_TRAITS_MIN_MAX_VALUE() macro can be used for the
154// less typical case where the enum must be in the range minvalue..maxvalue
155// inclusive.
[email protected]6476c72c2011-02-11 18:46:19156//
[email protected]e503a122011-03-17 18:20:52157// Do not place semicolons following these IPC_ macro invocations. There
158// is no reason to expect that their expansion corresponds one-to-one with
159// C++ statements.
160//
[email protected]6476c72c2011-02-11 18:46:19161// Once the types have been declared / registered, message definitions follow.
initial.commit09911bf2008-07-26 23:55:29162// "Sync" messages are just synchronous calls, the Send() call doesn't return
[email protected]7f994182011-08-23 10:18:10163// until a reply comes back. To declare a sync message, use the IPC_SYNC_
164// macros. The numbers at the end show how many input/output parameters there
165// are (i.e. 1_2 is 1 in, 2 out). Input parameters are first, followed by
166// output parameters. The caller uses Send([route id, ], in1, &out1, &out2).
initial.commit09911bf2008-07-26 23:55:29167// The receiver's handler function will be
168// void OnSyncMessageName(const type1& in1, type2* out1, type3* out2)
169//
initial.commit09911bf2008-07-26 23:55:29170// A caller can also send a synchronous message, while the receiver can respond
[email protected]d4240352009-12-10 17:32:31171// at a later time. This is transparent from the sender's side. The receiver
initial.commit09911bf2008-07-26 23:55:29172// needs to use a different handler that takes in a IPC::Message* as the output
173// type, stash the message, and when it has the data it can Send the message.
174//
175// Use the IPC_MESSAGE_HANDLER_DELAY_REPLY macro instead of IPC_MESSAGE_HANDLER
[email protected]d3216442009-03-05 21:07:27176// IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncMessageName,
177// OnSyncMessageName)
thestigcb959ce2016-11-17 05:56:32178// Unlike IPC_MESSAGE_HANDLER which works with IPC_BEGIN_MESSAGE_MAP as well as
179// IPC_BEGIN_MESSAGE_MAP_WITH_PARAM, one needs to use
180// IPC_MESSAGE_HANDLER_WITH_PARAM_DELAY_REPLY to properly handle the param.
initial.commit09911bf2008-07-26 23:55:29181//
182// The handler function will look like:
183// void OnSyncMessageName(const type1& in1, IPC::Message* reply_msg);
184//
185// Receiver stashes the IPC::Message* pointer, and when it's ready, it does:
186// ViewHostMsg_SyncMessageName::WriteReplyParams(reply_msg, out1, out2);
187// Send(reply_msg);
188
[email protected]7de84042012-02-21 16:04:50189// Files that want to export their ipc messages should do
190// #undef IPC_MESSAGE_EXPORT
191// #define IPC_MESSAGE_EXPORT VISIBILITY_MACRO
192// after including this header, but before using any of the macros below.
193// (This needs to be before the include guard.)
194#undef IPC_MESSAGE_EXPORT
195#define IPC_MESSAGE_EXPORT
196
[email protected]6476c72c2011-02-11 18:46:19197#ifndef IPC_IPC_MESSAGE_MACROS_H_
198#define IPC_IPC_MESSAGE_MACROS_H_
[email protected]82e5ee82009-04-03 02:29:45199
tfarina10a5c062015-09-04 18:47:57200#include <stdint.h>
201
tzik55e3e4d2016-03-08 05:47:44202#include <tuple>
203
Mounir Lamouri130ad752017-10-13 17:07:15204#include "base/export_template.h"
mdempsky8a519042016-02-09 05:41:47205#include "ipc/ipc_message_templates.h"
[email protected]6476c72c2011-02-11 18:46:19206#include "ipc/ipc_message_utils.h"
207#include "ipc/param_traits_macros.h"
[email protected]f91cb992009-02-04 20:10:12208
[email protected]600cdb7c2013-11-05 04:24:58209// Convenience macro for defining structs without inheritance. Should not need
[email protected]dedd0a92013-06-04 07:20:32210// to be subsequently redefined.
[email protected]8a8c9c72011-03-01 20:35:47211#define IPC_STRUCT_BEGIN(struct_name) \
[email protected]6766b172011-11-21 18:29:36212 IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, IPC::NoParams)
[email protected]dedd0a92013-06-04 07:20:32213
214// Macros for defining structs. Will be subsequently redefined.
[email protected]6766b172011-11-21 18:29:36215#define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \
[email protected]8a8c9c72011-03-01 20:35:47216 struct struct_name; \
217 IPC_STRUCT_TRAITS_BEGIN(struct_name) \
218 IPC_STRUCT_TRAITS_END() \
[email protected]6766b172011-11-21 18:29:36219 struct IPC_MESSAGE_EXPORT struct_name : parent { \
[email protected]8a8c9c72011-03-01 20:35:47220 struct_name(); \
221 ~struct_name();
[email protected]01cca0042012-04-16 19:13:02222// Optional variadic parameters specify the default value for this struct
223// member. They are passed through to the constructor for |type|.
224#define IPC_STRUCT_MEMBER(type, name, ...) type name;
[email protected]8a8c9c72011-03-01 20:35:47225#define IPC_STRUCT_END() };
226
mdempsky8a519042016-02-09 05:41:47227// Message macros collect arguments and funnel them into the common message
228// generation macro. These should never be redefined.
[email protected]8a8c9c72011-03-01 20:35:47229
mdempsky8a519042016-02-09 05:41:47230// Asynchronous messages have only in parameters and are declared like:
231// IPC_MESSAGE_CONTROL(FooMsg, int, float)
232#define IPC_MESSAGE_CONTROL(msg_class, ...) \
233 IPC_MESSAGE_DECL(msg_class, CONTROL, IPC_TUPLE(__VA_ARGS__), void)
234#define IPC_MESSAGE_ROUTED(msg_class, ...) \
235 IPC_MESSAGE_DECL(msg_class, ROUTED, IPC_TUPLE(__VA_ARGS__), void)
[email protected]8a8c9c72011-03-01 20:35:47236
mdempsky8a519042016-02-09 05:41:47237// Synchronous messages have both in and out parameters, so the lists need to
238// be parenthesized to disambiguate:
239// IPC_SYNC_MESSAGE_CONTROL(BarMsg, (int, int), (bool))
240//
241// Implementation detail: The parentheses supplied by the caller for
242// disambiguation are also used to trigger the IPC_TUPLE invocations below,
243// so "IPC_TUPLE in" and "IPC_TUPLE out" are intentional.
244#define IPC_SYNC_MESSAGE_CONTROL(msg_class, in, out) \
245 IPC_MESSAGE_DECL(msg_class, CONTROL, IPC_TUPLE in, IPC_TUPLE out)
246#define IPC_SYNC_MESSAGE_ROUTED(msg_class, in, out) \
247 IPC_MESSAGE_DECL(msg_class, ROUTED, IPC_TUPLE in, IPC_TUPLE out)
[email protected]8a8c9c72011-03-01 20:35:47248
dskiba2bc89462016-04-06 15:51:06249#define IPC_TUPLE(...) IPC::CheckedTuple<__VA_ARGS__>::Tuple
[email protected]8a8c9c72011-03-01 20:35:47250
mdempsky8a519042016-02-09 05:41:47251#define IPC_MESSAGE_DECL(msg_name, kind, in_tuple, out_tuple) \
252 struct IPC_MESSAGE_EXPORT msg_name##_Meta { \
253 using InTuple = in_tuple; \
254 using OutTuple = out_tuple; \
255 enum { ID = IPC_MESSAGE_ID() }; \
256 static const IPC::MessageKind kKind = IPC::MessageKind::kind; \
257 static const char kName[]; \
258 }; \
259 extern template class EXPORT_TEMPLATE_DECLARE(IPC_MESSAGE_EXPORT) \
260 IPC::MessageT<msg_name##_Meta>; \
261 using msg_name = IPC::MessageT<msg_name##_Meta>; \
262 IPC_MESSAGE_EXTRA(msg_name)
[email protected]8a8c9c72011-03-01 20:35:47263
264#if defined(IPC_MESSAGE_IMPL)
265
mdempsky8a519042016-02-09 05:41:47266// "Implementation" inclusion provides the explicit template definition
267// for msg_name.
268#define IPC_MESSAGE_EXTRA(msg_name) \
269 const char msg_name##_Meta::kName[] = #msg_name; \
270 IPC_MESSAGE_DEFINE_KIND(msg_name) \
271 template class EXPORT_TEMPLATE_DEFINE(IPC_MESSAGE_EXPORT) \
272 IPC::MessageT<msg_name##_Meta>;
[email protected]8a8c9c72011-03-01 20:35:47273
mdempsky8a519042016-02-09 05:41:47274// MSVC has an intentionally non-compliant "feature" that results in LNK2005
275// ("symbol already defined") errors if we provide an out-of-line definition
276// for kKind. Microsoft's official response is to test for _MSC_EXTENSIONS:
277// https://connect.microsoft.com/VisualStudio/feedback/details/786583/
278#if defined(_MSC_EXTENSIONS)
279#define IPC_MESSAGE_DEFINE_KIND(msg_name)
280#else
281#define IPC_MESSAGE_DEFINE_KIND(msg_name) \
282 const IPC::MessageKind msg_name##_Meta::kKind;
283#endif
[email protected]8a8c9c72011-03-01 20:35:47284
[email protected]21fa3a12010-12-08 23:34:16285#elif defined(IPC_MESSAGE_MACROS_LOG_ENABLED)
[email protected]f91cb992009-02-04 20:10:12286
[email protected]4f68ed72012-10-30 05:24:07287#ifndef IPC_LOG_TABLE_ADD_ENTRY
288#error You need to define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger)
289#endif
[email protected]f91cb992009-02-04 20:10:12290
[email protected]8a8c9c72011-03-01 20:35:47291// "Log table" inclusion produces extra logging registration code.
mdempsky8a519042016-02-09 05:41:47292#define IPC_MESSAGE_EXTRA(msg_name) \
293 class LoggerRegisterHelper##msg_name { \
294 public: \
295 LoggerRegisterHelper##msg_name() { \
296 const uint32_t msg_id = static_cast<uint32_t>(msg_name::ID); \
297 IPC_LOG_TABLE_ADD_ENTRY(msg_id, msg_name::Log); \
298 } \
299 }; \
300 LoggerRegisterHelper##msg_name g_LoggerRegisterHelper##msg_name;
[email protected]f91cb992009-02-04 20:10:12301
[email protected]8a8c9c72011-03-01 20:35:47302#else
initial.commit09911bf2008-07-26 23:55:29303
[email protected]8a8c9c72011-03-01 20:35:47304// Normal inclusion produces nothing extra.
mdempsky8a519042016-02-09 05:41:47305#define IPC_MESSAGE_EXTRA(msg_name)
initial.commit09911bf2008-07-26 23:55:29306
mdempsky8a519042016-02-09 05:41:47307#endif // defined(IPC_MESSAGE_IMPL)
[email protected]6d8ffc9f2010-03-12 18:27:53308
[email protected]d7a5e3e2011-03-12 16:28:36309// Message IDs
310// Note: we currently use __LINE__ to give unique IDs to messages within
311// a file. They're globally unique since each file defines its own
[email protected]3b3ec7212011-10-21 17:35:08312// IPC_MESSAGE_START.
[email protected]d7a5e3e2011-03-12 16:28:36313#define IPC_MESSAGE_ID() ((IPC_MESSAGE_START << 16) + __LINE__)
314#define IPC_MESSAGE_ID_CLASS(id) ((id) >> 16)
315#define IPC_MESSAGE_ID_LINE(id) ((id) & 0xffff)
316
[email protected]e44d1342014-05-16 21:29:33317// Message crackers and handlers. Usage:
initial.commit09911bf2008-07-26 23:55:29318//
[email protected]a95986a82010-12-24 06:19:28319// bool MyClass::OnMessageReceived(const IPC::Message& msg) {
320// bool handled = true;
[email protected]e44d1342014-05-16 21:29:33321// IPC_BEGIN_MESSAGE_MAP(MyClass, msg)
initial.commit09911bf2008-07-26 23:55:29322// IPC_MESSAGE_HANDLER(MsgClassOne, OnMsgClassOne)
323// ...more handlers here ...
324// IPC_MESSAGE_HANDLER(MsgClassTen, OnMsgClassTen)
[email protected]a95986a82010-12-24 06:19:28325// IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33326// IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28327// return handled;
initial.commit09911bf2008-07-26 23:55:29328// }
329
[email protected]21fa3a12010-12-08 23:34:16330
initial.commit09911bf2008-07-26 23:55:29331#define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \
332 { \
pkasting99867ef2014-10-16 23:49:24333 typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED_TYPE; \
[email protected]9d77dd4122014-05-14 21:43:59334 void* param__ = NULL; \
sunnypsb3c862b2016-02-05 01:55:08335 (void)param__; \
initial.commit09911bf2008-07-26 23:55:29336 const IPC::Message& ipc_message__ = msg; \
[email protected]9d77dd4122014-05-14 21:43:59337 switch (ipc_message__.type()) {
initial.commit09911bf2008-07-26 23:55:29338
pkasting99867ef2014-10-16 23:49:24339#define IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(class_name, msg, param) \
340 { \
341 typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED_TYPE; \
thakise6e95d92014-10-29 22:04:47342 decltype(param) param__ = param; \
pkasting99867ef2014-10-16 23:49:24343 const IPC::Message& ipc_message__ = msg; \
[email protected]9d77dd4122014-05-14 21:43:59344 switch (ipc_message__.type()) {
[email protected]5636d902014-05-13 23:19:10345
[email protected]e86a2552011-11-11 00:21:02346#define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \
347 case msg_class::ID: { \
[email protected]e44d1342014-05-16 21:29:33348 if (!msg_class::Dispatch(&ipc_message__, obj, this, param__, \
349 &member_func)) \
[email protected]ef2f6ba2014-05-15 23:06:07350 ipc_message__.set_dispatch_error(); \
[email protected]e86a2552011-11-11 00:21:02351 } \
352 break;
initial.commit09911bf2008-07-26 23:55:29353
354#define IPC_MESSAGE_HANDLER(msg_class, member_func) \
355 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func)
356
[email protected]e86a2552011-11-11 00:21:02357#define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \
358 case msg_class::ID: { \
[email protected]e44d1342014-05-16 21:29:33359 if (!msg_class::DispatchDelayReply(&ipc_message__, obj, param__, \
360 &member_func)) \
[email protected]ef2f6ba2014-05-15 23:06:07361 ipc_message__.set_dispatch_error(); \
[email protected]e86a2552011-11-11 00:21:02362 } \
363 break;
initial.commit09911bf2008-07-26 23:55:29364
[email protected]e86a2552011-11-11 00:21:02365#define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \
366 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \
367 _IpcMessageHandlerClass::member_func)
initial.commit09911bf2008-07-26 23:55:29368
thestigcb959ce2016-11-17 05:56:32369#define IPC_MESSAGE_FORWARD_WITH_PARAM_DELAY_REPLY(msg_class, obj, \
370 member_func) \
371 case msg_class::ID: { \
thestigcb959ce2016-11-17 05:56:32372 if (!msg_class::DispatchWithParamDelayReply(&ipc_message__, obj, param__, \
373 &member_func)) \
374 ipc_message__.set_dispatch_error(); \
375 } \
376 break;
377
378#define IPC_MESSAGE_HANDLER_WITH_PARAM_DELAY_REPLY(msg_class, member_func) \
379 IPC_MESSAGE_FORWARD_WITH_PARAM_DELAY_REPLY( \
380 msg_class, this, _IpcMessageHandlerClass::member_func)
381
[email protected]e86a2552011-11-11 00:21:02382#define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \
383 case msg_class::ID: { \
[email protected]e86a2552011-11-11 00:21:02384 code; \
385 } \
386 break;
initial.commit09911bf2008-07-26 23:55:29387
[email protected]e86a2552011-11-11 00:21:02388#define IPC_REPLY_HANDLER(func) \
389 case IPC_REPLY_ID: { \
[email protected]e86a2552011-11-11 00:21:02390 func(ipc_message__); \
391 } \
392 break;
initial.commit09911bf2008-07-26 23:55:29393
394
[email protected]e86a2552011-11-11 00:21:02395#define IPC_MESSAGE_UNHANDLED(code) \
396 default: { \
[email protected]e86a2552011-11-11 00:21:02397 code; \
398 } \
399 break;
initial.commit09911bf2008-07-26 23:55:29400
401#define IPC_MESSAGE_UNHANDLED_ERROR() \
402 IPC_MESSAGE_UNHANDLED(NOTREACHED() << \
403 "Invalid message with type = " << \
404 ipc_message__.type())
405
406#define IPC_END_MESSAGE_MAP() \
initial.commit09911bf2008-07-26 23:55:29407 } \
[email protected]8d70d5f2010-12-08 23:41:08408}
[email protected]9f547bf2010-12-13 17:00:42409
410// This corresponds to an enum value from IPCMessageStart.
lfgdb5c4ed2016-03-04 23:09:07411#define IPC_MESSAGE_CLASS(message) IPC_MESSAGE_ID_CLASS((message).type())
[email protected]6476c72c2011-02-11 18:46:19412
mdempsky8a519042016-02-09 05:41:47413// Deprecated legacy macro names.
414// TODO(mdempsky): Replace uses with generic names.
415
416#define IPC_MESSAGE_CONTROL0(msg) IPC_MESSAGE_CONTROL(msg)
417#define IPC_MESSAGE_CONTROL1(msg, a) IPC_MESSAGE_CONTROL(msg, a)
418#define IPC_MESSAGE_CONTROL2(msg, a, b) IPC_MESSAGE_CONTROL(msg, a, b)
419#define IPC_MESSAGE_CONTROL3(msg, a, b, c) IPC_MESSAGE_CONTROL(msg, a, b, c)
420#define IPC_MESSAGE_CONTROL4(msg, a, b, c, d) \
421 IPC_MESSAGE_CONTROL(msg, a, b, c, d)
422#define IPC_MESSAGE_CONTROL5(msg, a, b, c, d, e) \
423 IPC_MESSAGE_CONTROL(msg, a, b, c, d, e)
424
425#define IPC_MESSAGE_ROUTED0(msg) IPC_MESSAGE_ROUTED(msg)
426#define IPC_MESSAGE_ROUTED1(msg, a) IPC_MESSAGE_ROUTED(msg, a)
427#define IPC_MESSAGE_ROUTED2(msg, a, b) IPC_MESSAGE_ROUTED(msg, a, b)
428#define IPC_MESSAGE_ROUTED3(msg, a, b, c) IPC_MESSAGE_ROUTED(msg, a, b, c)
429#define IPC_MESSAGE_ROUTED4(msg, a, b, c, d) IPC_MESSAGE_ROUTED(msg, a, b, c, d)
430#define IPC_MESSAGE_ROUTED5(msg, a, b, c, d, e) \
431 IPC_MESSAGE_ROUTED(msg, a, b, c, d, e)
432
433#define IPC_SYNC_MESSAGE_CONTROL0_0(msg) IPC_SYNC_MESSAGE_CONTROL(msg, (), ())
434#define IPC_SYNC_MESSAGE_CONTROL0_1(msg, a) \
435 IPC_SYNC_MESSAGE_CONTROL(msg, (), (a))
436#define IPC_SYNC_MESSAGE_CONTROL0_2(msg, a, b) \
437 IPC_SYNC_MESSAGE_CONTROL(msg, (), (a, b))
438#define IPC_SYNC_MESSAGE_CONTROL0_3(msg, a, b, c) \
439 IPC_SYNC_MESSAGE_CONTROL(msg, (), (a, b, c))
440#define IPC_SYNC_MESSAGE_CONTROL0_4(msg, a, b, c, d) \
441 IPC_SYNC_MESSAGE_CONTROL(msg, (), (a, b, c, d))
442#define IPC_SYNC_MESSAGE_CONTROL1_0(msg, a) \
443 IPC_SYNC_MESSAGE_CONTROL(msg, (a), ())
444#define IPC_SYNC_MESSAGE_CONTROL1_1(msg, a, b) \
445 IPC_SYNC_MESSAGE_CONTROL(msg, (a), (b))
446#define IPC_SYNC_MESSAGE_CONTROL1_2(msg, a, b, c) \
447 IPC_SYNC_MESSAGE_CONTROL(msg, (a), (b, c))
448#define IPC_SYNC_MESSAGE_CONTROL1_3(msg, a, b, c, d) \
449 IPC_SYNC_MESSAGE_CONTROL(msg, (a), (b, c, d))
450#define IPC_SYNC_MESSAGE_CONTROL1_4(msg, a, b, c, d, e) \
451 IPC_SYNC_MESSAGE_CONTROL(msg, (a), (b, c, d, e))
452#define IPC_SYNC_MESSAGE_CONTROL2_0(msg, a, b) \
453 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b), ())
454#define IPC_SYNC_MESSAGE_CONTROL2_1(msg, a, b, c) \
455 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b), (c))
456#define IPC_SYNC_MESSAGE_CONTROL2_2(msg, a, b, c, d) \
457 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b), (c, d))
458#define IPC_SYNC_MESSAGE_CONTROL2_3(msg, a, b, c, d, e) \
459 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b), (c, d, e))
460#define IPC_SYNC_MESSAGE_CONTROL2_4(msg, a, b, c, d, e, f) \
461 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b), (c, d, e, f))
462#define IPC_SYNC_MESSAGE_CONTROL3_0(msg, a, b, c) \
463 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c), ())
464#define IPC_SYNC_MESSAGE_CONTROL3_1(msg, a, b, c, d) \
465 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c), (d))
466#define IPC_SYNC_MESSAGE_CONTROL3_2(msg, a, b, c, d, e) \
467 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c), (d, e))
468#define IPC_SYNC_MESSAGE_CONTROL3_3(msg, a, b, c, d, e, f) \
469 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c), (d, e, f))
470#define IPC_SYNC_MESSAGE_CONTROL3_4(msg, a, b, c, d, e, f, g) \
471 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c), (d, e, f, g))
472#define IPC_SYNC_MESSAGE_CONTROL4_0(msg, a, b, c, d) \
473 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d), ())
474#define IPC_SYNC_MESSAGE_CONTROL4_1(msg, a, b, c, d, e) \
475 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d), (e))
476#define IPC_SYNC_MESSAGE_CONTROL4_2(msg, a, b, c, d, e, f) \
477 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d), (e, f))
478#define IPC_SYNC_MESSAGE_CONTROL4_3(msg, a, b, c, d, e, f, g) \
479 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d), (e, f, g))
480#define IPC_SYNC_MESSAGE_CONTROL4_4(msg, a, b, c, d, e, f, g, h) \
481 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d), (e, f, g, h))
482#define IPC_SYNC_MESSAGE_CONTROL5_0(msg, a, b, c, d, e) \
483 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d, e), ())
484#define IPC_SYNC_MESSAGE_CONTROL5_1(msg, a, b, c, d, e, f) \
485 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d, e), (f))
486#define IPC_SYNC_MESSAGE_CONTROL5_2(msg, a, b, c, d, e, f, g) \
487 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d, e), (f, g))
488#define IPC_SYNC_MESSAGE_CONTROL5_3(msg, a, b, c, d, e, f, g, h) \
489 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d, e), (f, g, h))
490#define IPC_SYNC_MESSAGE_CONTROL5_4(msg, a, b, c, d, e, f, g, h, i) \
491 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d, e), (f, g, h, i))
492
493#define IPC_SYNC_MESSAGE_ROUTED0_0(msg) IPC_SYNC_MESSAGE_ROUTED(msg, (), ())
494#define IPC_SYNC_MESSAGE_ROUTED0_1(msg, a) IPC_SYNC_MESSAGE_ROUTED(msg, (), (a))
495#define IPC_SYNC_MESSAGE_ROUTED0_2(msg, a, b) \
496 IPC_SYNC_MESSAGE_ROUTED(msg, (), (a, b))
497#define IPC_SYNC_MESSAGE_ROUTED0_3(msg, a, b, c) \
498 IPC_SYNC_MESSAGE_ROUTED(msg, (), (a, b, c))
499#define IPC_SYNC_MESSAGE_ROUTED0_4(msg, a, b, c, d) \
500 IPC_SYNC_MESSAGE_ROUTED(msg, (), (a, b, c, d))
501#define IPC_SYNC_MESSAGE_ROUTED1_0(msg, a) IPC_SYNC_MESSAGE_ROUTED(msg, (a), ())
502#define IPC_SYNC_MESSAGE_ROUTED1_1(msg, a, b) \
503 IPC_SYNC_MESSAGE_ROUTED(msg, (a), (b))
504#define IPC_SYNC_MESSAGE_ROUTED1_2(msg, a, b, c) \
505 IPC_SYNC_MESSAGE_ROUTED(msg, (a), (b, c))
506#define IPC_SYNC_MESSAGE_ROUTED1_3(msg, a, b, c, d) \
507 IPC_SYNC_MESSAGE_ROUTED(msg, (a), (b, c, d))
508#define IPC_SYNC_MESSAGE_ROUTED1_4(msg, a, b, c, d, e) \
509 IPC_SYNC_MESSAGE_ROUTED(msg, (a), (b, c, d, e))
510#define IPC_SYNC_MESSAGE_ROUTED2_0(msg, a, b) \
511 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b), ())
512#define IPC_SYNC_MESSAGE_ROUTED2_1(msg, a, b, c) \
513 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b), (c))
514#define IPC_SYNC_MESSAGE_ROUTED2_2(msg, a, b, c, d) \
515 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b), (c, d))
516#define IPC_SYNC_MESSAGE_ROUTED2_3(msg, a, b, c, d, e) \
517 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b), (c, d, e))
518#define IPC_SYNC_MESSAGE_ROUTED2_4(msg, a, b, c, d, e, f) \
519 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b), (c, d, e, f))
520#define IPC_SYNC_MESSAGE_ROUTED3_0(msg, a, b, c) \
521 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c), ())
522#define IPC_SYNC_MESSAGE_ROUTED3_1(msg, a, b, c, d) \
523 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c), (d))
524#define IPC_SYNC_MESSAGE_ROUTED3_2(msg, a, b, c, d, e) \
525 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c), (d, e))
526#define IPC_SYNC_MESSAGE_ROUTED3_3(msg, a, b, c, d, e, f) \
527 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c), (d, e, f))
528#define IPC_SYNC_MESSAGE_ROUTED3_4(msg, a, b, c, d, e, f, g) \
529 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c), (d, e, f, g))
530#define IPC_SYNC_MESSAGE_ROUTED4_0(msg, a, b, c, d) \
531 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d), ())
532#define IPC_SYNC_MESSAGE_ROUTED4_1(msg, a, b, c, d, e) \
533 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d), (e))
534#define IPC_SYNC_MESSAGE_ROUTED4_2(msg, a, b, c, d, e, f) \
535 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d), (e, f))
536#define IPC_SYNC_MESSAGE_ROUTED4_3(msg, a, b, c, d, e, f, g) \
537 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d), (e, f, g))
538#define IPC_SYNC_MESSAGE_ROUTED4_4(msg, a, b, c, d, e, f, g, h) \
539 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d), (e, f, g, h))
540#define IPC_SYNC_MESSAGE_ROUTED5_0(msg, a, b, c, d, e) \
541 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d, e), ())
542#define IPC_SYNC_MESSAGE_ROUTED5_1(msg, a, b, c, d, e, f) \
543 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d, e), (f))
544#define IPC_SYNC_MESSAGE_ROUTED5_2(msg, a, b, c, d, e, f, g) \
545 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d, e), (f, g))
546#define IPC_SYNC_MESSAGE_ROUTED5_3(msg, a, b, c, d, e, f, g, h) \
547 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d, e), (f, g, h))
548#define IPC_SYNC_MESSAGE_ROUTED5_4(msg, a, b, c, d, e, f, g, h, i) \
549 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d, e), (f, g, h, i))
550
[email protected]6476c72c2011-02-11 18:46:19551#endif // IPC_IPC_MESSAGE_MACROS_H_
552
553// Clean up IPC_MESSAGE_START in this unguarded section so that the
554// XXX_messages.h files need not do so themselves. This makes the
555// XXX_messages.h files easier to write.
556#undef IPC_MESSAGE_START