Fix a build error
[platform/upstream/chromium.git] / ipc / ipc_message_macros.h
1 // Copyright (c) 2011 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.
4
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 // implemation file as well.
12 //
13 // The senders of your messages will include your XXX_messages.h file to
14 // get the full set of definitions they need to send your messages.
15 //
16 // Each XXX_messages.h file must be registered with the IPC system.  This
17 // requires adding two things:
18 //   - An XXXMsgStart value to the IPCMessageStart enum in ipc_message_utils.h
19 //   - An inclusion of XXX_messages.h file in a message generator .h file
20 //
21 // The XXXMsgStart value is an enumeration that ensures uniqueness for
22 // each different message file.  Later, you will use this inside your
23 // XXX_messages.h file before invoking message declatation macros:
24 //     #define IPC_MESSAGE_START XXXMsgStart
25 //       ( ... your macro invocations go here ... )
26 //
27 // Message Generator Files
28 //
29 // A message generator .h header file pulls in all other message-declaring
30 // headers for a given component.  It is included by a message generator
31 // .cc file, which is where all the generated code will wind up.  Typically,
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.
35 //
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"
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
63 //
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 ...)
69 //
70 // Multiple Inclusion
71 //
72 // The XXX_messages.h file will be multiply-included by the
73 // YYY_message_generator.cc file, so your XXX_messages file can't be
74 // guarded in the usual manner.  Ideally, there will be no need for any
75 // inclusion guard, since the XXX_messages.h file should consist soley
76 // of inclusions of other headers (which are self-guarding) and IPC
77 // macros (which are multiply evaluating).
78 //
79 // Note that there is no #pragma once either; doing so would mark the whole
80 // file as being singly-included.  Since your XXX_messages.h file is only
81 // partially-guarded, care must be taken to ensure that it is only included
82 // by other .cc files (and the YYY_message_generator.h file).  Including an
83 // XXX_messages.h file in some other .h file may result in duplicate
84 // declarations and a compilation failure.
85 //
86 // Type Declarations
87 //
88 // It is generally a bad idea to have type definitions in a XXX_messages.h
89 // file; most likely the typedef will then be used in the message, as opposed
90 // to the struct iself.  Later, an IPC message dispatcher wil need to call
91 // a function taking that type, and that function is declared in some other
92 // header.  Thus, in order to get the type definition, the other header
93 // would have to include the XXX_messages.h file, violating the rule above
94 // about not including XXX_messages.h file in other .h files.
95 //
96 // One approach here is to move these type definitions to another (guarded)
97 // .h file and include this second .h in your XXX_messages.h file.  This
98 // is still less than ideal, because the dispatched function would have to
99 // redeclare the typedef or include this second header.  This may be
100 // reasonable in a few cases.
101 //
102 // Failing all of the above, then you will want to bracket the smallest
103 // possible section of your XXX_messages.h file containing these types
104 // with an include guard macro.  Be aware that providing an incomplete
105 // class type declaration to avoid pulling in a long chain of headers is
106 // acceptable when your XXX_messages.h header is being included by the
107 // message sending caller's code, but not when the YYY_message_generator.c
108 // is building the messages. In addtion, due to the multiple inclusion
109 // restriction, these type ought to be guarded.  Follow a convention like:
110 //      #ifndef SOME_GUARD_MACRO
111 //      #define SOME_GUARD_MACRO
112 //      class some_class;        // One incomplete class declaration
113 //      class_some_other_class;  // Another incomplete class declaration
114 //      #endif  // SOME_GUARD_MACRO
115 //      #ifdef IPC_MESSAGE_IMPL
116 //      #inlcude "path/to/some_class.h"        // Full class declaration
117 //      #inlcude "path/to/some_other_class.h"  // Full class declaration
118 //      #endif  // IPC_MESSAGE_IMPL
119 //        (.. IPC macros using some_class and some_other_class ...)
120 //
121 // Macro Invocations
122 //
123 // You will use IPC message macro invocations for three things:
124 //   - New struct definitions for IPC
125 //   - Registering existing struct and enum definitions with IPC
126 //   - Defining the messages themselves
127 //
128 // New structs are defined with IPC_STRUCT_BEGIN(), IPC_STRUCT_MEMBER(),
129 // IPC_STRUCT_END() family of macros.  These cause the XXX_messages.h
130 // to proclaim equivalent struct declarations for use by callers, as well
131 // as later registering the type with the message generation.  Note that
132 // IPC_STRUCT_MEMBER() is only permitted inside matching calls to
133 // IPC_STRUCT_BEGIN() / IPC_STRUCT_END().
134 //
135 // Externally-defined structs are registered with IPC_STRUCT_TRAITS_BEGIN(),
136 // IPC_STRUCT_TRAITS_MEMBER(), and IPC_STRUCT_TRAITS_END() macros. These
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().
143 //
144 // Enum types are registered with a single IPC_ENUM_TRAITS() macro.  There
145 // is no need to enumerate each value to the IPC mechanism.
146 //
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
149 // C++ statements.
150 //
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.  Input parameters are first (const TYPE&), and
154 // To declare a sync message, use the IPC_SYNC_ macros.  The numbers at the
155 // end show how many input/output parameters there are (i.e. 1_2 is 1 in, 2
156 // out). The caller does a Send([route id, ], in1, &out1, &out2).
157 // The receiver's handler function will be
158 //     void OnSyncMessageName(const type1& in1, type2* out1, type3* out2)
159 //
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.
164 //
165 // Use the IPC_MESSAGE_HANDLER_DELAY_REPLY macro instead of IPC_MESSAGE_HANDLER
166 //     IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncMessageName,
167 //                                     OnSyncMessageName)
168 //
169 // The handler function will look like:
170 //     void OnSyncMessageName(const type1& in1, IPC::Message* reply_msg);
171 //
172 // Receiver stashes the IPC::Message* pointer, and when it's ready, it does:
173 //     ViewHostMsg_SyncMessageName::WriteReplyParams(reply_msg, out1, out2);
174 //     Send(reply_msg);
175
176 #ifndef IPC_IPC_MESSAGE_MACROS_H_
177 #define IPC_IPC_MESSAGE_MACROS_H_
178
179 #include "ipc/ipc_message_utils.h"
180 #include "ipc/param_traits_macros.h"
181
182 #if defined(IPC_MESSAGE_IMPL)
183 #include "ipc/ipc_message_utils_impl.h"
184 #endif
185
186 // Macros for defining structs.  May be subsequently redefined.
187 #define IPC_STRUCT_BEGIN(struct_name) \
188   struct struct_name; \
189   IPC_STRUCT_TRAITS_BEGIN(struct_name) \
190   IPC_STRUCT_TRAITS_END() \
191   struct struct_name : IPC::NoParams { \
192     struct_name(); \
193     ~struct_name();
194 #define IPC_STRUCT_MEMBER(type, name) type name;
195 #define IPC_STRUCT_END() };
196
197 // Message macros collect specific numbers of arguments and funnel them into
198 // the common message generation macro.  These should never be redefined.
199 #define IPC_MESSAGE_CONTROL0(msg_class) \
200   IPC_MESSAGE_DECL(EMPTY, CONTROL, msg_class, 0, 0, (), ())
201
202 #define IPC_MESSAGE_CONTROL1(msg_class, type1) \
203   IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 1, 0, (type1), ())
204
205 #define IPC_MESSAGE_CONTROL2(msg_class, type1, type2) \
206   IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 2, 0, (type1, type2), ())
207
208 #define IPC_MESSAGE_CONTROL3(msg_class, type1, type2, type3) \
209   IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 3, 0, (type1, type2, type3), ())
210
211 #define IPC_MESSAGE_CONTROL4(msg_class, type1, type2, type3, type4) \
212   IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 4, 0, (type1, type2, type3, type4), ())
213
214 #define IPC_MESSAGE_CONTROL5(msg_class, type1, type2, type3, type4, type5) \
215   IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 5, 0, (type1, type2, type3, type4, type5), ())
216
217 #define IPC_MESSAGE_CONTROL6(msg_class, type1, type2, type3, type4, type5, type6) \
218         IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 6, 0, (type1, type2, type3, type4, type5, type6), ())
219
220
221 #define IPC_MESSAGE_ROUTED0(msg_class) \
222   IPC_MESSAGE_DECL(EMPTY, ROUTED, msg_class, 0, 0, (), ())
223
224 #define IPC_MESSAGE_ROUTED1(msg_class, type1) \
225   IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 1, 0, (type1), ())
226
227 #define IPC_MESSAGE_ROUTED2(msg_class, type1, type2) \
228   IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 2, 0, (type1, type2), ())
229
230 #define IPC_MESSAGE_ROUTED3(msg_class, type1, type2, type3) \
231   IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 3, 0, (type1, type2, type3), ())
232
233 #define IPC_MESSAGE_ROUTED4(msg_class, type1, type2, type3, type4) \
234   IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 4, 0, (type1, type2, type3, type4), ())
235
236 #define IPC_MESSAGE_ROUTED5(msg_class, type1, type2, type3, type4, type5) \
237   IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 5, 0, (type1, type2, type3, type4, type5), ())
238
239 #define IPC_MESSAGE_ROUTED6(msg_class, type1, type2, type3, type4, type5, type6) \
240         IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 6, 0, (type1, type2, type3, type4, type5, type6), ())
241
242 #define IPC_SYNC_MESSAGE_CONTROL0_0(msg_class) \
243   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 0, (), ())
244
245 #define IPC_SYNC_MESSAGE_CONTROL0_1(msg_class, type1_out) \
246   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 1, (), (type1_out))
247
248 #define IPC_SYNC_MESSAGE_CONTROL0_2(msg_class, type1_out, type2_out) \
249   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 2, (), (type1_out, type2_out))
250
251 #define IPC_SYNC_MESSAGE_CONTROL0_3(msg_class, type1_out, type2_out, type3_out) \
252   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 3, (), (type1_out, type2_out, type3_out))
253
254 #define IPC_SYNC_MESSAGE_CONTROL0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \
255   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out))
256
257 #define IPC_SYNC_MESSAGE_CONTROL1_0(msg_class, type1_in) \
258   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 0, (type1_in), ())
259
260 #define IPC_SYNC_MESSAGE_CONTROL1_1(msg_class, type1_in, type1_out) \
261   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 1, (type1_in), (type1_out))
262
263 #define IPC_SYNC_MESSAGE_CONTROL1_2(msg_class, type1_in, type1_out, type2_out) \
264   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 2, (type1_in), (type1_out, type2_out))
265
266 #define IPC_SYNC_MESSAGE_CONTROL1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \
267   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out))
268
269 #define IPC_SYNC_MESSAGE_CONTROL1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \
270   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out))
271
272 #define IPC_SYNC_MESSAGE_CONTROL2_0(msg_class, type1_in, type2_in) \
273   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 0, (type1_in, type2_in), ())
274
275 #define IPC_SYNC_MESSAGE_CONTROL2_1(msg_class, type1_in, type2_in, type1_out) \
276   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 1, (type1_in, type2_in), (type1_out))
277
278 #define IPC_SYNC_MESSAGE_CONTROL2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \
279   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out))
280
281 #define IPC_SYNC_MESSAGE_CONTROL2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \
282   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out))
283
284 #define IPC_SYNC_MESSAGE_CONTROL2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \
285   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out))
286
287 #define IPC_SYNC_MESSAGE_CONTROL3_0(msg_class, type1_in, type2_in, type3_in) \
288   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 0, (type1_in, type2_in, type3_in), ())
289
290 #define IPC_SYNC_MESSAGE_CONTROL3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \
291   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out))
292
293 #define IPC_SYNC_MESSAGE_CONTROL3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \
294   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out))
295
296 #define IPC_SYNC_MESSAGE_CONTROL3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \
297   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out))
298
299 #define IPC_SYNC_MESSAGE_CONTROL3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \
300   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out))
301
302 #define IPC_SYNC_MESSAGE_CONTROL4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \
303   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 0, (type1_in, type2_in, type3_in, type4_in), ())
304
305 #define IPC_SYNC_MESSAGE_CONTROL4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \
306   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out))
307
308 #define IPC_SYNC_MESSAGE_CONTROL4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \
309   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out))
310
311 #define IPC_SYNC_MESSAGE_CONTROL4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \
312   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out))
313
314 #define IPC_SYNC_MESSAGE_CONTROL4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \
315   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))
316
317 #define IPC_SYNC_MESSAGE_CONTROL5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \
318   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 0, (type1_in, type2_in, type3_in, type4_in, type5_in), ())
319
320 #define IPC_SYNC_MESSAGE_CONTROL5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \
321   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out))
322
323 #define IPC_SYNC_MESSAGE_CONTROL5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \
324   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out))
325
326 #define IPC_SYNC_MESSAGE_CONTROL5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \
327   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))
328
329 #define IPC_SYNC_MESSAGE_CONTROL5_4(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out, type4_out) \
330   IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 4, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out, type3_out, type4_out))
331
332 #define IPC_SYNC_MESSAGE_CONTROL6_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type6_in) \
333         IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 6, 0, (type1_in, type2_in, type3_in, type4_in, type5_in, type6_in), ())
334
335 #define IPC_SYNC_MESSAGE_CONTROL6_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type6_in, type1_out) \
336         IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 6, 1, (type1_in, type2_in, type3_in, type4_in, type5_in, type6_in), (type1_out))
337
338 #define IPC_SYNC_MESSAGE_ROUTED0_0(msg_class) \
339   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 0, (), ())
340
341 #define IPC_SYNC_MESSAGE_ROUTED0_1(msg_class, type1_out) \
342   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 1, (), (type1_out))
343
344 #define IPC_SYNC_MESSAGE_ROUTED0_2(msg_class, type1_out, type2_out) \
345   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 2, (), (type1_out, type2_out))
346
347 #define IPC_SYNC_MESSAGE_ROUTED0_3(msg_class, type1_out, type2_out, type3_out) \
348   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 3, (), (type1_out, type2_out, type3_out))
349
350 #define IPC_SYNC_MESSAGE_ROUTED0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \
351   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out))
352
353 #define IPC_SYNC_MESSAGE_ROUTED1_0(msg_class, type1_in) \
354   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 0, (type1_in), ())
355
356 #define IPC_SYNC_MESSAGE_ROUTED1_1(msg_class, type1_in, type1_out) \
357   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 1, (type1_in), (type1_out))
358
359 #define IPC_SYNC_MESSAGE_ROUTED1_2(msg_class, type1_in, type1_out, type2_out) \
360   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 2, (type1_in), (type1_out, type2_out))
361
362 #define IPC_SYNC_MESSAGE_ROUTED1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \
363   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out))
364
365 #define IPC_SYNC_MESSAGE_ROUTED1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \
366   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out))
367
368 #define IPC_SYNC_MESSAGE_ROUTED2_0(msg_class, type1_in, type2_in) \
369   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 0, (type1_in, type2_in), ())
370
371 #define IPC_SYNC_MESSAGE_ROUTED2_1(msg_class, type1_in, type2_in, type1_out) \
372   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 1, (type1_in, type2_in), (type1_out))
373
374 #define IPC_SYNC_MESSAGE_ROUTED2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \
375   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out))
376
377 #define IPC_SYNC_MESSAGE_ROUTED2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \
378   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out))
379
380 #define IPC_SYNC_MESSAGE_ROUTED2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \
381   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out))
382
383 #define IPC_SYNC_MESSAGE_ROUTED3_0(msg_class, type1_in, type2_in, type3_in) \
384   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 0, (type1_in, type2_in, type3_in), ())
385
386 #define IPC_SYNC_MESSAGE_ROUTED3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \
387   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out))
388
389 #define IPC_SYNC_MESSAGE_ROUTED3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \
390   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out))
391
392 #define IPC_SYNC_MESSAGE_ROUTED3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \
393   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out))
394
395 #define IPC_SYNC_MESSAGE_ROUTED3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \
396   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out))
397
398 #define IPC_SYNC_MESSAGE_ROUTED4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \
399   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), ())
400
401 #define IPC_SYNC_MESSAGE_ROUTED4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \
402   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out))
403
404 #define IPC_SYNC_MESSAGE_ROUTED4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \
405   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out))
406
407 #define IPC_SYNC_MESSAGE_ROUTED4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \
408   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out))
409
410 #define IPC_SYNC_MESSAGE_ROUTED4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \
411   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))
412
413 #define IPC_SYNC_MESSAGE_ROUTED5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \
414   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), ())
415
416 #define IPC_SYNC_MESSAGE_ROUTED5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \
417   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out))
418
419 #define IPC_SYNC_MESSAGE_ROUTED5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \
420   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out))
421
422 #define IPC_SYNC_MESSAGE_ROUTED5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \
423   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))
424
425 #define IPC_SYNC_MESSAGE_ROUTED5_4(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out, type4_out) \
426   IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 4, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out, type3_out, type4_out))
427
428 // Common message macro which dispatches into one of the 6 (sync x kind)
429 // routines.  There is a way that these 6 cases can be lumped together,
430 // but the  macros get very complicated in that case.
431 // Note: intended be redefined to generate other information.
432 #define IPC_MESSAGE_DECL(sync, kind, msg_class,                               \
433                          in_cnt, out_cnt, in_list, out_list)                  \
434   IPC_##sync##_##kind##_DECL(msg_class, in_cnt, out_cnt, in_list, out_list)   \
435   IPC_MESSAGE_EXTRA(sync, kind, msg_class, in_cnt, out_cnt, in_list, out_list)
436
437 #define IPC_EMPTY_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
438   class __attribute__((visibility("default"))) msg_class : public IPC::Message\
439   {                                                                           \
440    public:                                                                    \
441     enum { ID = IPC_MESSAGE_ID() };                                           \
442     msg_class() : IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) {}   \
443   };
444
445 #define IPC_EMPTY_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list)  \
446   class __attribute__((visibility("default"))) msg_class : public IPC::Message\
447   {                                                                           \
448    public:                                                                    \
449     enum { ID = IPC_MESSAGE_ID() };                                           \
450     msg_class(int32 routing_id)                                               \
451         : IPC::Message(routing_id, ID, PRIORITY_NORMAL) {}                    \
452   };
453
454 #define IPC_ASYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \
455   class __attribute__((visibility("default"))) msg_class :                    \
456       public IPC::MessageWithTuple<IPC_TUPLE_IN_##in_cnt in_list> {           \
457    public:                                                                    \
458     enum { ID = IPC_MESSAGE_ID() };                                           \
459     msg_class(IPC_TYPE_IN_##in_cnt in_list);                                  \
460     virtual ~msg_class();                                                     \
461     static void Log(std::string* name, const Message* msg, std::string* l);   \
462   };
463
464 #define IPC_ASYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list)  \
465   class __attribute__((visibility("default"))) msg_class :                    \
466       public IPC::MessageWithTuple<IPC_TUPLE_IN_##in_cnt in_list> {           \
467    public:                                                                    \
468     enum { ID = IPC_MESSAGE_ID() };                                           \
469     msg_class(int32 routing_id IPC_COMMA_##in_cnt                             \
470               IPC_TYPE_IN_##in_cnt in_list);                                  \
471     virtual ~msg_class();                                                     \
472     static void Log(std::string* name, const Message* msg, std::string* l);   \
473   };
474
475 #define IPC_SYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list)  \
476   class __attribute__((visibility("default"))) msg_class :                    \
477       public IPC::MessageWithReply<IPC_TUPLE_IN_##in_cnt in_list,             \
478                                    IPC_TUPLE_OUT_##out_cnt out_list> {        \
479    public:                                                                    \
480     enum { ID = IPC_MESSAGE_ID() };                                           \
481     msg_class(IPC_TYPE_IN_##in_cnt in_list                                    \
482               IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt)                     \
483               IPC_TYPE_OUT_##out_cnt out_list);                               \
484     virtual ~msg_class();                                                     \
485     static void Log(std::string* name, const Message* msg, std::string* l);   \
486   };
487
488 #define IPC_SYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list)   \
489   class __attribute__((visibility("default"))) msg_class :                    \
490       public IPC::MessageWithReply<IPC_TUPLE_IN_##in_cnt in_list,             \
491                                    IPC_TUPLE_OUT_##out_cnt out_list> {        \
492    public:                                                                    \
493     enum { ID = IPC_MESSAGE_ID() };                                           \
494     msg_class(int32 routing_id                                                \
495               IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt)                      \
496               IPC_TYPE_IN_##in_cnt in_list                                    \
497               IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt)                     \
498               IPC_TYPE_OUT_##out_cnt out_list);                               \
499     virtual ~msg_class();                                                     \
500     static void Log(std::string* name, const Message* msg, std::string* l);   \
501   };
502
503 #if defined(IPC_MESSAGE_IMPL)
504
505 // "Implementation" inclusion produces constructors, destructors, and
506 // logging functions, except for the no-arg special cases, where the
507 // implementation occurs in the declaration, and there is no special
508 // logging function.
509 #define IPC_MESSAGE_EXTRA(sync, kind, msg_class,                              \
510                           in_cnt, out_cnt, in_list, out_list)                 \
511   IPC_##sync##_##kind##_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)   \
512   IPC_##sync##_MESSAGE_LOG(msg_class)
513
514 #define IPC_EMPTY_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)
515 #define IPC_EMPTY_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)
516
517 #define IPC_ASYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \
518   msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list) :                        \
519       IPC::MessageWithTuple<IPC_TUPLE_IN_##in_cnt in_list>                    \
520       (MSG_ROUTING_CONTROL, ID, IPC_NAME_IN_##in_cnt in_list)                 \
521       {}                                                                      \
522   msg_class::~msg_class() {}
523
524 #define IPC_ASYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)  \
525   msg_class::msg_class(int32 routing_id IPC_COMMA_##in_cnt                    \
526                        IPC_TYPE_IN_##in_cnt in_list) :                        \
527       IPC::MessageWithTuple<IPC_TUPLE_IN_##in_cnt in_list>                    \
528       (routing_id, ID, IPC_NAME_IN_##in_cnt in_list)                          \
529       {}                                                                      \
530   msg_class::~msg_class() {}
531
532 #define IPC_SYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)  \
533   msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list                           \
534                        IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt)            \
535                        IPC_TYPE_OUT_##out_cnt out_list) :                     \
536       IPC::MessageWithReply<IPC_TUPLE_IN_##in_cnt in_list,                    \
537                             IPC_TUPLE_OUT_##out_cnt out_list>                 \
538       (MSG_ROUTING_CONTROL, ID,                                               \
539        IPC_NAME_IN_##in_cnt in_list,                                          \
540        IPC_NAME_OUT_##out_cnt out_list)                                       \
541   {                                                                     \
542   }                                                                     \
543   msg_class::~msg_class() {}
544
545 #define IPC_SYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list)   \
546   msg_class::msg_class(int32 routing_id                                       \
547                        IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt)             \
548                        IPC_TYPE_IN_##in_cnt in_list                           \
549                        IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt)            \
550                        IPC_TYPE_OUT_##out_cnt out_list) :                     \
551       IPC::MessageWithReply<IPC_TUPLE_IN_##in_cnt in_list,                    \
552                             IPC_TUPLE_OUT_##out_cnt out_list>                 \
553       (routing_id, ID,                                                        \
554        IPC_NAME_IN_##in_cnt in_list,                                          \
555        IPC_NAME_OUT_##out_cnt out_list)                                       \
556       {}                                                                      \
557   msg_class::~msg_class() {}
558
559 #define IPC_EMPTY_MESSAGE_LOG(msg_class)
560
561 #define IPC_ASYNC_MESSAGE_LOG(msg_class)                                \
562   void msg_class::Log(std::string* name,                                \
563                       const Message* msg,                               \
564                       std::string* l) {                                 \
565     if (name)                                                           \
566         {                                                                                                                                       \
567       *name = #msg_class;                                               \
568         }                                                                                                                                       \
569     if (!msg || !l)                                                     \
570         {                                                                                                                                       \
571       return;                                                           \
572         }                                                                                                                                       \
573     Param p;                                                            \
574     if (Read(msg, &p))                                                  \
575         {                                                                                                                                       \
576       IPC::LogParam(p, l);                                              \
577         }                                                                                                                                       \
578   }
579
580 #define IPC_SYNC_MESSAGE_LOG(msg_class)                                 \
581   void msg_class::Log(std::string* name,                                \
582                       const Message* msg,                               \
583                       std::string* l) {                                 \
584     if (name)                                                           \
585         {                                                                                                                                       \
586       *name = #msg_class;                                               \
587         }                                                                                                                                       \
588     if (!msg || !l)                                                     \
589         {                                                                                                                                       \
590       return;                                                           \
591         }                                                                                                                                       \
592     if (msg->is_sync()) {                                               \
593       TupleTypes<SendParam>::ValueTuple p;                              \
594       if (ReadSendParam(msg, &p))                                       \
595           {                                                                                                                                     \
596         IPC::LogParam(p, l);                                            \
597           }                                                                                                                                     \
598       AddOutputParamsToLog(msg, l);                                     \
599     } else {                                                            \
600       TupleTypes<ReplyParam>::ValueTuple p;                             \
601       if (ReadReplyParam(msg, &p))                                      \
602           {                                                                                                                                     \
603         IPC::LogParam(p, l);                                            \
604           }                                                                                                                                     \
605     }                                                                   \
606   }
607
608 #elif defined(IPC_MESSAGE_MACROS_LOG_ENABLED)
609
610 #ifndef IPC_LOG_TABLE_CREATED
611 #define IPC_LOG_TABLE_CREATED
612
613 #include "base/hash_tables.h"
614
615 typedef void (*LogFunction)(std::string* name,
616                             const IPC::Message* msg,
617                             std::string* params);
618
619 typedef base::hash_map<uint32, LogFunction > LogFunctionMap;
620 LogFunctionMap g_log_function_mapping;
621
622 #endif  // IPC_LOG_TABLE_CREATED
623
624 // "Log table" inclusion produces extra logging registration code.
625 #define IPC_MESSAGE_EXTRA(sync, kind, msg_class,                        \
626                           in_cnt, out_cnt, in_list, out_list)           \
627   class __attribute__((visibility("default"))) LoggerRegisterHelper##msg_class { \
628  public:                                                                \
629     LoggerRegisterHelper##msg_class() {                                 \
630       g_log_function_mapping[msg_class::ID] = msg_class::Log;           \
631     }                                                                   \
632   };                                                                    \
633   LoggerRegisterHelper##msg_class g_LoggerRegisterHelper##msg_class;
634
635 #else
636
637 // Normal inclusion produces nothing extra.
638 #define IPC_MESSAGE_EXTRA(sync, kind, msg_class,                \
639                           in_cnt, out_cnt, in_list, out_list)
640
641 #endif // defined(IPC_MESSAGE_IMPL)
642
643 // Handle variable sized argument lists.  These are usually invoked by token
644 // pasting against the argument counts.
645 #define IPC_TYPE_IN_0()
646 #define IPC_TYPE_IN_1(t1)                   const t1& arg1
647 #define IPC_TYPE_IN_2(t1, t2)               const t1& arg1, const t2& arg2
648 #define IPC_TYPE_IN_3(t1, t2, t3)           const t1& arg1, const t2& arg2, const t3& arg3
649 #define IPC_TYPE_IN_4(t1, t2, t3, t4)       const t1& arg1, const t2& arg2, const t3& arg3, const t4& arg4
650 #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
651 #define IPC_TYPE_IN_6(t1, t2, t3, t4, t5, t6)   const t1& arg1, const t2& arg2, const t3& arg3, const t4& arg4, const t5& arg5, const t6& arg6
652
653 #define IPC_TYPE_OUT_0()
654 #define IPC_TYPE_OUT_1(t1)                  t1* arg7
655 #define IPC_TYPE_OUT_2(t1, t2)              t1* arg7, t2* arg8
656 #define IPC_TYPE_OUT_3(t1, t2, t3)          t1* arg7, t2* arg8, t3* arg9
657 #define IPC_TYPE_OUT_4(t1, t2, t3, t4)      t1* arg7, t2* arg8, t3* arg9, t4* arg10
658
659 #define IPC_TUPLE_IN_0()                    Tuple0
660 #define IPC_TUPLE_IN_1(t1)                  Tuple1<t1>
661 #define IPC_TUPLE_IN_2(t1, t2)              Tuple2<t1, t2>
662 #define IPC_TUPLE_IN_3(t1, t2, t3)          Tuple3<t1, t2, t3>
663 #define IPC_TUPLE_IN_4(t1, t2, t3, t4)      Tuple4<t1, t2, t3, t4>
664 #define IPC_TUPLE_IN_5(t1, t2, t3, t4, t5)  Tuple5<t1, t2, t3, t4, t5>
665 #define IPC_TUPLE_IN_6(t1, t2, t3, t4, t5, t6)  Tuple6<t1, t2, t3, t4, t5, t6>
666
667 #define IPC_TUPLE_OUT_0()                   Tuple0
668 #define IPC_TUPLE_OUT_1(t1)                 Tuple1<t1&>
669 #define IPC_TUPLE_OUT_2(t1, t2)             Tuple2<t1&, t2&>
670 #define IPC_TUPLE_OUT_3(t1, t2, t3)         Tuple3<t1&, t2&, t3&>
671 #define IPC_TUPLE_OUT_4(t1, t2, t3, t4)     Tuple4<t1&, t2&, t3&, t4&>
672
673 #define IPC_NAME_IN_0()                     MakeTuple()
674 #define IPC_NAME_IN_1(t1)                   MakeRefTuple(arg1)
675 #define IPC_NAME_IN_2(t1, t2)               MakeRefTuple(arg1, arg2)
676 #define IPC_NAME_IN_3(t1, t2, t3)           MakeRefTuple(arg1, arg2, arg3)
677 #define IPC_NAME_IN_4(t1, t2, t3, t4)       MakeRefTuple(arg1, arg2, arg3, arg4)
678 #define IPC_NAME_IN_5(t1, t2, t3, t4, t5)   MakeRefTuple(arg1, arg2, arg3, arg4, arg5)
679 #define IPC_NAME_IN_6(t1, t2, t3, t4, t5, t6)   MakeRefTuple(arg1, arg2, arg3, arg4, arg5, arg6)
680
681 #define IPC_NAME_OUT_0()                    MakeTuple()
682 #define IPC_NAME_OUT_1(t1)                  MakeRefTuple(*arg7)
683 #define IPC_NAME_OUT_2(t1, t2)              MakeRefTuple(*arg7, *arg8)
684 #define IPC_NAME_OUT_3(t1, t2, t3)          MakeRefTuple(*arg7, *arg8, *arg9)
685 #define IPC_NAME_OUT_4(t1, t2, t3, t4)      MakeRefTuple(*arg7, *arg8, *arg9, *arg10)
686
687 // There are places where the syntax requires a comma if there are input args,
688 // if there are input args and output args, or if there are input args or
689 // output args.  These macros allow generation of the comma as needed; invoke
690 // by token pasting against the argument counts.
691 #define IPC_COMMA_0
692 #define IPC_COMMA_1 ,
693 #define IPC_COMMA_2 ,
694 #define IPC_COMMA_3 ,
695 #define IPC_COMMA_4 ,
696 #define IPC_COMMA_5 ,
697 #define IPC_COMMA_6 ,
698
699 #define IPC_COMMA_AND_0(x)
700 #define IPC_COMMA_AND_1(x) x
701 #define IPC_COMMA_AND_2(x) x
702 #define IPC_COMMA_AND_3(x) x
703 #define IPC_COMMA_AND_4(x) x
704 #define IPC_COMMA_AND_5(x) x
705 #define IPC_COMMA_AND_6(x) x
706
707 #define IPC_COMMA_OR_0(x) x
708 #define IPC_COMMA_OR_1(x) ,
709 #define IPC_COMMA_OR_2(x) ,
710 #define IPC_COMMA_OR_3(x) ,
711 #define IPC_COMMA_OR_4(x) ,
712 #define IPC_COMMA_OR_5(x) ,
713 #define IPC_COMMA_OR_6(x) ,
714
715 // Message IDs
716 // Note: we currently use __LINE__ to give unique IDs to messages within
717 // a file.  They're globally unique since each file defines its own
718 // IPC_MESSAGE_START.  Ideally, we wouldn't use line numbers (a possibility
719 // is to instead use the __COUNTER__ macro, but it needs gcc 4.3 and xcode
720 // doesn't use it yet).
721 #define IPC_MESSAGE_ID() ((IPC_MESSAGE_START << 16) + __LINE__)
722 #define IPC_MESSAGE_ID_CLASS(id) ((id) >> 16)
723 #define IPC_MESSAGE_ID_LINE(id) ((id) & 0xffff)
724
725 // Message crackers and handlers.
726 // Prefer to use the IPC_BEGIN_MESSAGE_MAP_EX to the older macros since they
727 // allow you to detect when a message could not be de-serialized. Usage:
728 //
729 //   bool MyClass::OnMessageReceived(const IPC::Message& msg) {
730 //     bool handled = true;
731 //     bool msg_is_good = false;
732 //     IPC_BEGIN_MESSAGE_MAP_EX(MyClass, msg, msg_is_good)
733 //       IPC_MESSAGE_HANDLER(MsgClassOne, OnMsgClassOne)
734 //       ...more handlers here ...
735 //       IPC_MESSAGE_HANDLER(MsgClassTen, OnMsgClassTen)
736 //       IPC_MESSAGE_UNHANDLED(handled = false)
737 //     IPC_END_MESSAGE_MAP_EX()
738 //     if (!msg_is_good) {
739 //       // Signal error here or terminate offending process.
740 //     }
741 //     return handled;
742 //   }
743
744
745 #define IPC_BEGIN_MESSAGE_MAP_EX(class_name, msg, msg_is_ok) \
746   { \
747     typedef class_name _IpcMessageHandlerClass; \
748     const IPC::Message& ipc_message__ = msg; \
749     bool& msg_is_ok__ = msg_is_ok; \
750     switch (ipc_message__.type()) { \
751
752 #define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \
753   { \
754     typedef class_name _IpcMessageHandlerClass; \
755     const IPC::Message& ipc_message__ = msg; \
756     bool msg_is_ok__ = true; \
757     switch (ipc_message__.type()) { \
758
759 #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \
760   case msg_class::ID: \
761     msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, &member_func); \
762     break;
763
764 #define IPC_MESSAGE_FORWARD_EX(msg_class, obj, sender, member_func)     \
765   case msg_class::ID: \
766   msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, sender, &member_func); \
767     break;
768
769 #define IPC_MESSAGE_HANDLER(msg_class, member_func, sender)                     \
770     IPC_MESSAGE_FORWARD_EX(msg_class, this, sender, _IpcMessageHandlerClass::member_func)
771
772 #define IPC_MESSAGE_HANDLER_EX(msg_class, sender, member_func)                  \
773     IPC_MESSAGE_FORWARD_EX(msg_class, this, sender, _IpcMessageHandlerClass::member_func)
774
775 #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \
776     case msg_class::ID: \
777     msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, &member_func); \
778     break;
779
780 #define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \
781   IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \
782                                   _IpcMessageHandlerClass::member_func)
783
784 #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \
785   case msg_class::ID: \
786     code; \
787     break;
788
789 #define IPC_REPLY_HANDLER(func) \
790    case IPC_REPLY_ID: \
791      func(ipc_message__); \
792      break;
793
794
795 #define IPC_MESSAGE_UNHANDLED(code) \
796   default: \
797     code; \
798     break;
799
800 #define IPC_MESSAGE_UNHANDLED_ERROR() \
801   IPC_MESSAGE_UNHANDLED(NOTREACHED() << \
802                               "Invalid message with type = " << \
803                               ipc_message__.type())
804
805 #define IPC_END_MESSAGE_MAP() \
806   } \
807 }
808
809 #define IPC_END_MESSAGE_MAP_EX() \
810   } \
811 }
812
813 // This corresponds to an enum value from IPCMessageStart.
814 #define IPC_MESSAGE_CLASS(message) \
815   IPC_MESSAGE_ID_CLASS(message.type())
816
817 #endif  // IPC_IPC_MESSAGE_MACROS_H_
818
819 // Clean up IPC_MESSAGE_START in this unguarded section so that the
820 // XXX_messages.h files need not do so themselves.  This makes the
821 // XXX_messages.h files easier to write.
822 #undef IPC_MESSAGE_START