[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 5 | // Defining IPC Messages |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | // |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 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, |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 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. |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 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. |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 40 | // #define IPC_MESSAGE_IMPL |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 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" |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 48 | // // Generate param traits write methods. |
| 49 | // #include "ipc/param_traits_write_macros.h" |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 50 | // namespace IPC { |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 51 | // #include "path/to/YYY_message_generator.h" |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 52 | // } // namespace IPC |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 53 | // // Generate param traits read methods. |
| 54 | // #include "ipc/param_traits_read_macros.h" |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 55 | // namespace IPC { |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 56 | // #include "path/to/YYY_message_generator.h" |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 57 | // } // namespace IPC |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 58 | // // Generate param traits log methods. |
| 59 | // #include "ipc/param_traits_log_macros.h" |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 60 | // namespace IPC { |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 61 | // #include "path/to/YYY_message_generator.h" |
| 62 | // } // namespace IPC |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | // |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 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 |
[email protected] | 94dc971d | 2011-03-05 19:08:32 | [diff] [blame] | 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 |
[email protected] | e503a12 | 2011-03-17 18:20:52 | [diff] [blame] | 141 | // inside matching calls to IPC_STRUCT_TRAITS_BEGIN() / |
| 142 | // IPC_STRUCT_TRAITS_END(). |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 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 | // |
[email protected] | e503a12 | 2011-03-17 18:20:52 | [diff] [blame] | 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 | // |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 151 | // Once the types have been declared / registered, message definitions follow. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 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 |
[email protected] | d321644 | 2009-03-05 21:07:27 | [diff] [blame] | 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). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 157 | // The receiver's handler function will be |
| 158 | // void OnSyncMessageName(const type1& in1, type2* out1, type3* out2) |
| 159 | // |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 160 | // A caller can also send a synchronous message, while the receiver can respond |
[email protected] | d424035 | 2009-12-10 17:32:31 | [diff] [blame] | 161 | // at a later time. This is transparent from the sender's side. The receiver |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 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 |
[email protected] | d321644 | 2009-03-05 21:07:27 | [diff] [blame] | 166 | // IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncMessageName, |
| 167 | // OnSyncMessageName) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 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 | |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 176 | #ifndef IPC_IPC_MESSAGE_MACROS_H_ |
| 177 | #define IPC_IPC_MESSAGE_MACROS_H_ |
[email protected] | 82e5ee8 | 2009-04-03 02:29:45 | [diff] [blame] | 178 | |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 179 | #include "ipc/ipc_message_utils.h" |
| 180 | #include "ipc/param_traits_macros.h" |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 181 | |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 182 | #if defined(IPC_MESSAGE_IMPL) |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 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 |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 198 | // the common message generation macro. These should never be redefined. |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 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_ROUTED0(msg_class) \ |
| 218 | IPC_MESSAGE_DECL(EMPTY, ROUTED, msg_class, 0, 0, (), ()) |
| 219 | |
| 220 | #define IPC_MESSAGE_ROUTED1(msg_class, type1) \ |
| 221 | IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 1, 0, (type1), ()) |
| 222 | |
| 223 | #define IPC_MESSAGE_ROUTED2(msg_class, type1, type2) \ |
| 224 | IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 2, 0, (type1, type2), ()) |
| 225 | |
| 226 | #define IPC_MESSAGE_ROUTED3(msg_class, type1, type2, type3) \ |
| 227 | IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 3, 0, (type1, type2, type3), ()) |
| 228 | |
| 229 | #define IPC_MESSAGE_ROUTED4(msg_class, type1, type2, type3, type4) \ |
| 230 | IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 4, 0, (type1, type2, type3, type4), ()) |
| 231 | |
| 232 | #define IPC_MESSAGE_ROUTED5(msg_class, type1, type2, type3, type4, type5) \ |
| 233 | IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 5, 0, (type1, type2, type3, type4, type5), ()) |
| 234 | |
| 235 | #define IPC_SYNC_MESSAGE_CONTROL0_0(msg_class) \ |
| 236 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 0, (), ()) |
| 237 | |
| 238 | #define IPC_SYNC_MESSAGE_CONTROL0_1(msg_class, type1_out) \ |
| 239 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 1, (), (type1_out)) |
| 240 | |
| 241 | #define IPC_SYNC_MESSAGE_CONTROL0_2(msg_class, type1_out, type2_out) \ |
| 242 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 2, (), (type1_out, type2_out)) |
| 243 | |
| 244 | #define IPC_SYNC_MESSAGE_CONTROL0_3(msg_class, type1_out, type2_out, type3_out) \ |
| 245 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 3, (), (type1_out, type2_out, type3_out)) |
| 246 | |
| 247 | #define IPC_SYNC_MESSAGE_CONTROL0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \ |
| 248 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out)) |
| 249 | |
| 250 | #define IPC_SYNC_MESSAGE_CONTROL1_0(msg_class, type1_in) \ |
| 251 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 0, (type1_in), ()) |
| 252 | |
| 253 | #define IPC_SYNC_MESSAGE_CONTROL1_1(msg_class, type1_in, type1_out) \ |
| 254 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 1, (type1_in), (type1_out)) |
| 255 | |
| 256 | #define IPC_SYNC_MESSAGE_CONTROL1_2(msg_class, type1_in, type1_out, type2_out) \ |
| 257 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 2, (type1_in), (type1_out, type2_out)) |
| 258 | |
| 259 | #define IPC_SYNC_MESSAGE_CONTROL1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \ |
| 260 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out)) |
| 261 | |
| 262 | #define IPC_SYNC_MESSAGE_CONTROL1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \ |
| 263 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out)) |
| 264 | |
| 265 | #define IPC_SYNC_MESSAGE_CONTROL2_0(msg_class, type1_in, type2_in) \ |
| 266 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 0, (type1_in, type2_in), ()) |
| 267 | |
| 268 | #define IPC_SYNC_MESSAGE_CONTROL2_1(msg_class, type1_in, type2_in, type1_out) \ |
| 269 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 1, (type1_in, type2_in), (type1_out)) |
| 270 | |
| 271 | #define IPC_SYNC_MESSAGE_CONTROL2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \ |
| 272 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out)) |
| 273 | |
| 274 | #define IPC_SYNC_MESSAGE_CONTROL2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \ |
| 275 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out)) |
| 276 | |
| 277 | #define IPC_SYNC_MESSAGE_CONTROL2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \ |
| 278 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out)) |
| 279 | |
| 280 | #define IPC_SYNC_MESSAGE_CONTROL3_0(msg_class, type1_in, type2_in, type3_in) \ |
| 281 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 0, (type1_in, type2_in, type3_in), ()) |
| 282 | |
| 283 | #define IPC_SYNC_MESSAGE_CONTROL3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \ |
| 284 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out)) |
| 285 | |
| 286 | #define IPC_SYNC_MESSAGE_CONTROL3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \ |
| 287 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out)) |
| 288 | |
| 289 | #define IPC_SYNC_MESSAGE_CONTROL3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \ |
| 290 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out)) |
| 291 | |
| 292 | #define IPC_SYNC_MESSAGE_CONTROL3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \ |
| 293 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out)) |
| 294 | |
| 295 | #define IPC_SYNC_MESSAGE_CONTROL4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \ |
| 296 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 0, (type1_in, type2_in, type3_in, type4_in), ()) |
| 297 | |
| 298 | #define IPC_SYNC_MESSAGE_CONTROL4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \ |
| 299 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out)) |
| 300 | |
| 301 | #define IPC_SYNC_MESSAGE_CONTROL4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \ |
| 302 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out)) |
| 303 | |
| 304 | #define IPC_SYNC_MESSAGE_CONTROL4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \ |
| 305 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out)) |
| 306 | |
| 307 | #define IPC_SYNC_MESSAGE_CONTROL4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \ |
| 308 | 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)) |
| 309 | |
| 310 | #define IPC_SYNC_MESSAGE_CONTROL5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \ |
[email protected] | acd3d771 | 2011-03-10 15:34:21 | [diff] [blame] | 311 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 0, (type1_in, type2_in, type3_in, type4_in, type5_in), ()) |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 312 | |
| 313 | #define IPC_SYNC_MESSAGE_CONTROL5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \ |
| 314 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out)) |
| 315 | |
| 316 | #define IPC_SYNC_MESSAGE_CONTROL5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \ |
| 317 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out)) |
| 318 | |
| 319 | #define IPC_SYNC_MESSAGE_CONTROL5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \ |
| 320 | 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)) |
| 321 | |
| 322 | #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) \ |
| 323 | 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)) |
| 324 | |
| 325 | #define IPC_SYNC_MESSAGE_ROUTED0_0(msg_class) \ |
| 326 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 0, (), ()) |
| 327 | |
| 328 | #define IPC_SYNC_MESSAGE_ROUTED0_1(msg_class, type1_out) \ |
| 329 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 1, (), (type1_out)) |
| 330 | |
| 331 | #define IPC_SYNC_MESSAGE_ROUTED0_2(msg_class, type1_out, type2_out) \ |
| 332 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 2, (), (type1_out, type2_out)) |
| 333 | |
| 334 | #define IPC_SYNC_MESSAGE_ROUTED0_3(msg_class, type1_out, type2_out, type3_out) \ |
| 335 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 3, (), (type1_out, type2_out, type3_out)) |
| 336 | |
| 337 | #define IPC_SYNC_MESSAGE_ROUTED0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \ |
| 338 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out)) |
| 339 | |
| 340 | #define IPC_SYNC_MESSAGE_ROUTED1_0(msg_class, type1_in) \ |
| 341 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 0, (type1_in), ()) |
| 342 | |
| 343 | #define IPC_SYNC_MESSAGE_ROUTED1_1(msg_class, type1_in, type1_out) \ |
| 344 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 1, (type1_in), (type1_out)) |
| 345 | |
| 346 | #define IPC_SYNC_MESSAGE_ROUTED1_2(msg_class, type1_in, type1_out, type2_out) \ |
| 347 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 2, (type1_in), (type1_out, type2_out)) |
| 348 | |
| 349 | #define IPC_SYNC_MESSAGE_ROUTED1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \ |
| 350 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out)) |
| 351 | |
| 352 | #define IPC_SYNC_MESSAGE_ROUTED1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \ |
| 353 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out)) |
| 354 | |
| 355 | #define IPC_SYNC_MESSAGE_ROUTED2_0(msg_class, type1_in, type2_in) \ |
| 356 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 0, (type1_in, type2_in), ()) |
| 357 | |
| 358 | #define IPC_SYNC_MESSAGE_ROUTED2_1(msg_class, type1_in, type2_in, type1_out) \ |
| 359 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 1, (type1_in, type2_in), (type1_out)) |
| 360 | |
| 361 | #define IPC_SYNC_MESSAGE_ROUTED2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \ |
| 362 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out)) |
| 363 | |
| 364 | #define IPC_SYNC_MESSAGE_ROUTED2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \ |
| 365 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out)) |
| 366 | |
| 367 | #define IPC_SYNC_MESSAGE_ROUTED2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \ |
| 368 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out)) |
| 369 | |
| 370 | #define IPC_SYNC_MESSAGE_ROUTED3_0(msg_class, type1_in, type2_in, type3_in) \ |
| 371 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 0, (type1_in, type2_in, type3_in), ()) |
| 372 | |
| 373 | #define IPC_SYNC_MESSAGE_ROUTED3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \ |
| 374 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out)) |
| 375 | |
| 376 | #define IPC_SYNC_MESSAGE_ROUTED3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \ |
| 377 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out)) |
| 378 | |
| 379 | #define IPC_SYNC_MESSAGE_ROUTED3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \ |
| 380 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out)) |
| 381 | |
| 382 | #define IPC_SYNC_MESSAGE_ROUTED3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \ |
| 383 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out)) |
| 384 | |
| 385 | #define IPC_SYNC_MESSAGE_ROUTED4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \ |
| 386 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), ()) |
| 387 | |
| 388 | #define IPC_SYNC_MESSAGE_ROUTED4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \ |
| 389 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out)) |
| 390 | |
| 391 | #define IPC_SYNC_MESSAGE_ROUTED4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \ |
| 392 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out)) |
| 393 | |
| 394 | #define IPC_SYNC_MESSAGE_ROUTED4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \ |
| 395 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out)) |
| 396 | |
| 397 | #define IPC_SYNC_MESSAGE_ROUTED4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \ |
| 398 | 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)) |
| 399 | |
| 400 | #define IPC_SYNC_MESSAGE_ROUTED5_0(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in) \ |
[email protected] | acd3d771 | 2011-03-10 15:34:21 | [diff] [blame] | 401 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), ()) |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 402 | |
| 403 | #define IPC_SYNC_MESSAGE_ROUTED5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \ |
| 404 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out)) |
| 405 | |
| 406 | #define IPC_SYNC_MESSAGE_ROUTED5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \ |
| 407 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out)) |
| 408 | |
| 409 | #define IPC_SYNC_MESSAGE_ROUTED5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \ |
| 410 | 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)) |
| 411 | |
| 412 | #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) \ |
| 413 | 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)) |
| 414 | |
| 415 | // Common message macro which dispatches into one of the 6 (sync x kind) |
| 416 | // routines. There is a way that these 6 cases can be lumped together, |
| 417 | // but the macros get very complicated in that case. |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 418 | // Note: intended be redefined to generate other information. |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 419 | #define IPC_MESSAGE_DECL(sync, kind, msg_class, \ |
| 420 | in_cnt, out_cnt, in_list, out_list) \ |
| 421 | IPC_##sync##_##kind##_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 422 | IPC_MESSAGE_EXTRA(sync, kind, msg_class, in_cnt, out_cnt, in_list, out_list) |
| 423 | |
| 424 | #define IPC_EMPTY_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 425 | class msg_class : public IPC::Message { \ |
| 426 | public: \ |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 427 | enum { ID = IPC_MESSAGE_ID() }; \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 428 | msg_class() : IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) {} \ |
| 429 | }; |
| 430 | |
| 431 | #define IPC_EMPTY_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 432 | class msg_class : public IPC::Message { \ |
| 433 | public: \ |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 434 | enum { ID = IPC_MESSAGE_ID() }; \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 435 | msg_class(int32 routing_id) \ |
| 436 | : IPC::Message(routing_id, ID, PRIORITY_NORMAL) {} \ |
| 437 | }; |
| 438 | |
| 439 | #define IPC_ASYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 440 | class msg_class : \ |
| 441 | public IPC::MessageWithTuple<IPC_TUPLE_IN_##in_cnt in_list> { \ |
| 442 | public: \ |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 443 | enum { ID = IPC_MESSAGE_ID() }; \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 444 | msg_class(IPC_TYPE_IN_##in_cnt in_list); \ |
[email protected] | 3690ebe0 | 2011-05-25 09:08:19 | [diff] [blame^] | 445 | virtual ~msg_class(); \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 446 | static void Log(std::string* name, const Message* msg, std::string* l); \ |
| 447 | }; |
| 448 | |
| 449 | #define IPC_ASYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 450 | class msg_class : \ |
| 451 | public IPC::MessageWithTuple<IPC_TUPLE_IN_##in_cnt in_list> { \ |
| 452 | public: \ |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 453 | enum { ID = IPC_MESSAGE_ID() }; \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 454 | msg_class(int32 routing_id IPC_COMMA_##in_cnt \ |
| 455 | IPC_TYPE_IN_##in_cnt in_list); \ |
[email protected] | 3690ebe0 | 2011-05-25 09:08:19 | [diff] [blame^] | 456 | virtual ~msg_class(); \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 457 | static void Log(std::string* name, const Message* msg, std::string* l); \ |
| 458 | }; |
| 459 | |
| 460 | #define IPC_SYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 461 | class msg_class : \ |
| 462 | public IPC::MessageWithReply<IPC_TUPLE_IN_##in_cnt in_list, \ |
| 463 | IPC_TUPLE_OUT_##out_cnt out_list> { \ |
| 464 | public: \ |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 465 | enum { ID = IPC_MESSAGE_ID() }; \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 466 | msg_class(IPC_TYPE_IN_##in_cnt in_list \ |
| 467 | IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \ |
| 468 | IPC_TYPE_OUT_##out_cnt out_list); \ |
[email protected] | 3690ebe0 | 2011-05-25 09:08:19 | [diff] [blame^] | 469 | virtual ~msg_class(); \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 470 | static void Log(std::string* name, const Message* msg, std::string* l); \ |
| 471 | }; |
| 472 | |
| 473 | #define IPC_SYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 474 | class msg_class : \ |
| 475 | public IPC::MessageWithReply<IPC_TUPLE_IN_##in_cnt in_list, \ |
| 476 | IPC_TUPLE_OUT_##out_cnt out_list> { \ |
| 477 | public: \ |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 478 | enum { ID = IPC_MESSAGE_ID() }; \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 479 | msg_class(int32 routing_id \ |
| 480 | IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \ |
| 481 | 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); \ |
[email protected] | 3690ebe0 | 2011-05-25 09:08:19 | [diff] [blame^] | 484 | virtual ~msg_class(); \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 485 | static void Log(std::string* name, const Message* msg, std::string* l); \ |
| 486 | }; |
| 487 | |
| 488 | #if defined(IPC_MESSAGE_IMPL) |
| 489 | |
| 490 | // "Implementation" inclusion produces constructors, destructors, and |
| 491 | // logging functions, except for the no-arg special cases, where the |
| 492 | // implementation occurs in the declaration, and there is no special |
| 493 | // logging function. |
| 494 | #define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \ |
| 495 | in_cnt, out_cnt, in_list, out_list) \ |
| 496 | IPC_##sync##_##kind##_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 497 | IPC_##sync##_MESSAGE_LOG(msg_class) |
| 498 | |
| 499 | #define IPC_EMPTY_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) |
| 500 | #define IPC_EMPTY_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) |
| 501 | |
| 502 | #define IPC_ASYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 503 | msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list) : \ |
| 504 | IPC::MessageWithTuple<IPC_TUPLE_IN_##in_cnt in_list> \ |
| 505 | (MSG_ROUTING_CONTROL, ID, IPC_NAME_IN_##in_cnt in_list) \ |
| 506 | {} \ |
| 507 | msg_class::~msg_class() {} |
| 508 | |
| 509 | #define IPC_ASYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 510 | msg_class::msg_class(int32 routing_id IPC_COMMA_##in_cnt \ |
| 511 | IPC_TYPE_IN_##in_cnt in_list) : \ |
| 512 | IPC::MessageWithTuple<IPC_TUPLE_IN_##in_cnt in_list> \ |
| 513 | (routing_id, ID, IPC_NAME_IN_##in_cnt in_list) \ |
| 514 | {} \ |
| 515 | msg_class::~msg_class() {} |
| 516 | |
| 517 | #define IPC_SYNC_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_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \ |
| 520 | IPC_TYPE_OUT_##out_cnt out_list) : \ |
| 521 | IPC::MessageWithReply<IPC_TUPLE_IN_##in_cnt in_list, \ |
| 522 | IPC_TUPLE_OUT_##out_cnt out_list> \ |
| 523 | (MSG_ROUTING_CONTROL, ID, \ |
| 524 | IPC_NAME_IN_##in_cnt in_list, \ |
| 525 | IPC_NAME_OUT_##out_cnt out_list) \ |
| 526 | {} \ |
| 527 | msg_class::~msg_class() {} |
| 528 | |
| 529 | #define IPC_SYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 530 | msg_class::msg_class(int32 routing_id \ |
| 531 | IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \ |
| 532 | IPC_TYPE_IN_##in_cnt in_list \ |
| 533 | IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \ |
| 534 | IPC_TYPE_OUT_##out_cnt out_list) : \ |
| 535 | IPC::MessageWithReply<IPC_TUPLE_IN_##in_cnt in_list, \ |
| 536 | IPC_TUPLE_OUT_##out_cnt out_list> \ |
| 537 | (routing_id, ID, \ |
| 538 | IPC_NAME_IN_##in_cnt in_list, \ |
| 539 | IPC_NAME_OUT_##out_cnt out_list) \ |
| 540 | {} \ |
| 541 | msg_class::~msg_class() {} |
| 542 | |
| 543 | #define IPC_EMPTY_MESSAGE_LOG(msg_class) |
| 544 | |
| 545 | #define IPC_ASYNC_MESSAGE_LOG(msg_class) \ |
| 546 | void msg_class::Log(std::string* name, \ |
| 547 | const Message* msg, \ |
| 548 | std::string* l) { \ |
| 549 | if (name) \ |
| 550 | *name = #msg_class; \ |
| 551 | if (!msg || !l) \ |
| 552 | return; \ |
| 553 | Param p; \ |
| 554 | if (Read(msg, &p)) \ |
| 555 | IPC::LogParam(p, l); \ |
| 556 | } |
| 557 | |
| 558 | #define IPC_SYNC_MESSAGE_LOG(msg_class) \ |
| 559 | void msg_class::Log(std::string* name, \ |
| 560 | const Message* msg, \ |
| 561 | std::string* l) { \ |
| 562 | if (name) \ |
| 563 | *name = #msg_class; \ |
| 564 | if (!msg || !l) \ |
| 565 | return; \ |
| 566 | if (msg->is_sync()) { \ |
| 567 | TupleTypes<SendParam>::ValueTuple p; \ |
| 568 | if (ReadSendParam(msg, &p)) \ |
| 569 | IPC::LogParam(p, l); \ |
| 570 | AddOutputParamsToLog(msg, l); \ |
| 571 | } else { \ |
| 572 | TupleTypes<ReplyParam>::ValueTuple p; \ |
| 573 | if (ReadReplyParam(msg, &p)) \ |
| 574 | IPC::LogParam(p, l); \ |
| 575 | } \ |
| 576 | } |
| 577 | |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 578 | #elif defined(IPC_MESSAGE_MACROS_LOG_ENABLED) |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 579 | |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 580 | #ifndef IPC_LOG_TABLE_CREATED |
| 581 | #define IPC_LOG_TABLE_CREATED |
[email protected] | 82e5ee8 | 2009-04-03 02:29:45 | [diff] [blame] | 582 | |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 583 | #include "base/hash_tables.h" |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 584 | |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 585 | typedef void (*LogFunction)(std::string* name, |
| 586 | const IPC::Message* msg, |
| 587 | std::string* params); |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 588 | |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 589 | typedef base::hash_map<uint32, LogFunction > LogFunctionMap; |
| 590 | LogFunctionMap g_log_function_mapping; |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 591 | |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 592 | #endif // IPC_LOG_TABLE_CREATED |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 593 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 594 | // "Log table" inclusion produces extra logging registration code. |
| 595 | #define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \ |
| 596 | in_cnt, out_cnt, in_list, out_list) \ |
| 597 | class LoggerRegisterHelper##msg_class { \ |
| 598 | public: \ |
| 599 | LoggerRegisterHelper##msg_class() { \ |
| 600 | g_log_function_mapping[msg_class::ID] = msg_class::Log; \ |
| 601 | } \ |
| 602 | }; \ |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 603 | LoggerRegisterHelper##msg_class g_LoggerRegisterHelper##msg_class; |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 604 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 605 | #else |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 606 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 607 | // Normal inclusion produces nothing extra. |
| 608 | #define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \ |
| 609 | in_cnt, out_cnt, in_list, out_list) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 610 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 611 | #endif // defined(IPC_MESSAGE_IMPL) |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 612 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 613 | // Handle variable sized argument lists. These are usually invoked by token |
| 614 | // pasting against the argument counts. |
| 615 | #define IPC_TYPE_IN_0() |
| 616 | #define IPC_TYPE_IN_1(t1) const t1& arg1 |
| 617 | #define IPC_TYPE_IN_2(t1, t2) const t1& arg1, const t2& arg2 |
| 618 | #define IPC_TYPE_IN_3(t1, t2, t3) const t1& arg1, const t2& arg2, const t3& arg3 |
| 619 | #define IPC_TYPE_IN_4(t1, t2, t3, t4) const t1& arg1, const t2& arg2, const t3& arg3, const t4& arg4 |
| 620 | #define IPC_TYPE_IN_5(t1, t2, t3, t4, t5) const t1& arg1, const t2& arg2, const t3& arg3, const t4& arg4, const t5& arg5 |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 621 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 622 | #define IPC_TYPE_OUT_0() |
| 623 | #define IPC_TYPE_OUT_1(t1) t1* arg6 |
| 624 | #define IPC_TYPE_OUT_2(t1, t2) t1* arg6, t2* arg7 |
| 625 | #define IPC_TYPE_OUT_3(t1, t2, t3) t1* arg6, t2* arg7, t3* arg8 |
| 626 | #define IPC_TYPE_OUT_4(t1, t2, t3, t4) t1* arg6, t2* arg7, t3* arg8, t4* arg9 |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 627 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 628 | #define IPC_TUPLE_IN_0() Tuple0 |
| 629 | #define IPC_TUPLE_IN_1(t1) Tuple1<t1> |
| 630 | #define IPC_TUPLE_IN_2(t1, t2) Tuple2<t1, t2> |
| 631 | #define IPC_TUPLE_IN_3(t1, t2, t3) Tuple3<t1, t2, t3> |
| 632 | #define IPC_TUPLE_IN_4(t1, t2, t3, t4) Tuple4<t1, t2, t3, t4> |
| 633 | #define IPC_TUPLE_IN_5(t1, t2, t3, t4, t5) Tuple5<t1, t2, t3, t4, t5> |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 634 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 635 | #define IPC_TUPLE_OUT_0() Tuple0 |
| 636 | #define IPC_TUPLE_OUT_1(t1) Tuple1<t1&> |
| 637 | #define IPC_TUPLE_OUT_2(t1, t2) Tuple2<t1&, t2&> |
| 638 | #define IPC_TUPLE_OUT_3(t1, t2, t3) Tuple3<t1&, t2&, t3&> |
| 639 | #define IPC_TUPLE_OUT_4(t1, t2, t3, t4) Tuple4<t1&, t2&, t3&, t4&> |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 640 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 641 | #define IPC_NAME_IN_0() MakeTuple() |
| 642 | #define IPC_NAME_IN_1(t1) MakeRefTuple(arg1) |
| 643 | #define IPC_NAME_IN_2(t1, t2) MakeRefTuple(arg1, arg2) |
| 644 | #define IPC_NAME_IN_3(t1, t2, t3) MakeRefTuple(arg1, arg2, arg3) |
| 645 | #define IPC_NAME_IN_4(t1, t2, t3, t4) MakeRefTuple(arg1, arg2, arg3, arg4) |
| 646 | #define IPC_NAME_IN_5(t1, t2, t3, t4, t5) MakeRefTuple(arg1, arg2, arg3, arg4, arg5) |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 647 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 648 | #define IPC_NAME_OUT_0() MakeTuple() |
| 649 | #define IPC_NAME_OUT_1(t1) MakeRefTuple(*arg6) |
| 650 | #define IPC_NAME_OUT_2(t1, t2) MakeRefTuple(*arg6, *arg7) |
| 651 | #define IPC_NAME_OUT_3(t1, t2, t3) MakeRefTuple(*arg6, *arg7, *arg8) |
| 652 | #define IPC_NAME_OUT_4(t1, t2, t3, t4) MakeRefTuple(*arg6, *arg7, *arg8, *arg9) |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 653 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 654 | // There are places where the syntax requires a comma if there are input args, |
| 655 | // if there are input args and output args, or if there are input args or |
| 656 | // output args. These macros allow generation of the comma as needed; invoke |
| 657 | // by token pasting against the argument counts. |
| 658 | #define IPC_COMMA_0 |
| 659 | #define IPC_COMMA_1 , |
| 660 | #define IPC_COMMA_2 , |
| 661 | #define IPC_COMMA_3 , |
| 662 | #define IPC_COMMA_4 , |
| 663 | #define IPC_COMMA_5 , |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 664 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 665 | #define IPC_COMMA_AND_0(x) |
| 666 | #define IPC_COMMA_AND_1(x) x |
| 667 | #define IPC_COMMA_AND_2(x) x |
| 668 | #define IPC_COMMA_AND_3(x) x |
| 669 | #define IPC_COMMA_AND_4(x) x |
| 670 | #define IPC_COMMA_AND_5(x) x |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 671 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 672 | #define IPC_COMMA_OR_0(x) x |
| 673 | #define IPC_COMMA_OR_1(x) , |
| 674 | #define IPC_COMMA_OR_2(x) , |
| 675 | #define IPC_COMMA_OR_3(x) , |
| 676 | #define IPC_COMMA_OR_4(x) , |
| 677 | #define IPC_COMMA_OR_5(x) , |
[email protected] | 6d8ffc9f | 2010-03-12 18:27:53 | [diff] [blame] | 678 | |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 679 | // Message IDs |
| 680 | // Note: we currently use __LINE__ to give unique IDs to messages within |
| 681 | // a file. They're globally unique since each file defines its own |
| 682 | // IPC_MESSAGE_START. Ideally, we wouldn't use line numbers (a possibility |
| 683 | // is to instead use the __COUNTER__ macro, but it needs gcc 4.3 and xcode |
| 684 | // doesn't use it yet). |
| 685 | #define IPC_MESSAGE_ID() ((IPC_MESSAGE_START << 16) + __LINE__) |
| 686 | #define IPC_MESSAGE_ID_CLASS(id) ((id) >> 16) |
| 687 | #define IPC_MESSAGE_ID_LINE(id) ((id) & 0xffff) |
| 688 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 689 | // Message crackers and handlers. |
| 690 | // Prefer to use the IPC_BEGIN_MESSAGE_MAP_EX to the older macros since they |
| 691 | // allow you to detect when a message could not be de-serialized. Usage: |
| 692 | // |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 693 | // bool MyClass::OnMessageReceived(const IPC::Message& msg) { |
| 694 | // bool handled = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 695 | // bool msg_is_good = false; |
| 696 | // IPC_BEGIN_MESSAGE_MAP_EX(MyClass, msg, msg_is_good) |
| 697 | // IPC_MESSAGE_HANDLER(MsgClassOne, OnMsgClassOne) |
| 698 | // ...more handlers here ... |
| 699 | // IPC_MESSAGE_HANDLER(MsgClassTen, OnMsgClassTen) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 700 | // IPC_MESSAGE_UNHANDLED(handled = false) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 701 | // IPC_END_MESSAGE_MAP_EX() |
| 702 | // if (!msg_is_good) { |
| 703 | // // Signal error here or terminate offending process. |
| 704 | // } |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 705 | // return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 706 | // } |
| 707 | |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 708 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 709 | #define IPC_BEGIN_MESSAGE_MAP_EX(class_name, msg, msg_is_ok) \ |
| 710 | { \ |
| 711 | typedef class_name _IpcMessageHandlerClass; \ |
| 712 | const IPC::Message& ipc_message__ = msg; \ |
| 713 | bool& msg_is_ok__ = msg_is_ok; \ |
| 714 | switch (ipc_message__.type()) { \ |
| 715 | |
| 716 | #define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \ |
| 717 | { \ |
| 718 | typedef class_name _IpcMessageHandlerClass; \ |
| 719 | const IPC::Message& ipc_message__ = msg; \ |
| 720 | bool msg_is_ok__ = true; \ |
| 721 | switch (ipc_message__.type()) { \ |
| 722 | |
| 723 | #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \ |
| 724 | case msg_class::ID: \ |
[email protected] | 6541227 | 2010-12-21 20:03:24 | [diff] [blame] | 725 | msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, &member_func); \ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 726 | break; |
| 727 | |
| 728 | #define IPC_MESSAGE_HANDLER(msg_class, member_func) \ |
| 729 | IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func) |
| 730 | |
| 731 | #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \ |
| 732 | case msg_class::ID: \ |
[email protected] | 1e927691 | 2011-03-31 09:55:58 | [diff] [blame] | 733 | msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, &member_func); \ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 734 | break; |
| 735 | |
| 736 | #define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \ |
[email protected] | 751bf4b | 2010-11-05 22:06:31 | [diff] [blame] | 737 | IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \ |
| 738 | _IpcMessageHandlerClass::member_func) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 739 | |
| 740 | #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \ |
| 741 | case msg_class::ID: \ |
| 742 | code; \ |
| 743 | break; |
| 744 | |
| 745 | #define IPC_REPLY_HANDLER(func) \ |
| 746 | case IPC_REPLY_ID: \ |
| 747 | func(ipc_message__); \ |
| 748 | break; |
| 749 | |
| 750 | |
| 751 | #define IPC_MESSAGE_UNHANDLED(code) \ |
| 752 | default: \ |
| 753 | code; \ |
| 754 | break; |
| 755 | |
| 756 | #define IPC_MESSAGE_UNHANDLED_ERROR() \ |
| 757 | IPC_MESSAGE_UNHANDLED(NOTREACHED() << \ |
| 758 | "Invalid message with type = " << \ |
| 759 | ipc_message__.type()) |
| 760 | |
| 761 | #define IPC_END_MESSAGE_MAP() \ |
| 762 | DCHECK(msg_is_ok__); \ |
| 763 | } \ |
| 764 | } |
| 765 | |
| 766 | #define IPC_END_MESSAGE_MAP_EX() \ |
| 767 | } \ |
[email protected] | 8d70d5f | 2010-12-08 23:41:08 | [diff] [blame] | 768 | } |
[email protected] | 9f547bf | 2010-12-13 17:00:42 | [diff] [blame] | 769 | |
| 770 | // This corresponds to an enum value from IPCMessageStart. |
| 771 | #define IPC_MESSAGE_CLASS(message) \ |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 772 | IPC_MESSAGE_ID_CLASS(message.type()) |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 773 | |
| 774 | #endif // IPC_IPC_MESSAGE_MACROS_H_ |
| 775 | |
| 776 | // Clean up IPC_MESSAGE_START in this unguarded section so that the |
| 777 | // XXX_messages.h files need not do so themselves. This makes the |
| 778 | // XXX_messages.h files easier to write. |
| 779 | #undef IPC_MESSAGE_START |