1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Defining IPC Messages
7 // 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.
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.
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
21 // The XXXMsgStart value is an enumeration that ensures uniqueness for
22 // each different message file. Later, you will use this inside your
23 // XXX_messages.h file before invoking message declaration macros:
24 // #define IPC_MESSAGE_START XXXMsgStart
25 // ( ... your macro invocations go here ... )
27 // Message Generator Files
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,
32 // 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
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.
40 // #define IPC_MESSAGE_IMPL
41 // #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"
48 // // Generate param traits write methods.
49 // #include "ipc/param_traits_write_macros.h"
51 // #include "path/to/YYY_message_generator.h"
53 // // Generate param traits read methods.
54 // #include "ipc/param_traits_read_macros.h"
56 // #include "path/to/YYY_message_generator.h"
58 // // Generate param traits log methods.
59 // #include "ipc/param_traits_log_macros.h"
61 // #include "path/to/YYY_message_generator.h"
64 // 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 ...)
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).
79 // Note that #pragma once cannot be used here; 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.
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.
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.
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 ...)
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
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().
135 // Externally-defined structs are registered with IPC_STRUCT_TRAITS_BEGIN(),
136 // IPC_STRUCT_TRAITS_MEMBER(), and IPC_STRUCT_TRAITS_END() macros. These
137 // 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
141 // inside matching calls to IPC_STRUCT_TRAITS_BEGIN() /
142 // IPC_STRUCT_TRAITS_END().
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.
147 // Do not place semicolons following these IPC_ macro invocations. There
148 // is no reason to expect that their expansion corresponds one-to-one with
151 // Once the types have been declared / registered, message definitions follow.
152 // "Sync" messages are just synchronous calls, the Send() call doesn't return
153 // 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).
157 // The receiver's handler function will be
158 // void OnSyncMessageName(const type1& in1, type2* out1, type3* out2)
160 // A caller can also send a synchronous message, while the receiver can respond
161 // at a later time. This is transparent from the sender's side. The receiver
162 // 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.
165 // Use the IPC_MESSAGE_HANDLER_DELAY_REPLY macro instead of IPC_MESSAGE_HANDLER
166 // IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncMessageName,
167 // OnSyncMessageName)
169 // The handler function will look like:
170 // void OnSyncMessageName(const type1& in1, IPC::Message* reply_msg);
172 // Receiver stashes the IPC::Message* pointer, and when it's ready, it does:
173 // ViewHostMsg_SyncMessageName::WriteReplyParams(reply_msg, out1, out2);
176 // 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
184 #ifndef IPC_IPC_MESSAGE_MACROS_H_
185 #define IPC_IPC_MESSAGE_MACROS_H_
187 #include "base/profiler/scoped_profile.h"
188 #include "ipc/ipc_message_utils.h"
189 #include "ipc/param_traits_macros.h"
191 #if defined(IPC_MESSAGE_IMPL)
192 #include "ipc/ipc_message_utils_impl.h"
195 // Macros for defining structs. May be subsequently redefined.
196 #define IPC_STRUCT_BEGIN(struct_name) \
197 IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, IPC::NoParams)
198 #define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \
199 struct struct_name; \
200 IPC_STRUCT_TRAITS_BEGIN(struct_name) \
201 IPC_STRUCT_TRAITS_END() \
202 struct IPC_MESSAGE_EXPORT struct_name : parent { \
205 // 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;
208 #define IPC_STRUCT_END() };
210 // Message macros collect specific numbers of arguments and funnel them into
211 // the common message generation macro. These should never be redefined.
212 #define IPC_MESSAGE_CONTROL0(msg_class) \
213 IPC_MESSAGE_DECL(EMPTY, CONTROL, msg_class, 0, 0, (), ())
215 #define IPC_MESSAGE_CONTROL1(msg_class, type1) \
216 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 1, 0, (type1), ())
218 #define IPC_MESSAGE_CONTROL2(msg_class, type1, type2) \
219 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 2, 0, (type1, type2), ())
221 #define IPC_MESSAGE_CONTROL3(msg_class, type1, type2, type3) \
222 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 3, 0, (type1, type2, type3), ())
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), ())
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), ())
230 #define IPC_MESSAGE_ROUTED0(msg_class) \
231 IPC_MESSAGE_DECL(EMPTY, ROUTED, msg_class, 0, 0, (), ())
233 #define IPC_MESSAGE_ROUTED1(msg_class, type1) \
234 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 1, 0, (type1), ())
236 #define IPC_MESSAGE_ROUTED2(msg_class, type1, type2) \
237 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 2, 0, (type1, type2), ())
239 #define IPC_MESSAGE_ROUTED3(msg_class, type1, type2, type3) \
240 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 3, 0, (type1, type2, type3), ())
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), ())
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), ())
248 #define IPC_SYNC_MESSAGE_CONTROL0_0(msg_class) \
249 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 0, (), ())
251 #define IPC_SYNC_MESSAGE_CONTROL0_1(msg_class, type1_out) \
252 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 1, (), (type1_out))
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))
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))
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))
263 #define IPC_SYNC_MESSAGE_CONTROL1_0(msg_class, type1_in) \
264 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 0, (type1_in), ())
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))
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))
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))
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))
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), ())
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))
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))
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))
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))
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), ())
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))
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))
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))
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))
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), ())
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))
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))
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))
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))
323 #define IPC_SYNC_MESSAGE_CONTROL5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \
324 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 0, (type1_in, type2_in, type3_in, type4_in, type5_in), ())
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))
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))
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))
335 #define IPC_SYNC_MESSAGE_ROUTED0_0(msg_class) \
336 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 0, (), ())
338 #define IPC_SYNC_MESSAGE_ROUTED0_1(msg_class, type1_out) \
339 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 1, (), (type1_out))
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))
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))
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))
350 #define IPC_SYNC_MESSAGE_ROUTED1_0(msg_class, type1_in) \
351 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 0, (type1_in), ())
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))
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))
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))
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))
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), ())
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))
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))
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))
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))
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), ())
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))
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))
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))
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))
395 #define IPC_SYNC_MESSAGE_ROUTED4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \
396 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 0, (type1_in, type2_in, type3_in, type4_in), ())
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))
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))
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))
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))
410 #define IPC_SYNC_MESSAGE_ROUTED5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \
411 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 0, (type1_in, type2_in, type3_in, type4_in, type5_in), ())
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))
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))
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))
422 // The following macros define the common set of methods provided by ASYNC
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) { \
428 if (Read(msg, &p)) { \
429 DispatchToMethod(obj, func, p); \
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)) { \
440 if (Read(msg, &p)) { \
441 (obj->*func)(*msg, p.a); \
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)) { \
452 if (Read(msg, &p)) { \
453 (obj->*func)(*msg, p.a, p.b); \
458 template<typename TA, typename TB> \
459 static bool Read(const IPC::Message* msg, TA* a, TB* b) { \
461 if (!Read(msg, &p)) \
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)) { \
473 if (Read(msg, &p)) { \
474 (obj->*func)(*msg, p.a, p.b, p.c); \
479 template<typename TA, typename TB, typename TC> \
480 static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c) { \
482 if (!Read(msg, &p)) \
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, \
493 static bool Dispatch(const Message* msg, T* obj, S* sender, \
494 void (T::*func)(const Message&, TA, TB, TC, TD)) { \
496 if (Read(msg, &p)) { \
497 (obj->*func)(*msg, p.a, p.b, p.c, p.d); \
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) { \
505 if (!Read(msg, &p)) \
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)) { \
520 if (Read(msg, &p)) { \
521 (obj->*func)(*msg, p.a, p.b, p.c, p.d, p.e); \
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, \
530 if (!Read(msg, &p)) \
540 // The following macros define the common set of methods provided by SYNC
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, \
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, \
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); \
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); \
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); \
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); \
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); \
590 // 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.
593 // Note: intended be redefined to generate other information.
594 #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)
599 #define IPC_EMPTY_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
600 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
602 typedef IPC::Message Schema; \
603 enum { ID = IPC_MESSAGE_ID() }; \
604 msg_class() : IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) {} \
605 static void Log(std::string* name, const Message* msg, std::string* l); \
608 #define IPC_EMPTY_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
609 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
611 typedef IPC::Message Schema; \
612 enum { ID = IPC_MESSAGE_ID() }; \
613 msg_class(int32 routing_id) \
614 : IPC::Message(routing_id, ID, PRIORITY_NORMAL) {} \
615 static void Log(std::string* name, const Message* msg, std::string* l); \
618 #define IPC_ASYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
619 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
621 typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \
622 typedef Schema::Param Param; \
623 enum { ID = IPC_MESSAGE_ID() }; \
624 msg_class(IPC_TYPE_IN_##in_cnt in_list); \
625 virtual ~msg_class(); \
626 static bool Read(const Message* msg, Schema::Param* p); \
627 static void Log(std::string* name, const Message* msg, std::string* l); \
628 IPC_ASYNC_MESSAGE_METHODS_##in_cnt \
631 #define IPC_ASYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
632 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
634 typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \
635 typedef Schema::Param Param; \
636 enum { ID = IPC_MESSAGE_ID() }; \
637 msg_class(int32 routing_id IPC_COMMA_##in_cnt \
638 IPC_TYPE_IN_##in_cnt in_list); \
639 virtual ~msg_class(); \
640 static bool Read(const Message* msg, Schema::Param* p); \
641 static void Log(std::string* name, const Message* msg, std::string* l); \
642 IPC_ASYNC_MESSAGE_METHODS_##in_cnt \
645 #define IPC_SYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
646 class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \
648 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; \
652 enum { ID = IPC_MESSAGE_ID() }; \
653 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); \
656 virtual ~msg_class(); \
657 static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \
658 static bool ReadReplyParam( \
659 const Message* msg, \
660 TupleTypes<ReplyParam>::ValueTuple* p); \
661 static void Log(std::string* name, const Message* msg, std::string* l); \
662 IPC_SYNC_MESSAGE_METHODS_##out_cnt \
665 #define IPC_SYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
666 class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \
668 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; \
672 enum { ID = IPC_MESSAGE_ID() }; \
673 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); \
678 virtual ~msg_class(); \
679 static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \
680 static bool ReadReplyParam( \
681 const Message* msg, \
682 TupleTypes<ReplyParam>::ValueTuple* p); \
683 static void Log(std::string* name, const Message* msg, std::string* l); \
684 IPC_SYNC_MESSAGE_METHODS_##out_cnt \
687 #if defined(IPC_MESSAGE_IMPL)
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
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)
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)
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) : \
703 IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) { \
704 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
706 msg_class::~msg_class() {} \
707 bool msg_class::Read(const Message* msg, Schema::Param* p) { \
708 return Schema::Read(msg, p); \
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) : \
714 IPC::Message(routing_id, ID, PRIORITY_NORMAL) { \
715 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
717 msg_class::~msg_class() {} \
718 bool msg_class::Read(const Message* msg, Schema::Param* p) { \
719 return Schema::Read(msg, p); \
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) : \
726 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); \
731 msg_class::~msg_class() {} \
732 bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \
733 return Schema::ReadSendParam(msg, p); \
735 bool msg_class::ReadReplyParam(const Message* msg, \
736 TupleTypes<ReplyParam>::ValueTuple* p) { \
737 return Schema::ReadReplyParam(msg, p); \
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) : \
746 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); \
751 msg_class::~msg_class() {} \
752 bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \
753 return Schema::ReadSendParam(msg, p); \
755 bool msg_class::ReadReplyParam(const Message* msg, \
756 TupleTypes<ReplyParam>::ValueTuple* p) { \
757 return Schema::ReadReplyParam(msg, p); \
760 #define IPC_EMPTY_MESSAGE_LOG(msg_class) \
761 void msg_class::Log(std::string* name, \
762 const Message* msg, \
765 *name = #msg_class; \
768 #define IPC_ASYNC_MESSAGE_LOG(msg_class) \
769 void msg_class::Log(std::string* name, \
770 const Message* msg, \
773 *name = #msg_class; \
777 if (Schema::Read(msg, &p)) \
778 IPC::LogParam(p, l); \
781 #define IPC_SYNC_MESSAGE_LOG(msg_class) \
782 void msg_class::Log(std::string* name, \
783 const Message* msg, \
786 *name = #msg_class; \
789 if (msg->is_sync()) { \
790 TupleTypes<Schema::SendParam>::ValueTuple p; \
791 if (Schema::ReadSendParam(msg, &p)) \
792 IPC::LogParam(p, l); \
793 AddOutputParamsToLog(msg, l); \
795 TupleTypes<Schema::ReplyParam>::ValueTuple p; \
796 if (Schema::ReadReplyParam(msg, &p)) \
797 IPC::LogParam(p, l); \
801 #elif defined(IPC_MESSAGE_MACROS_LOG_ENABLED)
803 #ifndef IPC_LOG_TABLE_CREATED
804 #define IPC_LOG_TABLE_CREATED
806 #include "base/hash_tables.h"
808 typedef void (*LogFunction
)(std::string
* name
,
809 const IPC::Message
* msg
,
810 std::string
* params
);
812 typedef base::hash_map
<uint32
, LogFunction
> LogFunctionMap
;
813 LogFunctionMap g_log_function_mapping
;
815 #endif // IPC_LOG_TABLE_CREATED
817 // "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 { \
822 LoggerRegisterHelper##msg_class() { \
823 const uint32 msg_id = static_cast<uint32>(msg_class::ID); \
824 g_log_function_mapping[msg_id] = msg_class::Log; \
827 LoggerRegisterHelper##msg_class g_LoggerRegisterHelper##msg_class;
831 // Normal inclusion produces nothing extra.
832 #define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
833 in_cnt, out_cnt, in_list, out_list)
835 #endif // defined(IPC_MESSAGE_IMPL)
837 // 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
846 #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
852 #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>
859 #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&>
865 #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)
872 #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)
878 // 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.
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 ,
889 #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
896 #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) ,
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
906 // IPC_MESSAGE_START.
907 #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)
911 // 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:
915 // bool MyClass::OnMessageReceived(const IPC::Message& msg) {
916 // bool handled = true;
917 // 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)
922 // IPC_MESSAGE_UNHANDLED(handled = false)
923 // IPC_END_MESSAGE_MAP_EX()
924 // if (!msg_is_good) {
925 // // Signal error here or terminate offending process.
931 #define IPC_BEGIN_MESSAGE_MAP_EX(class_name, msg, msg_is_ok) \
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()) { \
938 #define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \
940 typedef class_name _IpcMessageHandlerClass; \
941 const IPC::Message& ipc_message__ = msg; \
942 bool msg_is_ok__ = true; \
943 switch (ipc_message__.type()) { \
945 #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \
946 case msg_class::ID: { \
947 TRACK_RUN_IN_IPC_HANDLER(member_func); \
948 msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, \
953 #define IPC_MESSAGE_HANDLER(msg_class, member_func) \
954 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func)
956 #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \
957 case msg_class::ID: { \
958 TRACK_RUN_IN_IPC_HANDLER(member_func); \
959 msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, \
964 #define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \
965 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \
966 _IpcMessageHandlerClass::member_func)
968 // TODO(jar): fix chrome frame to always supply |code| argument.
969 #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \
970 case msg_class::ID: { \
971 /* TRACK_RUN_IN_IPC_HANDLER(code); TODO(jar) */ \
976 #define IPC_REPLY_HANDLER(func) \
977 case IPC_REPLY_ID: { \
978 TRACK_RUN_IN_IPC_HANDLER(func); \
979 func(ipc_message__); \
984 #define IPC_MESSAGE_UNHANDLED(code) \
990 #define IPC_MESSAGE_UNHANDLED_ERROR() \
991 IPC_MESSAGE_UNHANDLED(NOTREACHED() << \
992 "Invalid message with type = " << \
993 ipc_message__.type())
995 #define IPC_END_MESSAGE_MAP() \
996 DCHECK(msg_is_ok__); \
1000 #define IPC_END_MESSAGE_MAP_EX() \
1004 // This corresponds to an enum value from IPCMessageStart.
1005 #define IPC_MESSAGE_CLASS(message) \
1006 IPC_MESSAGE_ID_CLASS(message.type())
1008 #endif // IPC_IPC_MESSAGE_MACROS_H_
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