blob: f77abb249229b3d8bf71c9930dca7b4cf6dad0c8 [file] [log] [blame]
[email protected]7de84042012-02-21 16:04:501// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]6476c72c2011-02-11 18:46:195// Defining IPC Messages
initial.commit09911bf2008-07-26 23:55:296//
[email protected]6476c72c2011-02-11 18:46:197// Your IPC messages will be defined by macros inside of an XXX_messages.h
8// header file. Most of the time, the system can automatically generate all
9// of messaging mechanism from these definitions, but sometimes some manual
10// coding is required. In these cases, you will also have an XXX_messages.cc
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:
[email protected]f9509812012-10-23 23:03:3518// - An XXXMsgStart value to the IPCMessageStart enum in ipc_message_start.h
[email protected]6476c72c2011-02-11 18:46:1919// - An inclusion of XXX_messages.h file in a message generator .h file
20//
21// The XXXMsgStart value is an enumeration that ensures uniqueness for
22// each different message file. Later, you will use this inside your
[email protected]e86a2552011-11-11 00:21:0223// XXX_messages.h file before invoking message declaration macros:
[email protected]6476c72c2011-02-11 18:46:1924// #define IPC_MESSAGE_START XXXMsgStart
25// ( ... your macro invocations go here ... )
26//
27// Message Generator Files
28//
29// A message generator .h header file pulls in all other message-declaring
30// headers for a given component. It is included by a message generator
31// .cc file, which is where all the generated code will wind up. Typically,
[email protected]d7a5e3e2011-03-12 16:28:3632// you will use an existing generator (e.g. common_message_generator.cc
33// in /chrome/common), but there are circumstances where you may add a
34// new one.
[email protected]6476c72c2011-02-11 18:46:1935//
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//
[email protected]01c86ec2012-07-11 19:01:4379// Note that #pragma once cannot be used here; doing so would mark the whole
[email protected]6476c72c2011-02-11 18:46:1980// file as being singly-included. Since your XXX_messages.h file is only
81// partially-guarded, care must be taken to ensure that it is only included
82// by other .cc files (and the YYY_message_generator.h file). Including an
83// XXX_messages.h file in some other .h file may result in duplicate
84// declarations and a compilation failure.
85//
86// Type Declarations
87//
88// It is generally a bad idea to have type definitions in a XXX_messages.h
89// file; most likely the typedef will then be used in the message, as opposed
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]7de84042012-02-21 16:04:50176// Files that want to export their ipc messages should do
177// #undef IPC_MESSAGE_EXPORT
178// #define IPC_MESSAGE_EXPORT VISIBILITY_MACRO
179// after including this header, but before using any of the macros below.
180// (This needs to be before the include guard.)
181#undef IPC_MESSAGE_EXPORT
182#define IPC_MESSAGE_EXPORT
183
[email protected]6476c72c2011-02-11 18:46:19184#ifndef IPC_IPC_MESSAGE_MACROS_H_
185#define IPC_IPC_MESSAGE_MACROS_H_
[email protected]82e5ee82009-04-03 02:29:45186
[email protected]e86a2552011-11-11 00:21:02187#include "base/profiler/scoped_profile.h"
[email protected]6476c72c2011-02-11 18:46:19188#include "ipc/ipc_message_utils.h"
189#include "ipc/param_traits_macros.h"
[email protected]f91cb992009-02-04 20:10:12190
[email protected]21fa3a12010-12-08 23:34:16191#if defined(IPC_MESSAGE_IMPL)
[email protected]8a8c9c72011-03-01 20:35:47192#include "ipc/ipc_message_utils_impl.h"
193#endif
194
195// Macros for defining structs. May be subsequently redefined.
196#define IPC_STRUCT_BEGIN(struct_name) \
[email protected]6766b172011-11-21 18:29:36197 IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, IPC::NoParams)
198#define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \
[email protected]8a8c9c72011-03-01 20:35:47199 struct struct_name; \
200 IPC_STRUCT_TRAITS_BEGIN(struct_name) \
201 IPC_STRUCT_TRAITS_END() \
[email protected]6766b172011-11-21 18:29:36202 struct IPC_MESSAGE_EXPORT struct_name : parent { \
[email protected]8a8c9c72011-03-01 20:35:47203 struct_name(); \
204 ~struct_name();
[email protected]01cca0042012-04-16 19:13:02205// Optional variadic parameters specify the default value for this struct
206// member. They are passed through to the constructor for |type|.
207#define IPC_STRUCT_MEMBER(type, name, ...) type name;
[email protected]8a8c9c72011-03-01 20:35:47208#define IPC_STRUCT_END() };
209
210// Message macros collect specific numbers of arguments and funnel them into
[email protected]d7a5e3e2011-03-12 16:28:36211// the common message generation macro. These should never be redefined.
[email protected]8a8c9c72011-03-01 20:35:47212#define IPC_MESSAGE_CONTROL0(msg_class) \
213 IPC_MESSAGE_DECL(EMPTY, CONTROL, msg_class, 0, 0, (), ())
214
215#define IPC_MESSAGE_CONTROL1(msg_class, type1) \
216 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 1, 0, (type1), ())
217
218#define IPC_MESSAGE_CONTROL2(msg_class, type1, type2) \
219 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 2, 0, (type1, type2), ())
220
221#define IPC_MESSAGE_CONTROL3(msg_class, type1, type2, type3) \
222 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 3, 0, (type1, type2, type3), ())
223
224#define IPC_MESSAGE_CONTROL4(msg_class, type1, type2, type3, type4) \
225 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 4, 0, (type1, type2, type3, type4), ())
226
227#define IPC_MESSAGE_CONTROL5(msg_class, type1, type2, type3, type4, type5) \
228 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 5, 0, (type1, type2, type3, type4, type5), ())
229
230#define IPC_MESSAGE_ROUTED0(msg_class) \
231 IPC_MESSAGE_DECL(EMPTY, ROUTED, msg_class, 0, 0, (), ())
232
233#define IPC_MESSAGE_ROUTED1(msg_class, type1) \
234 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 1, 0, (type1), ())
235
236#define IPC_MESSAGE_ROUTED2(msg_class, type1, type2) \
237 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 2, 0, (type1, type2), ())
238
239#define IPC_MESSAGE_ROUTED3(msg_class, type1, type2, type3) \
240 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 3, 0, (type1, type2, type3), ())
241
242#define IPC_MESSAGE_ROUTED4(msg_class, type1, type2, type3, type4) \
243 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 4, 0, (type1, type2, type3, type4), ())
244
245#define IPC_MESSAGE_ROUTED5(msg_class, type1, type2, type3, type4, type5) \
246 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 5, 0, (type1, type2, type3, type4, type5), ())
247
248#define IPC_SYNC_MESSAGE_CONTROL0_0(msg_class) \
249 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 0, (), ())
250
251#define IPC_SYNC_MESSAGE_CONTROL0_1(msg_class, type1_out) \
252 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 1, (), (type1_out))
253
254#define IPC_SYNC_MESSAGE_CONTROL0_2(msg_class, type1_out, type2_out) \
255 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 2, (), (type1_out, type2_out))
256
257#define IPC_SYNC_MESSAGE_CONTROL0_3(msg_class, type1_out, type2_out, type3_out) \
258 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 3, (), (type1_out, type2_out, type3_out))
259
260#define IPC_SYNC_MESSAGE_CONTROL0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \
261 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out))
262
263#define IPC_SYNC_MESSAGE_CONTROL1_0(msg_class, type1_in) \
264 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 0, (type1_in), ())
265
266#define IPC_SYNC_MESSAGE_CONTROL1_1(msg_class, type1_in, type1_out) \
267 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 1, (type1_in), (type1_out))
268
269#define IPC_SYNC_MESSAGE_CONTROL1_2(msg_class, type1_in, type1_out, type2_out) \
270 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 2, (type1_in), (type1_out, type2_out))
271
272#define IPC_SYNC_MESSAGE_CONTROL1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \
273 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out))
274
275#define IPC_SYNC_MESSAGE_CONTROL1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \
276 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out))
277
278#define IPC_SYNC_MESSAGE_CONTROL2_0(msg_class, type1_in, type2_in) \
279 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 0, (type1_in, type2_in), ())
280
281#define IPC_SYNC_MESSAGE_CONTROL2_1(msg_class, type1_in, type2_in, type1_out) \
282 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 1, (type1_in, type2_in), (type1_out))
283
284#define IPC_SYNC_MESSAGE_CONTROL2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \
285 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out))
286
287#define IPC_SYNC_MESSAGE_CONTROL2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \
288 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out))
289
290#define IPC_SYNC_MESSAGE_CONTROL2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \
291 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out))
292
293#define IPC_SYNC_MESSAGE_CONTROL3_0(msg_class, type1_in, type2_in, type3_in) \
294 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 0, (type1_in, type2_in, type3_in), ())
295
296#define IPC_SYNC_MESSAGE_CONTROL3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \
297 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out))
298
299#define IPC_SYNC_MESSAGE_CONTROL3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \
300 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out))
301
302#define IPC_SYNC_MESSAGE_CONTROL3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \
303 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out))
304
305#define IPC_SYNC_MESSAGE_CONTROL3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \
306 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out))
307
308#define IPC_SYNC_MESSAGE_CONTROL4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \
309 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 0, (type1_in, type2_in, type3_in, type4_in), ())
310
311#define IPC_SYNC_MESSAGE_CONTROL4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \
312 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out))
313
314#define IPC_SYNC_MESSAGE_CONTROL4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \
315 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out))
316
317#define IPC_SYNC_MESSAGE_CONTROL4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \
318 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out))
319
320#define IPC_SYNC_MESSAGE_CONTROL4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \
321 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))
322
323#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:21324 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:47325
326#define IPC_SYNC_MESSAGE_CONTROL5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \
327 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out))
328
329#define IPC_SYNC_MESSAGE_CONTROL5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \
330 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out))
331
332#define IPC_SYNC_MESSAGE_CONTROL5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \
333 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))
334
[email protected]8a8c9c72011-03-01 20:35:47335#define IPC_SYNC_MESSAGE_ROUTED0_0(msg_class) \
336 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 0, (), ())
337
338#define IPC_SYNC_MESSAGE_ROUTED0_1(msg_class, type1_out) \
339 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 1, (), (type1_out))
340
341#define IPC_SYNC_MESSAGE_ROUTED0_2(msg_class, type1_out, type2_out) \
342 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 2, (), (type1_out, type2_out))
343
344#define IPC_SYNC_MESSAGE_ROUTED0_3(msg_class, type1_out, type2_out, type3_out) \
345 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 3, (), (type1_out, type2_out, type3_out))
346
347#define IPC_SYNC_MESSAGE_ROUTED0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \
348 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out))
349
350#define IPC_SYNC_MESSAGE_ROUTED1_0(msg_class, type1_in) \
351 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 0, (type1_in), ())
352
353#define IPC_SYNC_MESSAGE_ROUTED1_1(msg_class, type1_in, type1_out) \
354 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 1, (type1_in), (type1_out))
355
356#define IPC_SYNC_MESSAGE_ROUTED1_2(msg_class, type1_in, type1_out, type2_out) \
357 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 2, (type1_in), (type1_out, type2_out))
358
359#define IPC_SYNC_MESSAGE_ROUTED1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \
360 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out))
361
362#define IPC_SYNC_MESSAGE_ROUTED1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \
363 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out))
364
365#define IPC_SYNC_MESSAGE_ROUTED2_0(msg_class, type1_in, type2_in) \
366 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 0, (type1_in, type2_in), ())
367
368#define IPC_SYNC_MESSAGE_ROUTED2_1(msg_class, type1_in, type2_in, type1_out) \
369 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 1, (type1_in, type2_in), (type1_out))
370
371#define IPC_SYNC_MESSAGE_ROUTED2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \
372 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out))
373
374#define IPC_SYNC_MESSAGE_ROUTED2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \
375 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out))
376
377#define IPC_SYNC_MESSAGE_ROUTED2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \
378 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out))
379
380#define IPC_SYNC_MESSAGE_ROUTED3_0(msg_class, type1_in, type2_in, type3_in) \
381 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 0, (type1_in, type2_in, type3_in), ())
382
383#define IPC_SYNC_MESSAGE_ROUTED3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \
384 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out))
385
386#define IPC_SYNC_MESSAGE_ROUTED3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \
387 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out))
388
389#define IPC_SYNC_MESSAGE_ROUTED3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \
390 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out))
391
392#define IPC_SYNC_MESSAGE_ROUTED3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \
393 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out))
394
395#define IPC_SYNC_MESSAGE_ROUTED4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \
[email protected]45217a22012-08-01 19:43:10396 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 0, (type1_in, type2_in, type3_in, type4_in), ())
[email protected]8a8c9c72011-03-01 20:35:47397
398#define IPC_SYNC_MESSAGE_ROUTED4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \
399 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out))
400
401#define IPC_SYNC_MESSAGE_ROUTED4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \
402 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out))
403
404#define IPC_SYNC_MESSAGE_ROUTED4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \
405 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out))
406
407#define IPC_SYNC_MESSAGE_ROUTED4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \
408 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))
409
410#define IPC_SYNC_MESSAGE_ROUTED5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \
[email protected]45217a22012-08-01 19:43:10411 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 0, (type1_in, type2_in, type3_in, type4_in, type5_in), ())
[email protected]8a8c9c72011-03-01 20:35:47412
413#define IPC_SYNC_MESSAGE_ROUTED5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \
414 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out))
415
416#define IPC_SYNC_MESSAGE_ROUTED5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \
417 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out))
418
419#define IPC_SYNC_MESSAGE_ROUTED5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \
420 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))
421
[email protected]1d4ecf42011-08-26 21:27:30422// The following macros define the common set of methods provided by ASYNC
423// message classes.
424#define IPC_ASYNC_MESSAGE_METHODS_GENERIC \
425 template<class T, class S, class Method> \
426 static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) { \
427 Schema::Param p; \
428 if (Read(msg, &p)) { \
429 DispatchToMethod(obj, func, p); \
430 return true; \
431 } \
432 return false; \
433 }
434#define IPC_ASYNC_MESSAGE_METHODS_1 \
435 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
436 template<class T, class S, typename TA> \
437 static bool Dispatch(const Message* msg, T* obj, S* sender, \
438 void (T::*func)(const Message&, TA)) { \
439 Schema::Param p; \
440 if (Read(msg, &p)) { \
441 (obj->*func)(*msg, p.a); \
442 return true; \
443 } \
444 return false; \
445 }
446#define IPC_ASYNC_MESSAGE_METHODS_2 \
447 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
448 template<class T, class S, typename TA, typename TB> \
449 static bool Dispatch(const Message* msg, T* obj, S* sender, \
450 void (T::*func)(const Message&, TA, TB)) { \
451 Schema::Param p; \
452 if (Read(msg, &p)) { \
453 (obj->*func)(*msg, p.a, p.b); \
454 return true; \
455 } \
456 return false; \
457 } \
458 template<typename TA, typename TB> \
459 static bool Read(const IPC::Message* msg, TA* a, TB* b) { \
460 Schema::Param p; \
461 if (!Read(msg, &p)) \
462 return false; \
463 *a = p.a; \
464 *b = p.b; \
465 return true; \
466 }
467#define IPC_ASYNC_MESSAGE_METHODS_3 \
468 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
469 template<class T, class S, typename TA, typename TB, typename TC> \
470 static bool Dispatch(const Message* msg, T* obj, S* sender, \
471 void (T::*func)(const Message&, TA, TB, TC)) { \
472 Schema::Param p; \
473 if (Read(msg, &p)) { \
474 (obj->*func)(*msg, p.a, p.b, p.c); \
475 return true; \
476 } \
477 return false; \
478 } \
479 template<typename TA, typename TB, typename TC> \
480 static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c) { \
481 Schema::Param p; \
482 if (!Read(msg, &p)) \
483 return false; \
484 *a = p.a; \
485 *b = p.b; \
486 *c = p.c; \
487 return true; \
488 }
489#define IPC_ASYNC_MESSAGE_METHODS_4 \
490 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
491 template<class T, class S, typename TA, typename TB, typename TC, \
492 typename TD> \
493 static bool Dispatch(const Message* msg, T* obj, S* sender, \
494 void (T::*func)(const Message&, TA, TB, TC, TD)) { \
495 Schema::Param p; \
496 if (Read(msg, &p)) { \
497 (obj->*func)(*msg, p.a, p.b, p.c, p.d); \
498 return true; \
499 } \
500 return false; \
501 } \
502 template<typename TA, typename TB, typename TC, typename TD> \
503 static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d) { \
504 Schema::Param p; \
505 if (!Read(msg, &p)) \
506 return false; \
507 *a = p.a; \
508 *b = p.b; \
509 *c = p.c; \
510 *d = p.d; \
511 return true; \
512 }
513#define IPC_ASYNC_MESSAGE_METHODS_5 \
514 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
515 template<class T, class S, typename TA, typename TB, typename TC, \
516 typename TD, typename TE> \
517 static bool Dispatch(const Message* msg, T* obj, S* sender, \
518 void (T::*func)(const Message&, TA, TB, TC, TD, TE)) { \
519 Schema::Param p; \
520 if (Read(msg, &p)) { \
521 (obj->*func)(*msg, p.a, p.b, p.c, p.d, p.e); \
522 return true; \
523 } \
524 return false; \
525 } \
526 template<typename TA, typename TB, typename TC, typename TD, typename TE> \
527 static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d, \
528 TE* e) { \
529 Schema::Param p; \
530 if (!Read(msg, &p)) \
531 return false; \
532 *a = p.a; \
533 *b = p.b; \
534 *c = p.c; \
535 *d = p.d; \
536 *e = p.e; \
537 return true; \
538 }
539
540// The following macros define the common set of methods provided by SYNC
541// message classes.
542#define IPC_SYNC_MESSAGE_METHODS_GENERIC \
543 template<class T, class S, class Method> \
544 static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) { \
545 Schema::SendParam send_params; \
546 bool ok = ReadSendParam(msg, &send_params); \
547 return Schema::DispatchWithSendParams(ok, send_params, msg, obj, sender, \
548 func); \
549 } \
550 template<class T, class Method> \
551 static bool DispatchDelayReply(const Message* msg, T* obj, Method func) { \
552 Schema::SendParam send_params; \
553 bool ok = ReadSendParam(msg, &send_params); \
554 return Schema::DispatchDelayReplyWithSendParams(ok, send_params, msg, \
555 obj, func); \
556 }
557#define IPC_SYNC_MESSAGE_METHODS_0 \
558 IPC_SYNC_MESSAGE_METHODS_GENERIC
559#define IPC_SYNC_MESSAGE_METHODS_1 \
560 IPC_SYNC_MESSAGE_METHODS_GENERIC \
561 template<typename TA> \
562 static void WriteReplyParams(Message* reply, TA a) { \
563 Schema::WriteReplyParams(reply, a); \
564 }
565#define IPC_SYNC_MESSAGE_METHODS_2 \
566 IPC_SYNC_MESSAGE_METHODS_GENERIC \
567 template<typename TA, typename TB> \
568 static void WriteReplyParams(Message* reply, TA a, TB b) { \
569 Schema::WriteReplyParams(reply, a, b); \
570 }
571#define IPC_SYNC_MESSAGE_METHODS_3 \
572 IPC_SYNC_MESSAGE_METHODS_GENERIC \
573 template<typename TA, typename TB, typename TC> \
574 static void WriteReplyParams(Message* reply, TA a, TB b, TC c) { \
575 Schema::WriteReplyParams(reply, a, b, c); \
576 }
577#define IPC_SYNC_MESSAGE_METHODS_4 \
578 IPC_SYNC_MESSAGE_METHODS_GENERIC \
579 template<typename TA, typename TB, typename TC, typename TD> \
580 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d) { \
581 Schema::WriteReplyParams(reply, a, b, c, d); \
582 }
583#define IPC_SYNC_MESSAGE_METHODS_5 \
584 IPC_SYNC_MESSAGE_METHODS_GENERIC \
585 template<typename TA, typename TB, typename TC, typename TD, typename TE> \
586 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d, TE e) { \
587 Schema::WriteReplyParams(reply, a, b, c, d, e); \
588 }
589
[email protected]8a8c9c72011-03-01 20:35:47590// Common message macro which dispatches into one of the 6 (sync x kind)
591// routines. There is a way that these 6 cases can be lumped together,
592// but the macros get very complicated in that case.
[email protected]d7a5e3e2011-03-12 16:28:36593// Note: intended be redefined to generate other information.
[email protected]8a8c9c72011-03-01 20:35:47594#define IPC_MESSAGE_DECL(sync, kind, msg_class, \
595 in_cnt, out_cnt, in_list, out_list) \
596 IPC_##sync##_##kind##_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
597 IPC_MESSAGE_EXTRA(sync, kind, msg_class, in_cnt, out_cnt, in_list, out_list)
598
599#define IPC_EMPTY_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
[email protected]7b604962011-10-27 01:45:58600 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
[email protected]8a8c9c72011-03-01 20:35:47601 public: \
[email protected]1d4ecf42011-08-26 21:27:30602 typedef IPC::Message Schema; \
[email protected]d7a5e3e2011-03-12 16:28:36603 enum { ID = IPC_MESSAGE_ID() }; \
[email protected]8a8c9c72011-03-01 20:35:47604 msg_class() : IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) {} \
[email protected]8bf55ca2011-10-17 22:15:27605 static void Log(std::string* name, const Message* msg, std::string* l); \
[email protected]8a8c9c72011-03-01 20:35:47606 };
607
608#define IPC_EMPTY_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
[email protected]7b604962011-10-27 01:45:58609 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
[email protected]8a8c9c72011-03-01 20:35:47610 public: \
[email protected]1d4ecf42011-08-26 21:27:30611 typedef IPC::Message Schema; \
[email protected]d7a5e3e2011-03-12 16:28:36612 enum { ID = IPC_MESSAGE_ID() }; \
[email protected]8a8c9c72011-03-01 20:35:47613 msg_class(int32 routing_id) \
614 : IPC::Message(routing_id, ID, PRIORITY_NORMAL) {} \
[email protected]8bf55ca2011-10-17 22:15:27615 static void Log(std::string* name, const Message* msg, std::string* l); \
[email protected]8a8c9c72011-03-01 20:35:47616 };
617
618#define IPC_ASYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
[email protected]1d4ecf42011-08-26 21:27:30619 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
[email protected]8a8c9c72011-03-01 20:35:47620 public: \
[email protected]1d4ecf42011-08-26 21:27:30621 typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \
622 typedef Schema::Param Param; \
[email protected]d7a5e3e2011-03-12 16:28:36623 enum { ID = IPC_MESSAGE_ID() }; \
[email protected]8a8c9c72011-03-01 20:35:47624 msg_class(IPC_TYPE_IN_##in_cnt in_list); \
[email protected]3690ebe02011-05-25 09:08:19625 virtual ~msg_class(); \
[email protected]1d4ecf42011-08-26 21:27:30626 static bool Read(const Message* msg, Schema::Param* p); \
[email protected]8a8c9c72011-03-01 20:35:47627 static void Log(std::string* name, const Message* msg, std::string* l); \
[email protected]1d4ecf42011-08-26 21:27:30628 IPC_ASYNC_MESSAGE_METHODS_##in_cnt \
[email protected]8a8c9c72011-03-01 20:35:47629 };
630
631#define IPC_ASYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
[email protected]1d4ecf42011-08-26 21:27:30632 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
[email protected]8a8c9c72011-03-01 20:35:47633 public: \
[email protected]1d4ecf42011-08-26 21:27:30634 typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \
635 typedef Schema::Param Param; \
[email protected]d7a5e3e2011-03-12 16:28:36636 enum { ID = IPC_MESSAGE_ID() }; \
[email protected]8a8c9c72011-03-01 20:35:47637 msg_class(int32 routing_id IPC_COMMA_##in_cnt \
638 IPC_TYPE_IN_##in_cnt in_list); \
[email protected]3690ebe02011-05-25 09:08:19639 virtual ~msg_class(); \
[email protected]1d4ecf42011-08-26 21:27:30640 static bool Read(const Message* msg, Schema::Param* p); \
[email protected]8a8c9c72011-03-01 20:35:47641 static void Log(std::string* name, const Message* msg, std::string* l); \
[email protected]1d4ecf42011-08-26 21:27:30642 IPC_ASYNC_MESSAGE_METHODS_##in_cnt \
[email protected]8a8c9c72011-03-01 20:35:47643 };
644
645#define IPC_SYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
[email protected]1d4ecf42011-08-26 21:27:30646 class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \
[email protected]8a8c9c72011-03-01 20:35:47647 public: \
[email protected]1d4ecf42011-08-26 21:27:30648 typedef IPC::SyncMessageSchema<IPC_TUPLE_IN_##in_cnt in_list, \
649 IPC_TUPLE_OUT_##out_cnt out_list> Schema; \
650 typedef Schema::ReplyParam ReplyParam; \
651 typedef Schema::SendParam SendParam; \
[email protected]d7a5e3e2011-03-12 16:28:36652 enum { ID = IPC_MESSAGE_ID() }; \
[email protected]8a8c9c72011-03-01 20:35:47653 msg_class(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); \
[email protected]3690ebe02011-05-25 09:08:19656 virtual ~msg_class(); \
[email protected]1d4ecf42011-08-26 21:27:30657 static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \
658 static bool ReadReplyParam( \
659 const Message* msg, \
660 TupleTypes<ReplyParam>::ValueTuple* p); \
[email protected]8a8c9c72011-03-01 20:35:47661 static void Log(std::string* name, const Message* msg, std::string* l); \
[email protected]1d4ecf42011-08-26 21:27:30662 IPC_SYNC_MESSAGE_METHODS_##out_cnt \
[email protected]8a8c9c72011-03-01 20:35:47663 };
664
665#define IPC_SYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
[email protected]1d4ecf42011-08-26 21:27:30666 class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \
[email protected]8a8c9c72011-03-01 20:35:47667 public: \
[email protected]1d4ecf42011-08-26 21:27:30668 typedef IPC::SyncMessageSchema<IPC_TUPLE_IN_##in_cnt in_list, \
669 IPC_TUPLE_OUT_##out_cnt out_list> Schema; \
670 typedef Schema::ReplyParam ReplyParam; \
671 typedef Schema::SendParam SendParam; \
[email protected]d7a5e3e2011-03-12 16:28:36672 enum { ID = IPC_MESSAGE_ID() }; \
[email protected]8a8c9c72011-03-01 20:35:47673 msg_class(int32 routing_id \
674 IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \
675 IPC_TYPE_IN_##in_cnt in_list \
676 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
677 IPC_TYPE_OUT_##out_cnt out_list); \
[email protected]3690ebe02011-05-25 09:08:19678 virtual ~msg_class(); \
[email protected]1d4ecf42011-08-26 21:27:30679 static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \
680 static bool ReadReplyParam( \
681 const Message* msg, \
682 TupleTypes<ReplyParam>::ValueTuple* p); \
[email protected]8a8c9c72011-03-01 20:35:47683 static void Log(std::string* name, const Message* msg, std::string* l); \
[email protected]1d4ecf42011-08-26 21:27:30684 IPC_SYNC_MESSAGE_METHODS_##out_cnt \
[email protected]8a8c9c72011-03-01 20:35:47685 };
686
687#if defined(IPC_MESSAGE_IMPL)
688
689// "Implementation" inclusion produces constructors, destructors, and
690// logging functions, except for the no-arg special cases, where the
691// implementation occurs in the declaration, and there is no special
692// logging function.
693#define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
694 in_cnt, out_cnt, in_list, out_list) \
695 IPC_##sync##_##kind##_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
696 IPC_##sync##_MESSAGE_LOG(msg_class)
697
698#define IPC_EMPTY_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)
699#define IPC_EMPTY_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)
700
701#define IPC_ASYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
702 msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list) : \
[email protected]1d4ecf42011-08-26 21:27:30703 IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) { \
704 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
705 } \
706 msg_class::~msg_class() {} \
707 bool msg_class::Read(const Message* msg, Schema::Param* p) { \
708 return Schema::Read(msg, p); \
709 }
[email protected]8a8c9c72011-03-01 20:35:47710
711#define IPC_ASYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
712 msg_class::msg_class(int32 routing_id IPC_COMMA_##in_cnt \
713 IPC_TYPE_IN_##in_cnt in_list) : \
[email protected]1d4ecf42011-08-26 21:27:30714 IPC::Message(routing_id, ID, PRIORITY_NORMAL) { \
715 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
716 } \
717 msg_class::~msg_class() {} \
718 bool msg_class::Read(const Message* msg, Schema::Param* p) { \
719 return Schema::Read(msg, p); \
720 }
[email protected]8a8c9c72011-03-01 20:35:47721
722#define IPC_SYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
723 msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list \
724 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
725 IPC_TYPE_OUT_##out_cnt out_list) : \
[email protected]1d4ecf42011-08-26 21:27:30726 IPC::SyncMessage(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL, \
727 new IPC::ParamDeserializer<Schema::ReplyParam>( \
728 IPC_NAME_OUT_##out_cnt out_list)) { \
729 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
730 } \
731 msg_class::~msg_class() {} \
732 bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \
733 return Schema::ReadSendParam(msg, p); \
734 } \
735 bool msg_class::ReadReplyParam(const Message* msg, \
736 TupleTypes<ReplyParam>::ValueTuple* p) { \
737 return Schema::ReadReplyParam(msg, p); \
738 }
[email protected]8a8c9c72011-03-01 20:35:47739
740#define IPC_SYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
741 msg_class::msg_class(int32 routing_id \
742 IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \
743 IPC_TYPE_IN_##in_cnt in_list \
744 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
745 IPC_TYPE_OUT_##out_cnt out_list) : \
[email protected]1d4ecf42011-08-26 21:27:30746 IPC::SyncMessage(routing_id, ID, PRIORITY_NORMAL, \
747 new IPC::ParamDeserializer<Schema::ReplyParam>( \
748 IPC_NAME_OUT_##out_cnt out_list)) { \
749 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
750 } \
751 msg_class::~msg_class() {} \
752 bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \
753 return Schema::ReadSendParam(msg, p); \
754 } \
755 bool msg_class::ReadReplyParam(const Message* msg, \
756 TupleTypes<ReplyParam>::ValueTuple* p) { \
757 return Schema::ReadReplyParam(msg, p); \
758 }
[email protected]8a8c9c72011-03-01 20:35:47759
[email protected]8bf55ca2011-10-17 22:15:27760#define IPC_EMPTY_MESSAGE_LOG(msg_class) \
761 void msg_class::Log(std::string* name, \
762 const Message* msg, \
763 std::string* l) { \
764 if (name) \
765 *name = #msg_class; \
766 }
[email protected]8a8c9c72011-03-01 20:35:47767
768#define IPC_ASYNC_MESSAGE_LOG(msg_class) \
769 void msg_class::Log(std::string* name, \
770 const Message* msg, \
771 std::string* l) { \
772 if (name) \
773 *name = #msg_class; \
774 if (!msg || !l) \
775 return; \
[email protected]1d4ecf42011-08-26 21:27:30776 Schema::Param p; \
777 if (Schema::Read(msg, &p)) \
[email protected]8a8c9c72011-03-01 20:35:47778 IPC::LogParam(p, l); \
779 }
780
781#define IPC_SYNC_MESSAGE_LOG(msg_class) \
782 void msg_class::Log(std::string* name, \
783 const Message* msg, \
784 std::string* l) { \
785 if (name) \
786 *name = #msg_class; \
787 if (!msg || !l) \
788 return; \
789 if (msg->is_sync()) { \
[email protected]1d4ecf42011-08-26 21:27:30790 TupleTypes<Schema::SendParam>::ValueTuple p; \
791 if (Schema::ReadSendParam(msg, &p)) \
[email protected]8a8c9c72011-03-01 20:35:47792 IPC::LogParam(p, l); \
793 AddOutputParamsToLog(msg, l); \
794 } else { \
[email protected]1d4ecf42011-08-26 21:27:30795 TupleTypes<Schema::ReplyParam>::ValueTuple p; \
796 if (Schema::ReadReplyParam(msg, &p)) \
[email protected]8a8c9c72011-03-01 20:35:47797 IPC::LogParam(p, l); \
798 } \
799 }
800
[email protected]21fa3a12010-12-08 23:34:16801#elif defined(IPC_MESSAGE_MACROS_LOG_ENABLED)
[email protected]f91cb992009-02-04 20:10:12802
[email protected]21fa3a12010-12-08 23:34:16803#ifndef IPC_LOG_TABLE_CREATED
804#define IPC_LOG_TABLE_CREATED
[email protected]82e5ee82009-04-03 02:29:45805
[email protected]21fa3a12010-12-08 23:34:16806#include "base/hash_tables.h"
[email protected]f91cb992009-02-04 20:10:12807
[email protected]21fa3a12010-12-08 23:34:16808typedef void (*LogFunction)(std::string* name,
809 const IPC::Message* msg,
810 std::string* params);
[email protected]f91cb992009-02-04 20:10:12811
[email protected]21fa3a12010-12-08 23:34:16812typedef base::hash_map<uint32, LogFunction > LogFunctionMap;
813LogFunctionMap g_log_function_mapping;
[email protected]f91cb992009-02-04 20:10:12814
[email protected]6476c72c2011-02-11 18:46:19815#endif // IPC_LOG_TABLE_CREATED
[email protected]f91cb992009-02-04 20:10:12816
[email protected]8a8c9c72011-03-01 20:35:47817// "Log table" inclusion produces extra logging registration code.
818#define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
819 in_cnt, out_cnt, in_list, out_list) \
820 class LoggerRegisterHelper##msg_class { \
821 public: \
822 LoggerRegisterHelper##msg_class() { \
[email protected]6fa21d02011-11-04 00:14:16823 const uint32 msg_id = static_cast<uint32>(msg_class::ID); \
824 g_log_function_mapping[msg_id] = msg_class::Log; \
[email protected]8a8c9c72011-03-01 20:35:47825 } \
826 }; \
[email protected]21fa3a12010-12-08 23:34:16827 LoggerRegisterHelper##msg_class g_LoggerRegisterHelper##msg_class;
[email protected]f91cb992009-02-04 20:10:12828
[email protected]8a8c9c72011-03-01 20:35:47829#else
initial.commit09911bf2008-07-26 23:55:29830
[email protected]8a8c9c72011-03-01 20:35:47831// Normal inclusion produces nothing extra.
832#define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
833 in_cnt, out_cnt, in_list, out_list)
initial.commit09911bf2008-07-26 23:55:29834
[email protected]8a8c9c72011-03-01 20:35:47835#endif // defined(IPC_MESSAGE_IMPL)
[email protected]21fa3a12010-12-08 23:34:16836
[email protected]8a8c9c72011-03-01 20:35:47837// Handle variable sized argument lists. These are usually invoked by token
838// pasting against the argument counts.
839#define IPC_TYPE_IN_0()
840#define IPC_TYPE_IN_1(t1) const t1& arg1
841#define IPC_TYPE_IN_2(t1, t2) const t1& arg1, const t2& arg2
842#define IPC_TYPE_IN_3(t1, t2, t3) const t1& arg1, const t2& arg2, const t3& arg3
843#define IPC_TYPE_IN_4(t1, t2, t3, t4) const t1& arg1, const t2& arg2, const t3& arg3, const t4& arg4
844#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:16845
[email protected]8a8c9c72011-03-01 20:35:47846#define IPC_TYPE_OUT_0()
847#define IPC_TYPE_OUT_1(t1) t1* arg6
848#define IPC_TYPE_OUT_2(t1, t2) t1* arg6, t2* arg7
849#define IPC_TYPE_OUT_3(t1, t2, t3) t1* arg6, t2* arg7, t3* arg8
850#define IPC_TYPE_OUT_4(t1, t2, t3, t4) t1* arg6, t2* arg7, t3* arg8, t4* arg9
[email protected]21fa3a12010-12-08 23:34:16851
[email protected]8a8c9c72011-03-01 20:35:47852#define IPC_TUPLE_IN_0() Tuple0
853#define IPC_TUPLE_IN_1(t1) Tuple1<t1>
854#define IPC_TUPLE_IN_2(t1, t2) Tuple2<t1, t2>
855#define IPC_TUPLE_IN_3(t1, t2, t3) Tuple3<t1, t2, t3>
856#define IPC_TUPLE_IN_4(t1, t2, t3, t4) Tuple4<t1, t2, t3, t4>
857#define IPC_TUPLE_IN_5(t1, t2, t3, t4, t5) Tuple5<t1, t2, t3, t4, t5>
[email protected]21fa3a12010-12-08 23:34:16858
[email protected]8a8c9c72011-03-01 20:35:47859#define IPC_TUPLE_OUT_0() Tuple0
860#define IPC_TUPLE_OUT_1(t1) Tuple1<t1&>
861#define IPC_TUPLE_OUT_2(t1, t2) Tuple2<t1&, t2&>
862#define IPC_TUPLE_OUT_3(t1, t2, t3) Tuple3<t1&, t2&, t3&>
863#define IPC_TUPLE_OUT_4(t1, t2, t3, t4) Tuple4<t1&, t2&, t3&, t4&>
[email protected]21fa3a12010-12-08 23:34:16864
[email protected]8a8c9c72011-03-01 20:35:47865#define IPC_NAME_IN_0() MakeTuple()
866#define IPC_NAME_IN_1(t1) MakeRefTuple(arg1)
867#define IPC_NAME_IN_2(t1, t2) MakeRefTuple(arg1, arg2)
868#define IPC_NAME_IN_3(t1, t2, t3) MakeRefTuple(arg1, arg2, arg3)
869#define IPC_NAME_IN_4(t1, t2, t3, t4) MakeRefTuple(arg1, arg2, arg3, arg4)
870#define IPC_NAME_IN_5(t1, t2, t3, t4, t5) MakeRefTuple(arg1, arg2, arg3, arg4, arg5)
[email protected]21fa3a12010-12-08 23:34:16871
[email protected]8a8c9c72011-03-01 20:35:47872#define IPC_NAME_OUT_0() MakeTuple()
873#define IPC_NAME_OUT_1(t1) MakeRefTuple(*arg6)
874#define IPC_NAME_OUT_2(t1, t2) MakeRefTuple(*arg6, *arg7)
875#define IPC_NAME_OUT_3(t1, t2, t3) MakeRefTuple(*arg6, *arg7, *arg8)
876#define IPC_NAME_OUT_4(t1, t2, t3, t4) MakeRefTuple(*arg6, *arg7, *arg8, *arg9)
[email protected]21fa3a12010-12-08 23:34:16877
[email protected]8a8c9c72011-03-01 20:35:47878// There are places where the syntax requires a comma if there are input args,
879// if there are input args and output args, or if there are input args or
880// output args. These macros allow generation of the comma as needed; invoke
881// by token pasting against the argument counts.
882#define IPC_COMMA_0
883#define IPC_COMMA_1 ,
884#define IPC_COMMA_2 ,
885#define IPC_COMMA_3 ,
886#define IPC_COMMA_4 ,
887#define IPC_COMMA_5 ,
[email protected]21fa3a12010-12-08 23:34:16888
[email protected]8a8c9c72011-03-01 20:35:47889#define IPC_COMMA_AND_0(x)
890#define IPC_COMMA_AND_1(x) x
891#define IPC_COMMA_AND_2(x) x
892#define IPC_COMMA_AND_3(x) x
893#define IPC_COMMA_AND_4(x) x
894#define IPC_COMMA_AND_5(x) x
[email protected]21fa3a12010-12-08 23:34:16895
[email protected]8a8c9c72011-03-01 20:35:47896#define IPC_COMMA_OR_0(x) x
897#define IPC_COMMA_OR_1(x) ,
898#define IPC_COMMA_OR_2(x) ,
899#define IPC_COMMA_OR_3(x) ,
900#define IPC_COMMA_OR_4(x) ,
901#define IPC_COMMA_OR_5(x) ,
[email protected]6d8ffc9f2010-03-12 18:27:53902
[email protected]d7a5e3e2011-03-12 16:28:36903// Message IDs
904// Note: we currently use __LINE__ to give unique IDs to messages within
905// a file. They're globally unique since each file defines its own
[email protected]3b3ec7212011-10-21 17:35:08906// IPC_MESSAGE_START.
[email protected]d7a5e3e2011-03-12 16:28:36907#define IPC_MESSAGE_ID() ((IPC_MESSAGE_START << 16) + __LINE__)
908#define IPC_MESSAGE_ID_CLASS(id) ((id) >> 16)
909#define IPC_MESSAGE_ID_LINE(id) ((id) & 0xffff)
910
initial.commit09911bf2008-07-26 23:55:29911// Message crackers and handlers.
912// Prefer to use the IPC_BEGIN_MESSAGE_MAP_EX to the older macros since they
913// allow you to detect when a message could not be de-serialized. Usage:
914//
[email protected]a95986a82010-12-24 06:19:28915// bool MyClass::OnMessageReceived(const IPC::Message& msg) {
916// bool handled = true;
initial.commit09911bf2008-07-26 23:55:29917// bool msg_is_good = false;
918// IPC_BEGIN_MESSAGE_MAP_EX(MyClass, msg, msg_is_good)
919// IPC_MESSAGE_HANDLER(MsgClassOne, OnMsgClassOne)
920// ...more handlers here ...
921// IPC_MESSAGE_HANDLER(MsgClassTen, OnMsgClassTen)
[email protected]a95986a82010-12-24 06:19:28922// IPC_MESSAGE_UNHANDLED(handled = false)
initial.commit09911bf2008-07-26 23:55:29923// IPC_END_MESSAGE_MAP_EX()
924// if (!msg_is_good) {
925// // Signal error here or terminate offending process.
926// }
[email protected]a95986a82010-12-24 06:19:28927// return handled;
initial.commit09911bf2008-07-26 23:55:29928// }
929
[email protected]21fa3a12010-12-08 23:34:16930
initial.commit09911bf2008-07-26 23:55:29931#define IPC_BEGIN_MESSAGE_MAP_EX(class_name, msg, msg_is_ok) \
932 { \
933 typedef class_name _IpcMessageHandlerClass; \
934 const IPC::Message& ipc_message__ = msg; \
935 bool& msg_is_ok__ = msg_is_ok; \
936 switch (ipc_message__.type()) { \
937
938#define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \
939 { \
940 typedef class_name _IpcMessageHandlerClass; \
941 const IPC::Message& ipc_message__ = msg; \
942 bool msg_is_ok__ = true; \
943 switch (ipc_message__.type()) { \
944
[email protected]e86a2552011-11-11 00:21:02945#define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \
946 case msg_class::ID: { \
[email protected]c67f8c22011-11-11 01:00:17947 TRACK_RUN_IN_IPC_HANDLER(member_func); \
[email protected]e86a2552011-11-11 00:21:02948 msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, \
949 &member_func); \
950 } \
951 break;
initial.commit09911bf2008-07-26 23:55:29952
953#define IPC_MESSAGE_HANDLER(msg_class, member_func) \
954 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func)
955
[email protected]e86a2552011-11-11 00:21:02956#define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \
957 case msg_class::ID: { \
[email protected]562016342011-11-15 17:51:43958 TRACK_RUN_IN_IPC_HANDLER(member_func); \
[email protected]e86a2552011-11-11 00:21:02959 msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, \
960 &member_func); \
961 } \
962 break;
initial.commit09911bf2008-07-26 23:55:29963
[email protected]e86a2552011-11-11 00:21:02964#define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \
965 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \
966 _IpcMessageHandlerClass::member_func)
initial.commit09911bf2008-07-26 23:55:29967
[email protected]562016342011-11-15 17:51:43968// TODO(jar): fix chrome frame to always supply |code| argument.
[email protected]e86a2552011-11-11 00:21:02969#define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \
970 case msg_class::ID: { \
[email protected]b75d4a042011-11-12 02:58:59971 /* TRACK_RUN_IN_IPC_HANDLER(code); TODO(jar) */ \
[email protected]e86a2552011-11-11 00:21:02972 code; \
973 } \
974 break;
initial.commit09911bf2008-07-26 23:55:29975
[email protected]e86a2552011-11-11 00:21:02976#define IPC_REPLY_HANDLER(func) \
977 case IPC_REPLY_ID: { \
[email protected]e3bd15c2011-11-11 22:41:08978 TRACK_RUN_IN_IPC_HANDLER(func); \
[email protected]e86a2552011-11-11 00:21:02979 func(ipc_message__); \
980 } \
981 break;
initial.commit09911bf2008-07-26 23:55:29982
983
[email protected]e86a2552011-11-11 00:21:02984#define IPC_MESSAGE_UNHANDLED(code) \
985 default: { \
[email protected]e86a2552011-11-11 00:21:02986 code; \
987 } \
988 break;
initial.commit09911bf2008-07-26 23:55:29989
990#define IPC_MESSAGE_UNHANDLED_ERROR() \
991 IPC_MESSAGE_UNHANDLED(NOTREACHED() << \
992 "Invalid message with type = " << \
993 ipc_message__.type())
994
995#define IPC_END_MESSAGE_MAP() \
996 DCHECK(msg_is_ok__); \
997 } \
998}
999
1000#define IPC_END_MESSAGE_MAP_EX() \
1001 } \
[email protected]8d70d5f2010-12-08 23:41:081002}
[email protected]9f547bf2010-12-13 17:00:421003
1004// This corresponds to an enum value from IPCMessageStart.
1005#define IPC_MESSAGE_CLASS(message) \
[email protected]d7a5e3e2011-03-12 16:28:361006 IPC_MESSAGE_ID_CLASS(message.type())
[email protected]6476c72c2011-02-11 18:46:191007
1008#endif // IPC_IPC_MESSAGE_MACROS_H_
1009
1010// Clean up IPC_MESSAGE_START in this unguarded section so that the
1011// XXX_messages.h files need not do so themselves. This makes the
1012// XXX_messages.h files easier to write.
1013#undef IPC_MESSAGE_START