GN: Put .jar files in lib.java rather than gen/
[chromium-blink-merge.git] / ipc / ipc_message_macros.h
blob49382923ab618a8b57893af5d7376914c6cbe8af
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 "base/profiler/scoped_profile.h"
198 #include "ipc/ipc_message_utils.h"
199 #include "ipc/param_traits_macros.h"
201 #if defined(IPC_MESSAGE_IMPL)
202 #include "ipc/ipc_message_utils_impl.h"
203 #endif
205 // Convenience macro for defining structs without inheritance. Should not need
206 // to be subsequently redefined.
207 #define IPC_STRUCT_BEGIN(struct_name) \
208 IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, IPC::NoParams)
210 // Macros for defining structs. Will be subsequently redefined.
211 #define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \
212 struct struct_name; \
213 IPC_STRUCT_TRAITS_BEGIN(struct_name) \
214 IPC_STRUCT_TRAITS_END() \
215 struct IPC_MESSAGE_EXPORT struct_name : parent { \
216 struct_name(); \
217 ~struct_name();
218 // Optional variadic parameters specify the default value for this struct
219 // member. They are passed through to the constructor for |type|.
220 #define IPC_STRUCT_MEMBER(type, name, ...) type name;
221 #define IPC_STRUCT_END() };
223 // Message macros collect specific numbers of arguments and funnel them into
224 // the common message generation macro. These should never be redefined.
225 #define IPC_MESSAGE_CONTROL0(msg_class) \
226 IPC_MESSAGE_DECL(EMPTY, CONTROL, msg_class, 0, 0, (), ())
228 #define IPC_MESSAGE_CONTROL1(msg_class, type1) \
229 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 1, 0, (type1), ())
231 #define IPC_MESSAGE_CONTROL2(msg_class, type1, type2) \
232 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 2, 0, (type1, type2), ())
234 #define IPC_MESSAGE_CONTROL3(msg_class, type1, type2, type3) \
235 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 3, 0, (type1, type2, type3), ())
237 #define IPC_MESSAGE_CONTROL4(msg_class, type1, type2, type3, type4) \
238 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 4, 0, (type1, type2, type3, type4), ())
240 #define IPC_MESSAGE_CONTROL5(msg_class, type1, type2, type3, type4, type5) \
241 IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 5, 0, (type1, type2, type3, type4, type5), ())
243 #define IPC_MESSAGE_ROUTED0(msg_class) \
244 IPC_MESSAGE_DECL(EMPTY, ROUTED, msg_class, 0, 0, (), ())
246 #define IPC_MESSAGE_ROUTED1(msg_class, type1) \
247 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 1, 0, (type1), ())
249 #define IPC_MESSAGE_ROUTED2(msg_class, type1, type2) \
250 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 2, 0, (type1, type2), ())
252 #define IPC_MESSAGE_ROUTED3(msg_class, type1, type2, type3) \
253 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 3, 0, (type1, type2, type3), ())
255 #define IPC_MESSAGE_ROUTED4(msg_class, type1, type2, type3, type4) \
256 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 4, 0, (type1, type2, type3, type4), ())
258 #define IPC_MESSAGE_ROUTED5(msg_class, type1, type2, type3, type4, type5) \
259 IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 5, 0, (type1, type2, type3, type4, type5), ())
261 #define IPC_SYNC_MESSAGE_CONTROL0_0(msg_class) \
262 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 0, (), ())
264 #define IPC_SYNC_MESSAGE_CONTROL0_1(msg_class, type1_out) \
265 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 1, (), (type1_out))
267 #define IPC_SYNC_MESSAGE_CONTROL0_2(msg_class, type1_out, type2_out) \
268 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 2, (), (type1_out, type2_out))
270 #define IPC_SYNC_MESSAGE_CONTROL0_3(msg_class, type1_out, type2_out, type3_out) \
271 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 3, (), (type1_out, type2_out, type3_out))
273 #define IPC_SYNC_MESSAGE_CONTROL0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \
274 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out))
276 #define IPC_SYNC_MESSAGE_CONTROL1_0(msg_class, type1_in) \
277 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 0, (type1_in), ())
279 #define IPC_SYNC_MESSAGE_CONTROL1_1(msg_class, type1_in, type1_out) \
280 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 1, (type1_in), (type1_out))
282 #define IPC_SYNC_MESSAGE_CONTROL1_2(msg_class, type1_in, type1_out, type2_out) \
283 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 2, (type1_in), (type1_out, type2_out))
285 #define IPC_SYNC_MESSAGE_CONTROL1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \
286 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out))
288 #define IPC_SYNC_MESSAGE_CONTROL1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \
289 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out))
291 #define IPC_SYNC_MESSAGE_CONTROL2_0(msg_class, type1_in, type2_in) \
292 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 0, (type1_in, type2_in), ())
294 #define IPC_SYNC_MESSAGE_CONTROL2_1(msg_class, type1_in, type2_in, type1_out) \
295 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 1, (type1_in, type2_in), (type1_out))
297 #define IPC_SYNC_MESSAGE_CONTROL2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \
298 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out))
300 #define IPC_SYNC_MESSAGE_CONTROL2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \
301 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out))
303 #define IPC_SYNC_MESSAGE_CONTROL2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \
304 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out))
306 #define IPC_SYNC_MESSAGE_CONTROL3_0(msg_class, type1_in, type2_in, type3_in) \
307 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 0, (type1_in, type2_in, type3_in), ())
309 #define IPC_SYNC_MESSAGE_CONTROL3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \
310 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out))
312 #define IPC_SYNC_MESSAGE_CONTROL3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \
313 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out))
315 #define IPC_SYNC_MESSAGE_CONTROL3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \
316 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out))
318 #define IPC_SYNC_MESSAGE_CONTROL3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \
319 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out))
321 #define IPC_SYNC_MESSAGE_CONTROL4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \
322 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 0, (type1_in, type2_in, type3_in, type4_in), ())
324 #define IPC_SYNC_MESSAGE_CONTROL4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \
325 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out))
327 #define IPC_SYNC_MESSAGE_CONTROL4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \
328 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out))
330 #define IPC_SYNC_MESSAGE_CONTROL4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \
331 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out))
333 #define IPC_SYNC_MESSAGE_CONTROL4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \
334 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 4, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out, type4_out))
336 #define IPC_SYNC_MESSAGE_CONTROL5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \
337 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 0, (type1_in, type2_in, type3_in, type4_in, type5_in), ())
339 #define IPC_SYNC_MESSAGE_CONTROL5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \
340 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out))
342 #define IPC_SYNC_MESSAGE_CONTROL5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \
343 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out))
345 #define IPC_SYNC_MESSAGE_CONTROL5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \
346 IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 3, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out, type3_out))
348 #define IPC_SYNC_MESSAGE_ROUTED0_0(msg_class) \
349 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 0, (), ())
351 #define IPC_SYNC_MESSAGE_ROUTED0_1(msg_class, type1_out) \
352 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 1, (), (type1_out))
354 #define IPC_SYNC_MESSAGE_ROUTED0_2(msg_class, type1_out, type2_out) \
355 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 2, (), (type1_out, type2_out))
357 #define IPC_SYNC_MESSAGE_ROUTED0_3(msg_class, type1_out, type2_out, type3_out) \
358 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 3, (), (type1_out, type2_out, type3_out))
360 #define IPC_SYNC_MESSAGE_ROUTED0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \
361 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out))
363 #define IPC_SYNC_MESSAGE_ROUTED1_0(msg_class, type1_in) \
364 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 0, (type1_in), ())
366 #define IPC_SYNC_MESSAGE_ROUTED1_1(msg_class, type1_in, type1_out) \
367 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 1, (type1_in), (type1_out))
369 #define IPC_SYNC_MESSAGE_ROUTED1_2(msg_class, type1_in, type1_out, type2_out) \
370 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 2, (type1_in), (type1_out, type2_out))
372 #define IPC_SYNC_MESSAGE_ROUTED1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \
373 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out))
375 #define IPC_SYNC_MESSAGE_ROUTED1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \
376 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out))
378 #define IPC_SYNC_MESSAGE_ROUTED2_0(msg_class, type1_in, type2_in) \
379 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 0, (type1_in, type2_in), ())
381 #define IPC_SYNC_MESSAGE_ROUTED2_1(msg_class, type1_in, type2_in, type1_out) \
382 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 1, (type1_in, type2_in), (type1_out))
384 #define IPC_SYNC_MESSAGE_ROUTED2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \
385 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out))
387 #define IPC_SYNC_MESSAGE_ROUTED2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \
388 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out))
390 #define IPC_SYNC_MESSAGE_ROUTED2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \
391 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out))
393 #define IPC_SYNC_MESSAGE_ROUTED3_0(msg_class, type1_in, type2_in, type3_in) \
394 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 0, (type1_in, type2_in, type3_in), ())
396 #define IPC_SYNC_MESSAGE_ROUTED3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \
397 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out))
399 #define IPC_SYNC_MESSAGE_ROUTED3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \
400 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out))
402 #define IPC_SYNC_MESSAGE_ROUTED3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \
403 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out))
405 #define IPC_SYNC_MESSAGE_ROUTED3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \
406 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out))
408 #define IPC_SYNC_MESSAGE_ROUTED4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \
409 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 0, (type1_in, type2_in, type3_in, type4_in), ())
411 #define IPC_SYNC_MESSAGE_ROUTED4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \
412 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out))
414 #define IPC_SYNC_MESSAGE_ROUTED4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \
415 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out))
417 #define IPC_SYNC_MESSAGE_ROUTED4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \
418 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out))
420 #define IPC_SYNC_MESSAGE_ROUTED4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \
421 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 4, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out, type4_out))
423 #define IPC_SYNC_MESSAGE_ROUTED5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \
424 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 0, (type1_in, type2_in, type3_in, type4_in, type5_in), ())
426 #define IPC_SYNC_MESSAGE_ROUTED5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \
427 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out))
429 #define IPC_SYNC_MESSAGE_ROUTED5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \
430 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out))
432 #define IPC_SYNC_MESSAGE_ROUTED5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \
433 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 3, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out, type3_out))
435 // The following macros define the common set of methods provided by ASYNC
436 // message classes.
437 // This macro is for all the async IPCs that don't pass an extra parameter using
438 // IPC_BEGIN_MESSAGE_MAP_WITH_PARAM.
439 #define IPC_ASYNC_MESSAGE_METHODS_GENERIC \
440 template<class T, class S, class P, class Method> \
441 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
442 Method func) { \
443 Schema::Param p; \
444 if (Read(msg, &p)) { \
445 DispatchToMethod(obj, func, p); \
446 return true; \
448 return false; \
451 // The following macros are for for async IPCs which have a dispatcher with an
452 // extra parameter specified using IPC_BEGIN_MESSAGE_MAP_WITH_PARAM.
453 #define IPC_ASYNC_MESSAGE_METHODS_1 \
454 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
455 template<class T, class S, class P, typename TA> \
456 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
457 void (T::*func)(P*, TA)) { \
458 Schema::Param p; \
459 if (Read(msg, &p)) { \
460 (obj->*func)(parameter, base::get<0>(p)); \
461 return true; \
463 return false; \
465 #define IPC_ASYNC_MESSAGE_METHODS_2 \
466 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
467 template<class T, class S, class P, typename TA, typename TB> \
468 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
469 void (T::*func)(P*, TA, TB)) { \
470 Schema::Param p; \
471 if (Read(msg, &p)) { \
472 (obj->*func)(parameter, base::get<0>(p), base::get<1>(p)); \
473 return true; \
475 return false; \
477 #define IPC_ASYNC_MESSAGE_METHODS_3 \
478 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
479 template<class T, class S, class P, typename TA, typename TB, typename TC> \
480 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
481 void (T::*func)(P*, TA, TB, TC)) { \
482 Schema::Param p; \
483 if (Read(msg, &p)) { \
484 (obj->*func)(parameter, base::get<0>(p), base::get<1>(p), \
485 base::get<2>(p)); \
486 return true; \
488 return false; \
490 #define IPC_ASYNC_MESSAGE_METHODS_4 \
491 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
492 template<class T, class S, class P, typename TA, typename TB, typename TC, \
493 typename TD> \
494 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
495 void (T::*func)(P*, TA, TB, TC, TD)) { \
496 Schema::Param p; \
497 if (Read(msg, &p)) { \
498 (obj->*func)(parameter, base::get<0>(p), base::get<1>(p), \
499 base::get<2>(p), base::get<3>(p)); \
500 return true; \
502 return false; \
504 #define IPC_ASYNC_MESSAGE_METHODS_5 \
505 IPC_ASYNC_MESSAGE_METHODS_GENERIC \
506 template<class T, class S, class P, typename TA, typename TB, typename TC, \
507 typename TD, typename TE> \
508 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
509 void (T::*func)(P*, TA, TB, TC, TD, TE)) { \
510 Schema::Param p; \
511 if (Read(msg, &p)) { \
512 (obj->*func)(parameter, base::get<0>(p), base::get<1>(p), \
513 base::get<2>(p), base::get<3>(p), base::get<4>(p)); \
514 return true; \
516 return false; \
519 // The following macros define the common set of methods provided by SYNC
520 // message classes.
521 #define IPC_SYNC_MESSAGE_METHODS_GENERIC \
522 template<class T, class S, class P, class Method> \
523 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \
524 Method func) { \
525 Schema::SendParam send_params; \
526 bool ok = ReadSendParam(msg, &send_params); \
527 return Schema::DispatchWithSendParams(ok, send_params, msg, obj, sender, \
528 func); \
530 template<class T, class P, class Method> \
531 static bool DispatchDelayReply(const Message* msg, T* obj, P* parameter, \
532 Method func) { \
533 Schema::SendParam send_params; \
534 bool ok = ReadSendParam(msg, &send_params); \
535 return Schema::DispatchDelayReplyWithSendParams(ok, send_params, msg, \
536 obj, func); \
538 #define IPC_SYNC_MESSAGE_METHODS_0 \
539 IPC_SYNC_MESSAGE_METHODS_GENERIC
540 #define IPC_SYNC_MESSAGE_METHODS_1 \
541 IPC_SYNC_MESSAGE_METHODS_GENERIC \
542 template<typename TA> \
543 static void WriteReplyParams(Message* reply, TA a) { \
544 Schema::WriteReplyParams(reply, a); \
546 #define IPC_SYNC_MESSAGE_METHODS_2 \
547 IPC_SYNC_MESSAGE_METHODS_GENERIC \
548 template<typename TA, typename TB> \
549 static void WriteReplyParams(Message* reply, TA a, TB b) { \
550 Schema::WriteReplyParams(reply, a, b); \
552 #define IPC_SYNC_MESSAGE_METHODS_3 \
553 IPC_SYNC_MESSAGE_METHODS_GENERIC \
554 template<typename TA, typename TB, typename TC> \
555 static void WriteReplyParams(Message* reply, TA a, TB b, TC c) { \
556 Schema::WriteReplyParams(reply, a, b, c); \
558 #define IPC_SYNC_MESSAGE_METHODS_4 \
559 IPC_SYNC_MESSAGE_METHODS_GENERIC \
560 template<typename TA, typename TB, typename TC, typename TD> \
561 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d) { \
562 Schema::WriteReplyParams(reply, a, b, c, d); \
564 #define IPC_SYNC_MESSAGE_METHODS_5 \
565 IPC_SYNC_MESSAGE_METHODS_GENERIC \
566 template<typename TA, typename TB, typename TC, typename TD, typename TE> \
567 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d, TE e) { \
568 Schema::WriteReplyParams(reply, a, b, c, d, e); \
571 // Common message macro which dispatches into one of the 6 (sync x kind)
572 // routines. There is a way that these 6 cases can be lumped together,
573 // but the macros get very complicated in that case.
574 // Note: intended be redefined to generate other information.
575 #define IPC_MESSAGE_DECL(sync, kind, msg_class, \
576 in_cnt, out_cnt, in_list, out_list) \
577 IPC_##sync##_##kind##_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
578 IPC_MESSAGE_EXTRA(sync, kind, msg_class, in_cnt, out_cnt, in_list, out_list)
580 #define IPC_EMPTY_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
581 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
582 public: \
583 typedef IPC::Message Schema; \
584 enum { ID = IPC_MESSAGE_ID() }; \
585 msg_class() : IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) {} \
586 static void Log(std::string* name, const Message* msg, std::string* l); \
589 #define IPC_EMPTY_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
590 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
591 public: \
592 typedef IPC::Message Schema; \
593 enum { ID = IPC_MESSAGE_ID() }; \
594 msg_class(int32 routing_id) \
595 : IPC::Message(routing_id, ID, PRIORITY_NORMAL) {} \
596 static void Log(std::string* name, const Message* msg, std::string* l); \
599 #define IPC_ASYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
600 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
601 public: \
602 typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \
603 typedef Schema::Param Param; \
604 enum { ID = IPC_MESSAGE_ID() }; \
605 msg_class(IPC_TYPE_IN_##in_cnt in_list); \
606 ~msg_class() override; \
607 static bool Read(const Message* msg, Schema::Param* p); \
608 static void Log(std::string* name, const Message* msg, std::string* l); \
609 IPC_ASYNC_MESSAGE_METHODS_##in_cnt \
612 #define IPC_ASYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
613 class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \
614 public: \
615 typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \
616 typedef Schema::Param Param; \
617 enum { ID = IPC_MESSAGE_ID() }; \
618 msg_class(int32 routing_id IPC_COMMA_##in_cnt \
619 IPC_TYPE_IN_##in_cnt in_list); \
620 ~msg_class() override; \
621 static bool Read(const Message* msg, Schema::Param* p); \
622 static void Log(std::string* name, const Message* msg, std::string* l); \
623 IPC_ASYNC_MESSAGE_METHODS_##in_cnt \
626 #define IPC_SYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
627 class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \
628 public: \
629 typedef IPC::SyncMessageSchema<IPC_TUPLE_IN_##in_cnt in_list, \
630 IPC_TUPLE_OUT_##out_cnt out_list> Schema; \
631 typedef Schema::ReplyParam ReplyParam; \
632 typedef Schema::SendParam SendParam; \
633 enum { ID = IPC_MESSAGE_ID() }; \
634 msg_class(IPC_TYPE_IN_##in_cnt in_list \
635 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
636 IPC_TYPE_OUT_##out_cnt out_list); \
637 ~msg_class() override; \
638 static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \
639 static bool ReadReplyParam( \
640 const Message* msg, \
641 base::TupleTypes<ReplyParam>::ValueTuple* p); \
642 static void Log(std::string* name, const Message* msg, std::string* l); \
643 IPC_SYNC_MESSAGE_METHODS_##out_cnt \
646 #define IPC_SYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
647 class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \
648 public: \
649 typedef IPC::SyncMessageSchema<IPC_TUPLE_IN_##in_cnt in_list, \
650 IPC_TUPLE_OUT_##out_cnt out_list> Schema; \
651 typedef Schema::ReplyParam ReplyParam; \
652 typedef Schema::SendParam SendParam; \
653 enum { ID = IPC_MESSAGE_ID() }; \
654 msg_class(int32 routing_id \
655 IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \
656 IPC_TYPE_IN_##in_cnt in_list \
657 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
658 IPC_TYPE_OUT_##out_cnt out_list); \
659 ~msg_class() override; \
660 static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \
661 static bool ReadReplyParam( \
662 const Message* msg, \
663 base::TupleTypes<ReplyParam>::ValueTuple* p); \
664 static void Log(std::string* name, const Message* msg, std::string* l); \
665 IPC_SYNC_MESSAGE_METHODS_##out_cnt \
668 #if defined(IPC_MESSAGE_IMPL)
670 // "Implementation" inclusion produces constructors, destructors, and
671 // logging functions, except for the no-arg special cases, where the
672 // implementation occurs in the declaration, and there is no special
673 // logging function.
674 #define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
675 in_cnt, out_cnt, in_list, out_list) \
676 IPC_##sync##_##kind##_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
677 IPC_##sync##_MESSAGE_LOG(msg_class)
679 #define IPC_EMPTY_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)
680 #define IPC_EMPTY_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)
682 #define IPC_ASYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
683 msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list) : \
684 IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) { \
685 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
687 msg_class::~msg_class() {} \
688 bool msg_class::Read(const Message* msg, Schema::Param* p) { \
689 return Schema::Read(msg, p); \
692 #define IPC_ASYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
693 msg_class::msg_class(int32 routing_id IPC_COMMA_##in_cnt \
694 IPC_TYPE_IN_##in_cnt in_list) : \
695 IPC::Message(routing_id, ID, PRIORITY_NORMAL) { \
696 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
698 msg_class::~msg_class() {} \
699 bool msg_class::Read(const Message* msg, Schema::Param* p) { \
700 return Schema::Read(msg, p); \
703 #define IPC_SYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
704 msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list \
705 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
706 IPC_TYPE_OUT_##out_cnt out_list) : \
707 IPC::SyncMessage(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL, \
708 new IPC::ParamDeserializer<Schema::ReplyParam>( \
709 IPC_NAME_OUT_##out_cnt out_list)) { \
710 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
712 msg_class::~msg_class() {} \
713 bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \
714 return Schema::ReadSendParam(msg, p); \
716 bool msg_class::ReadReplyParam( \
717 const Message* msg, \
718 base::TupleTypes<ReplyParam>::ValueTuple* p) { \
719 return Schema::ReadReplyParam(msg, p); \
722 #define IPC_SYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
723 msg_class::msg_class(int32 routing_id \
724 IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \
725 IPC_TYPE_IN_##in_cnt in_list \
726 IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \
727 IPC_TYPE_OUT_##out_cnt out_list) : \
728 IPC::SyncMessage(routing_id, ID, PRIORITY_NORMAL, \
729 new IPC::ParamDeserializer<Schema::ReplyParam>( \
730 IPC_NAME_OUT_##out_cnt out_list)) { \
731 Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \
733 msg_class::~msg_class() {} \
734 bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \
735 return Schema::ReadSendParam(msg, p); \
737 bool msg_class::ReadReplyParam( \
738 const Message* msg, \
739 base::TupleTypes<ReplyParam>::ValueTuple* p) { \
740 return Schema::ReadReplyParam(msg, p); \
743 #define IPC_EMPTY_MESSAGE_LOG(msg_class) \
744 void msg_class::Log(std::string* name, \
745 const Message* msg, \
746 std::string* l) { \
747 if (name) \
748 *name = #msg_class; \
751 #define IPC_ASYNC_MESSAGE_LOG(msg_class) \
752 void msg_class::Log(std::string* name, \
753 const Message* msg, \
754 std::string* l) { \
755 if (name) \
756 *name = #msg_class; \
757 if (!msg || !l) \
758 return; \
759 Schema::Param p; \
760 if (Schema::Read(msg, &p)) \
761 IPC::LogParam(p, l); \
764 #define IPC_SYNC_MESSAGE_LOG(msg_class) \
765 void msg_class::Log(std::string* name, \
766 const Message* msg, \
767 std::string* l) { \
768 if (name) \
769 *name = #msg_class; \
770 if (!msg || !l) \
771 return; \
772 if (msg->is_sync()) { \
773 base::TupleTypes<Schema::SendParam>::ValueTuple p; \
774 if (Schema::ReadSendParam(msg, &p)) \
775 IPC::LogParam(p, l); \
776 AddOutputParamsToLog(msg, l); \
777 } else { \
778 base::TupleTypes<Schema::ReplyParam>::ValueTuple p; \
779 if (Schema::ReadReplyParam(msg, &p)) \
780 IPC::LogParam(p, l); \
784 #elif defined(IPC_MESSAGE_MACROS_LOG_ENABLED)
786 #ifndef IPC_LOG_TABLE_ADD_ENTRY
787 #error You need to define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger)
788 #endif
790 // "Log table" inclusion produces extra logging registration code.
791 #define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
792 in_cnt, out_cnt, in_list, out_list) \
793 class LoggerRegisterHelper##msg_class { \
794 public: \
795 LoggerRegisterHelper##msg_class() { \
796 const uint32 msg_id = static_cast<uint32>(msg_class::ID); \
797 IPC_LOG_TABLE_ADD_ENTRY(msg_id, msg_class::Log); \
799 }; \
800 LoggerRegisterHelper##msg_class g_LoggerRegisterHelper##msg_class;
802 #else
804 // Normal inclusion produces nothing extra.
805 #define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \
806 in_cnt, out_cnt, in_list, out_list)
808 #endif // defined(IPC_MESSAGE_IMPL)
810 // Handle variable sized argument lists. These are usually invoked by token
811 // pasting against the argument counts.
812 #define IPC_TYPE_IN_0()
813 #define IPC_TYPE_IN_1(t1) const t1& arg1
814 #define IPC_TYPE_IN_2(t1, t2) const t1& arg1, const t2& arg2
815 #define IPC_TYPE_IN_3(t1, t2, t3) const t1& arg1, const t2& arg2, const t3& arg3
816 #define IPC_TYPE_IN_4(t1, t2, t3, t4) const t1& arg1, const t2& arg2, const t3& arg3, const t4& arg4
817 #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
819 #define IPC_TYPE_OUT_0()
820 #define IPC_TYPE_OUT_1(t1) t1* arg6
821 #define IPC_TYPE_OUT_2(t1, t2) t1* arg6, t2* arg7
822 #define IPC_TYPE_OUT_3(t1, t2, t3) t1* arg6, t2* arg7, t3* arg8
823 #define IPC_TYPE_OUT_4(t1, t2, t3, t4) t1* arg6, t2* arg7, t3* arg8, \
824 t4* arg9
826 #define IPC_TUPLE_IN_0() base::Tuple<>
827 #define IPC_TUPLE_IN_1(t1) base::Tuple<t1>
828 #define IPC_TUPLE_IN_2(t1, t2) base::Tuple<t1, t2>
829 #define IPC_TUPLE_IN_3(t1, t2, t3) base::Tuple<t1, t2, t3>
830 #define IPC_TUPLE_IN_4(t1, t2, t3, t4) base::Tuple<t1, t2, t3, t4>
831 #define IPC_TUPLE_IN_5(t1, t2, t3, t4, t5) base::Tuple<t1, t2, t3, t4, t5>
833 #define IPC_TUPLE_OUT_0() base::Tuple<>
834 #define IPC_TUPLE_OUT_1(t1) base::Tuple<t1&>
835 #define IPC_TUPLE_OUT_2(t1, t2) base::Tuple<t1&, t2&>
836 #define IPC_TUPLE_OUT_3(t1, t2, t3) base::Tuple<t1&, t2&, t3&>
837 #define IPC_TUPLE_OUT_4(t1, t2, t3, t4) base::Tuple<t1&, t2&, t3&, t4&>
839 #define IPC_NAME_IN_0() base::MakeTuple()
840 #define IPC_NAME_IN_1(t1) base::MakeRefTuple(arg1)
841 #define IPC_NAME_IN_2(t1, t2) base::MakeRefTuple(arg1, arg2)
842 #define IPC_NAME_IN_3(t1, t2, t3) base::MakeRefTuple(arg1, arg2, arg3)
843 #define IPC_NAME_IN_4(t1, t2, t3, t4) base::MakeRefTuple(arg1, arg2, \
844 arg3, arg4)
845 #define IPC_NAME_IN_5(t1, t2, t3, t4, t5) base::MakeRefTuple(arg1, arg2, \
846 arg3, arg4, arg5)
848 #define IPC_NAME_OUT_0() base::MakeTuple()
849 #define IPC_NAME_OUT_1(t1) base::MakeRefTuple(*arg6)
850 #define IPC_NAME_OUT_2(t1, t2) base::MakeRefTuple(*arg6, *arg7)
851 #define IPC_NAME_OUT_3(t1, t2, t3) base::MakeRefTuple(*arg6, *arg7, \
852 *arg8)
853 #define IPC_NAME_OUT_4(t1, t2, t3, t4) base::MakeRefTuple(*arg6, *arg7, \
854 *arg8, *arg9)
856 // There are places where the syntax requires a comma if there are input args,
857 // if there are input args and output args, or if there are input args or
858 // output args. These macros allow generation of the comma as needed; invoke
859 // by token pasting against the argument counts.
860 #define IPC_COMMA_0
861 #define IPC_COMMA_1 ,
862 #define IPC_COMMA_2 ,
863 #define IPC_COMMA_3 ,
864 #define IPC_COMMA_4 ,
865 #define IPC_COMMA_5 ,
867 #define IPC_COMMA_AND_0(x)
868 #define IPC_COMMA_AND_1(x) x
869 #define IPC_COMMA_AND_2(x) x
870 #define IPC_COMMA_AND_3(x) x
871 #define IPC_COMMA_AND_4(x) x
872 #define IPC_COMMA_AND_5(x) x
874 #define IPC_COMMA_OR_0(x) x
875 #define IPC_COMMA_OR_1(x) ,
876 #define IPC_COMMA_OR_2(x) ,
877 #define IPC_COMMA_OR_3(x) ,
878 #define IPC_COMMA_OR_4(x) ,
879 #define IPC_COMMA_OR_5(x) ,
881 // Message IDs
882 // Note: we currently use __LINE__ to give unique IDs to messages within
883 // a file. They're globally unique since each file defines its own
884 // IPC_MESSAGE_START.
885 #define IPC_MESSAGE_ID() ((IPC_MESSAGE_START << 16) + __LINE__)
886 #define IPC_MESSAGE_ID_CLASS(id) ((id) >> 16)
887 #define IPC_MESSAGE_ID_LINE(id) ((id) & 0xffff)
889 // Message crackers and handlers. Usage:
891 // bool MyClass::OnMessageReceived(const IPC::Message& msg) {
892 // bool handled = true;
893 // IPC_BEGIN_MESSAGE_MAP(MyClass, msg)
894 // IPC_MESSAGE_HANDLER(MsgClassOne, OnMsgClassOne)
895 // ...more handlers here ...
896 // IPC_MESSAGE_HANDLER(MsgClassTen, OnMsgClassTen)
897 // IPC_MESSAGE_UNHANDLED(handled = false)
898 // IPC_END_MESSAGE_MAP()
899 // return handled;
900 // }
903 #define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \
905 typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED_TYPE; \
906 void* param__ = NULL; \
907 const IPC::Message& ipc_message__ = msg; \
908 switch (ipc_message__.type()) {
910 #define IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(class_name, msg, param) \
912 typedef class_name _IpcMessageHandlerClass ALLOW_UNUSED_TYPE; \
913 decltype(param) param__ = param; \
914 const IPC::Message& ipc_message__ = msg; \
915 switch (ipc_message__.type()) {
917 #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \
918 case msg_class::ID: { \
919 TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \
920 if (!msg_class::Dispatch(&ipc_message__, obj, this, param__, \
921 &member_func)) \
922 ipc_message__.set_dispatch_error(); \
924 break;
926 #define IPC_MESSAGE_HANDLER(msg_class, member_func) \
927 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func)
929 #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \
930 case msg_class::ID: { \
931 TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \
932 if (!msg_class::DispatchDelayReply(&ipc_message__, obj, param__, \
933 &member_func)) \
934 ipc_message__.set_dispatch_error(); \
936 break;
938 #define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \
939 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \
940 _IpcMessageHandlerClass::member_func)
942 // TODO(jar): fix chrome frame to always supply |code| argument.
943 #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \
944 case msg_class::ID: { \
945 /* TRACK_RUN_IN_THIS_SCOPED_REGION(code); TODO(jar) */ \
946 code; \
948 break;
950 #define IPC_REPLY_HANDLER(func) \
951 case IPC_REPLY_ID: { \
952 TRACK_RUN_IN_THIS_SCOPED_REGION(func); \
953 func(ipc_message__); \
955 break;
958 #define IPC_MESSAGE_UNHANDLED(code) \
959 default: { \
960 code; \
962 break;
964 #define IPC_MESSAGE_UNHANDLED_ERROR() \
965 IPC_MESSAGE_UNHANDLED(NOTREACHED() << \
966 "Invalid message with type = " << \
967 ipc_message__.type())
969 #define IPC_END_MESSAGE_MAP() \
973 // This corresponds to an enum value from IPCMessageStart.
974 #define IPC_MESSAGE_CLASS(message) \
975 IPC_MESSAGE_ID_CLASS(message.type())
977 #endif // IPC_IPC_MESSAGE_MACROS_H_
979 // Clean up IPC_MESSAGE_START in this unguarded section so that the
980 // XXX_messages.h files need not do so themselves. This makes the
981 // XXX_messages.h files easier to write.
982 #undef IPC_MESSAGE_START