blob: e0e256ec605c649573380a1a388d376841e10a21 [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"
[email protected]6476c72c2011-02-11 18:46:1945// // Generate param traits write methods.
46// #include "ipc/param_traits_write_macros.h"
[email protected]d7a5e3e2011-03-12 16:28:3647// namespace IPC {
[email protected]6476c72c2011-02-11 18:46:1948// #include "path/to/YYY_message_generator.h"
[email protected]d7a5e3e2011-03-12 16:28:3649// } // namespace IPC
[email protected]6476c72c2011-02-11 18:46:1950// // Generate param traits read methods.
51// #include "ipc/param_traits_read_macros.h"
[email protected]d7a5e3e2011-03-12 16:28:3652// namespace IPC {
[email protected]6476c72c2011-02-11 18:46:1953// #include "path/to/YYY_message_generator.h"
[email protected]d7a5e3e2011-03-12 16:28:3654// } // namespace IPC
[email protected]6476c72c2011-02-11 18:46:1955// // Generate param traits log methods.
56// #include "ipc/param_traits_log_macros.h"
[email protected]d7a5e3e2011-03-12 16:28:3657// namespace IPC {
[email protected]6476c72c2011-02-11 18:46:1958// #include "path/to/YYY_message_generator.h"
59// } // namespace IPC
initial.commit09911bf2008-07-26 23:55:2960//
[email protected]6476c72c2011-02-11 18:46:1961// In cases where manual generation is required, in your XXX_messages.cc
62// file, put the following after all the includes for param types:
63// #define IPC_MESSAGE_IMPL
64// #include "XXX_messages.h"
65// (... implementation of traits not auto-generated ...)
66//
67// Multiple Inclusion
68//
69// The XXX_messages.h file will be multiply-included by the
70// YYY_message_generator.cc file, so your XXX_messages file can't be
71// guarded in the usual manner. Ideally, there will be no need for any
philipjb3b3f8e2015-08-12 08:30:0172// inclusion guard, since the XXX_messages.h file should consist solely
[email protected]6476c72c2011-02-11 18:46:1973// of inclusions of other headers (which are self-guarding) and IPC
74// macros (which are multiply evaluating).
75//
[email protected]01c86ec2012-07-11 19:01:4376// Note that #pragma once cannot be used here; doing so would mark the whole
[email protected]6476c72c2011-02-11 18:46:1977// file as being singly-included. Since your XXX_messages.h file is only
78// partially-guarded, care must be taken to ensure that it is only included
79// by other .cc files (and the YYY_message_generator.h file). Including an
80// XXX_messages.h file in some other .h file may result in duplicate
81// declarations and a compilation failure.
82//
83// Type Declarations
84//
85// It is generally a bad idea to have type definitions in a XXX_messages.h
86// file; most likely the typedef will then be used in the message, as opposed
philipjb3b3f8e2015-08-12 08:30:0187// to the struct itself. Later, an IPC message dispatcher will need to call
[email protected]6476c72c2011-02-11 18:46:1988// a function taking that type, and that function is declared in some other
89// header. Thus, in order to get the type definition, the other header
90// would have to include the XXX_messages.h file, violating the rule above
91// about not including XXX_messages.h file in other .h files.
92//
93// One approach here is to move these type definitions to another (guarded)
94// .h file and include this second .h in your XXX_messages.h file. This
95// is still less than ideal, because the dispatched function would have to
96// redeclare the typedef or include this second header. This may be
97// reasonable in a few cases.
98//
99// Failing all of the above, then you will want to bracket the smallest
100// possible section of your XXX_messages.h file containing these types
101// with an include guard macro. Be aware that providing an incomplete
102// class type declaration to avoid pulling in a long chain of headers is
103// acceptable when your XXX_messages.h header is being included by the
104// message sending caller's code, but not when the YYY_message_generator.c
philipjb3b3f8e2015-08-12 08:30:01105// is building the messages. In addition, due to the multiple inclusion
[email protected]6476c72c2011-02-11 18:46:19106// restriction, these type ought to be guarded. Follow a convention like:
107// #ifndef SOME_GUARD_MACRO
108// #define SOME_GUARD_MACRO
109// class some_class; // One incomplete class declaration
110// class_some_other_class; // Another incomplete class declaration
111// #endif // SOME_GUARD_MACRO
112// #ifdef IPC_MESSAGE_IMPL
[email protected]c13849c2014-06-18 17:32:42113// #include "path/to/some_class.h" // Full class declaration
114// #include "path/to/some_other_class.h" // Full class declaration
[email protected]6476c72c2011-02-11 18:46:19115// #endif // IPC_MESSAGE_IMPL
116// (.. IPC macros using some_class and some_other_class ...)
117//
118// Macro Invocations
119//
120// You will use IPC message macro invocations for three things:
121// - New struct definitions for IPC
122// - Registering existing struct and enum definitions with IPC
123// - Defining the messages themselves
124//
125// New structs are defined with IPC_STRUCT_BEGIN(), IPC_STRUCT_MEMBER(),
126// IPC_STRUCT_END() family of macros. These cause the XXX_messages.h
127// to proclaim equivalent struct declarations for use by callers, as well
128// as later registering the type with the message generation. Note that
129// IPC_STRUCT_MEMBER() is only permitted inside matching calls to
[email protected]dedd0a92013-06-04 07:20:32130// IPC_STRUCT_BEGIN() / IPC_STRUCT_END(). There is also an
131// IPC_STRUCT_BEGIN_WITH_PARENT(), which behaves like IPC_STRUCT_BEGIN(),
philipjb3b3f8e2015-08-12 08:30:01132// but also accommodates structs that inherit from other structs.
[email protected]6476c72c2011-02-11 18:46:19133//
134// Externally-defined structs are registered with IPC_STRUCT_TRAITS_BEGIN(),
135// IPC_STRUCT_TRAITS_MEMBER(), and IPC_STRUCT_TRAITS_END() macros. These
[email protected]94dc971d2011-03-05 19:08:32136// cause registration of the types with message generation only.
137// There's also IPC_STRUCT_TRAITS_PARENT, which is used to register a parent
138// class (whose own traits are already defined). Note that
139// IPC_STRUCT_TRAITS_MEMBER() and IPC_STRUCT_TRAITS_PARENT are only permitted
[email protected]e503a122011-03-17 18:20:52140// inside matching calls to IPC_STRUCT_TRAITS_BEGIN() /
141// IPC_STRUCT_TRAITS_END().
[email protected]6476c72c2011-02-11 18:46:19142//
[email protected]dedd0a92013-06-04 07:20:32143// Enum types are registered with a single IPC_ENUM_TRAITS_VALIDATE() macro.
144// There is no need to enumerate each value to the IPC mechanism. Instead,
145// pass an expression in terms of the parameter |value| to provide
146// range-checking. For convenience, the IPC_ENUM_TRAITS() is provided which
147// performs no checking, passing everything including out-of-range values.
148// Its use is discouraged. The IPC_ENUM_TRAITS_MAX_VALUE() macro can be used
149// for the typical case where the enum must be in the range 0..maxvalue
150// inclusive. The IPC_ENUM_TRAITS_MIN_MAX_VALUE() macro can be used for the
151// less typical case where the enum must be in the range minvalue..maxvalue
152// inclusive.
[email protected]6476c72c2011-02-11 18:46:19153//
[email protected]e503a122011-03-17 18:20:52154// Do not place semicolons following these IPC_ macro invocations. There
155// is no reason to expect that their expansion corresponds one-to-one with
156// C++ statements.
157//
[email protected]6476c72c2011-02-11 18:46:19158// Once the types have been declared / registered, message definitions follow.
initial.commit09911bf2008-07-26 23:55:29159// "Sync" messages are just synchronous calls, the Send() call doesn't return
[email protected]7f994182011-08-23 10:18:10160// until a reply comes back. To declare a sync message, use the IPC_SYNC_
161// macros. The numbers at the end show how many input/output parameters there
162// are (i.e. 1_2 is 1 in, 2 out). Input parameters are first, followed by
163// output parameters. The caller uses Send([route id, ], in1, &out1, &out2).
initial.commit09911bf2008-07-26 23:55:29164// The receiver's handler function will be
165// void OnSyncMessageName(const type1& in1, type2* out1, type3* out2)
166//
initial.commit09911bf2008-07-26 23:55:29167// A caller can also send a synchronous message, while the receiver can respond
[email protected]d4240352009-12-10 17:32:31168// at a later time. This is transparent from the sender's side. The receiver
initial.commit09911bf2008-07-26 23:55:29169// needs to use a different handler that takes in a IPC::Message* as the output
170// type, stash the message, and when it has the data it can Send the message.
171//
172// Use the IPC_MESSAGE_HANDLER_DELAY_REPLY macro instead of IPC_MESSAGE_HANDLER
[email protected]d3216442009-03-05 21:07:27173// IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncMessageName,
174// OnSyncMessageName)
thestigcb959ce2016-11-17 05:56:32175// Unlike IPC_MESSAGE_HANDLER which works with IPC_BEGIN_MESSAGE_MAP as well as
176// IPC_BEGIN_MESSAGE_MAP_WITH_PARAM, one needs to use
177// IPC_MESSAGE_HANDLER_WITH_PARAM_DELAY_REPLY to properly handle the param.
initial.commit09911bf2008-07-26 23:55:29178//
179// The handler function will look like:
180// void OnSyncMessageName(const type1& in1, IPC::Message* reply_msg);
181//
182// Receiver stashes the IPC::Message* pointer, and when it's ready, it does:
183// ViewHostMsg_SyncMessageName::WriteReplyParams(reply_msg, out1, out2);
184// Send(reply_msg);
185
[email protected]7de84042012-02-21 16:04:50186// Files that want to export their ipc messages should do
187// #undef IPC_MESSAGE_EXPORT
188// #define IPC_MESSAGE_EXPORT VISIBILITY_MACRO
189// after including this header, but before using any of the macros below.
190// (This needs to be before the include guard.)
191#undef IPC_MESSAGE_EXPORT
192#define IPC_MESSAGE_EXPORT
193
[email protected]6476c72c2011-02-11 18:46:19194#ifndef IPC_IPC_MESSAGE_MACROS_H_
195#define IPC_IPC_MESSAGE_MACROS_H_
[email protected]82e5ee82009-04-03 02:29:45196
tfarina10a5c062015-09-04 18:47:57197#include <stdint.h>
198
tzik55e3e4d2016-03-08 05:47:44199#include <tuple>
200
Mounir Lamouri130ad752017-10-13 17:07:15201#include "base/export_template.h"
mdempsky8a519042016-02-09 05:41:47202#include "ipc/ipc_message_templates.h"
[email protected]6476c72c2011-02-11 18:46:19203#include "ipc/ipc_message_utils.h"
204#include "ipc/param_traits_macros.h"
[email protected]f91cb992009-02-04 20:10:12205
[email protected]600cdb7c2013-11-05 04:24:58206// Convenience macro for defining structs without inheritance. Should not need
[email protected]dedd0a92013-06-04 07:20:32207// to be subsequently redefined.
[email protected]8a8c9c72011-03-01 20:35:47208#define IPC_STRUCT_BEGIN(struct_name) \
[email protected]6766b172011-11-21 18:29:36209 IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, IPC::NoParams)
[email protected]dedd0a92013-06-04 07:20:32210
211// Macros for defining structs. Will be subsequently redefined.
[email protected]6766b172011-11-21 18:29:36212#define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \
[email protected]8a8c9c72011-03-01 20:35:47213 struct struct_name; \
214 IPC_STRUCT_TRAITS_BEGIN(struct_name) \
215 IPC_STRUCT_TRAITS_END() \
[email protected]6766b172011-11-21 18:29:36216 struct IPC_MESSAGE_EXPORT struct_name : parent { \
Hans Wennborgb6f010b12018-11-22 07:26:07217 struct_name();
[email protected]01cca0042012-04-16 19:13:02218// Optional variadic parameters specify the default value for this struct
219// member. They are passed through to the constructor for |type|.
220#define IPC_STRUCT_MEMBER(type, name, ...) type name;
[email protected]8a8c9c72011-03-01 20:35:47221#define IPC_STRUCT_END() };
222
mdempsky8a519042016-02-09 05:41:47223// Message macros collect arguments and funnel them into the common message
224// generation macro. These should never be redefined.
[email protected]8a8c9c72011-03-01 20:35:47225
mdempsky8a519042016-02-09 05:41:47226// Asynchronous messages have only in parameters and are declared like:
227// IPC_MESSAGE_CONTROL(FooMsg, int, float)
228#define IPC_MESSAGE_CONTROL(msg_class, ...) \
229 IPC_MESSAGE_DECL(msg_class, CONTROL, IPC_TUPLE(__VA_ARGS__), void)
230#define IPC_MESSAGE_ROUTED(msg_class, ...) \
231 IPC_MESSAGE_DECL(msg_class, ROUTED, IPC_TUPLE(__VA_ARGS__), void)
[email protected]8a8c9c72011-03-01 20:35:47232
mdempsky8a519042016-02-09 05:41:47233// Synchronous messages have both in and out parameters, so the lists need to
234// be parenthesized to disambiguate:
235// IPC_SYNC_MESSAGE_CONTROL(BarMsg, (int, int), (bool))
236//
237// Implementation detail: The parentheses supplied by the caller for
238// disambiguation are also used to trigger the IPC_TUPLE invocations below,
239// so "IPC_TUPLE in" and "IPC_TUPLE out" are intentional.
240#define IPC_SYNC_MESSAGE_CONTROL(msg_class, in, out) \
241 IPC_MESSAGE_DECL(msg_class, CONTROL, IPC_TUPLE in, IPC_TUPLE out)
242#define IPC_SYNC_MESSAGE_ROUTED(msg_class, in, out) \
243 IPC_MESSAGE_DECL(msg_class, ROUTED, IPC_TUPLE in, IPC_TUPLE out)
[email protected]8a8c9c72011-03-01 20:35:47244
dskiba2bc89462016-04-06 15:51:06245#define IPC_TUPLE(...) IPC::CheckedTuple<__VA_ARGS__>::Tuple
[email protected]8a8c9c72011-03-01 20:35:47246
mdempsky8a519042016-02-09 05:41:47247#define IPC_MESSAGE_DECL(msg_name, kind, in_tuple, out_tuple) \
248 struct IPC_MESSAGE_EXPORT msg_name##_Meta { \
249 using InTuple = in_tuple; \
250 using OutTuple = out_tuple; \
251 enum { ID = IPC_MESSAGE_ID() }; \
252 static const IPC::MessageKind kKind = IPC::MessageKind::kind; \
253 static const char kName[]; \
254 }; \
255 extern template class EXPORT_TEMPLATE_DECLARE(IPC_MESSAGE_EXPORT) \
256 IPC::MessageT<msg_name##_Meta>; \
257 using msg_name = IPC::MessageT<msg_name##_Meta>; \
258 IPC_MESSAGE_EXTRA(msg_name)
[email protected]8a8c9c72011-03-01 20:35:47259
260#if defined(IPC_MESSAGE_IMPL)
261
mdempsky8a519042016-02-09 05:41:47262// "Implementation" inclusion provides the explicit template definition
263// for msg_name.
264#define IPC_MESSAGE_EXTRA(msg_name) \
265 const char msg_name##_Meta::kName[] = #msg_name; \
266 IPC_MESSAGE_DEFINE_KIND(msg_name) \
267 template class EXPORT_TEMPLATE_DEFINE(IPC_MESSAGE_EXPORT) \
268 IPC::MessageT<msg_name##_Meta>;
[email protected]8a8c9c72011-03-01 20:35:47269
mdempsky8a519042016-02-09 05:41:47270// MSVC has an intentionally non-compliant "feature" that results in LNK2005
271// ("symbol already defined") errors if we provide an out-of-line definition
272// for kKind. Microsoft's official response is to test for _MSC_EXTENSIONS:
273// https://connect.microsoft.com/VisualStudio/feedback/details/786583/
274#if defined(_MSC_EXTENSIONS)
275#define IPC_MESSAGE_DEFINE_KIND(msg_name)
276#else
277#define IPC_MESSAGE_DEFINE_KIND(msg_name) \
278 const IPC::MessageKind msg_name##_Meta::kKind;
279#endif
[email protected]8a8c9c72011-03-01 20:35:47280
[email protected]21fa3a12010-12-08 23:34:16281#elif defined(IPC_MESSAGE_MACROS_LOG_ENABLED)
[email protected]f91cb992009-02-04 20:10:12282
[email protected]4f68ed72012-10-30 05:24:07283#ifndef IPC_LOG_TABLE_ADD_ENTRY
284#error You need to define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger)
285#endif
[email protected]f91cb992009-02-04 20:10:12286
[email protected]8a8c9c72011-03-01 20:35:47287// "Log table" inclusion produces extra logging registration code.
mdempsky8a519042016-02-09 05:41:47288#define IPC_MESSAGE_EXTRA(msg_name) \
289 class LoggerRegisterHelper##msg_name { \
290 public: \
291 LoggerRegisterHelper##msg_name() { \
292 const uint32_t msg_id = static_cast<uint32_t>(msg_name::ID); \
293 IPC_LOG_TABLE_ADD_ENTRY(msg_id, msg_name::Log); \
294 } \
295 }; \
296 LoggerRegisterHelper##msg_name g_LoggerRegisterHelper##msg_name;
[email protected]f91cb992009-02-04 20:10:12297
[email protected]8a8c9c72011-03-01 20:35:47298#else
initial.commit09911bf2008-07-26 23:55:29299
[email protected]8a8c9c72011-03-01 20:35:47300// Normal inclusion produces nothing extra.
mdempsky8a519042016-02-09 05:41:47301#define IPC_MESSAGE_EXTRA(msg_name)
initial.commit09911bf2008-07-26 23:55:29302
mdempsky8a519042016-02-09 05:41:47303#endif // defined(IPC_MESSAGE_IMPL)
[email protected]6d8ffc9f2010-03-12 18:27:53304
[email protected]d7a5e3e2011-03-12 16:28:36305// Message IDs
306// Note: we currently use __LINE__ to give unique IDs to messages within
307// a file. They're globally unique since each file defines its own
[email protected]3b3ec7212011-10-21 17:35:08308// IPC_MESSAGE_START.
[email protected]d7a5e3e2011-03-12 16:28:36309#define IPC_MESSAGE_ID() ((IPC_MESSAGE_START << 16) + __LINE__)
310#define IPC_MESSAGE_ID_CLASS(id) ((id) >> 16)
311#define IPC_MESSAGE_ID_LINE(id) ((id) & 0xffff)
312
[email protected]e44d1342014-05-16 21:29:33313// Message crackers and handlers. Usage:
initial.commit09911bf2008-07-26 23:55:29314//
[email protected]a95986a82010-12-24 06:19:28315// bool MyClass::OnMessageReceived(const IPC::Message& msg) {
316// bool handled = true;
[email protected]e44d1342014-05-16 21:29:33317// IPC_BEGIN_MESSAGE_MAP(MyClass, msg)
initial.commit09911bf2008-07-26 23:55:29318// IPC_MESSAGE_HANDLER(MsgClassOne, OnMsgClassOne)
319// ...more handlers here ...
320// IPC_MESSAGE_HANDLER(MsgClassTen, OnMsgClassTen)
[email protected]a95986a82010-12-24 06:19:28321// IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33322// IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28323// return handled;
initial.commit09911bf2008-07-26 23:55:29324// }
325
[email protected]21fa3a12010-12-08 23:34:16326
initial.commit09911bf2008-07-26 23:55:29327#define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \
328 { \
pkasting99867ef2014-10-16 23:49:24329 typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED_TYPE; \
[email protected]9d77dd4122014-05-14 21:43:59330 void* param__ = NULL; \
sunnypsb3c862b2016-02-05 01:55:08331 (void)param__; \
initial.commit09911bf2008-07-26 23:55:29332 const IPC::Message& ipc_message__ = msg; \
[email protected]9d77dd4122014-05-14 21:43:59333 switch (ipc_message__.type()) {
initial.commit09911bf2008-07-26 23:55:29334
pkasting99867ef2014-10-16 23:49:24335#define IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(class_name, msg, param) \
336 { \
337 typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED_TYPE; \
thakise6e95d92014-10-29 22:04:47338 decltype(param) param__ = param; \
pkasting99867ef2014-10-16 23:49:24339 const IPC::Message& ipc_message__ = msg; \
[email protected]9d77dd4122014-05-14 21:43:59340 switch (ipc_message__.type()) {
[email protected]5636d902014-05-13 23:19:10341
[email protected]e86a2552011-11-11 00:21:02342#define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \
343 case msg_class::ID: { \
[email protected]e44d1342014-05-16 21:29:33344 if (!msg_class::Dispatch(&ipc_message__, obj, this, param__, \
345 &member_func)) \
[email protected]ef2f6ba2014-05-15 23:06:07346 ipc_message__.set_dispatch_error(); \
[email protected]e86a2552011-11-11 00:21:02347 } \
348 break;
initial.commit09911bf2008-07-26 23:55:29349
350#define IPC_MESSAGE_HANDLER(msg_class, member_func) \
351 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func)
352
[email protected]e86a2552011-11-11 00:21:02353#define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \
354 case msg_class::ID: { \
[email protected]e44d1342014-05-16 21:29:33355 if (!msg_class::DispatchDelayReply(&ipc_message__, obj, param__, \
356 &member_func)) \
[email protected]ef2f6ba2014-05-15 23:06:07357 ipc_message__.set_dispatch_error(); \
[email protected]e86a2552011-11-11 00:21:02358 } \
359 break;
initial.commit09911bf2008-07-26 23:55:29360
[email protected]e86a2552011-11-11 00:21:02361#define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \
362 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \
363 _IpcMessageHandlerClass::member_func)
initial.commit09911bf2008-07-26 23:55:29364
thestigcb959ce2016-11-17 05:56:32365#define IPC_MESSAGE_FORWARD_WITH_PARAM_DELAY_REPLY(msg_class, obj, \
366 member_func) \
367 case msg_class::ID: { \
thestigcb959ce2016-11-17 05:56:32368 if (!msg_class::DispatchWithParamDelayReply(&ipc_message__, obj, param__, \
369 &member_func)) \
370 ipc_message__.set_dispatch_error(); \
371 } \
372 break;
373
374#define IPC_MESSAGE_HANDLER_WITH_PARAM_DELAY_REPLY(msg_class, member_func) \
375 IPC_MESSAGE_FORWARD_WITH_PARAM_DELAY_REPLY( \
376 msg_class, this, _IpcMessageHandlerClass::member_func)
377
[email protected]e86a2552011-11-11 00:21:02378#define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \
379 case msg_class::ID: { \
[email protected]e86a2552011-11-11 00:21:02380 code; \
381 } \
382 break;
initial.commit09911bf2008-07-26 23:55:29383
[email protected]e86a2552011-11-11 00:21:02384#define IPC_REPLY_HANDLER(func) \
385 case IPC_REPLY_ID: { \
[email protected]e86a2552011-11-11 00:21:02386 func(ipc_message__); \
387 } \
388 break;
initial.commit09911bf2008-07-26 23:55:29389
390
[email protected]e86a2552011-11-11 00:21:02391#define IPC_MESSAGE_UNHANDLED(code) \
392 default: { \
[email protected]e86a2552011-11-11 00:21:02393 code; \
394 } \
395 break;
initial.commit09911bf2008-07-26 23:55:29396
397#define IPC_MESSAGE_UNHANDLED_ERROR() \
398 IPC_MESSAGE_UNHANDLED(NOTREACHED() << \
399 "Invalid message with type = " << \
400 ipc_message__.type())
401
402#define IPC_END_MESSAGE_MAP() \
initial.commit09911bf2008-07-26 23:55:29403 } \
[email protected]8d70d5f2010-12-08 23:41:08404}
[email protected]9f547bf2010-12-13 17:00:42405
406// This corresponds to an enum value from IPCMessageStart.
lfgdb5c4ed2016-03-04 23:09:07407#define IPC_MESSAGE_CLASS(message) IPC_MESSAGE_ID_CLASS((message).type())
[email protected]6476c72c2011-02-11 18:46:19408
mdempsky8a519042016-02-09 05:41:47409// Deprecated legacy macro names.
410// TODO(mdempsky): Replace uses with generic names.
411
412#define IPC_MESSAGE_CONTROL0(msg) IPC_MESSAGE_CONTROL(msg)
413#define IPC_MESSAGE_CONTROL1(msg, a) IPC_MESSAGE_CONTROL(msg, a)
414#define IPC_MESSAGE_CONTROL2(msg, a, b) IPC_MESSAGE_CONTROL(msg, a, b)
415#define IPC_MESSAGE_CONTROL3(msg, a, b, c) IPC_MESSAGE_CONTROL(msg, a, b, c)
416#define IPC_MESSAGE_CONTROL4(msg, a, b, c, d) \
417 IPC_MESSAGE_CONTROL(msg, a, b, c, d)
418#define IPC_MESSAGE_CONTROL5(msg, a, b, c, d, e) \
419 IPC_MESSAGE_CONTROL(msg, a, b, c, d, e)
420
421#define IPC_MESSAGE_ROUTED0(msg) IPC_MESSAGE_ROUTED(msg)
422#define IPC_MESSAGE_ROUTED1(msg, a) IPC_MESSAGE_ROUTED(msg, a)
423#define IPC_MESSAGE_ROUTED2(msg, a, b) IPC_MESSAGE_ROUTED(msg, a, b)
424#define IPC_MESSAGE_ROUTED3(msg, a, b, c) IPC_MESSAGE_ROUTED(msg, a, b, c)
425#define IPC_MESSAGE_ROUTED4(msg, a, b, c, d) IPC_MESSAGE_ROUTED(msg, a, b, c, d)
426#define IPC_MESSAGE_ROUTED5(msg, a, b, c, d, e) \
427 IPC_MESSAGE_ROUTED(msg, a, b, c, d, e)
428
429#define IPC_SYNC_MESSAGE_CONTROL0_0(msg) IPC_SYNC_MESSAGE_CONTROL(msg, (), ())
430#define IPC_SYNC_MESSAGE_CONTROL0_1(msg, a) \
431 IPC_SYNC_MESSAGE_CONTROL(msg, (), (a))
432#define IPC_SYNC_MESSAGE_CONTROL0_2(msg, a, b) \
433 IPC_SYNC_MESSAGE_CONTROL(msg, (), (a, b))
434#define IPC_SYNC_MESSAGE_CONTROL0_3(msg, a, b, c) \
435 IPC_SYNC_MESSAGE_CONTROL(msg, (), (a, b, c))
436#define IPC_SYNC_MESSAGE_CONTROL0_4(msg, a, b, c, d) \
437 IPC_SYNC_MESSAGE_CONTROL(msg, (), (a, b, c, d))
438#define IPC_SYNC_MESSAGE_CONTROL1_0(msg, a) \
439 IPC_SYNC_MESSAGE_CONTROL(msg, (a), ())
440#define IPC_SYNC_MESSAGE_CONTROL1_1(msg, a, b) \
441 IPC_SYNC_MESSAGE_CONTROL(msg, (a), (b))
442#define IPC_SYNC_MESSAGE_CONTROL1_2(msg, a, b, c) \
443 IPC_SYNC_MESSAGE_CONTROL(msg, (a), (b, c))
444#define IPC_SYNC_MESSAGE_CONTROL1_3(msg, a, b, c, d) \
445 IPC_SYNC_MESSAGE_CONTROL(msg, (a), (b, c, d))
446#define IPC_SYNC_MESSAGE_CONTROL1_4(msg, a, b, c, d, e) \
447 IPC_SYNC_MESSAGE_CONTROL(msg, (a), (b, c, d, e))
448#define IPC_SYNC_MESSAGE_CONTROL2_0(msg, a, b) \
449 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b), ())
450#define IPC_SYNC_MESSAGE_CONTROL2_1(msg, a, b, c) \
451 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b), (c))
452#define IPC_SYNC_MESSAGE_CONTROL2_2(msg, a, b, c, d) \
453 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b), (c, d))
454#define IPC_SYNC_MESSAGE_CONTROL2_3(msg, a, b, c, d, e) \
455 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b), (c, d, e))
456#define IPC_SYNC_MESSAGE_CONTROL2_4(msg, a, b, c, d, e, f) \
457 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b), (c, d, e, f))
458#define IPC_SYNC_MESSAGE_CONTROL3_0(msg, a, b, c) \
459 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c), ())
460#define IPC_SYNC_MESSAGE_CONTROL3_1(msg, a, b, c, d) \
461 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c), (d))
462#define IPC_SYNC_MESSAGE_CONTROL3_2(msg, a, b, c, d, e) \
463 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c), (d, e))
464#define IPC_SYNC_MESSAGE_CONTROL3_3(msg, a, b, c, d, e, f) \
465 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c), (d, e, f))
466#define IPC_SYNC_MESSAGE_CONTROL3_4(msg, a, b, c, d, e, f, g) \
467 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c), (d, e, f, g))
468#define IPC_SYNC_MESSAGE_CONTROL4_0(msg, a, b, c, d) \
469 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d), ())
470#define IPC_SYNC_MESSAGE_CONTROL4_1(msg, a, b, c, d, e) \
471 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d), (e))
472#define IPC_SYNC_MESSAGE_CONTROL4_2(msg, a, b, c, d, e, f) \
473 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d), (e, f))
474#define IPC_SYNC_MESSAGE_CONTROL4_3(msg, a, b, c, d, e, f, g) \
475 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d), (e, f, g))
476#define IPC_SYNC_MESSAGE_CONTROL4_4(msg, a, b, c, d, e, f, g, h) \
477 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d), (e, f, g, h))
478#define IPC_SYNC_MESSAGE_CONTROL5_0(msg, a, b, c, d, e) \
479 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d, e), ())
480#define IPC_SYNC_MESSAGE_CONTROL5_1(msg, a, b, c, d, e, f) \
481 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d, e), (f))
482#define IPC_SYNC_MESSAGE_CONTROL5_2(msg, a, b, c, d, e, f, g) \
483 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d, e), (f, g))
484#define IPC_SYNC_MESSAGE_CONTROL5_3(msg, a, b, c, d, e, f, g, h) \
485 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d, e), (f, g, h))
486#define IPC_SYNC_MESSAGE_CONTROL5_4(msg, a, b, c, d, e, f, g, h, i) \
487 IPC_SYNC_MESSAGE_CONTROL(msg, (a, b, c, d, e), (f, g, h, i))
488
489#define IPC_SYNC_MESSAGE_ROUTED0_0(msg) IPC_SYNC_MESSAGE_ROUTED(msg, (), ())
490#define IPC_SYNC_MESSAGE_ROUTED0_1(msg, a) IPC_SYNC_MESSAGE_ROUTED(msg, (), (a))
491#define IPC_SYNC_MESSAGE_ROUTED0_2(msg, a, b) \
492 IPC_SYNC_MESSAGE_ROUTED(msg, (), (a, b))
493#define IPC_SYNC_MESSAGE_ROUTED0_3(msg, a, b, c) \
494 IPC_SYNC_MESSAGE_ROUTED(msg, (), (a, b, c))
495#define IPC_SYNC_MESSAGE_ROUTED0_4(msg, a, b, c, d) \
496 IPC_SYNC_MESSAGE_ROUTED(msg, (), (a, b, c, d))
497#define IPC_SYNC_MESSAGE_ROUTED1_0(msg, a) IPC_SYNC_MESSAGE_ROUTED(msg, (a), ())
498#define IPC_SYNC_MESSAGE_ROUTED1_1(msg, a, b) \
499 IPC_SYNC_MESSAGE_ROUTED(msg, (a), (b))
500#define IPC_SYNC_MESSAGE_ROUTED1_2(msg, a, b, c) \
501 IPC_SYNC_MESSAGE_ROUTED(msg, (a), (b, c))
502#define IPC_SYNC_MESSAGE_ROUTED1_3(msg, a, b, c, d) \
503 IPC_SYNC_MESSAGE_ROUTED(msg, (a), (b, c, d))
504#define IPC_SYNC_MESSAGE_ROUTED1_4(msg, a, b, c, d, e) \
505 IPC_SYNC_MESSAGE_ROUTED(msg, (a), (b, c, d, e))
506#define IPC_SYNC_MESSAGE_ROUTED2_0(msg, a, b) \
507 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b), ())
508#define IPC_SYNC_MESSAGE_ROUTED2_1(msg, a, b, c) \
509 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b), (c))
510#define IPC_SYNC_MESSAGE_ROUTED2_2(msg, a, b, c, d) \
511 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b), (c, d))
512#define IPC_SYNC_MESSAGE_ROUTED2_3(msg, a, b, c, d, e) \
513 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b), (c, d, e))
514#define IPC_SYNC_MESSAGE_ROUTED2_4(msg, a, b, c, d, e, f) \
515 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b), (c, d, e, f))
516#define IPC_SYNC_MESSAGE_ROUTED3_0(msg, a, b, c) \
517 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c), ())
518#define IPC_SYNC_MESSAGE_ROUTED3_1(msg, a, b, c, d) \
519 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c), (d))
520#define IPC_SYNC_MESSAGE_ROUTED3_2(msg, a, b, c, d, e) \
521 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c), (d, e))
522#define IPC_SYNC_MESSAGE_ROUTED3_3(msg, a, b, c, d, e, f) \
523 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c), (d, e, f))
524#define IPC_SYNC_MESSAGE_ROUTED3_4(msg, a, b, c, d, e, f, g) \
525 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c), (d, e, f, g))
526#define IPC_SYNC_MESSAGE_ROUTED4_0(msg, a, b, c, d) \
527 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d), ())
528#define IPC_SYNC_MESSAGE_ROUTED4_1(msg, a, b, c, d, e) \
529 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d), (e))
530#define IPC_SYNC_MESSAGE_ROUTED4_2(msg, a, b, c, d, e, f) \
531 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d), (e, f))
532#define IPC_SYNC_MESSAGE_ROUTED4_3(msg, a, b, c, d, e, f, g) \
533 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d), (e, f, g))
534#define IPC_SYNC_MESSAGE_ROUTED4_4(msg, a, b, c, d, e, f, g, h) \
535 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d), (e, f, g, h))
536#define IPC_SYNC_MESSAGE_ROUTED5_0(msg, a, b, c, d, e) \
537 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d, e), ())
538#define IPC_SYNC_MESSAGE_ROUTED5_1(msg, a, b, c, d, e, f) \
539 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d, e), (f))
540#define IPC_SYNC_MESSAGE_ROUTED5_2(msg, a, b, c, d, e, f, g) \
541 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d, e), (f, g))
542#define IPC_SYNC_MESSAGE_ROUTED5_3(msg, a, b, c, d, e, f, g, h) \
543 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d, e), (f, g, h))
544#define IPC_SYNC_MESSAGE_ROUTED5_4(msg, a, b, c, d, e, f, g, h, i) \
545 IPC_SYNC_MESSAGE_ROUTED(msg, (a, b, c, d, e), (f, g, h, i))
546
[email protected]6476c72c2011-02-11 18:46:19547#endif // IPC_IPC_MESSAGE_MACROS_H_
548
549// Clean up IPC_MESSAGE_START in this unguarded section so that the
550// XXX_messages.h files need not do so themselves. This makes the
551// XXX_messages.h files easier to write.
552#undef IPC_MESSAGE_START