blob: 4644113e3996e0283e7fbf6e7cd842cf299e9f76 [file] [log] [blame]
thakis@chromium.orgfead1e62012-02-22 01:04:50 +09001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
agl@chromium.org1c6dcf22009-07-23 08:57:21 +09002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
tsepez@chromium.org1ac46132011-02-12 03:46:19 +09005// Defining IPC Messages
agl@chromium.org1c6dcf22009-07-23 08:57:21 +09006//
tsepez@chromium.org1ac46132011-02-12 03:46:19 +09007// 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
11// implemation file as well.
12//
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:
tsepez@chromium.org4afe8f72012-10-24 08:03:35 +090018// - An XXXMsgStart value to the IPCMessageStart enum in ipc_message_start.h
tsepez@chromium.org1ac46132011-02-12 03:46:19 +090019// - 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
jar@chromium.org16111832011-11-11 09:21:02 +090023// XXX_messages.h file before invoking message declaration macros:
tsepez@chromium.org1ac46132011-02-12 03:46:19 +090024// #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,
tsepez@chromium.org7272e462011-03-13 01:28:36 +090032// 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.
tsepez@chromium.org1ac46132011-02-12 03:46:19 +090035//
36// In the rare cicrucmstances where you can't re-use an existing file,
37// your YYY_message_generator.cc file for a component YYY would contain
38// the following code:
39// // Get basic type definitions.
jam@chromium.org86a8de12010-12-09 08:34:16 +090040// #define IPC_MESSAGE_IMPL
tsepez@chromium.org1ac46132011-02-12 03:46:19 +090041// #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"
tsepez@chromium.org1ac46132011-02-12 03:46:19 +090048// // Generate param traits write methods.
49// #include "ipc/param_traits_write_macros.h"
tsepez@chromium.org7272e462011-03-13 01:28:36 +090050// namespace IPC {
tsepez@chromium.org1ac46132011-02-12 03:46:19 +090051// #include "path/to/YYY_message_generator.h"
tsepez@chromium.org7272e462011-03-13 01:28:36 +090052// } // namespace IPC
tsepez@chromium.org1ac46132011-02-12 03:46:19 +090053// // Generate param traits read methods.
54// #include "ipc/param_traits_read_macros.h"
tsepez@chromium.org7272e462011-03-13 01:28:36 +090055// namespace IPC {
tsepez@chromium.org1ac46132011-02-12 03:46:19 +090056// #include "path/to/YYY_message_generator.h"
tsepez@chromium.org7272e462011-03-13 01:28:36 +090057// } // namespace IPC
tsepez@chromium.org1ac46132011-02-12 03:46:19 +090058// // Generate param traits log methods.
59// #include "ipc/param_traits_log_macros.h"
tsepez@chromium.org7272e462011-03-13 01:28:36 +090060// namespace IPC {
tsepez@chromium.org1ac46132011-02-12 03:46:19 +090061// #include "path/to/YYY_message_generator.h"
62// } // namespace IPC
agl@chromium.org1c6dcf22009-07-23 08:57:21 +090063//
tsepez@chromium.org1ac46132011-02-12 03:46:19 +090064// 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
75// inclusion guard, since the XXX_messages.h file should consist soley
76// of inclusions of other headers (which are self-guarding) and IPC
77// macros (which are multiply evaluating).
78//
ajwong@chromium.org1d967bf2012-07-12 04:01:43 +090079// Note that #pragma once cannot be used here; doing so would mark the whole
tsepez@chromium.org1ac46132011-02-12 03:46:19 +090080// 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
90// to the struct iself. Later, an IPC message dispatcher wil need to call
91// 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
108// is building the messages. In addtion, due to the multiple inclusion
109// 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
tsepez@chromium.org76df5bd2014-06-19 02:32:42 +0900116// #include "path/to/some_class.h" // Full class declaration
117// #include "path/to/some_other_class.h" // Full class declaration
tsepez@chromium.org1ac46132011-02-12 03:46:19 +0900118// #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
tsepez@chromium.org384d9762013-06-04 16:20:32 +0900133// IPC_STRUCT_BEGIN() / IPC_STRUCT_END(). There is also an
134// IPC_STRUCT_BEGIN_WITH_PARENT(), which behaves like IPC_STRUCT_BEGIN(),
135// but also accomodates structs that inherit from other structs.
tsepez@chromium.org1ac46132011-02-12 03:46:19 +0900136//
137// Externally-defined structs are registered with IPC_STRUCT_TRAITS_BEGIN(),
138// IPC_STRUCT_TRAITS_MEMBER(), and IPC_STRUCT_TRAITS_END() macros. These
jam@chromium.org4ae3f562011-03-06 04:08:32 +0900139// 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
tsepez@chromium.org92316aa2011-03-18 03:20:52 +0900143// inside matching calls to IPC_STRUCT_TRAITS_BEGIN() /
144// IPC_STRUCT_TRAITS_END().
tsepez@chromium.org1ac46132011-02-12 03:46:19 +0900145//
tsepez@chromium.org384d9762013-06-04 16:20:32 +0900146// 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.
tsepez@chromium.org1ac46132011-02-12 03:46:19 +0900156//
tsepez@chromium.org92316aa2011-03-18 03:20:52 +0900157// 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//
tsepez@chromium.org1ac46132011-02-12 03:46:19 +0900161// Once the types have been declared / registered, message definitions follow.
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900162// "Sync" messages are just synchronous calls, the Send() call doesn't return
steveblock@chromium.orgbecc14d2011-08-23 19:18:10 +0900163// 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).
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900167// The receiver's handler function will be
168// void OnSyncMessageName(const type1& in1, type2* out1, type3* out2)
169//
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900170// A caller can also send a synchronous message, while the receiver can respond
dglazkov@chromium.orgc7cdd6c2009-12-11 02:32:31 +0900171// at a later time. This is transparent from the sender's side. The receiver
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900172// 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
176// IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncMessageName,
177// OnSyncMessageName)
178//
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
thakis@chromium.orgfead1e62012-02-22 01:04:50 +0900186// 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
tsepez@chromium.org1ac46132011-02-12 03:46:19 +0900194#ifndef IPC_IPC_MESSAGE_MACROS_H_
195#define IPC_IPC_MESSAGE_MACROS_H_
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900196
jar@chromium.org16111832011-11-11 09:21:02 +0900197#include "base/profiler/scoped_profile.h"
tsepez@chromium.org1ac46132011-02-12 03:46:19 +0900198#include "ipc/ipc_message_utils.h"
199#include "ipc/param_traits_macros.h"
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900200
jam@chromium.org86a8de12010-12-09 08:34:16 +0900201#if defined(IPC_MESSAGE_IMPL)
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900202#include "ipc/ipc_message_utils_impl.h"
203#endif
204
thakis@chromium.org7bfcfc42013-11-05 13:24:58 +0900205// Convenience macro for defining structs without inheritance. Should not need
tsepez@chromium.org384d9762013-06-04 16:20:32 +0900206// to be subsequently redefined.
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900207#define IPC_STRUCT_BEGIN(struct_name) \
jam@chromium.org959e5f72011-11-22 03:29:36 +0900208 IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, IPC::NoParams)
tsepez@chromium.org384d9762013-06-04 16:20:32 +0900209
210// Macros for defining structs. Will be subsequently redefined.
jam@chromium.org959e5f72011-11-22 03:29:36 +0900211#define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900212 struct struct_name; \
213 IPC_STRUCT_TRAITS_BEGIN(struct_name) \
214 IPC_STRUCT_TRAITS_END() \
jam@chromium.org959e5f72011-11-22 03:29:36 +0900215 struct IPC_MESSAGE_EXPORT struct_name : parent { \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900216 struct_name(); \
217 ~struct_name();
jbates@chromium.orgd96f2ad2012-04-17 04:13:02 +0900218// 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;
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900221#define IPC_STRUCT_END() };
222
223// Message macros collect specific numbers of arguments and funnel them into
tsepez@chromium.org7272e462011-03-13 01:28:36 +0900224// the common message generation macro. These should never be redefined.
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900225#define IPC_MESSAGE_CONTROL0(msg_class) \
226 IPC_MESSAGE_DECL(EMPTY, CONTROL, msg_class, 0, 0, (), ())
227
228#define IPC_MESSAGE_CONTROL1(msg_class, type1) \
229 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 1, 0, (type1), ())
230
231#define IPC_MESSAGE_CONTROL2(msg_class, type1, type2) \
232 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 2, 0, (type1, type2), ())
233
234#define IPC_MESSAGE_CONTROL3(msg_class, type1, type2, type3) \
235 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 3, 0, (type1, type2, type3), ())
236
237#define IPC_MESSAGE_CONTROL4(msg_class, type1, type2, type3, type4) \
238 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 4, 0, (type1, type2, type3, type4), ())
239
240#define IPC_MESSAGE_CONTROL5(msg_class, type1, type2, type3, type4, type5) \
241 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 5, 0, (type1, type2, type3, type4, type5), ())
242
243#define IPC_MESSAGE_ROUTED0(msg_class) \
244 IPC_MESSAGE_DECL(EMPTY, ROUTED, msg_class, 0, 0, (), ())
245
246#define IPC_MESSAGE_ROUTED1(msg_class, type1) \
247 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 1, 0, (type1), ())
248
249#define IPC_MESSAGE_ROUTED2(msg_class, type1, type2) \
250 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 2, 0, (type1, type2), ())
251
252#define IPC_MESSAGE_ROUTED3(msg_class, type1, type2, type3) \
253 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 3, 0, (type1, type2, type3), ())
254
255#define IPC_MESSAGE_ROUTED4(msg_class, type1, type2, type3, type4) \
256 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 4, 0, (type1, type2, type3, type4), ())
257
258#define IPC_MESSAGE_ROUTED5(msg_class, type1, type2, type3, type4, type5) \
259 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 5, 0, (type1, type2, type3, type4, type5), ())
260
261#define IPC_SYNC_MESSAGE_CONTROL0_0(msg_class) \
262 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 0, (), ())
263
264#define IPC_SYNC_MESSAGE_CONTROL0_1(msg_class, type1_out) \
265 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 1, (), (type1_out))
266
267#define IPC_SYNC_MESSAGE_CONTROL0_2(msg_class, type1_out, type2_out) \
268 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 2, (), (type1_out, type2_out))
269
270#define IPC_SYNC_MESSAGE_CONTROL0_3(msg_class, type1_out, type2_out, type3_out) \
271 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 3, (), (type1_out, type2_out, type3_out))
272
273#define IPC_SYNC_MESSAGE_CONTROL0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \
274 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out))
275
276#define IPC_SYNC_MESSAGE_CONTROL1_0(msg_class, type1_in) \
277 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 0, (type1_in), ())
278
279#define IPC_SYNC_MESSAGE_CONTROL1_1(msg_class, type1_in, type1_out) \
280 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 1, (type1_in), (type1_out))
281
282#define IPC_SYNC_MESSAGE_CONTROL1_2(msg_class, type1_in, type1_out, type2_out) \
283 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 2, (type1_in), (type1_out, type2_out))
284
285#define IPC_SYNC_MESSAGE_CONTROL1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \
286 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out))
287
288#define IPC_SYNC_MESSAGE_CONTROL1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \
289 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out))
290
291#define IPC_SYNC_MESSAGE_CONTROL2_0(msg_class, type1_in, type2_in) \
292 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 0, (type1_in, type2_in), ())
293
294#define IPC_SYNC_MESSAGE_CONTROL2_1(msg_class, type1_in, type2_in, type1_out) \
295 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 1, (type1_in, type2_in), (type1_out))
296
297#define IPC_SYNC_MESSAGE_CONTROL2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \
298 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out))
299
300#define IPC_SYNC_MESSAGE_CONTROL2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \
301 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out))
302
303#define IPC_SYNC_MESSAGE_CONTROL2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \
304 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out))
305
306#define IPC_SYNC_MESSAGE_CONTROL3_0(msg_class, type1_in, type2_in, type3_in) \
307 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 0, (type1_in, type2_in, type3_in), ())
308
309#define IPC_SYNC_MESSAGE_CONTROL3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \
310 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out))
311
312#define IPC_SYNC_MESSAGE_CONTROL3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \
313 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out))
314
315#define IPC_SYNC_MESSAGE_CONTROL3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \
316 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out))
317
318#define IPC_SYNC_MESSAGE_CONTROL3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \
319 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out))
320
321#define IPC_SYNC_MESSAGE_CONTROL4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \
322 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 0, (type1_in, type2_in, type3_in, type4_in), ())
323
324#define IPC_SYNC_MESSAGE_CONTROL4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \
325 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out))
326
327#define IPC_SYNC_MESSAGE_CONTROL4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \
328 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out))
329
330#define IPC_SYNC_MESSAGE_CONTROL4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \
331 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out))
332
333#define IPC_SYNC_MESSAGE_CONTROL4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \
334 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 4, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out, type4_out))
335
336#define IPC_SYNC_MESSAGE_CONTROL5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \
danno@chromium.org44f2e6c2011-03-11 00:34:21 +0900337 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 0, (type1_in, type2_in, type3_in, type4_in, type5_in), ())
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900338
339#define IPC_SYNC_MESSAGE_CONTROL5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \
340 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out))
341
342#define IPC_SYNC_MESSAGE_CONTROL5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \
343 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out))
344
345#define IPC_SYNC_MESSAGE_CONTROL5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \
346 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 3, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out, type3_out))
347
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900348#define IPC_SYNC_MESSAGE_ROUTED0_0(msg_class) \
349 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 0, (), ())
350
351#define IPC_SYNC_MESSAGE_ROUTED0_1(msg_class, type1_out) \
352 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 1, (), (type1_out))
353
354#define IPC_SYNC_MESSAGE_ROUTED0_2(msg_class, type1_out, type2_out) \
355 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 2, (), (type1_out, type2_out))
356
357#define IPC_SYNC_MESSAGE_ROUTED0_3(msg_class, type1_out, type2_out, type3_out) \
358 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 3, (), (type1_out, type2_out, type3_out))
359
360#define IPC_SYNC_MESSAGE_ROUTED0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \
361 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out))
362
363#define IPC_SYNC_MESSAGE_ROUTED1_0(msg_class, type1_in) \
364 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 0, (type1_in), ())
365
366#define IPC_SYNC_MESSAGE_ROUTED1_1(msg_class, type1_in, type1_out) \
367 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 1, (type1_in), (type1_out))
368
369#define IPC_SYNC_MESSAGE_ROUTED1_2(msg_class, type1_in, type1_out, type2_out) \
370 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 2, (type1_in), (type1_out, type2_out))
371
372#define IPC_SYNC_MESSAGE_ROUTED1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \
373 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out))
374
375#define IPC_SYNC_MESSAGE_ROUTED1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \
376 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out))
377
378#define IPC_SYNC_MESSAGE_ROUTED2_0(msg_class, type1_in, type2_in) \
379 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 0, (type1_in, type2_in), ())
380
381#define IPC_SYNC_MESSAGE_ROUTED2_1(msg_class, type1_in, type2_in, type1_out) \
382 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 1, (type1_in, type2_in), (type1_out))
383
384#define IPC_SYNC_MESSAGE_ROUTED2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \
385 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out))
386
387#define IPC_SYNC_MESSAGE_ROUTED2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \
388 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out))
389
390#define IPC_SYNC_MESSAGE_ROUTED2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \
391 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out))
392
393#define IPC_SYNC_MESSAGE_ROUTED3_0(msg_class, type1_in, type2_in, type3_in) \
394 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 0, (type1_in, type2_in, type3_in), ())
395
396#define IPC_SYNC_MESSAGE_ROUTED3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \
397 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out))
398
399#define IPC_SYNC_MESSAGE_ROUTED3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \
400 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out))
401
402#define IPC_SYNC_MESSAGE_ROUTED3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \
403 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out))
404
405#define IPC_SYNC_MESSAGE_ROUTED3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \
406 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out))
407
408#define IPC_SYNC_MESSAGE_ROUTED4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \
fsamuel@chromium.orgb0e3e322012-08-02 04:43:10 +0900409 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 0, (type1_in, type2_in, type3_in, type4_in), ())
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900410
411#define IPC_SYNC_MESSAGE_ROUTED4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \
412 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out))
413
414#define IPC_SYNC_MESSAGE_ROUTED4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \
415 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out))
416
417#define IPC_SYNC_MESSAGE_ROUTED4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \
418 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out))
419
420#define IPC_SYNC_MESSAGE_ROUTED4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \
421 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 4, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out, type4_out))
422
423#define IPC_SYNC_MESSAGE_ROUTED5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \
fsamuel@chromium.orgb0e3e322012-08-02 04:43:10 +0900424 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 0, (type1_in, type2_in, type3_in, type4_in, type5_in), ())
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900425
426#define IPC_SYNC_MESSAGE_ROUTED5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \
427 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out))
428
429#define IPC_SYNC_MESSAGE_ROUTED5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \
430 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out))
431
432#define IPC_SYNC_MESSAGE_ROUTED5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \
433 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 3, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out, type3_out))
434
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900435// The following macros define the common set of methods provided by ASYNC
436// message classes.
jam@chromium.orgf6370182014-05-14 08:19:10 +0900437// This macro is for all the async IPCs that don't pass an extra parameter using
438// IPC_BEGIN_MESSAGE_MAP_WITH_PARAM.
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900439#define IPC_ASYNC_MESSAGE_METHODS_GENERIC \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900440 template<class T, class S, class P, class Method> \
441 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
442 Method func) { \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900443 Schema::Param p; \
444 if (Read(msg, &p)) { \
445 DispatchToMethod(obj, func, p); \
446 return true; \
447 } \
448 return false; \
449 }
jam@chromium.orgf6370182014-05-14 08:19:10 +0900450
451// The following macros are for for async IPCs which have a dispatcher with an
452// extra parameter specified using IPC_BEGIN_MESSAGE_MAP_WITH_PARAM.
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900453#define IPC_ASYNC_MESSAGE_METHODS_1 \
454 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900455 template<class T, class S, class P, typename TA> \
456 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
457 void (T::*func)(P*, TA)) { \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900458 Schema::Param p; \
459 if (Read(msg, &p)) { \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900460 (obj->*func)(parameter, p.a); \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900461 return true; \
462 } \
463 return false; \
464 }
465#define IPC_ASYNC_MESSAGE_METHODS_2 \
466 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900467 template<class T, class S, class P, typename TA, typename TB> \
468 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
469 void (T::*func)(P*, TA, TB)) { \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900470 Schema::Param p; \
471 if (Read(msg, &p)) { \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900472 (obj->*func)(parameter, p.a, p.b); \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900473 return true; \
474 } \
475 return false; \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900476 }
477#define IPC_ASYNC_MESSAGE_METHODS_3 \
478 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900479 template<class T, class S, class P, typename TA, typename TB, typename TC> \
480 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
481 void (T::*func)(P*, TA, TB, TC)) { \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900482 Schema::Param p; \
483 if (Read(msg, &p)) { \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900484 (obj->*func)(parameter, p.a, p.b, p.c); \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900485 return true; \
486 } \
487 return false; \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900488 }
489#define IPC_ASYNC_MESSAGE_METHODS_4 \
490 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900491 template<class T, class S, class P, typename TA, typename TB, typename TC, \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900492 typename TD> \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900493 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
494 void (T::*func)(P*, TA, TB, TC, TD)) { \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900495 Schema::Param p; \
496 if (Read(msg, &p)) { \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900497 (obj->*func)(parameter, p.a, p.b, p.c, p.d); \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900498 return true; \
499 } \
500 return false; \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900501 }
502#define IPC_ASYNC_MESSAGE_METHODS_5 \
503 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900504 template<class T, class S, class P, typename TA, typename TB, typename TC, \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900505 typename TD, typename TE> \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900506 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
507 void (T::*func)(P*, TA, TB, TC, TD, TE)) { \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900508 Schema::Param p; \
509 if (Read(msg, &p)) { \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900510 (obj->*func)(parameter, p.a, p.b, p.c, p.d, p.e); \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900511 return true; \
512 } \
513 return false; \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900514 }
515
516// The following macros define the common set of methods provided by SYNC
517// message classes.
518#define IPC_SYNC_MESSAGE_METHODS_GENERIC \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900519 template<class T, class S, class P, class Method> \
520 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
521 Method func) { \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900522 Schema::SendParam send_params; \
523 bool ok = ReadSendParam(msg, &send_params); \
524 return Schema::DispatchWithSendParams(ok, send_params, msg, obj, sender, \
525 func); \
526 } \
jam@chromium.orgf6370182014-05-14 08:19:10 +0900527 template<class T, class P, class Method> \
528 static bool DispatchDelayReply(const Message* msg, T* obj, P* parameter, \
529 Method func) { \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900530 Schema::SendParam send_params; \
531 bool ok = ReadSendParam(msg, &send_params); \
532 return Schema::DispatchDelayReplyWithSendParams(ok, send_params, msg, \
533 obj, func); \
534 }
535#define IPC_SYNC_MESSAGE_METHODS_0 \
536 IPC_SYNC_MESSAGE_METHODS_GENERIC
537#define IPC_SYNC_MESSAGE_METHODS_1 \
538 IPC_SYNC_MESSAGE_METHODS_GENERIC \
539 template<typename TA> \
540 static void WriteReplyParams(Message* reply, TA a) { \
541 Schema::WriteReplyParams(reply, a); \
542 }
543#define IPC_SYNC_MESSAGE_METHODS_2 \
544 IPC_SYNC_MESSAGE_METHODS_GENERIC \
545 template<typename TA, typename TB> \
546 static void WriteReplyParams(Message* reply, TA a, TB b) { \
547 Schema::WriteReplyParams(reply, a, b); \
548 }
549#define IPC_SYNC_MESSAGE_METHODS_3 \
550 IPC_SYNC_MESSAGE_METHODS_GENERIC \
551 template<typename TA, typename TB, typename TC> \
552 static void WriteReplyParams(Message* reply, TA a, TB b, TC c) { \
553 Schema::WriteReplyParams(reply, a, b, c); \
554 }
555#define IPC_SYNC_MESSAGE_METHODS_4 \
556 IPC_SYNC_MESSAGE_METHODS_GENERIC \
557 template<typename TA, typename TB, typename TC, typename TD> \
558 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d) { \
559 Schema::WriteReplyParams(reply, a, b, c, d); \
560 }
561#define IPC_SYNC_MESSAGE_METHODS_5 \
562 IPC_SYNC_MESSAGE_METHODS_GENERIC \
563 template<typename TA, typename TB, typename TC, typename TD, typename TE> \
564 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d, TE e) { \
565 Schema::WriteReplyParams(reply, a, b, c, d, e); \
566 }
567
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900568// Common message macro which dispatches into one of the 6 (sync x kind)
569// routines. There is a way that these 6 cases can be lumped together,
570// but the macros get very complicated in that case.
tsepez@chromium.org7272e462011-03-13 01:28:36 +0900571// Note: intended be redefined to generate other information.
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900572#define IPC_MESSAGE_DECL(sync, kind, msg_class, \
573 in_cnt, out_cnt, in_list, out_list) \
574 IPC_##sync##_##kind##_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
575 IPC_MESSAGE_EXTRA(sync, kind, msg_class, in_cnt, out_cnt, in_list, out_list)
576
577#define IPC_EMPTY_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
dpranke@chromium.org22a3e432011-10-27 10:45:58 +0900578 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900579 public: \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900580 typedef IPC::Message Schema; \
tsepez@chromium.org7272e462011-03-13 01:28:36 +0900581 enum { ID = IPC_MESSAGE_ID() }; \
bbudge@chromium.orgab4c6bc2013-11-05 07:28:12 +0900582 msg_class() : IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) {} \
jam@chromium.org1d8d4d12011-10-18 07:15:27 +0900583 static void Log(std::string* name, const Message* msg, std::string* l); \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900584 };
585
586#define IPC_EMPTY_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
dpranke@chromium.org22a3e432011-10-27 10:45:58 +0900587 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900588 public: \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900589 typedef IPC::Message Schema; \
tsepez@chromium.org7272e462011-03-13 01:28:36 +0900590 enum { ID = IPC_MESSAGE_ID() }; \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900591 msg_class(int32 routing_id) \
bbudge@chromium.orgab4c6bc2013-11-05 07:28:12 +0900592 : IPC::Message(routing_id, ID, PRIORITY_NORMAL) {} \
jam@chromium.org1d8d4d12011-10-18 07:15:27 +0900593 static void Log(std::string* name, const Message* msg, std::string* l); \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900594 };
595
596#define IPC_ASYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900597 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900598 public: \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900599 typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \
600 typedef Schema::Param Param; \
tsepez@chromium.org7272e462011-03-13 01:28:36 +0900601 enum { ID = IPC_MESSAGE_ID() }; \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900602 msg_class(IPC_TYPE_IN_##in_cnt in_list); \
hans@chromium.org78b75932011-05-25 18:08:19 +0900603 virtual ~msg_class(); \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900604 static bool Read(const Message* msg, Schema::Param* p); \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900605 static void Log(std::string* name, const Message* msg, std::string* l); \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900606 IPC_ASYNC_MESSAGE_METHODS_##in_cnt \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900607 };
608
609#define IPC_ASYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900610 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900611 public: \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900612 typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \
613 typedef Schema::Param Param; \
tsepez@chromium.org7272e462011-03-13 01:28:36 +0900614 enum { ID = IPC_MESSAGE_ID() }; \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900615 msg_class(int32 routing_id IPC_COMMA_##in_cnt \
616 IPC_TYPE_IN_##in_cnt in_list); \
hans@chromium.org78b75932011-05-25 18:08:19 +0900617 virtual ~msg_class(); \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900618 static bool Read(const Message* msg, Schema::Param* p); \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900619 static void Log(std::string* name, const Message* msg, std::string* l); \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900620 IPC_ASYNC_MESSAGE_METHODS_##in_cnt \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900621 };
622
623#define IPC_SYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900624 class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900625 public: \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900626 typedef IPC::SyncMessageSchema<IPC_TUPLE_IN_##in_cnt in_list, \
627 IPC_TUPLE_OUT_##out_cnt out_list> Schema; \
628 typedef Schema::ReplyParam ReplyParam; \
629 typedef Schema::SendParam SendParam; \
tsepez@chromium.org7272e462011-03-13 01:28:36 +0900630 enum { ID = IPC_MESSAGE_ID() }; \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900631 msg_class(IPC_TYPE_IN_##in_cnt in_list \
632 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
633 IPC_TYPE_OUT_##out_cnt out_list); \
hans@chromium.org78b75932011-05-25 18:08:19 +0900634 virtual ~msg_class(); \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900635 static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \
636 static bool ReadReplyParam( \
637 const Message* msg, \
638 TupleTypes<ReplyParam>::ValueTuple* p); \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900639 static void Log(std::string* name, const Message* msg, std::string* l); \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900640 IPC_SYNC_MESSAGE_METHODS_##out_cnt \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900641 };
642
643#define IPC_SYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900644 class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900645 public: \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900646 typedef IPC::SyncMessageSchema<IPC_TUPLE_IN_##in_cnt in_list, \
647 IPC_TUPLE_OUT_##out_cnt out_list> Schema; \
648 typedef Schema::ReplyParam ReplyParam; \
649 typedef Schema::SendParam SendParam; \
tsepez@chromium.org7272e462011-03-13 01:28:36 +0900650 enum { ID = IPC_MESSAGE_ID() }; \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900651 msg_class(int32 routing_id \
652 IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \
653 IPC_TYPE_IN_##in_cnt in_list \
654 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
655 IPC_TYPE_OUT_##out_cnt out_list); \
hans@chromium.org78b75932011-05-25 18:08:19 +0900656 virtual ~msg_class(); \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900657 static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \
658 static bool ReadReplyParam( \
659 const Message* msg, \
660 TupleTypes<ReplyParam>::ValueTuple* p); \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900661 static void Log(std::string* name, const Message* msg, std::string* l); \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900662 IPC_SYNC_MESSAGE_METHODS_##out_cnt \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900663 };
664
665#if defined(IPC_MESSAGE_IMPL)
666
667// "Implementation" inclusion produces constructors, destructors, and
668// logging functions, except for the no-arg special cases, where the
669// implementation occurs in the declaration, and there is no special
670// logging function.
671#define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
672 in_cnt, out_cnt, in_list, out_list) \
673 IPC_##sync##_##kind##_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
674 IPC_##sync##_MESSAGE_LOG(msg_class)
675
676#define IPC_EMPTY_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)
677#define IPC_EMPTY_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)
678
679#define IPC_ASYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
680 msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list) : \
bbudge@chromium.orgab4c6bc2013-11-05 07:28:12 +0900681 IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) { \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900682 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
683 } \
684 msg_class::~msg_class() {} \
685 bool msg_class::Read(const Message* msg, Schema::Param* p) { \
686 return Schema::Read(msg, p); \
687 }
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900688
689#define IPC_ASYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
690 msg_class::msg_class(int32 routing_id IPC_COMMA_##in_cnt \
691 IPC_TYPE_IN_##in_cnt in_list) : \
bbudge@chromium.orgab4c6bc2013-11-05 07:28:12 +0900692 IPC::Message(routing_id, ID, PRIORITY_NORMAL) { \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900693 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
694 } \
695 msg_class::~msg_class() {} \
696 bool msg_class::Read(const Message* msg, Schema::Param* p) { \
697 return Schema::Read(msg, p); \
698 }
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900699
700#define IPC_SYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
701 msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list \
702 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
703 IPC_TYPE_OUT_##out_cnt out_list) : \
bbudge@chromium.orgab4c6bc2013-11-05 07:28:12 +0900704 IPC::SyncMessage(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL, \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900705 new IPC::ParamDeserializer<Schema::ReplyParam>( \
706 IPC_NAME_OUT_##out_cnt out_list)) { \
707 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
708 } \
709 msg_class::~msg_class() {} \
710 bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \
711 return Schema::ReadSendParam(msg, p); \
712 } \
713 bool msg_class::ReadReplyParam(const Message* msg, \
714 TupleTypes<ReplyParam>::ValueTuple* p) { \
715 return Schema::ReadReplyParam(msg, p); \
716 }
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900717
718#define IPC_SYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
719 msg_class::msg_class(int32 routing_id \
720 IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \
721 IPC_TYPE_IN_##in_cnt in_list \
722 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
723 IPC_TYPE_OUT_##out_cnt out_list) : \
bbudge@chromium.orgab4c6bc2013-11-05 07:28:12 +0900724 IPC::SyncMessage(routing_id, ID, PRIORITY_NORMAL, \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900725 new IPC::ParamDeserializer<Schema::ReplyParam>( \
726 IPC_NAME_OUT_##out_cnt out_list)) { \
727 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
728 } \
729 msg_class::~msg_class() {} \
730 bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \
731 return Schema::ReadSendParam(msg, p); \
732 } \
733 bool msg_class::ReadReplyParam(const Message* msg, \
734 TupleTypes<ReplyParam>::ValueTuple* p) { \
735 return Schema::ReadReplyParam(msg, p); \
736 }
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900737
jam@chromium.org1d8d4d12011-10-18 07:15:27 +0900738#define IPC_EMPTY_MESSAGE_LOG(msg_class) \
739 void msg_class::Log(std::string* name, \
740 const Message* msg, \
741 std::string* l) { \
742 if (name) \
743 *name = #msg_class; \
744 }
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900745
746#define IPC_ASYNC_MESSAGE_LOG(msg_class) \
747 void msg_class::Log(std::string* name, \
748 const Message* msg, \
749 std::string* l) { \
750 if (name) \
751 *name = #msg_class; \
752 if (!msg || !l) \
753 return; \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900754 Schema::Param p; \
755 if (Schema::Read(msg, &p)) \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900756 IPC::LogParam(p, l); \
757 }
758
759#define IPC_SYNC_MESSAGE_LOG(msg_class) \
760 void msg_class::Log(std::string* name, \
761 const Message* msg, \
762 std::string* l) { \
763 if (name) \
764 *name = #msg_class; \
765 if (!msg || !l) \
766 return; \
767 if (msg->is_sync()) { \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900768 TupleTypes<Schema::SendParam>::ValueTuple p; \
769 if (Schema::ReadSendParam(msg, &p)) \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900770 IPC::LogParam(p, l); \
771 AddOutputParamsToLog(msg, l); \
772 } else { \
darin@chromium.orgb4587d52011-08-27 06:27:30 +0900773 TupleTypes<Schema::ReplyParam>::ValueTuple p; \
774 if (Schema::ReadReplyParam(msg, &p)) \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900775 IPC::LogParam(p, l); \
776 } \
777 }
778
jam@chromium.org86a8de12010-12-09 08:34:16 +0900779#elif defined(IPC_MESSAGE_MACROS_LOG_ENABLED)
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900780
jochen@chromium.orgffc24df2012-10-30 14:24:07 +0900781#ifndef IPC_LOG_TABLE_ADD_ENTRY
782#error You need to define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger)
783#endif
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900784
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900785// "Log table" inclusion produces extra logging registration code.
786#define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
787 in_cnt, out_cnt, in_list, out_list) \
788 class LoggerRegisterHelper##msg_class { \
789 public: \
790 LoggerRegisterHelper##msg_class() { \
jrg@chromium.org2eb192e2011-11-04 09:14:16 +0900791 const uint32 msg_id = static_cast<uint32>(msg_class::ID); \
jochen@chromium.orgffc24df2012-10-30 14:24:07 +0900792 IPC_LOG_TABLE_ADD_ENTRY(msg_id, msg_class::Log); \
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900793 } \
794 }; \
jam@chromium.org86a8de12010-12-09 08:34:16 +0900795 LoggerRegisterHelper##msg_class g_LoggerRegisterHelper##msg_class;
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900796
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900797#else
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900798
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900799// Normal inclusion produces nothing extra.
800#define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
801 in_cnt, out_cnt, in_list, out_list)
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900802
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900803#endif // defined(IPC_MESSAGE_IMPL)
jam@chromium.org86a8de12010-12-09 08:34:16 +0900804
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900805// Handle variable sized argument lists. These are usually invoked by token
806// pasting against the argument counts.
807#define IPC_TYPE_IN_0()
808#define IPC_TYPE_IN_1(t1) const t1& arg1
809#define IPC_TYPE_IN_2(t1, t2) const t1& arg1, const t2& arg2
810#define IPC_TYPE_IN_3(t1, t2, t3) const t1& arg1, const t2& arg2, const t3& arg3
811#define IPC_TYPE_IN_4(t1, t2, t3, t4) const t1& arg1, const t2& arg2, const t3& arg3, const t4& arg4
812#define IPC_TYPE_IN_5(t1, t2, t3, t4, t5) const t1& arg1, const t2& arg2, const t3& arg3, const t4& arg4, const t5& arg5
jam@chromium.org86a8de12010-12-09 08:34:16 +0900813
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900814#define IPC_TYPE_OUT_0()
815#define IPC_TYPE_OUT_1(t1) t1* arg6
816#define IPC_TYPE_OUT_2(t1, t2) t1* arg6, t2* arg7
817#define IPC_TYPE_OUT_3(t1, t2, t3) t1* arg6, t2* arg7, t3* arg8
818#define IPC_TYPE_OUT_4(t1, t2, t3, t4) t1* arg6, t2* arg7, t3* arg8, t4* arg9
jam@chromium.org86a8de12010-12-09 08:34:16 +0900819
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900820#define IPC_TUPLE_IN_0() Tuple0
821#define IPC_TUPLE_IN_1(t1) Tuple1<t1>
822#define IPC_TUPLE_IN_2(t1, t2) Tuple2<t1, t2>
823#define IPC_TUPLE_IN_3(t1, t2, t3) Tuple3<t1, t2, t3>
824#define IPC_TUPLE_IN_4(t1, t2, t3, t4) Tuple4<t1, t2, t3, t4>
825#define IPC_TUPLE_IN_5(t1, t2, t3, t4, t5) Tuple5<t1, t2, t3, t4, t5>
jam@chromium.org86a8de12010-12-09 08:34:16 +0900826
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900827#define IPC_TUPLE_OUT_0() Tuple0
828#define IPC_TUPLE_OUT_1(t1) Tuple1<t1&>
829#define IPC_TUPLE_OUT_2(t1, t2) Tuple2<t1&, t2&>
830#define IPC_TUPLE_OUT_3(t1, t2, t3) Tuple3<t1&, t2&, t3&>
831#define IPC_TUPLE_OUT_4(t1, t2, t3, t4) Tuple4<t1&, t2&, t3&, t4&>
jam@chromium.org86a8de12010-12-09 08:34:16 +0900832
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900833#define IPC_NAME_IN_0() MakeTuple()
834#define IPC_NAME_IN_1(t1) MakeRefTuple(arg1)
835#define IPC_NAME_IN_2(t1, t2) MakeRefTuple(arg1, arg2)
836#define IPC_NAME_IN_3(t1, t2, t3) MakeRefTuple(arg1, arg2, arg3)
837#define IPC_NAME_IN_4(t1, t2, t3, t4) MakeRefTuple(arg1, arg2, arg3, arg4)
838#define IPC_NAME_IN_5(t1, t2, t3, t4, t5) MakeRefTuple(arg1, arg2, arg3, arg4, arg5)
jam@chromium.org86a8de12010-12-09 08:34:16 +0900839
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900840#define IPC_NAME_OUT_0() MakeTuple()
841#define IPC_NAME_OUT_1(t1) MakeRefTuple(*arg6)
842#define IPC_NAME_OUT_2(t1, t2) MakeRefTuple(*arg6, *arg7)
843#define IPC_NAME_OUT_3(t1, t2, t3) MakeRefTuple(*arg6, *arg7, *arg8)
844#define IPC_NAME_OUT_4(t1, t2, t3, t4) MakeRefTuple(*arg6, *arg7, *arg8, *arg9)
jam@chromium.org86a8de12010-12-09 08:34:16 +0900845
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900846// There are places where the syntax requires a comma if there are input args,
847// if there are input args and output args, or if there are input args or
848// output args. These macros allow generation of the comma as needed; invoke
849// by token pasting against the argument counts.
850#define IPC_COMMA_0
851#define IPC_COMMA_1 ,
852#define IPC_COMMA_2 ,
853#define IPC_COMMA_3 ,
854#define IPC_COMMA_4 ,
855#define IPC_COMMA_5 ,
jam@chromium.org86a8de12010-12-09 08:34:16 +0900856
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900857#define IPC_COMMA_AND_0(x)
858#define IPC_COMMA_AND_1(x) x
859#define IPC_COMMA_AND_2(x) x
860#define IPC_COMMA_AND_3(x) x
861#define IPC_COMMA_AND_4(x) x
862#define IPC_COMMA_AND_5(x) x
jam@chromium.org86a8de12010-12-09 08:34:16 +0900863
tsepez@chromium.orgd65bab52011-03-02 05:35:47 +0900864#define IPC_COMMA_OR_0(x) x
865#define IPC_COMMA_OR_1(x) ,
866#define IPC_COMMA_OR_2(x) ,
867#define IPC_COMMA_OR_3(x) ,
868#define IPC_COMMA_OR_4(x) ,
869#define IPC_COMMA_OR_5(x) ,
jrg@chromium.orgf6c20d92010-03-13 03:27:53 +0900870
tsepez@chromium.org7272e462011-03-13 01:28:36 +0900871// Message IDs
872// Note: we currently use __LINE__ to give unique IDs to messages within
873// a file. They're globally unique since each file defines its own
jam@chromium.org4057ce32011-10-22 02:35:08 +0900874// IPC_MESSAGE_START.
tsepez@chromium.org7272e462011-03-13 01:28:36 +0900875#define IPC_MESSAGE_ID() ((IPC_MESSAGE_START << 16) + __LINE__)
876#define IPC_MESSAGE_ID_CLASS(id) ((id) >> 16)
877#define IPC_MESSAGE_ID_LINE(id) ((id) & 0xffff)
878
jam@chromium.org862a5e02014-05-17 06:29:33 +0900879// Message crackers and handlers. Usage:
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900880//
jam@chromium.org8a2c7842010-12-24 15:19:28 +0900881// bool MyClass::OnMessageReceived(const IPC::Message& msg) {
882// bool handled = true;
jam@chromium.org862a5e02014-05-17 06:29:33 +0900883// IPC_BEGIN_MESSAGE_MAP(MyClass, msg)
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900884// IPC_MESSAGE_HANDLER(MsgClassOne, OnMsgClassOne)
885// ...more handlers here ...
886// IPC_MESSAGE_HANDLER(MsgClassTen, OnMsgClassTen)
jam@chromium.org8a2c7842010-12-24 15:19:28 +0900887// IPC_MESSAGE_UNHANDLED(handled = false)
jam@chromium.org862a5e02014-05-17 06:29:33 +0900888// IPC_END_MESSAGE_MAP()
jam@chromium.org8a2c7842010-12-24 15:19:28 +0900889// return handled;
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900890// }
891
jam@chromium.org86a8de12010-12-09 08:34:16 +0900892
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900893#define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \
894 { \
thakis@chromium.orgaccd6972014-07-29 16:55:22 +0900895 typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED; \
jam@chromium.org65bedbc2014-05-15 06:43:59 +0900896 void* param__ = NULL; \
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900897 const IPC::Message& ipc_message__ = msg; \
jam@chromium.org65bedbc2014-05-15 06:43:59 +0900898 switch (ipc_message__.type()) {
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900899
jam@chromium.org65bedbc2014-05-15 06:43:59 +0900900// gcc gives the following error now when using decltype so type typeof there:
901// error: identifier 'decltype' will become a keyword in C++0x [-Werror=c++0x-compat]
902#if defined(OS_WIN)
903#define IPC_DECLTYPE decltype
904#else
905#define IPC_DECLTYPE typeof
906#endif
907
thakis@chromium.orgaccd6972014-07-29 16:55:22 +0900908#define IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(class_name, msg, param) \
909 { \
910 typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED; \
911 IPC_DECLTYPE(param) param__ = param; \
912 const IPC::Message& ipc_message__ = msg; \
jam@chromium.org65bedbc2014-05-15 06:43:59 +0900913 switch (ipc_message__.type()) {
jam@chromium.orgf6370182014-05-14 08:19:10 +0900914
jar@chromium.org16111832011-11-11 09:21:02 +0900915#define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \
916 case msg_class::ID: { \
jar@chromium.orgb0babea2011-11-11 10:00:17 +0900917 TRACK_RUN_IN_IPC_HANDLER(member_func); \
jam@chromium.org862a5e02014-05-17 06:29:33 +0900918 if (!msg_class::Dispatch(&ipc_message__, obj, this, param__, \
919 &member_func)) \
jam@chromium.org822f1fb2014-05-16 08:06:07 +0900920 ipc_message__.set_dispatch_error(); \
jar@chromium.org16111832011-11-11 09:21:02 +0900921 } \
922 break;
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900923
924#define IPC_MESSAGE_HANDLER(msg_class, member_func) \
925 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func)
926
jar@chromium.org16111832011-11-11 09:21:02 +0900927#define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \
928 case msg_class::ID: { \
jar@chromium.org1b19a352011-11-16 02:51:43 +0900929 TRACK_RUN_IN_IPC_HANDLER(member_func); \
jam@chromium.org862a5e02014-05-17 06:29:33 +0900930 if (!msg_class::DispatchDelayReply(&ipc_message__, obj, param__, \
931 &member_func)) \
jam@chromium.org822f1fb2014-05-16 08:06:07 +0900932 ipc_message__.set_dispatch_error(); \
jar@chromium.org16111832011-11-11 09:21:02 +0900933 } \
934 break;
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900935
jar@chromium.org16111832011-11-11 09:21:02 +0900936#define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \
937 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \
938 _IpcMessageHandlerClass::member_func)
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900939
jar@chromium.org1b19a352011-11-16 02:51:43 +0900940// TODO(jar): fix chrome frame to always supply |code| argument.
jar@chromium.org16111832011-11-11 09:21:02 +0900941#define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \
942 case msg_class::ID: { \
jar@chromium.org4646d822011-11-12 11:58:59 +0900943 /* TRACK_RUN_IN_IPC_HANDLER(code); TODO(jar) */ \
jar@chromium.org16111832011-11-11 09:21:02 +0900944 code; \
945 } \
946 break;
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900947
jar@chromium.org16111832011-11-11 09:21:02 +0900948#define IPC_REPLY_HANDLER(func) \
949 case IPC_REPLY_ID: { \
jar@chromium.orgee705152011-11-12 07:41:08 +0900950 TRACK_RUN_IN_IPC_HANDLER(func); \
jar@chromium.org16111832011-11-11 09:21:02 +0900951 func(ipc_message__); \
952 } \
953 break;
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900954
955
jar@chromium.org16111832011-11-11 09:21:02 +0900956#define IPC_MESSAGE_UNHANDLED(code) \
957 default: { \
jar@chromium.org16111832011-11-11 09:21:02 +0900958 code; \
959 } \
960 break;
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900961
962#define IPC_MESSAGE_UNHANDLED_ERROR() \
963 IPC_MESSAGE_UNHANDLED(NOTREACHED() << \
964 "Invalid message with type = " << \
965 ipc_message__.type())
966
967#define IPC_END_MESSAGE_MAP() \
agl@chromium.org1c6dcf22009-07-23 08:57:21 +0900968 } \
jam@chromium.org5eaa2f52010-12-09 08:41:08 +0900969}
jam@chromium.orgb0876412010-12-14 02:00:42 +0900970
971// This corresponds to an enum value from IPCMessageStart.
972#define IPC_MESSAGE_CLASS(message) \
tsepez@chromium.org7272e462011-03-13 01:28:36 +0900973 IPC_MESSAGE_ID_CLASS(message.type())
tsepez@chromium.org1ac46132011-02-12 03:46:19 +0900974
975#endif // IPC_IPC_MESSAGE_MACROS_H_
976
zturner@chromium.orge8cd3672013-10-12 10:29:56 +0900977// The following #ifdef cannot be removed. Although the code is semantically
978// equivalent without the #ifdef, VS2013 contains a bug where it is
979// over-aggressive in optimizing out #includes. Putting the #ifdef is a
980// workaround for this bug. See http://goo.gl/eGt2Fb for more details.
981// This can be removed once VS2013 is fixed.
982#ifdef IPC_MESSAGE_START
tsepez@chromium.org1ac46132011-02-12 03:46:19 +0900983// Clean up IPC_MESSAGE_START in this unguarded section so that the
984// XXX_messages.h files need not do so themselves. This makes the
985// XXX_messages.h files easier to write.
986#undef IPC_MESSAGE_START
thakis@chromium.orgf9d5c0c2013-10-12 15:25:35 +0900987#endif