Remove base's implicit_cast.
[chromium-blink-merge.git] / ipc / ipc_message_macros.h
blobdaeb617c452fdd92504f26753a37eea49e8dc851
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
6 //
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 // implementation 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_start.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
34 // new one.
36 // In the rare circumstances 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"
50 // namespace IPC {
51 // #include "path/to/YYY_message_generator.h"
52 // } // namespace IPC
53 // // Generate param traits read methods.
54 // #include "ipc/param_traits_read_macros.h"
55 // namespace IPC {
56 // #include "path/to/YYY_message_generator.h"
57 // } // namespace IPC
58 // // Generate param traits log methods.
59 // #include "ipc/param_traits_log_macros.h"
60 // namespace IPC {
61 // #include "path/to/YYY_message_generator.h"
62 // } // namespace IPC
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 ...)
70 // Multiple Inclusion
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 solely
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.
86 // Type Declarations
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 itself. Later, an IPC message dispatcher will 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 addition, 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 // #include "path/to/some_class.h" // Full class declaration
117 // #include "path/to/some_other_class.h" // Full class declaration
118 // #endif // IPC_MESSAGE_IMPL
119 // (.. IPC macros using some_class and some_other_class ...)
121 // Macro Invocations
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(). There is also an
134 // IPC_STRUCT_BEGIN_WITH_PARENT(), which behaves like IPC_STRUCT_BEGIN(),
135 // but also accommodates structs that inherit from other structs.
137 // Externally-defined structs are registered with IPC_STRUCT_TRAITS_BEGIN(),
138 // IPC_STRUCT_TRAITS_MEMBER(), and IPC_STRUCT_TRAITS_END() macros. These
139 // cause registration of the types with message generation only.
140 // There's also IPC_STRUCT_TRAITS_PARENT, which is used to register a parent
141 // class (whose own traits are already defined). Note that
142 // IPC_STRUCT_TRAITS_MEMBER() and IPC_STRUCT_TRAITS_PARENT are only permitted
143 // inside matching calls to IPC_STRUCT_TRAITS_BEGIN() /
144 // IPC_STRUCT_TRAITS_END().
146 // Enum types are registered with a single IPC_ENUM_TRAITS_VALIDATE() macro.
147 // There is no need to enumerate each value to the IPC mechanism. Instead,
148 // pass an expression in terms of the parameter |value| to provide
149 // range-checking. For convenience, the IPC_ENUM_TRAITS() is provided which
150 // performs no checking, passing everything including out-of-range values.
151 // Its use is discouraged. The IPC_ENUM_TRAITS_MAX_VALUE() macro can be used
152 // for the typical case where the enum must be in the range 0..maxvalue
153 // inclusive. The IPC_ENUM_TRAITS_MIN_MAX_VALUE() macro can be used for the
154 // less typical case where the enum must be in the range minvalue..maxvalue
155 // inclusive.
157 // Do not place semicolons following these IPC_ macro invocations. There
158 // is no reason to expect that their expansion corresponds one-to-one with
159 // C++ statements.
161 // Once the types have been declared / registered, message definitions follow.
162 // "Sync" messages are just synchronous calls, the Send() call doesn't return
163 // until a reply comes back. To declare a sync message, use the IPC_SYNC_
164 // macros. The numbers at the end show how many input/output parameters there
165 // are (i.e. 1_2 is 1 in, 2 out). Input parameters are first, followed by
166 // output parameters. The caller uses Send([route id, ], in1, &out1, &out2).
167 // The receiver's handler function will be
168 // void OnSyncMessageName(const type1& in1, type2* out1, type3* out2)
170 // A caller can also send a synchronous message, while the receiver can respond
171 // at a later time. This is transparent from the sender's side. The receiver
172 // needs to use a different handler that takes in a IPC::Message* as the output
173 // type, stash the message, and when it has the data it can Send the message.
175 // Use the IPC_MESSAGE_HANDLER_DELAY_REPLY macro instead of IPC_MESSAGE_HANDLER
176 // IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncMessageName,
177 // OnSyncMessageName)
179 // The handler function will look like:
180 // void OnSyncMessageName(const type1& in1, IPC::Message* reply_msg);
182 // Receiver stashes the IPC::Message* pointer, and when it's ready, it does:
183 // ViewHostMsg_SyncMessageName::WriteReplyParams(reply_msg, out1, out2);
184 // Send(reply_msg);
186 // Files that want to export their ipc messages should do
187 // #undef IPC_MESSAGE_EXPORT
188 // #define IPC_MESSAGE_EXPORT VISIBILITY_MACRO
189 // after including this header, but before using any of the macros below.
190 // (This needs to be before the include guard.)
191 #undef IPC_MESSAGE_EXPORT
192 #define IPC_MESSAGE_EXPORT
194 #ifndef IPC_IPC_MESSAGE_MACROS_H_
195 #define IPC_IPC_MESSAGE_MACROS_H_
197 #include <stdint.h>
199 #include "base/profiler/scoped_profile.h"
200 #include "ipc/ipc_message_utils.h"
201 #include "ipc/param_traits_macros.h"
203 #if defined(IPC_MESSAGE_IMPL)
204 #include "ipc/ipc_message_utils_impl.h"
205 #endif
207 // Convenience macro for defining structs without inheritance. Should not need
208 // to be subsequently redefined.
209 #define IPC_STRUCT_BEGIN(struct_name) \
210 IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, IPC::NoParams)
212 // Macros for defining structs. Will be subsequently redefined.
213 #define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \
214 struct struct_name; \
215 IPC_STRUCT_TRAITS_BEGIN(struct_name) \
216 IPC_STRUCT_TRAITS_END() \
217 struct IPC_MESSAGE_EXPORT struct_name : parent { \
218 struct_name(); \
219 ~struct_name();
220 // Optional variadic parameters specify the default value for this struct
221 // member. They are passed through to the constructor for |type|.
222 #define IPC_STRUCT_MEMBER(type, name, ...) type name;
223 #define IPC_STRUCT_END() };
225 // Message macros collect specific numbers of arguments and funnel them into
226 // the common message generation macro. These should never be redefined.
227 #define IPC_MESSAGE_CONTROL0(msg_class) \
228 IPC_MESSAGE_DECL(EMPTY, CONTROL, msg_class, 0, 0, (), ())
230 #define IPC_MESSAGE_CONTROL1(msg_class, type1) \
231 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 1, 0, (type1), ())
233 #define IPC_MESSAGE_CONTROL2(msg_class, type1, type2) \
234 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 2, 0, (type1, type2), ())
236 #define IPC_MESSAGE_CONTROL3(msg_class, type1, type2, type3) \
237 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 3, 0, (type1, type2, type3), ())
239 #define IPC_MESSAGE_CONTROL4(msg_class, type1, type2, type3, type4) \
240 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 4, 0, (type1, type2, type3, type4), ())
242 #define IPC_MESSAGE_CONTROL5(msg_class, type1, type2, type3, type4, type5) \
243 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 5, 0, (type1, type2, type3, type4, type5), ())
245 #define IPC_MESSAGE_ROUTED0(msg_class) \
246 IPC_MESSAGE_DECL(EMPTY, ROUTED, msg_class, 0, 0, (), ())
248 #define IPC_MESSAGE_ROUTED1(msg_class, type1) \
249 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 1, 0, (type1), ())
251 #define IPC_MESSAGE_ROUTED2(msg_class, type1, type2) \
252 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 2, 0, (type1, type2), ())
254 #define IPC_MESSAGE_ROUTED3(msg_class, type1, type2, type3) \
255 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 3, 0, (type1, type2, type3), ())
257 #define IPC_MESSAGE_ROUTED4(msg_class, type1, type2, type3, type4) \
258 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 4, 0, (type1, type2, type3, type4), ())
260 #define IPC_MESSAGE_ROUTED5(msg_class, type1, type2, type3, type4, type5) \
261 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 5, 0, (type1, type2, type3, type4, type5), ())
263 #define IPC_SYNC_MESSAGE_CONTROL0_0(msg_class) \
264 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 0, (), ())
266 #define IPC_SYNC_MESSAGE_CONTROL0_1(msg_class, type1_out) \
267 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 1, (), (type1_out))
269 #define IPC_SYNC_MESSAGE_CONTROL0_2(msg_class, type1_out, type2_out) \
270 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 2, (), (type1_out, type2_out))
272 #define IPC_SYNC_MESSAGE_CONTROL0_3(msg_class, type1_out, type2_out, type3_out) \
273 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 3, (), (type1_out, type2_out, type3_out))
275 #define IPC_SYNC_MESSAGE_CONTROL0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \
276 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out))
278 #define IPC_SYNC_MESSAGE_CONTROL1_0(msg_class, type1_in) \
279 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 0, (type1_in), ())
281 #define IPC_SYNC_MESSAGE_CONTROL1_1(msg_class, type1_in, type1_out) \
282 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 1, (type1_in), (type1_out))
284 #define IPC_SYNC_MESSAGE_CONTROL1_2(msg_class, type1_in, type1_out, type2_out) \
285 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 2, (type1_in), (type1_out, type2_out))
287 #define IPC_SYNC_MESSAGE_CONTROL1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \
288 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out))
290 #define IPC_SYNC_MESSAGE_CONTROL1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \
291 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out))
293 #define IPC_SYNC_MESSAGE_CONTROL2_0(msg_class, type1_in, type2_in) \
294 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 0, (type1_in, type2_in), ())
296 #define IPC_SYNC_MESSAGE_CONTROL2_1(msg_class, type1_in, type2_in, type1_out) \
297 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 1, (type1_in, type2_in), (type1_out))
299 #define IPC_SYNC_MESSAGE_CONTROL2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \
300 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out))
302 #define IPC_SYNC_MESSAGE_CONTROL2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \
303 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out))
305 #define IPC_SYNC_MESSAGE_CONTROL2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \
306 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out))
308 #define IPC_SYNC_MESSAGE_CONTROL3_0(msg_class, type1_in, type2_in, type3_in) \
309 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 0, (type1_in, type2_in, type3_in), ())
311 #define IPC_SYNC_MESSAGE_CONTROL3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \
312 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out))
314 #define IPC_SYNC_MESSAGE_CONTROL3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \
315 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out))
317 #define IPC_SYNC_MESSAGE_CONTROL3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \
318 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out))
320 #define IPC_SYNC_MESSAGE_CONTROL3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \
321 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out))
323 #define IPC_SYNC_MESSAGE_CONTROL4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \
324 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 0, (type1_in, type2_in, type3_in, type4_in), ())
326 #define IPC_SYNC_MESSAGE_CONTROL4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \
327 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out))
329 #define IPC_SYNC_MESSAGE_CONTROL4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \
330 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out))
332 #define IPC_SYNC_MESSAGE_CONTROL4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \
333 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out))
335 #define IPC_SYNC_MESSAGE_CONTROL4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \
336 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))
338 #define IPC_SYNC_MESSAGE_CONTROL5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \
339 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 0, (type1_in, type2_in, type3_in, type4_in, type5_in), ())
341 #define IPC_SYNC_MESSAGE_CONTROL5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \
342 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out))
344 #define IPC_SYNC_MESSAGE_CONTROL5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \
345 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out))
347 #define IPC_SYNC_MESSAGE_CONTROL5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \
348 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))
350 #define IPC_SYNC_MESSAGE_ROUTED0_0(msg_class) \
351 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 0, (), ())
353 #define IPC_SYNC_MESSAGE_ROUTED0_1(msg_class, type1_out) \
354 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 1, (), (type1_out))
356 #define IPC_SYNC_MESSAGE_ROUTED0_2(msg_class, type1_out, type2_out) \
357 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 2, (), (type1_out, type2_out))
359 #define IPC_SYNC_MESSAGE_ROUTED0_3(msg_class, type1_out, type2_out, type3_out) \
360 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 3, (), (type1_out, type2_out, type3_out))
362 #define IPC_SYNC_MESSAGE_ROUTED0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \
363 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out))
365 #define IPC_SYNC_MESSAGE_ROUTED1_0(msg_class, type1_in) \
366 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 0, (type1_in), ())
368 #define IPC_SYNC_MESSAGE_ROUTED1_1(msg_class, type1_in, type1_out) \
369 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 1, (type1_in), (type1_out))
371 #define IPC_SYNC_MESSAGE_ROUTED1_2(msg_class, type1_in, type1_out, type2_out) \
372 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 2, (type1_in), (type1_out, type2_out))
374 #define IPC_SYNC_MESSAGE_ROUTED1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \
375 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out))
377 #define IPC_SYNC_MESSAGE_ROUTED1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \
378 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out))
380 #define IPC_SYNC_MESSAGE_ROUTED2_0(msg_class, type1_in, type2_in) \
381 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 0, (type1_in, type2_in), ())
383 #define IPC_SYNC_MESSAGE_ROUTED2_1(msg_class, type1_in, type2_in, type1_out) \
384 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 1, (type1_in, type2_in), (type1_out))
386 #define IPC_SYNC_MESSAGE_ROUTED2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \
387 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out))
389 #define IPC_SYNC_MESSAGE_ROUTED2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \
390 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out))
392 #define IPC_SYNC_MESSAGE_ROUTED2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \
393 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out))
395 #define IPC_SYNC_MESSAGE_ROUTED3_0(msg_class, type1_in, type2_in, type3_in) \
396 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 0, (type1_in, type2_in, type3_in), ())
398 #define IPC_SYNC_MESSAGE_ROUTED3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \
399 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out))
401 #define IPC_SYNC_MESSAGE_ROUTED3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \
402 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out))
404 #define IPC_SYNC_MESSAGE_ROUTED3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \
405 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out))
407 #define IPC_SYNC_MESSAGE_ROUTED3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \
408 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out))
410 #define IPC_SYNC_MESSAGE_ROUTED4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \
411 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 0, (type1_in, type2_in, type3_in, type4_in), ())
413 #define IPC_SYNC_MESSAGE_ROUTED4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \
414 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out))
416 #define IPC_SYNC_MESSAGE_ROUTED4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \
417 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out))
419 #define IPC_SYNC_MESSAGE_ROUTED4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \
420 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out))
422 #define IPC_SYNC_MESSAGE_ROUTED4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \
423 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))
425 #define IPC_SYNC_MESSAGE_ROUTED5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \
426 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 0, (type1_in, type2_in, type3_in, type4_in, type5_in), ())
428 #define IPC_SYNC_MESSAGE_ROUTED5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \
429 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out))
431 #define IPC_SYNC_MESSAGE_ROUTED5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \
432 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out))
434 #define IPC_SYNC_MESSAGE_ROUTED5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \
435 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))
437 // The following macros define the common set of methods provided by ASYNC
438 // message classes.
439 // This macro is for all the async IPCs that don't pass an extra parameter using
440 // IPC_BEGIN_MESSAGE_MAP_WITH_PARAM.
441 #define IPC_ASYNC_MESSAGE_METHODS_GENERIC \
442 template<class T, class S, class P, class Method> \
443 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
444 Method func) { \
445 Schema::Param p; \
446 if (Read(msg, &p)) { \
447 DispatchToMethod(obj, func, p); \
448 return true; \
450 return false; \
453 // The following macros are for for async IPCs which have a dispatcher with an
454 // extra parameter specified using IPC_BEGIN_MESSAGE_MAP_WITH_PARAM.
455 #define IPC_ASYNC_MESSAGE_METHODS_1 \
456 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
457 template<class T, class S, class P, typename TA> \
458 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
459 void (T::*func)(P*, TA)) { \
460 Schema::Param p; \
461 if (Read(msg, &p)) { \
462 (obj->*func)(parameter, base::get<0>(p)); \
463 return true; \
465 return false; \
467 #define IPC_ASYNC_MESSAGE_METHODS_2 \
468 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
469 template<class T, class S, class P, typename TA, typename TB> \
470 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
471 void (T::*func)(P*, TA, TB)) { \
472 Schema::Param p; \
473 if (Read(msg, &p)) { \
474 (obj->*func)(parameter, base::get<0>(p), base::get<1>(p)); \
475 return true; \
477 return false; \
479 #define IPC_ASYNC_MESSAGE_METHODS_3 \
480 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
481 template<class T, class S, class P, typename TA, typename TB, typename TC> \
482 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
483 void (T::*func)(P*, TA, TB, TC)) { \
484 Schema::Param p; \
485 if (Read(msg, &p)) { \
486 (obj->*func)(parameter, base::get<0>(p), base::get<1>(p), \
487 base::get<2>(p)); \
488 return true; \
490 return false; \
492 #define IPC_ASYNC_MESSAGE_METHODS_4 \
493 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
494 template<class T, class S, class P, typename TA, typename TB, typename TC, \
495 typename TD> \
496 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
497 void (T::*func)(P*, TA, TB, TC, TD)) { \
498 Schema::Param p; \
499 if (Read(msg, &p)) { \
500 (obj->*func)(parameter, base::get<0>(p), base::get<1>(p), \
501 base::get<2>(p), base::get<3>(p)); \
502 return true; \
504 return false; \
506 #define IPC_ASYNC_MESSAGE_METHODS_5 \
507 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
508 template<class T, class S, class P, typename TA, typename TB, typename TC, \
509 typename TD, typename TE> \
510 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
511 void (T::*func)(P*, TA, TB, TC, TD, TE)) { \
512 Schema::Param p; \
513 if (Read(msg, &p)) { \
514 (obj->*func)(parameter, base::get<0>(p), base::get<1>(p), \
515 base::get<2>(p), base::get<3>(p), base::get<4>(p)); \
516 return true; \
518 return false; \
521 // The following macros define the common set of methods provided by SYNC
522 // message classes.
523 #define IPC_SYNC_MESSAGE_METHODS_GENERIC \
524 template<class T, class S, class P, class Method> \
525 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
526 Method func) { \
527 Schema::SendParam send_params; \
528 bool ok = ReadSendParam(msg, &send_params); \
529 return Schema::DispatchWithSendParams(ok, send_params, msg, obj, sender, \
530 func); \
532 template<class T, class P, class Method> \
533 static bool DispatchDelayReply(const Message* msg, T* obj, P* parameter, \
534 Method func) { \
535 Schema::SendParam send_params; \
536 bool ok = ReadSendParam(msg, &send_params); \
537 return Schema::DispatchDelayReplyWithSendParams(ok, send_params, msg, \
538 obj, func); \
540 #define IPC_SYNC_MESSAGE_METHODS_0 \
541 IPC_SYNC_MESSAGE_METHODS_GENERIC
542 #define IPC_SYNC_MESSAGE_METHODS_1 \
543 IPC_SYNC_MESSAGE_METHODS_GENERIC \
544 template<typename TA> \
545 static void WriteReplyParams(Message* reply, TA a) { \
546 Schema::WriteReplyParams(reply, a); \
548 #define IPC_SYNC_MESSAGE_METHODS_2 \
549 IPC_SYNC_MESSAGE_METHODS_GENERIC \
550 template<typename TA, typename TB> \
551 static void WriteReplyParams(Message* reply, TA a, TB b) { \
552 Schema::WriteReplyParams(reply, a, b); \
554 #define IPC_SYNC_MESSAGE_METHODS_3 \
555 IPC_SYNC_MESSAGE_METHODS_GENERIC \
556 template<typename TA, typename TB, typename TC> \
557 static void WriteReplyParams(Message* reply, TA a, TB b, TC c) { \
558 Schema::WriteReplyParams(reply, a, b, c); \
560 #define IPC_SYNC_MESSAGE_METHODS_4 \
561 IPC_SYNC_MESSAGE_METHODS_GENERIC \
562 template<typename TA, typename TB, typename TC, typename TD> \
563 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d) { \
564 Schema::WriteReplyParams(reply, a, b, c, d); \
566 #define IPC_SYNC_MESSAGE_METHODS_5 \
567 IPC_SYNC_MESSAGE_METHODS_GENERIC \
568 template<typename TA, typename TB, typename TC, typename TD, typename TE> \
569 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d, TE e) { \
570 Schema::WriteReplyParams(reply, a, b, c, d, e); \
573 // Common message macro which dispatches into one of the 6 (sync x kind)
574 // routines. There is a way that these 6 cases can be lumped together,
575 // but the macros get very complicated in that case.
576 // Note: intended be redefined to generate other information.
577 #define IPC_MESSAGE_DECL(sync, kind, msg_class, \
578 in_cnt, out_cnt, in_list, out_list) \
579 IPC_##sync##_##kind##_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
580 IPC_MESSAGE_EXTRA(sync, kind, msg_class, in_cnt, out_cnt, in_list, out_list)
582 #define IPC_EMPTY_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
583 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
584 public: \
585 typedef IPC::Message Schema; \
586 enum { ID = IPC_MESSAGE_ID() }; \
587 msg_class() : IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) {} \
588 static void Log(std::string* name, const Message* msg, std::string* l); \
591 #define IPC_EMPTY_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
592 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
593 public: \
594 typedef IPC::Message Schema; \
595 enum { ID = IPC_MESSAGE_ID() }; \
596 msg_class(int32_t routing_id) \
597 : IPC::Message(routing_id, ID, PRIORITY_NORMAL) {} \
598 static void Log(std::string* name, const Message* msg, std::string* l); \
601 #define IPC_ASYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
602 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
603 public: \
604 typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \
605 typedef Schema::Param Param; \
606 enum { ID = IPC_MESSAGE_ID() }; \
607 msg_class(IPC_TYPE_IN_##in_cnt in_list); \
608 ~msg_class() override; \
609 static bool Read(const Message* msg, Schema::Param* p); \
610 static void Log(std::string* name, const Message* msg, std::string* l); \
611 IPC_ASYNC_MESSAGE_METHODS_##in_cnt \
614 #define IPC_ASYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
615 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
616 public: \
617 typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \
618 typedef Schema::Param Param; \
619 enum { ID = IPC_MESSAGE_ID() }; \
620 msg_class(int32_t routing_id IPC_COMMA_##in_cnt \
621 IPC_TYPE_IN_##in_cnt in_list); \
622 ~msg_class() override; \
623 static bool Read(const Message* msg, Schema::Param* p); \
624 static void Log(std::string* name, const Message* msg, std::string* l); \
625 IPC_ASYNC_MESSAGE_METHODS_##in_cnt \
628 #define IPC_SYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
629 class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \
630 public: \
631 typedef IPC::SyncMessageSchema<IPC_TUPLE_IN_##in_cnt in_list, \
632 IPC_TUPLE_OUT_##out_cnt out_list> Schema; \
633 typedef Schema::ReplyParam ReplyParam; \
634 typedef Schema::SendParam SendParam; \
635 enum { ID = IPC_MESSAGE_ID() }; \
636 msg_class(IPC_TYPE_IN_##in_cnt in_list \
637 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
638 IPC_TYPE_OUT_##out_cnt out_list); \
639 ~msg_class() override; \
640 static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \
641 static bool ReadReplyParam( \
642 const Message* msg, \
643 base::TupleTypes<ReplyParam>::ValueTuple* p); \
644 static void Log(std::string* name, const Message* msg, std::string* l); \
645 IPC_SYNC_MESSAGE_METHODS_##out_cnt \
648 #define IPC_SYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
649 class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \
650 public: \
651 typedef IPC::SyncMessageSchema<IPC_TUPLE_IN_##in_cnt in_list, \
652 IPC_TUPLE_OUT_##out_cnt out_list> Schema; \
653 typedef Schema::ReplyParam ReplyParam; \
654 typedef Schema::SendParam SendParam; \
655 enum { ID = IPC_MESSAGE_ID() }; \
656 msg_class(int32_t routing_id \
657 IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \
658 IPC_TYPE_IN_##in_cnt in_list \
659 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
660 IPC_TYPE_OUT_##out_cnt out_list); \
661 ~msg_class() override; \
662 static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \
663 static bool ReadReplyParam( \
664 const Message* msg, \
665 base::TupleTypes<ReplyParam>::ValueTuple* p); \
666 static void Log(std::string* name, const Message* msg, std::string* l); \
667 IPC_SYNC_MESSAGE_METHODS_##out_cnt \
670 #if defined(IPC_MESSAGE_IMPL)
672 // "Implementation" inclusion produces constructors, destructors, and
673 // logging functions, except for the no-arg special cases, where the
674 // implementation occurs in the declaration, and there is no special
675 // logging function.
676 #define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
677 in_cnt, out_cnt, in_list, out_list) \
678 IPC_##sync##_##kind##_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
679 IPC_##sync##_MESSAGE_LOG(msg_class)
681 #define IPC_EMPTY_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)
682 #define IPC_EMPTY_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)
684 #define IPC_ASYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
685 msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list) : \
686 IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) { \
687 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
689 msg_class::~msg_class() {} \
690 bool msg_class::Read(const Message* msg, Schema::Param* p) { \
691 return Schema::Read(msg, p); \
694 #define IPC_ASYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
695 msg_class::msg_class(int32_t routing_id IPC_COMMA_##in_cnt \
696 IPC_TYPE_IN_##in_cnt in_list) : \
697 IPC::Message(routing_id, ID, PRIORITY_NORMAL) { \
698 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
700 msg_class::~msg_class() {} \
701 bool msg_class::Read(const Message* msg, Schema::Param* p) { \
702 return Schema::Read(msg, p); \
705 #define IPC_SYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
706 msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list \
707 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
708 IPC_TYPE_OUT_##out_cnt out_list) : \
709 IPC::SyncMessage(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL, \
710 new IPC::ParamDeserializer<Schema::ReplyParam>( \
711 IPC_NAME_OUT_##out_cnt out_list)) { \
712 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
714 msg_class::~msg_class() {} \
715 bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \
716 return Schema::ReadSendParam(msg, p); \
718 bool msg_class::ReadReplyParam( \
719 const Message* msg, \
720 base::TupleTypes<ReplyParam>::ValueTuple* p) { \
721 return Schema::ReadReplyParam(msg, p); \
724 #define IPC_SYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
725 msg_class::msg_class(int32_t routing_id \
726 IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \
727 IPC_TYPE_IN_##in_cnt in_list \
728 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
729 IPC_TYPE_OUT_##out_cnt out_list) : \
730 IPC::SyncMessage(routing_id, ID, PRIORITY_NORMAL, \
731 new IPC::ParamDeserializer<Schema::ReplyParam>( \
732 IPC_NAME_OUT_##out_cnt out_list)) { \
733 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
735 msg_class::~msg_class() {} \
736 bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \
737 return Schema::ReadSendParam(msg, p); \
739 bool msg_class::ReadReplyParam( \
740 const Message* msg, \
741 base::TupleTypes<ReplyParam>::ValueTuple* p) { \
742 return Schema::ReadReplyParam(msg, p); \
745 #define IPC_EMPTY_MESSAGE_LOG(msg_class) \
746 void msg_class::Log(std::string* name, \
747 const Message* msg, \
748 std::string* l) { \
749 if (name) \
750 *name = #msg_class; \
753 #define IPC_ASYNC_MESSAGE_LOG(msg_class) \
754 void msg_class::Log(std::string* name, \
755 const Message* msg, \
756 std::string* l) { \
757 if (name) \
758 *name = #msg_class; \
759 if (!msg || !l) \
760 return; \
761 Schema::Param p; \
762 if (Schema::Read(msg, &p)) \
763 IPC::LogParam(p, l); \
766 #define IPC_SYNC_MESSAGE_LOG(msg_class) \
767 void msg_class::Log(std::string* name, \
768 const Message* msg, \
769 std::string* l) { \
770 if (name) \
771 *name = #msg_class; \
772 if (!msg || !l) \
773 return; \
774 if (msg->is_sync()) { \
775 base::TupleTypes<Schema::SendParam>::ValueTuple p; \
776 if (Schema::ReadSendParam(msg, &p)) \
777 IPC::LogParam(p, l); \
778 AddOutputParamsToLog(msg, l); \
779 } else { \
780 base::TupleTypes<Schema::ReplyParam>::ValueTuple p; \
781 if (Schema::ReadReplyParam(msg, &p)) \
782 IPC::LogParam(p, l); \
786 #elif defined(IPC_MESSAGE_MACROS_LOG_ENABLED)
788 #ifndef IPC_LOG_TABLE_ADD_ENTRY
789 #error You need to define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger)
790 #endif
792 // "Log table" inclusion produces extra logging registration code.
793 #define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
794 in_cnt, out_cnt, in_list, out_list) \
795 class LoggerRegisterHelper##msg_class { \
796 public: \
797 LoggerRegisterHelper##msg_class() { \
798 const uint32_t msg_id = static_cast<uint32_t>(msg_class::ID); \
799 IPC_LOG_TABLE_ADD_ENTRY(msg_id, msg_class::Log); \
801 }; \
802 LoggerRegisterHelper##msg_class g_LoggerRegisterHelper##msg_class;
804 #else
806 // Normal inclusion produces nothing extra.
807 #define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
808 in_cnt, out_cnt, in_list, out_list)
810 #endif // defined(IPC_MESSAGE_IMPL)
812 // Handle variable sized argument lists. These are usually invoked by token
813 // pasting against the argument counts.
814 #define IPC_TYPE_IN_0()
815 #define IPC_TYPE_IN_1(t1) const t1& arg1
816 #define IPC_TYPE_IN_2(t1, t2) const t1& arg1, const t2& arg2
817 #define IPC_TYPE_IN_3(t1, t2, t3) const t1& arg1, const t2& arg2, const t3& arg3
818 #define IPC_TYPE_IN_4(t1, t2, t3, t4) const t1& arg1, const t2& arg2, const t3& arg3, const t4& arg4
819 #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
821 #define IPC_TYPE_OUT_0()
822 #define IPC_TYPE_OUT_1(t1) t1* arg6
823 #define IPC_TYPE_OUT_2(t1, t2) t1* arg6, t2* arg7
824 #define IPC_TYPE_OUT_3(t1, t2, t3) t1* arg6, t2* arg7, t3* arg8
825 #define IPC_TYPE_OUT_4(t1, t2, t3, t4) t1* arg6, t2* arg7, t3* arg8, \
826 t4* arg9
828 #define IPC_TUPLE_IN_0() base::Tuple<>
829 #define IPC_TUPLE_IN_1(t1) base::Tuple<t1>
830 #define IPC_TUPLE_IN_2(t1, t2) base::Tuple<t1, t2>
831 #define IPC_TUPLE_IN_3(t1, t2, t3) base::Tuple<t1, t2, t3>
832 #define IPC_TUPLE_IN_4(t1, t2, t3, t4) base::Tuple<t1, t2, t3, t4>
833 #define IPC_TUPLE_IN_5(t1, t2, t3, t4, t5) base::Tuple<t1, t2, t3, t4, t5>
835 #define IPC_TUPLE_OUT_0() base::Tuple<>
836 #define IPC_TUPLE_OUT_1(t1) base::Tuple<t1&>
837 #define IPC_TUPLE_OUT_2(t1, t2) base::Tuple<t1&, t2&>
838 #define IPC_TUPLE_OUT_3(t1, t2, t3) base::Tuple<t1&, t2&, t3&>
839 #define IPC_TUPLE_OUT_4(t1, t2, t3, t4) base::Tuple<t1&, t2&, t3&, t4&>
841 #define IPC_NAME_IN_0() base::MakeTuple()
842 #define IPC_NAME_IN_1(t1) base::MakeRefTuple(arg1)
843 #define IPC_NAME_IN_2(t1, t2) base::MakeRefTuple(arg1, arg2)
844 #define IPC_NAME_IN_3(t1, t2, t3) base::MakeRefTuple(arg1, arg2, arg3)
845 #define IPC_NAME_IN_4(t1, t2, t3, t4) base::MakeRefTuple(arg1, arg2, \
846 arg3, arg4)
847 #define IPC_NAME_IN_5(t1, t2, t3, t4, t5) base::MakeRefTuple(arg1, arg2, \
848 arg3, arg4, arg5)
850 #define IPC_NAME_OUT_0() base::MakeTuple()
851 #define IPC_NAME_OUT_1(t1) base::MakeRefTuple(*arg6)
852 #define IPC_NAME_OUT_2(t1, t2) base::MakeRefTuple(*arg6, *arg7)
853 #define IPC_NAME_OUT_3(t1, t2, t3) base::MakeRefTuple(*arg6, *arg7, \
854 *arg8)
855 #define IPC_NAME_OUT_4(t1, t2, t3, t4) base::MakeRefTuple(*arg6, *arg7, \
856 *arg8, *arg9)
858 // There are places where the syntax requires a comma if there are input args,
859 // if there are input args and output args, or if there are input args or
860 // output args. These macros allow generation of the comma as needed; invoke
861 // by token pasting against the argument counts.
862 #define IPC_COMMA_0
863 #define IPC_COMMA_1 ,
864 #define IPC_COMMA_2 ,
865 #define IPC_COMMA_3 ,
866 #define IPC_COMMA_4 ,
867 #define IPC_COMMA_5 ,
869 #define IPC_COMMA_AND_0(x)
870 #define IPC_COMMA_AND_1(x) x
871 #define IPC_COMMA_AND_2(x) x
872 #define IPC_COMMA_AND_3(x) x
873 #define IPC_COMMA_AND_4(x) x
874 #define IPC_COMMA_AND_5(x) x
876 #define IPC_COMMA_OR_0(x) x
877 #define IPC_COMMA_OR_1(x) ,
878 #define IPC_COMMA_OR_2(x) ,
879 #define IPC_COMMA_OR_3(x) ,
880 #define IPC_COMMA_OR_4(x) ,
881 #define IPC_COMMA_OR_5(x) ,
883 // Message IDs
884 // Note: we currently use __LINE__ to give unique IDs to messages within
885 // a file. They're globally unique since each file defines its own
886 // IPC_MESSAGE_START.
887 #define IPC_MESSAGE_ID() ((IPC_MESSAGE_START << 16) + __LINE__)
888 #define IPC_MESSAGE_ID_CLASS(id) ((id) >> 16)
889 #define IPC_MESSAGE_ID_LINE(id) ((id) & 0xffff)
891 // Message crackers and handlers. Usage:
893 // bool MyClass::OnMessageReceived(const IPC::Message& msg) {
894 // bool handled = true;
895 // IPC_BEGIN_MESSAGE_MAP(MyClass, msg)
896 // IPC_MESSAGE_HANDLER(MsgClassOne, OnMsgClassOne)
897 // ...more handlers here ...
898 // IPC_MESSAGE_HANDLER(MsgClassTen, OnMsgClassTen)
899 // IPC_MESSAGE_UNHANDLED(handled = false)
900 // IPC_END_MESSAGE_MAP()
901 // return handled;
902 // }
905 #define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \
907 typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED_TYPE; \
908 void* param__ = NULL; \
909 const IPC::Message& ipc_message__ = msg; \
910 switch (ipc_message__.type()) {
912 #define IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(class_name, msg, param) \
914 typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED_TYPE; \
915 decltype(param) param__ = param; \
916 const IPC::Message& ipc_message__ = msg; \
917 switch (ipc_message__.type()) {
919 #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \
920 case msg_class::ID: { \
921 TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \
922 if (!msg_class::Dispatch(&ipc_message__, obj, this, param__, \
923 &member_func)) \
924 ipc_message__.set_dispatch_error(); \
926 break;
928 #define IPC_MESSAGE_HANDLER(msg_class, member_func) \
929 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func)
931 #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \
932 case msg_class::ID: { \
933 TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \
934 if (!msg_class::DispatchDelayReply(&ipc_message__, obj, param__, \
935 &member_func)) \
936 ipc_message__.set_dispatch_error(); \
938 break;
940 #define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \
941 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \
942 _IpcMessageHandlerClass::member_func)
944 // TODO(jar): fix chrome frame to always supply |code| argument.
945 #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \
946 case msg_class::ID: { \
947 /* TRACK_RUN_IN_THIS_SCOPED_REGION(code); TODO(jar) */ \
948 code; \
950 break;
952 #define IPC_REPLY_HANDLER(func) \
953 case IPC_REPLY_ID: { \
954 TRACK_RUN_IN_THIS_SCOPED_REGION(func); \
955 func(ipc_message__); \
957 break;
960 #define IPC_MESSAGE_UNHANDLED(code) \
961 default: { \
962 code; \
964 break;
966 #define IPC_MESSAGE_UNHANDLED_ERROR() \
967 IPC_MESSAGE_UNHANDLED(NOTREACHED() << \
968 "Invalid message with type = " << \
969 ipc_message__.type())
971 #define IPC_END_MESSAGE_MAP() \
975 // This corresponds to an enum value from IPCMessageStart.
976 #define IPC_MESSAGE_CLASS(message) \
977 IPC_MESSAGE_ID_CLASS(message.type())
979 #endif // IPC_IPC_MESSAGE_MACROS_H_
981 // Clean up IPC_MESSAGE_START in this unguarded section so that the
982 // XXX_messages.h files need not do so themselves. This makes the
983 // XXX_messages.h files easier to write.
984 #undef IPC_MESSAGE_START