blob: 783108eaab4c9a1c702b404b1f5ae20bc8f0d031 [file] [log] [blame]
[email protected]6476c72c2011-02-11 18:46:191// Copyright (c) 2011 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
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:
18// - An XXXMsgStart value to the IPCMessageStart enum in ipc_message_utils.h
19// - 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//
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.
[email protected]21fa3a12010-12-08 23:34:1640// #define IPC_MESSAGE_IMPL
[email protected]6476c72c2011-02-11 18:46:1941// #include "path/to/YYY_message_generator.h"
42// // Generate constructors.
43// #include "ipc/struct_constructor_macros.h"
44// #include "path/to/YYY_message_generator.h"
45// // Generate destructors.
46// #include "ipc/struct_destructor_macros.h"
47// #include "path/to/YYY_message_generator.h"
[email protected]6476c72c2011-02-11 18:46:1948// // Generate param traits write methods.
49// #include "ipc/param_traits_write_macros.h"
[email protected]d7a5e3e2011-03-12 16:28:3650// namespace IPC {
[email protected]6476c72c2011-02-11 18:46:1951// #include "path/to/YYY_message_generator.h"
[email protected]d7a5e3e2011-03-12 16:28:3652// } // namespace IPC
[email protected]6476c72c2011-02-11 18:46:1953// // Generate param traits read methods.
54// #include "ipc/param_traits_read_macros.h"
[email protected]d7a5e3e2011-03-12 16:28:3655// namespace IPC {
[email protected]6476c72c2011-02-11 18:46:1956// #include "path/to/YYY_message_generator.h"
[email protected]d7a5e3e2011-03-12 16:28:3657// } // namespace IPC
[email protected]6476c72c2011-02-11 18:46:1958// // Generate param traits log methods.
59// #include "ipc/param_traits_log_macros.h"
[email protected]d7a5e3e2011-03-12 16:28:3660// namespace IPC {
[email protected]6476c72c2011-02-11 18:46:1961// #include "path/to/YYY_message_generator.h"
62// } // namespace IPC
initial.commit09911bf2008-07-26 23:55:2963//
[email protected]6476c72c2011-02-11 18:46:1964// In cases where manual generation is required, in your XXX_messages.cc
65// file, put the following after all the includes for param types:
66// #define IPC_MESSAGE_IMPL
67// #include "XXX_messages.h"
68// (... implementation of traits not auto-generated ...)
69//
70// Multiple Inclusion
71//
72// The XXX_messages.h file will be multiply-included by the
73// YYY_message_generator.cc file, so your XXX_messages file can't be
74// guarded in the usual manner. Ideally, there will be no need for any
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//
79// Note that there is no #pragma once either; doing so would mark the whole
80// 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
116// #inlcude "path/to/some_class.h" // Full class declaration
117// #inlcude "path/to/some_other_class.h" // Full class declaration
118// #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
133// IPC_STRUCT_BEGIN() / IPC_STRUCT_END().
134//
135// Externally-defined structs are registered with IPC_STRUCT_TRAITS_BEGIN(),
136// IPC_STRUCT_TRAITS_MEMBER(), and IPC_STRUCT_TRAITS_END() macros. These
[email protected]94dc971d2011-03-05 19:08:32137// cause registration of the types with message generation only.
138// There's also IPC_STRUCT_TRAITS_PARENT, which is used to register a parent
139// class (whose own traits are already defined). Note that
140// IPC_STRUCT_TRAITS_MEMBER() and IPC_STRUCT_TRAITS_PARENT are only permitted
[email protected]e503a122011-03-17 18:20:52141// inside matching calls to IPC_STRUCT_TRAITS_BEGIN() /
142// IPC_STRUCT_TRAITS_END().
[email protected]6476c72c2011-02-11 18:46:19143//
144// Enum types are registered with a single IPC_ENUM_TRAITS() macro. There
145// is no need to enumerate each value to the IPC mechanism.
146//
[email protected]e503a122011-03-17 18:20:52147// Do not place semicolons following these IPC_ macro invocations. There
148// is no reason to expect that their expansion corresponds one-to-one with
149// C++ statements.
150//
[email protected]6476c72c2011-02-11 18:46:19151// Once the types have been declared / registered, message definitions follow.
initial.commit09911bf2008-07-26 23:55:29152// "Sync" messages are just synchronous calls, the Send() call doesn't return
[email protected]7f994182011-08-23 10:18:10153// until a reply comes back. To declare a sync message, use the IPC_SYNC_
154// macros. The numbers at the end show how many input/output parameters there
155// are (i.e. 1_2 is 1 in, 2 out). Input parameters are first, followed by
156// output parameters. The caller uses Send([route id, ], in1, &out1, &out2).
initial.commit09911bf2008-07-26 23:55:29157// The receiver's handler function will be
158// void OnSyncMessageName(const type1& in1, type2* out1, type3* out2)
159//
initial.commit09911bf2008-07-26 23:55:29160// A caller can also send a synchronous message, while the receiver can respond
[email protected]d4240352009-12-10 17:32:31161// at a later time. This is transparent from the sender's side. The receiver
initial.commit09911bf2008-07-26 23:55:29162// needs to use a different handler that takes in a IPC::Message* as the output
163// type, stash the message, and when it has the data it can Send the message.
164//
165// Use the IPC_MESSAGE_HANDLER_DELAY_REPLY macro instead of IPC_MESSAGE_HANDLER
[email protected]d3216442009-03-05 21:07:27166// IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncMessageName,
167// OnSyncMessageName)
initial.commit09911bf2008-07-26 23:55:29168//
169// The handler function will look like:
170// void OnSyncMessageName(const type1& in1, IPC::Message* reply_msg);
171//
172// Receiver stashes the IPC::Message* pointer, and when it's ready, it does:
173// ViewHostMsg_SyncMessageName::WriteReplyParams(reply_msg, out1, out2);
174// Send(reply_msg);
175
[email protected]6476c72c2011-02-11 18:46:19176#ifndef IPC_IPC_MESSAGE_MACROS_H_
177#define IPC_IPC_MESSAGE_MACROS_H_
[email protected]82e5ee82009-04-03 02:29:45178
[email protected]e86a2552011-11-11 00:21:02179#include "base/profiler/scoped_profile.h"
[email protected]6476c72c2011-02-11 18:46:19180#include "ipc/ipc_message_utils.h"
181#include "ipc/param_traits_macros.h"
[email protected]f91cb992009-02-04 20:10:12182
[email protected]21fa3a12010-12-08 23:34:16183#if defined(IPC_MESSAGE_IMPL)
[email protected]8a8c9c72011-03-01 20:35:47184#include "ipc/ipc_message_utils_impl.h"
185#endif
186
[email protected]50473c12011-09-06 22:51:11187// Override this to force message classes to be exported.
188#ifndef IPC_MESSAGE_EXPORT
189#define IPC_MESSAGE_EXPORT
190#endif
191
[email protected]8a8c9c72011-03-01 20:35:47192// Macros for defining structs. May be subsequently redefined.
193#define IPC_STRUCT_BEGIN(struct_name) \
[email protected]6766b172011-11-21 18:29:36194 IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, IPC::NoParams)
195#define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \
[email protected]8a8c9c72011-03-01 20:35:47196 struct struct_name; \
197 IPC_STRUCT_TRAITS_BEGIN(struct_name) \
198 IPC_STRUCT_TRAITS_END() \
[email protected]6766b172011-11-21 18:29:36199 struct IPC_MESSAGE_EXPORT struct_name : parent { \
[email protected]8a8c9c72011-03-01 20:35:47200 struct_name(); \
201 ~struct_name();
202#define IPC_STRUCT_MEMBER(type, name) type name;
203#define IPC_STRUCT_END() };
204
205// Message macros collect specific numbers of arguments and funnel them into
[email protected]d7a5e3e2011-03-12 16:28:36206// the common message generation macro. These should never be redefined.
[email protected]8a8c9c72011-03-01 20:35:47207#define IPC_MESSAGE_CONTROL0(msg_class) \
208 IPC_MESSAGE_DECL(EMPTY, CONTROL, msg_class, 0, 0, (), ())
209
210#define IPC_MESSAGE_CONTROL1(msg_class, type1) \
211 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 1, 0, (type1), ())
212
213#define IPC_MESSAGE_CONTROL2(msg_class, type1, type2) \
214 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 2, 0, (type1, type2), ())
215
216#define IPC_MESSAGE_CONTROL3(msg_class, type1, type2, type3) \
217 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 3, 0, (type1, type2, type3), ())
218
219#define IPC_MESSAGE_CONTROL4(msg_class, type1, type2, type3, type4) \
220 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 4, 0, (type1, type2, type3, type4), ())
221
222#define IPC_MESSAGE_CONTROL5(msg_class, type1, type2, type3, type4, type5) \
223 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 5, 0, (type1, type2, type3, type4, type5), ())
224
225#define IPC_MESSAGE_ROUTED0(msg_class) \
226 IPC_MESSAGE_DECL(EMPTY, ROUTED, msg_class, 0, 0, (), ())
227
228#define IPC_MESSAGE_ROUTED1(msg_class, type1) \
229 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 1, 0, (type1), ())
230
231#define IPC_MESSAGE_ROUTED2(msg_class, type1, type2) \
232 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 2, 0, (type1, type2), ())
233
234#define IPC_MESSAGE_ROUTED3(msg_class, type1, type2, type3) \
235 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 3, 0, (type1, type2, type3), ())
236
237#define IPC_MESSAGE_ROUTED4(msg_class, type1, type2, type3, type4) \
238 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 4, 0, (type1, type2, type3, type4), ())
239
240#define IPC_MESSAGE_ROUTED5(msg_class, type1, type2, type3, type4, type5) \
241 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 5, 0, (type1, type2, type3, type4, type5), ())
242
243#define IPC_SYNC_MESSAGE_CONTROL0_0(msg_class) \
244 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 0, (), ())
245
246#define IPC_SYNC_MESSAGE_CONTROL0_1(msg_class, type1_out) \
247 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 1, (), (type1_out))
248
249#define IPC_SYNC_MESSAGE_CONTROL0_2(msg_class, type1_out, type2_out) \
250 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 2, (), (type1_out, type2_out))
251
252#define IPC_SYNC_MESSAGE_CONTROL0_3(msg_class, type1_out, type2_out, type3_out) \
253 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 3, (), (type1_out, type2_out, type3_out))
254
255#define IPC_SYNC_MESSAGE_CONTROL0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \
256 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out))
257
258#define IPC_SYNC_MESSAGE_CONTROL1_0(msg_class, type1_in) \
259 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 0, (type1_in), ())
260
261#define IPC_SYNC_MESSAGE_CONTROL1_1(msg_class, type1_in, type1_out) \
262 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 1, (type1_in), (type1_out))
263
264#define IPC_SYNC_MESSAGE_CONTROL1_2(msg_class, type1_in, type1_out, type2_out) \
265 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 2, (type1_in), (type1_out, type2_out))
266
267#define IPC_SYNC_MESSAGE_CONTROL1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \
268 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out))
269
270#define IPC_SYNC_MESSAGE_CONTROL1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \
271 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out))
272
273#define IPC_SYNC_MESSAGE_CONTROL2_0(msg_class, type1_in, type2_in) \
274 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 0, (type1_in, type2_in), ())
275
276#define IPC_SYNC_MESSAGE_CONTROL2_1(msg_class, type1_in, type2_in, type1_out) \
277 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 1, (type1_in, type2_in), (type1_out))
278
279#define IPC_SYNC_MESSAGE_CONTROL2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \
280 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out))
281
282#define IPC_SYNC_MESSAGE_CONTROL2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \
283 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out))
284
285#define IPC_SYNC_MESSAGE_CONTROL2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \
286 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out))
287
288#define IPC_SYNC_MESSAGE_CONTROL3_0(msg_class, type1_in, type2_in, type3_in) \
289 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 0, (type1_in, type2_in, type3_in), ())
290
291#define IPC_SYNC_MESSAGE_CONTROL3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \
292 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out))
293
294#define IPC_SYNC_MESSAGE_CONTROL3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \
295 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out))
296
297#define IPC_SYNC_MESSAGE_CONTROL3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \
298 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out))
299
300#define IPC_SYNC_MESSAGE_CONTROL3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \
301 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out))
302
303#define IPC_SYNC_MESSAGE_CONTROL4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \
304 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 0, (type1_in, type2_in, type3_in, type4_in), ())
305
306#define IPC_SYNC_MESSAGE_CONTROL4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \
307 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out))
308
309#define IPC_SYNC_MESSAGE_CONTROL4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \
310 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out))
311
312#define IPC_SYNC_MESSAGE_CONTROL4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \
313 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out))
314
315#define IPC_SYNC_MESSAGE_CONTROL4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \
316 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))
317
318#define IPC_SYNC_MESSAGE_CONTROL5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \
[email protected]acd3d7712011-03-10 15:34:21319 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 0, (type1_in, type2_in, type3_in, type4_in, type5_in), ())
[email protected]8a8c9c72011-03-01 20:35:47320
321#define IPC_SYNC_MESSAGE_CONTROL5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \
322 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out))
323
324#define IPC_SYNC_MESSAGE_CONTROL5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \
325 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out))
326
327#define IPC_SYNC_MESSAGE_CONTROL5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \
328 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))
329
330#define IPC_SYNC_MESSAGE_CONTROL5_4(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out, type4_out) \
331 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 4, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out, type3_out, type4_out))
332
333#define IPC_SYNC_MESSAGE_ROUTED0_0(msg_class) \
334 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 0, (), ())
335
336#define IPC_SYNC_MESSAGE_ROUTED0_1(msg_class, type1_out) \
337 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 1, (), (type1_out))
338
339#define IPC_SYNC_MESSAGE_ROUTED0_2(msg_class, type1_out, type2_out) \
340 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 2, (), (type1_out, type2_out))
341
342#define IPC_SYNC_MESSAGE_ROUTED0_3(msg_class, type1_out, type2_out, type3_out) \
343 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 3, (), (type1_out, type2_out, type3_out))
344
345#define IPC_SYNC_MESSAGE_ROUTED0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \
346 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out))
347
348#define IPC_SYNC_MESSAGE_ROUTED1_0(msg_class, type1_in) \
349 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 0, (type1_in), ())
350
351#define IPC_SYNC_MESSAGE_ROUTED1_1(msg_class, type1_in, type1_out) \
352 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 1, (type1_in), (type1_out))
353
354#define IPC_SYNC_MESSAGE_ROUTED1_2(msg_class, type1_in, type1_out, type2_out) \
355 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 2, (type1_in), (type1_out, type2_out))
356
357#define IPC_SYNC_MESSAGE_ROUTED1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \
358 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out))
359
360#define IPC_SYNC_MESSAGE_ROUTED1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \
361 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out))
362
363#define IPC_SYNC_MESSAGE_ROUTED2_0(msg_class, type1_in, type2_in) \
364 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 0, (type1_in, type2_in), ())
365
366#define IPC_SYNC_MESSAGE_ROUTED2_1(msg_class, type1_in, type2_in, type1_out) \
367 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 1, (type1_in, type2_in), (type1_out))
368
369#define IPC_SYNC_MESSAGE_ROUTED2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \
370 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out))
371
372#define IPC_SYNC_MESSAGE_ROUTED2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \
373 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out))
374
375#define IPC_SYNC_MESSAGE_ROUTED2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \
376 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out))
377
378#define IPC_SYNC_MESSAGE_ROUTED3_0(msg_class, type1_in, type2_in, type3_in) \
379 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 0, (type1_in, type2_in, type3_in), ())
380
381#define IPC_SYNC_MESSAGE_ROUTED3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \
382 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out))
383
384#define IPC_SYNC_MESSAGE_ROUTED3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \
385 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out))
386
387#define IPC_SYNC_MESSAGE_ROUTED3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \
388 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out))
389
390#define IPC_SYNC_MESSAGE_ROUTED3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \
391 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out))
392
393#define IPC_SYNC_MESSAGE_ROUTED4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \
394 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), ())
395
396#define IPC_SYNC_MESSAGE_ROUTED4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \
397 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out))
398
399#define IPC_SYNC_MESSAGE_ROUTED4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \
400 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out))
401
402#define IPC_SYNC_MESSAGE_ROUTED4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \
403 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out))
404
405#define IPC_SYNC_MESSAGE_ROUTED4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \
406 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))
407
408#define IPC_SYNC_MESSAGE_ROUTED5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \
[email protected]acd3d7712011-03-10 15:34:21409 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), ())
[email protected]8a8c9c72011-03-01 20:35:47410
411#define IPC_SYNC_MESSAGE_ROUTED5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \
412 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out))
413
414#define IPC_SYNC_MESSAGE_ROUTED5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \
415 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out))
416
417#define IPC_SYNC_MESSAGE_ROUTED5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \
418 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))
419
420#define IPC_SYNC_MESSAGE_ROUTED5_4(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out, type4_out) \
421 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 4, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out, type3_out, type4_out))
422
[email protected]1d4ecf42011-08-26 21:27:30423// The following macros define the common set of methods provided by ASYNC
424// message classes.
425#define IPC_ASYNC_MESSAGE_METHODS_GENERIC \
426 template<class T, class S, class Method> \
427 static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) { \
428 Schema::Param p; \
429 if (Read(msg, &p)) { \
430 DispatchToMethod(obj, func, p); \
431 return true; \
432 } \
433 return false; \
434 }
435#define IPC_ASYNC_MESSAGE_METHODS_1 \
436 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
437 template<class T, class S, typename TA> \
438 static bool Dispatch(const Message* msg, T* obj, S* sender, \
439 void (T::*func)(const Message&, TA)) { \
440 Schema::Param p; \
441 if (Read(msg, &p)) { \
442 (obj->*func)(*msg, p.a); \
443 return true; \
444 } \
445 return false; \
446 }
447#define IPC_ASYNC_MESSAGE_METHODS_2 \
448 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
449 template<class T, class S, typename TA, typename TB> \
450 static bool Dispatch(const Message* msg, T* obj, S* sender, \
451 void (T::*func)(const Message&, TA, TB)) { \
452 Schema::Param p; \
453 if (Read(msg, &p)) { \
454 (obj->*func)(*msg, p.a, p.b); \
455 return true; \
456 } \
457 return false; \
458 } \
459 template<typename TA, typename TB> \
460 static bool Read(const IPC::Message* msg, TA* a, TB* b) { \
461 Schema::Param p; \
462 if (!Read(msg, &p)) \
463 return false; \
464 *a = p.a; \
465 *b = p.b; \
466 return true; \
467 }
468#define IPC_ASYNC_MESSAGE_METHODS_3 \
469 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
470 template<class T, class S, typename TA, typename TB, typename TC> \
471 static bool Dispatch(const Message* msg, T* obj, S* sender, \
472 void (T::*func)(const Message&, TA, TB, TC)) { \
473 Schema::Param p; \
474 if (Read(msg, &p)) { \
475 (obj->*func)(*msg, p.a, p.b, p.c); \
476 return true; \
477 } \
478 return false; \
479 } \
480 template<typename TA, typename TB, typename TC> \
481 static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c) { \
482 Schema::Param p; \
483 if (!Read(msg, &p)) \
484 return false; \
485 *a = p.a; \
486 *b = p.b; \
487 *c = p.c; \
488 return true; \
489 }
490#define IPC_ASYNC_MESSAGE_METHODS_4 \
491 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
492 template<class T, class S, typename TA, typename TB, typename TC, \
493 typename TD> \
494 static bool Dispatch(const Message* msg, T* obj, S* sender, \
495 void (T::*func)(const Message&, TA, TB, TC, TD)) { \
496 Schema::Param p; \
497 if (Read(msg, &p)) { \
498 (obj->*func)(*msg, p.a, p.b, p.c, p.d); \
499 return true; \
500 } \
501 return false; \
502 } \
503 template<typename TA, typename TB, typename TC, typename TD> \
504 static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d) { \
505 Schema::Param p; \
506 if (!Read(msg, &p)) \
507 return false; \
508 *a = p.a; \
509 *b = p.b; \
510 *c = p.c; \
511 *d = p.d; \
512 return true; \
513 }
514#define IPC_ASYNC_MESSAGE_METHODS_5 \
515 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
516 template<class T, class S, typename TA, typename TB, typename TC, \
517 typename TD, typename TE> \
518 static bool Dispatch(const Message* msg, T* obj, S* sender, \
519 void (T::*func)(const Message&, TA, TB, TC, TD, TE)) { \
520 Schema::Param p; \
521 if (Read(msg, &p)) { \
522 (obj->*func)(*msg, p.a, p.b, p.c, p.d, p.e); \
523 return true; \
524 } \
525 return false; \
526 } \
527 template<typename TA, typename TB, typename TC, typename TD, typename TE> \
528 static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d, \
529 TE* e) { \
530 Schema::Param p; \
531 if (!Read(msg, &p)) \
532 return false; \
533 *a = p.a; \
534 *b = p.b; \
535 *c = p.c; \
536 *d = p.d; \
537 *e = p.e; \
538 return true; \
539 }
540
541// The following macros define the common set of methods provided by SYNC
542// message classes.
543#define IPC_SYNC_MESSAGE_METHODS_GENERIC \
544 template<class T, class S, class Method> \
545 static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) { \
546 Schema::SendParam send_params; \
547 bool ok = ReadSendParam(msg, &send_params); \
548 return Schema::DispatchWithSendParams(ok, send_params, msg, obj, sender, \
549 func); \
550 } \
551 template<class T, class Method> \
552 static bool DispatchDelayReply(const Message* msg, T* obj, Method func) { \
553 Schema::SendParam send_params; \
554 bool ok = ReadSendParam(msg, &send_params); \
555 return Schema::DispatchDelayReplyWithSendParams(ok, send_params, msg, \
556 obj, func); \
557 }
558#define IPC_SYNC_MESSAGE_METHODS_0 \
559 IPC_SYNC_MESSAGE_METHODS_GENERIC
560#define IPC_SYNC_MESSAGE_METHODS_1 \
561 IPC_SYNC_MESSAGE_METHODS_GENERIC \
562 template<typename TA> \
563 static void WriteReplyParams(Message* reply, TA a) { \
564 Schema::WriteReplyParams(reply, a); \
565 }
566#define IPC_SYNC_MESSAGE_METHODS_2 \
567 IPC_SYNC_MESSAGE_METHODS_GENERIC \
568 template<typename TA, typename TB> \
569 static void WriteReplyParams(Message* reply, TA a, TB b) { \
570 Schema::WriteReplyParams(reply, a, b); \
571 }
572#define IPC_SYNC_MESSAGE_METHODS_3 \
573 IPC_SYNC_MESSAGE_METHODS_GENERIC \
574 template<typename TA, typename TB, typename TC> \
575 static void WriteReplyParams(Message* reply, TA a, TB b, TC c) { \
576 Schema::WriteReplyParams(reply, a, b, c); \
577 }
578#define IPC_SYNC_MESSAGE_METHODS_4 \
579 IPC_SYNC_MESSAGE_METHODS_GENERIC \
580 template<typename TA, typename TB, typename TC, typename TD> \
581 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d) { \
582 Schema::WriteReplyParams(reply, a, b, c, d); \
583 }
584#define IPC_SYNC_MESSAGE_METHODS_5 \
585 IPC_SYNC_MESSAGE_METHODS_GENERIC \
586 template<typename TA, typename TB, typename TC, typename TD, typename TE> \
587 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d, TE e) { \
588 Schema::WriteReplyParams(reply, a, b, c, d, e); \
589 }
590
[email protected]8a8c9c72011-03-01 20:35:47591// Common message macro which dispatches into one of the 6 (sync x kind)
592// routines. There is a way that these 6 cases can be lumped together,
593// but the macros get very complicated in that case.
[email protected]d7a5e3e2011-03-12 16:28:36594// Note: intended be redefined to generate other information.
[email protected]8a8c9c72011-03-01 20:35:47595#define IPC_MESSAGE_DECL(sync, kind, msg_class, \
596 in_cnt, out_cnt, in_list, out_list) \
597 IPC_##sync##_##kind##_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
598 IPC_MESSAGE_EXTRA(sync, kind, msg_class, in_cnt, out_cnt, in_list, out_list)
599
600#define IPC_EMPTY_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
[email protected]7b604962011-10-27 01:45:58601 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
[email protected]8a8c9c72011-03-01 20:35:47602 public: \
[email protected]1d4ecf42011-08-26 21:27:30603 typedef IPC::Message Schema; \
[email protected]d7a5e3e2011-03-12 16:28:36604 enum { ID = IPC_MESSAGE_ID() }; \
[email protected]8a8c9c72011-03-01 20:35:47605 msg_class() : IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) {} \
[email protected]8bf55ca2011-10-17 22:15:27606 static void Log(std::string* name, const Message* msg, std::string* l); \
[email protected]8a8c9c72011-03-01 20:35:47607 };
608
609#define IPC_EMPTY_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
[email protected]7b604962011-10-27 01:45:58610 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
[email protected]8a8c9c72011-03-01 20:35:47611 public: \
[email protected]1d4ecf42011-08-26 21:27:30612 typedef IPC::Message Schema; \
[email protected]d7a5e3e2011-03-12 16:28:36613 enum { ID = IPC_MESSAGE_ID() }; \
[email protected]8a8c9c72011-03-01 20:35:47614 msg_class(int32 routing_id) \
615 : IPC::Message(routing_id, ID, PRIORITY_NORMAL) {} \
[email protected]8bf55ca2011-10-17 22:15:27616 static void Log(std::string* name, const Message* msg, std::string* l); \
[email protected]8a8c9c72011-03-01 20:35:47617 };
618
619#define IPC_ASYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
[email protected]1d4ecf42011-08-26 21:27:30620 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
[email protected]8a8c9c72011-03-01 20:35:47621 public: \
[email protected]1d4ecf42011-08-26 21:27:30622 typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \
623 typedef Schema::Param Param; \
[email protected]d7a5e3e2011-03-12 16:28:36624 enum { ID = IPC_MESSAGE_ID() }; \
[email protected]8a8c9c72011-03-01 20:35:47625 msg_class(IPC_TYPE_IN_##in_cnt in_list); \
[email protected]3690ebe02011-05-25 09:08:19626 virtual ~msg_class(); \
[email protected]1d4ecf42011-08-26 21:27:30627 static bool Read(const Message* msg, Schema::Param* p); \
[email protected]8a8c9c72011-03-01 20:35:47628 static void Log(std::string* name, const Message* msg, std::string* l); \
[email protected]1d4ecf42011-08-26 21:27:30629 IPC_ASYNC_MESSAGE_METHODS_##in_cnt \
[email protected]8a8c9c72011-03-01 20:35:47630 };
631
632#define IPC_ASYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
[email protected]1d4ecf42011-08-26 21:27:30633 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
[email protected]8a8c9c72011-03-01 20:35:47634 public: \
[email protected]1d4ecf42011-08-26 21:27:30635 typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \
636 typedef Schema::Param Param; \
[email protected]d7a5e3e2011-03-12 16:28:36637 enum { ID = IPC_MESSAGE_ID() }; \
[email protected]8a8c9c72011-03-01 20:35:47638 msg_class(int32 routing_id IPC_COMMA_##in_cnt \
639 IPC_TYPE_IN_##in_cnt in_list); \
[email protected]3690ebe02011-05-25 09:08:19640 virtual ~msg_class(); \
[email protected]1d4ecf42011-08-26 21:27:30641 static bool Read(const Message* msg, Schema::Param* p); \
[email protected]8a8c9c72011-03-01 20:35:47642 static void Log(std::string* name, const Message* msg, std::string* l); \
[email protected]1d4ecf42011-08-26 21:27:30643 IPC_ASYNC_MESSAGE_METHODS_##in_cnt \
[email protected]8a8c9c72011-03-01 20:35:47644 };
645
646#define IPC_SYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
[email protected]1d4ecf42011-08-26 21:27:30647 class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \
[email protected]8a8c9c72011-03-01 20:35:47648 public: \
[email protected]1d4ecf42011-08-26 21:27:30649 typedef IPC::SyncMessageSchema<IPC_TUPLE_IN_##in_cnt in_list, \
650 IPC_TUPLE_OUT_##out_cnt out_list> Schema; \
651 typedef Schema::ReplyParam ReplyParam; \
652 typedef Schema::SendParam SendParam; \
[email protected]d7a5e3e2011-03-12 16:28:36653 enum { ID = IPC_MESSAGE_ID() }; \
[email protected]8a8c9c72011-03-01 20:35:47654 msg_class(IPC_TYPE_IN_##in_cnt in_list \
655 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
656 IPC_TYPE_OUT_##out_cnt out_list); \
[email protected]3690ebe02011-05-25 09:08:19657 virtual ~msg_class(); \
[email protected]1d4ecf42011-08-26 21:27:30658 static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \
659 static bool ReadReplyParam( \
660 const Message* msg, \
661 TupleTypes<ReplyParam>::ValueTuple* p); \
[email protected]8a8c9c72011-03-01 20:35:47662 static void Log(std::string* name, const Message* msg, std::string* l); \
[email protected]1d4ecf42011-08-26 21:27:30663 IPC_SYNC_MESSAGE_METHODS_##out_cnt \
[email protected]8a8c9c72011-03-01 20:35:47664 };
665
666#define IPC_SYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
[email protected]1d4ecf42011-08-26 21:27:30667 class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \
[email protected]8a8c9c72011-03-01 20:35:47668 public: \
[email protected]1d4ecf42011-08-26 21:27:30669 typedef IPC::SyncMessageSchema<IPC_TUPLE_IN_##in_cnt in_list, \
670 IPC_TUPLE_OUT_##out_cnt out_list> Schema; \
671 typedef Schema::ReplyParam ReplyParam; \
672 typedef Schema::SendParam SendParam; \
[email protected]d7a5e3e2011-03-12 16:28:36673 enum { ID = IPC_MESSAGE_ID() }; \
[email protected]8a8c9c72011-03-01 20:35:47674 msg_class(int32 routing_id \
675 IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \
676 IPC_TYPE_IN_##in_cnt in_list \
677 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
678 IPC_TYPE_OUT_##out_cnt out_list); \
[email protected]3690ebe02011-05-25 09:08:19679 virtual ~msg_class(); \
[email protected]1d4ecf42011-08-26 21:27:30680 static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \
681 static bool ReadReplyParam( \
682 const Message* msg, \
683 TupleTypes<ReplyParam>::ValueTuple* p); \
[email protected]8a8c9c72011-03-01 20:35:47684 static void Log(std::string* name, const Message* msg, std::string* l); \
[email protected]1d4ecf42011-08-26 21:27:30685 IPC_SYNC_MESSAGE_METHODS_##out_cnt \
[email protected]8a8c9c72011-03-01 20:35:47686 };
687
688#if defined(IPC_MESSAGE_IMPL)
689
690// "Implementation" inclusion produces constructors, destructors, and
691// logging functions, except for the no-arg special cases, where the
692// implementation occurs in the declaration, and there is no special
693// logging function.
694#define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
695 in_cnt, out_cnt, in_list, out_list) \
696 IPC_##sync##_##kind##_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
697 IPC_##sync##_MESSAGE_LOG(msg_class)
698
699#define IPC_EMPTY_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)
700#define IPC_EMPTY_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)
701
702#define IPC_ASYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
703 msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list) : \
[email protected]1d4ecf42011-08-26 21:27:30704 IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) { \
705 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
706 } \
707 msg_class::~msg_class() {} \
708 bool msg_class::Read(const Message* msg, Schema::Param* p) { \
709 return Schema::Read(msg, p); \
710 }
[email protected]8a8c9c72011-03-01 20:35:47711
712#define IPC_ASYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
713 msg_class::msg_class(int32 routing_id IPC_COMMA_##in_cnt \
714 IPC_TYPE_IN_##in_cnt in_list) : \
[email protected]1d4ecf42011-08-26 21:27:30715 IPC::Message(routing_id, ID, PRIORITY_NORMAL) { \
716 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
717 } \
718 msg_class::~msg_class() {} \
719 bool msg_class::Read(const Message* msg, Schema::Param* p) { \
720 return Schema::Read(msg, p); \
721 }
[email protected]8a8c9c72011-03-01 20:35:47722
723#define IPC_SYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
724 msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list \
725 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
726 IPC_TYPE_OUT_##out_cnt out_list) : \
[email protected]1d4ecf42011-08-26 21:27:30727 IPC::SyncMessage(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL, \
728 new IPC::ParamDeserializer<Schema::ReplyParam>( \
729 IPC_NAME_OUT_##out_cnt out_list)) { \
730 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
731 } \
732 msg_class::~msg_class() {} \
733 bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \
734 return Schema::ReadSendParam(msg, p); \
735 } \
736 bool msg_class::ReadReplyParam(const Message* msg, \
737 TupleTypes<ReplyParam>::ValueTuple* p) { \
738 return Schema::ReadReplyParam(msg, p); \
739 }
[email protected]8a8c9c72011-03-01 20:35:47740
741#define IPC_SYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
742 msg_class::msg_class(int32 routing_id \
743 IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \
744 IPC_TYPE_IN_##in_cnt in_list \
745 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
746 IPC_TYPE_OUT_##out_cnt out_list) : \
[email protected]1d4ecf42011-08-26 21:27:30747 IPC::SyncMessage(routing_id, ID, PRIORITY_NORMAL, \
748 new IPC::ParamDeserializer<Schema::ReplyParam>( \
749 IPC_NAME_OUT_##out_cnt out_list)) { \
750 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
751 } \
752 msg_class::~msg_class() {} \
753 bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \
754 return Schema::ReadSendParam(msg, p); \
755 } \
756 bool msg_class::ReadReplyParam(const Message* msg, \
757 TupleTypes<ReplyParam>::ValueTuple* p) { \
758 return Schema::ReadReplyParam(msg, p); \
759 }
[email protected]8a8c9c72011-03-01 20:35:47760
[email protected]8bf55ca2011-10-17 22:15:27761#define IPC_EMPTY_MESSAGE_LOG(msg_class) \
762 void msg_class::Log(std::string* name, \
763 const Message* msg, \
764 std::string* l) { \
765 if (name) \
766 *name = #msg_class; \
767 }
[email protected]8a8c9c72011-03-01 20:35:47768
769#define IPC_ASYNC_MESSAGE_LOG(msg_class) \
770 void msg_class::Log(std::string* name, \
771 const Message* msg, \
772 std::string* l) { \
773 if (name) \
774 *name = #msg_class; \
775 if (!msg || !l) \
776 return; \
[email protected]1d4ecf42011-08-26 21:27:30777 Schema::Param p; \
778 if (Schema::Read(msg, &p)) \
[email protected]8a8c9c72011-03-01 20:35:47779 IPC::LogParam(p, l); \
780 }
781
782#define IPC_SYNC_MESSAGE_LOG(msg_class) \
783 void msg_class::Log(std::string* name, \
784 const Message* msg, \
785 std::string* l) { \
786 if (name) \
787 *name = #msg_class; \
788 if (!msg || !l) \
789 return; \
790 if (msg->is_sync()) { \
[email protected]1d4ecf42011-08-26 21:27:30791 TupleTypes<Schema::SendParam>::ValueTuple p; \
792 if (Schema::ReadSendParam(msg, &p)) \
[email protected]8a8c9c72011-03-01 20:35:47793 IPC::LogParam(p, l); \
794 AddOutputParamsToLog(msg, l); \
795 } else { \
[email protected]1d4ecf42011-08-26 21:27:30796 TupleTypes<Schema::ReplyParam>::ValueTuple p; \
797 if (Schema::ReadReplyParam(msg, &p)) \
[email protected]8a8c9c72011-03-01 20:35:47798 IPC::LogParam(p, l); \
799 } \
800 }
801
[email protected]21fa3a12010-12-08 23:34:16802#elif defined(IPC_MESSAGE_MACROS_LOG_ENABLED)
[email protected]f91cb992009-02-04 20:10:12803
[email protected]21fa3a12010-12-08 23:34:16804#ifndef IPC_LOG_TABLE_CREATED
805#define IPC_LOG_TABLE_CREATED
[email protected]82e5ee82009-04-03 02:29:45806
[email protected]21fa3a12010-12-08 23:34:16807#include "base/hash_tables.h"
[email protected]f91cb992009-02-04 20:10:12808
[email protected]21fa3a12010-12-08 23:34:16809typedef void (*LogFunction)(std::string* name,
810 const IPC::Message* msg,
811 std::string* params);
[email protected]f91cb992009-02-04 20:10:12812
[email protected]21fa3a12010-12-08 23:34:16813typedef base::hash_map<uint32, LogFunction > LogFunctionMap;
814LogFunctionMap g_log_function_mapping;
[email protected]f91cb992009-02-04 20:10:12815
[email protected]6476c72c2011-02-11 18:46:19816#endif // IPC_LOG_TABLE_CREATED
[email protected]f91cb992009-02-04 20:10:12817
[email protected]8a8c9c72011-03-01 20:35:47818// "Log table" inclusion produces extra logging registration code.
819#define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
820 in_cnt, out_cnt, in_list, out_list) \
821 class LoggerRegisterHelper##msg_class { \
822 public: \
823 LoggerRegisterHelper##msg_class() { \
[email protected]6fa21d02011-11-04 00:14:16824 const uint32 msg_id = static_cast<uint32>(msg_class::ID); \
825 g_log_function_mapping[msg_id] = msg_class::Log; \
[email protected]8a8c9c72011-03-01 20:35:47826 } \
827 }; \
[email protected]21fa3a12010-12-08 23:34:16828 LoggerRegisterHelper##msg_class g_LoggerRegisterHelper##msg_class;
[email protected]f91cb992009-02-04 20:10:12829
[email protected]8a8c9c72011-03-01 20:35:47830#else
initial.commit09911bf2008-07-26 23:55:29831
[email protected]8a8c9c72011-03-01 20:35:47832// Normal inclusion produces nothing extra.
833#define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
834 in_cnt, out_cnt, in_list, out_list)
initial.commit09911bf2008-07-26 23:55:29835
[email protected]8a8c9c72011-03-01 20:35:47836#endif // defined(IPC_MESSAGE_IMPL)
[email protected]21fa3a12010-12-08 23:34:16837
[email protected]8a8c9c72011-03-01 20:35:47838// Handle variable sized argument lists. These are usually invoked by token
839// pasting against the argument counts.
840#define IPC_TYPE_IN_0()
841#define IPC_TYPE_IN_1(t1) const t1& arg1
842#define IPC_TYPE_IN_2(t1, t2) const t1& arg1, const t2& arg2
843#define IPC_TYPE_IN_3(t1, t2, t3) const t1& arg1, const t2& arg2, const t3& arg3
844#define IPC_TYPE_IN_4(t1, t2, t3, t4) const t1& arg1, const t2& arg2, const t3& arg3, const t4& arg4
845#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
[email protected]21fa3a12010-12-08 23:34:16846
[email protected]8a8c9c72011-03-01 20:35:47847#define IPC_TYPE_OUT_0()
848#define IPC_TYPE_OUT_1(t1) t1* arg6
849#define IPC_TYPE_OUT_2(t1, t2) t1* arg6, t2* arg7
850#define IPC_TYPE_OUT_3(t1, t2, t3) t1* arg6, t2* arg7, t3* arg8
851#define IPC_TYPE_OUT_4(t1, t2, t3, t4) t1* arg6, t2* arg7, t3* arg8, t4* arg9
[email protected]21fa3a12010-12-08 23:34:16852
[email protected]8a8c9c72011-03-01 20:35:47853#define IPC_TUPLE_IN_0() Tuple0
854#define IPC_TUPLE_IN_1(t1) Tuple1<t1>
855#define IPC_TUPLE_IN_2(t1, t2) Tuple2<t1, t2>
856#define IPC_TUPLE_IN_3(t1, t2, t3) Tuple3<t1, t2, t3>
857#define IPC_TUPLE_IN_4(t1, t2, t3, t4) Tuple4<t1, t2, t3, t4>
858#define IPC_TUPLE_IN_5(t1, t2, t3, t4, t5) Tuple5<t1, t2, t3, t4, t5>
[email protected]21fa3a12010-12-08 23:34:16859
[email protected]8a8c9c72011-03-01 20:35:47860#define IPC_TUPLE_OUT_0() Tuple0
861#define IPC_TUPLE_OUT_1(t1) Tuple1<t1&>
862#define IPC_TUPLE_OUT_2(t1, t2) Tuple2<t1&, t2&>
863#define IPC_TUPLE_OUT_3(t1, t2, t3) Tuple3<t1&, t2&, t3&>
864#define IPC_TUPLE_OUT_4(t1, t2, t3, t4) Tuple4<t1&, t2&, t3&, t4&>
[email protected]21fa3a12010-12-08 23:34:16865
[email protected]8a8c9c72011-03-01 20:35:47866#define IPC_NAME_IN_0() MakeTuple()
867#define IPC_NAME_IN_1(t1) MakeRefTuple(arg1)
868#define IPC_NAME_IN_2(t1, t2) MakeRefTuple(arg1, arg2)
869#define IPC_NAME_IN_3(t1, t2, t3) MakeRefTuple(arg1, arg2, arg3)
870#define IPC_NAME_IN_4(t1, t2, t3, t4) MakeRefTuple(arg1, arg2, arg3, arg4)
871#define IPC_NAME_IN_5(t1, t2, t3, t4, t5) MakeRefTuple(arg1, arg2, arg3, arg4, arg5)
[email protected]21fa3a12010-12-08 23:34:16872
[email protected]8a8c9c72011-03-01 20:35:47873#define IPC_NAME_OUT_0() MakeTuple()
874#define IPC_NAME_OUT_1(t1) MakeRefTuple(*arg6)
875#define IPC_NAME_OUT_2(t1, t2) MakeRefTuple(*arg6, *arg7)
876#define IPC_NAME_OUT_3(t1, t2, t3) MakeRefTuple(*arg6, *arg7, *arg8)
877#define IPC_NAME_OUT_4(t1, t2, t3, t4) MakeRefTuple(*arg6, *arg7, *arg8, *arg9)
[email protected]21fa3a12010-12-08 23:34:16878
[email protected]8a8c9c72011-03-01 20:35:47879// There are places where the syntax requires a comma if there are input args,
880// if there are input args and output args, or if there are input args or
881// output args. These macros allow generation of the comma as needed; invoke
882// by token pasting against the argument counts.
883#define IPC_COMMA_0
884#define IPC_COMMA_1 ,
885#define IPC_COMMA_2 ,
886#define IPC_COMMA_3 ,
887#define IPC_COMMA_4 ,
888#define IPC_COMMA_5 ,
[email protected]21fa3a12010-12-08 23:34:16889
[email protected]8a8c9c72011-03-01 20:35:47890#define IPC_COMMA_AND_0(x)
891#define IPC_COMMA_AND_1(x) x
892#define IPC_COMMA_AND_2(x) x
893#define IPC_COMMA_AND_3(x) x
894#define IPC_COMMA_AND_4(x) x
895#define IPC_COMMA_AND_5(x) x
[email protected]21fa3a12010-12-08 23:34:16896
[email protected]8a8c9c72011-03-01 20:35:47897#define IPC_COMMA_OR_0(x) x
898#define IPC_COMMA_OR_1(x) ,
899#define IPC_COMMA_OR_2(x) ,
900#define IPC_COMMA_OR_3(x) ,
901#define IPC_COMMA_OR_4(x) ,
902#define IPC_COMMA_OR_5(x) ,
[email protected]6d8ffc9f2010-03-12 18:27:53903
[email protected]d7a5e3e2011-03-12 16:28:36904// Message IDs
905// Note: we currently use __LINE__ to give unique IDs to messages within
906// a file. They're globally unique since each file defines its own
[email protected]3b3ec7212011-10-21 17:35:08907// IPC_MESSAGE_START.
[email protected]d7a5e3e2011-03-12 16:28:36908#define IPC_MESSAGE_ID() ((IPC_MESSAGE_START << 16) + __LINE__)
909#define IPC_MESSAGE_ID_CLASS(id) ((id) >> 16)
910#define IPC_MESSAGE_ID_LINE(id) ((id) & 0xffff)
911
initial.commit09911bf2008-07-26 23:55:29912// Message crackers and handlers.
913// Prefer to use the IPC_BEGIN_MESSAGE_MAP_EX to the older macros since they
914// allow you to detect when a message could not be de-serialized. Usage:
915//
[email protected]a95986a82010-12-24 06:19:28916// bool MyClass::OnMessageReceived(const IPC::Message& msg) {
917// bool handled = true;
initial.commit09911bf2008-07-26 23:55:29918// bool msg_is_good = false;
919// IPC_BEGIN_MESSAGE_MAP_EX(MyClass, msg, msg_is_good)
920// IPC_MESSAGE_HANDLER(MsgClassOne, OnMsgClassOne)
921// ...more handlers here ...
922// IPC_MESSAGE_HANDLER(MsgClassTen, OnMsgClassTen)
[email protected]a95986a82010-12-24 06:19:28923// IPC_MESSAGE_UNHANDLED(handled = false)
initial.commit09911bf2008-07-26 23:55:29924// IPC_END_MESSAGE_MAP_EX()
925// if (!msg_is_good) {
926// // Signal error here or terminate offending process.
927// }
[email protected]a95986a82010-12-24 06:19:28928// return handled;
initial.commit09911bf2008-07-26 23:55:29929// }
930
[email protected]21fa3a12010-12-08 23:34:16931
initial.commit09911bf2008-07-26 23:55:29932#define IPC_BEGIN_MESSAGE_MAP_EX(class_name, msg, msg_is_ok) \
933 { \
934 typedef class_name _IpcMessageHandlerClass; \
935 const IPC::Message& ipc_message__ = msg; \
936 bool& msg_is_ok__ = msg_is_ok; \
937 switch (ipc_message__.type()) { \
938
939#define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \
940 { \
941 typedef class_name _IpcMessageHandlerClass; \
942 const IPC::Message& ipc_message__ = msg; \
943 bool msg_is_ok__ = true; \
944 switch (ipc_message__.type()) { \
945
[email protected]e86a2552011-11-11 00:21:02946#define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \
947 case msg_class::ID: { \
[email protected]c67f8c22011-11-11 01:00:17948 TRACK_RUN_IN_IPC_HANDLER(member_func); \
[email protected]e86a2552011-11-11 00:21:02949 msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, \
950 &member_func); \
951 } \
952 break;
initial.commit09911bf2008-07-26 23:55:29953
954#define IPC_MESSAGE_HANDLER(msg_class, member_func) \
955 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func)
956
[email protected]e86a2552011-11-11 00:21:02957#define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \
958 case msg_class::ID: { \
[email protected]562016342011-11-15 17:51:43959 TRACK_RUN_IN_IPC_HANDLER(member_func); \
[email protected]e86a2552011-11-11 00:21:02960 msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, \
961 &member_func); \
962 } \
963 break;
initial.commit09911bf2008-07-26 23:55:29964
[email protected]e86a2552011-11-11 00:21:02965#define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \
966 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \
967 _IpcMessageHandlerClass::member_func)
initial.commit09911bf2008-07-26 23:55:29968
[email protected]562016342011-11-15 17:51:43969// TODO(jar): fix chrome frame to always supply |code| argument.
[email protected]e86a2552011-11-11 00:21:02970#define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \
971 case msg_class::ID: { \
[email protected]b75d4a042011-11-12 02:58:59972 /* TRACK_RUN_IN_IPC_HANDLER(code); TODO(jar) */ \
[email protected]e86a2552011-11-11 00:21:02973 code; \
974 } \
975 break;
initial.commit09911bf2008-07-26 23:55:29976
[email protected]e86a2552011-11-11 00:21:02977#define IPC_REPLY_HANDLER(func) \
978 case IPC_REPLY_ID: { \
[email protected]e3bd15c2011-11-11 22:41:08979 TRACK_RUN_IN_IPC_HANDLER(func); \
[email protected]e86a2552011-11-11 00:21:02980 func(ipc_message__); \
981 } \
982 break;
initial.commit09911bf2008-07-26 23:55:29983
984
[email protected]e86a2552011-11-11 00:21:02985#define IPC_MESSAGE_UNHANDLED(code) \
986 default: { \
[email protected]e86a2552011-11-11 00:21:02987 code; \
988 } \
989 break;
initial.commit09911bf2008-07-26 23:55:29990
991#define IPC_MESSAGE_UNHANDLED_ERROR() \
992 IPC_MESSAGE_UNHANDLED(NOTREACHED() << \
993 "Invalid message with type = " << \
994 ipc_message__.type())
995
996#define IPC_END_MESSAGE_MAP() \
997 DCHECK(msg_is_ok__); \
998 } \
999}
1000
1001#define IPC_END_MESSAGE_MAP_EX() \
1002 } \
[email protected]8d70d5f2010-12-08 23:41:081003}
[email protected]9f547bf2010-12-13 17:00:421004
1005// This corresponds to an enum value from IPCMessageStart.
1006#define IPC_MESSAGE_CLASS(message) \
[email protected]d7a5e3e2011-03-12 16:28:361007 IPC_MESSAGE_ID_CLASS(message.type())
[email protected]6476c72c2011-02-11 18:46:191008
1009#endif // IPC_IPC_MESSAGE_MACROS_H_
1010
1011// Clean up IPC_MESSAGE_START in this unguarded section so that the
1012// XXX_messages.h files need not do so themselves. This makes the
1013// XXX_messages.h files easier to write.
1014#undef IPC_MESSAGE_START