[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 |
[email protected] | e86a255 | 2011-11-11 00:21:02 | [diff] [blame^] | 23 | // XXX_messages.h file before invoking message declaration macros: |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 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 |
[email protected] | 7f99418 | 2011-08-23 10:18:10 | [diff] [blame] | 153 | // until a reply comes back. To declare a sync message, use the IPC_SYNC_ |
| 154 | // macros. The numbers at the end show how many input/output parameters there |
| 155 | // are (i.e. 1_2 is 1 in, 2 out). Input parameters are first, followed by |
| 156 | // output parameters. The caller uses Send([route id, ], in1, &out1, &out2). |
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] | e86a255 | 2011-11-11 00:21:02 | [diff] [blame^] | 179 | #include "base/profiler/scoped_profile.h" |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 180 | #include "ipc/ipc_message_utils.h" |
| 181 | #include "ipc/param_traits_macros.h" |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 182 | |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 183 | #if defined(IPC_MESSAGE_IMPL) |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 184 | #include "ipc/ipc_message_utils_impl.h" |
| 185 | #endif |
| 186 | |
[email protected] | 50473c1 | 2011-09-06 22:51:11 | [diff] [blame] | 187 | // Override this to force message classes to be exported. |
| 188 | #ifndef IPC_MESSAGE_EXPORT |
| 189 | #define IPC_MESSAGE_EXPORT |
| 190 | #endif |
| 191 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 192 | // Macros for defining structs. May be subsequently redefined. |
| 193 | #define IPC_STRUCT_BEGIN(struct_name) \ |
| 194 | struct struct_name; \ |
| 195 | IPC_STRUCT_TRAITS_BEGIN(struct_name) \ |
| 196 | IPC_STRUCT_TRAITS_END() \ |
[email protected] | 50473c1 | 2011-09-06 22:51:11 | [diff] [blame] | 197 | struct IPC_MESSAGE_EXPORT struct_name : IPC::NoParams { \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 198 | struct_name(); \ |
| 199 | ~struct_name(); |
| 200 | #define IPC_STRUCT_MEMBER(type, name) type name; |
| 201 | #define IPC_STRUCT_END() }; |
| 202 | |
| 203 | // Message macros collect specific numbers of arguments and funnel them into |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 204 | // the common message generation macro. These should never be redefined. |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 205 | #define IPC_MESSAGE_CONTROL0(msg_class) \ |
| 206 | IPC_MESSAGE_DECL(EMPTY, CONTROL, msg_class, 0, 0, (), ()) |
| 207 | |
| 208 | #define IPC_MESSAGE_CONTROL1(msg_class, type1) \ |
| 209 | IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 1, 0, (type1), ()) |
| 210 | |
| 211 | #define IPC_MESSAGE_CONTROL2(msg_class, type1, type2) \ |
| 212 | IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 2, 0, (type1, type2), ()) |
| 213 | |
| 214 | #define IPC_MESSAGE_CONTROL3(msg_class, type1, type2, type3) \ |
| 215 | IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 3, 0, (type1, type2, type3), ()) |
| 216 | |
| 217 | #define IPC_MESSAGE_CONTROL4(msg_class, type1, type2, type3, type4) \ |
| 218 | IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 4, 0, (type1, type2, type3, type4), ()) |
| 219 | |
| 220 | #define IPC_MESSAGE_CONTROL5(msg_class, type1, type2, type3, type4, type5) \ |
| 221 | IPC_MESSAGE_DECL(ASYNC, CONTROL, msg_class, 5, 0, (type1, type2, type3, type4, type5), ()) |
| 222 | |
| 223 | #define IPC_MESSAGE_ROUTED0(msg_class) \ |
| 224 | IPC_MESSAGE_DECL(EMPTY, ROUTED, msg_class, 0, 0, (), ()) |
| 225 | |
| 226 | #define IPC_MESSAGE_ROUTED1(msg_class, type1) \ |
| 227 | IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 1, 0, (type1), ()) |
| 228 | |
| 229 | #define IPC_MESSAGE_ROUTED2(msg_class, type1, type2) \ |
| 230 | IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 2, 0, (type1, type2), ()) |
| 231 | |
| 232 | #define IPC_MESSAGE_ROUTED3(msg_class, type1, type2, type3) \ |
| 233 | IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 3, 0, (type1, type2, type3), ()) |
| 234 | |
| 235 | #define IPC_MESSAGE_ROUTED4(msg_class, type1, type2, type3, type4) \ |
| 236 | IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 4, 0, (type1, type2, type3, type4), ()) |
| 237 | |
| 238 | #define IPC_MESSAGE_ROUTED5(msg_class, type1, type2, type3, type4, type5) \ |
| 239 | IPC_MESSAGE_DECL(ASYNC, ROUTED, msg_class, 5, 0, (type1, type2, type3, type4, type5), ()) |
| 240 | |
| 241 | #define IPC_SYNC_MESSAGE_CONTROL0_0(msg_class) \ |
| 242 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 0, (), ()) |
| 243 | |
| 244 | #define IPC_SYNC_MESSAGE_CONTROL0_1(msg_class, type1_out) \ |
| 245 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 1, (), (type1_out)) |
| 246 | |
| 247 | #define IPC_SYNC_MESSAGE_CONTROL0_2(msg_class, type1_out, type2_out) \ |
| 248 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 2, (), (type1_out, type2_out)) |
| 249 | |
| 250 | #define IPC_SYNC_MESSAGE_CONTROL0_3(msg_class, type1_out, type2_out, type3_out) \ |
| 251 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 3, (), (type1_out, type2_out, type3_out)) |
| 252 | |
| 253 | #define IPC_SYNC_MESSAGE_CONTROL0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \ |
| 254 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out)) |
| 255 | |
| 256 | #define IPC_SYNC_MESSAGE_CONTROL1_0(msg_class, type1_in) \ |
| 257 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 0, (type1_in), ()) |
| 258 | |
| 259 | #define IPC_SYNC_MESSAGE_CONTROL1_1(msg_class, type1_in, type1_out) \ |
| 260 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 1, (type1_in), (type1_out)) |
| 261 | |
| 262 | #define IPC_SYNC_MESSAGE_CONTROL1_2(msg_class, type1_in, type1_out, type2_out) \ |
| 263 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 2, (type1_in), (type1_out, type2_out)) |
| 264 | |
| 265 | #define IPC_SYNC_MESSAGE_CONTROL1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \ |
| 266 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out)) |
| 267 | |
| 268 | #define IPC_SYNC_MESSAGE_CONTROL1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \ |
| 269 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out)) |
| 270 | |
| 271 | #define IPC_SYNC_MESSAGE_CONTROL2_0(msg_class, type1_in, type2_in) \ |
| 272 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 0, (type1_in, type2_in), ()) |
| 273 | |
| 274 | #define IPC_SYNC_MESSAGE_CONTROL2_1(msg_class, type1_in, type2_in, type1_out) \ |
| 275 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 1, (type1_in, type2_in), (type1_out)) |
| 276 | |
| 277 | #define IPC_SYNC_MESSAGE_CONTROL2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \ |
| 278 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out)) |
| 279 | |
| 280 | #define IPC_SYNC_MESSAGE_CONTROL2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \ |
| 281 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out)) |
| 282 | |
| 283 | #define IPC_SYNC_MESSAGE_CONTROL2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \ |
| 284 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out)) |
| 285 | |
| 286 | #define IPC_SYNC_MESSAGE_CONTROL3_0(msg_class, type1_in, type2_in, type3_in) \ |
| 287 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 0, (type1_in, type2_in, type3_in), ()) |
| 288 | |
| 289 | #define IPC_SYNC_MESSAGE_CONTROL3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \ |
| 290 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out)) |
| 291 | |
| 292 | #define IPC_SYNC_MESSAGE_CONTROL3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \ |
| 293 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out)) |
| 294 | |
| 295 | #define IPC_SYNC_MESSAGE_CONTROL3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \ |
| 296 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out)) |
| 297 | |
| 298 | #define IPC_SYNC_MESSAGE_CONTROL3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \ |
| 299 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out)) |
| 300 | |
| 301 | #define IPC_SYNC_MESSAGE_CONTROL4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \ |
| 302 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 0, (type1_in, type2_in, type3_in, type4_in), ()) |
| 303 | |
| 304 | #define IPC_SYNC_MESSAGE_CONTROL4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \ |
| 305 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out)) |
| 306 | |
| 307 | #define IPC_SYNC_MESSAGE_CONTROL4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \ |
| 308 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out)) |
| 309 | |
| 310 | #define IPC_SYNC_MESSAGE_CONTROL4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \ |
| 311 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out)) |
| 312 | |
| 313 | #define IPC_SYNC_MESSAGE_CONTROL4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \ |
| 314 | 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)) |
| 315 | |
| 316 | #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] | 317 | 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] | 318 | |
| 319 | #define IPC_SYNC_MESSAGE_CONTROL5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \ |
| 320 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out)) |
| 321 | |
| 322 | #define IPC_SYNC_MESSAGE_CONTROL5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \ |
| 323 | IPC_MESSAGE_DECL(SYNC, CONTROL, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out)) |
| 324 | |
| 325 | #define IPC_SYNC_MESSAGE_CONTROL5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \ |
| 326 | 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)) |
| 327 | |
| 328 | #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) \ |
| 329 | 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)) |
| 330 | |
| 331 | #define IPC_SYNC_MESSAGE_ROUTED0_0(msg_class) \ |
| 332 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 0, (), ()) |
| 333 | |
| 334 | #define IPC_SYNC_MESSAGE_ROUTED0_1(msg_class, type1_out) \ |
| 335 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 1, (), (type1_out)) |
| 336 | |
| 337 | #define IPC_SYNC_MESSAGE_ROUTED0_2(msg_class, type1_out, type2_out) \ |
| 338 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 2, (), (type1_out, type2_out)) |
| 339 | |
| 340 | #define IPC_SYNC_MESSAGE_ROUTED0_3(msg_class, type1_out, type2_out, type3_out) \ |
| 341 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 3, (), (type1_out, type2_out, type3_out)) |
| 342 | |
| 343 | #define IPC_SYNC_MESSAGE_ROUTED0_4(msg_class, type1_out, type2_out, type3_out, type4_out) \ |
| 344 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 0, 4, (), (type1_out, type2_out, type3_out, type4_out)) |
| 345 | |
| 346 | #define IPC_SYNC_MESSAGE_ROUTED1_0(msg_class, type1_in) \ |
| 347 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 0, (type1_in), ()) |
| 348 | |
| 349 | #define IPC_SYNC_MESSAGE_ROUTED1_1(msg_class, type1_in, type1_out) \ |
| 350 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 1, (type1_in), (type1_out)) |
| 351 | |
| 352 | #define IPC_SYNC_MESSAGE_ROUTED1_2(msg_class, type1_in, type1_out, type2_out) \ |
| 353 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 2, (type1_in), (type1_out, type2_out)) |
| 354 | |
| 355 | #define IPC_SYNC_MESSAGE_ROUTED1_3(msg_class, type1_in, type1_out, type2_out, type3_out) \ |
| 356 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 3, (type1_in), (type1_out, type2_out, type3_out)) |
| 357 | |
| 358 | #define IPC_SYNC_MESSAGE_ROUTED1_4(msg_class, type1_in, type1_out, type2_out, type3_out, type4_out) \ |
| 359 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 1, 4, (type1_in), (type1_out, type2_out, type3_out, type4_out)) |
| 360 | |
| 361 | #define IPC_SYNC_MESSAGE_ROUTED2_0(msg_class, type1_in, type2_in) \ |
| 362 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 0, (type1_in, type2_in), ()) |
| 363 | |
| 364 | #define IPC_SYNC_MESSAGE_ROUTED2_1(msg_class, type1_in, type2_in, type1_out) \ |
| 365 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 1, (type1_in, type2_in), (type1_out)) |
| 366 | |
| 367 | #define IPC_SYNC_MESSAGE_ROUTED2_2(msg_class, type1_in, type2_in, type1_out, type2_out) \ |
| 368 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 2, (type1_in, type2_in), (type1_out, type2_out)) |
| 369 | |
| 370 | #define IPC_SYNC_MESSAGE_ROUTED2_3(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out) \ |
| 371 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 3, (type1_in, type2_in), (type1_out, type2_out, type3_out)) |
| 372 | |
| 373 | #define IPC_SYNC_MESSAGE_ROUTED2_4(msg_class, type1_in, type2_in, type1_out, type2_out, type3_out, type4_out) \ |
| 374 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 2, 4, (type1_in, type2_in), (type1_out, type2_out, type3_out, type4_out)) |
| 375 | |
| 376 | #define IPC_SYNC_MESSAGE_ROUTED3_0(msg_class, type1_in, type2_in, type3_in) \ |
| 377 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 0, (type1_in, type2_in, type3_in), ()) |
| 378 | |
| 379 | #define IPC_SYNC_MESSAGE_ROUTED3_1(msg_class, type1_in, type2_in, type3_in, type1_out) \ |
| 380 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 1, (type1_in, type2_in, type3_in), (type1_out)) |
| 381 | |
| 382 | #define IPC_SYNC_MESSAGE_ROUTED3_2(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out) \ |
| 383 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 2, (type1_in, type2_in, type3_in), (type1_out, type2_out)) |
| 384 | |
| 385 | #define IPC_SYNC_MESSAGE_ROUTED3_3(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out) \ |
| 386 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 3, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out)) |
| 387 | |
| 388 | #define IPC_SYNC_MESSAGE_ROUTED3_4(msg_class, type1_in, type2_in, type3_in, type1_out, type2_out, type3_out, type4_out) \ |
| 389 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 3, 4, (type1_in, type2_in, type3_in), (type1_out, type2_out, type3_out, type4_out)) |
| 390 | |
| 391 | #define IPC_SYNC_MESSAGE_ROUTED4_0(msg_class, type1_in, type2_in, type3_in, type4_in) \ |
| 392 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), ()) |
| 393 | |
| 394 | #define IPC_SYNC_MESSAGE_ROUTED4_1(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out) \ |
| 395 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 1, (type1_in, type2_in, type3_in, type4_in), (type1_out)) |
| 396 | |
| 397 | #define IPC_SYNC_MESSAGE_ROUTED4_2(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out) \ |
| 398 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 2, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out)) |
| 399 | |
| 400 | #define IPC_SYNC_MESSAGE_ROUTED4_3(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out) \ |
| 401 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 4, 3, (type1_in, type2_in, type3_in, type4_in), (type1_out, type2_out, type3_out)) |
| 402 | |
| 403 | #define IPC_SYNC_MESSAGE_ROUTED4_4(msg_class, type1_in, type2_in, type3_in, type4_in, type1_out, type2_out, type3_out, type4_out) \ |
| 404 | 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)) |
| 405 | |
| 406 | #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] | 407 | 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] | 408 | |
| 409 | #define IPC_SYNC_MESSAGE_ROUTED5_1(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out) \ |
| 410 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 1, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out)) |
| 411 | |
| 412 | #define IPC_SYNC_MESSAGE_ROUTED5_2(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out) \ |
| 413 | IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 2, (type1_in, type2_in, type3_in, type4_in, type5_in), (type1_out, type2_out)) |
| 414 | |
| 415 | #define IPC_SYNC_MESSAGE_ROUTED5_3(msg_class, type1_in, type2_in, type3_in, type4_in, type5_in, type1_out, type2_out, type3_out) \ |
| 416 | 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)) |
| 417 | |
| 418 | #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) \ |
| 419 | 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)) |
| 420 | |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 421 | // The following macros define the common set of methods provided by ASYNC |
| 422 | // message classes. |
| 423 | #define IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
| 424 | template<class T, class S, class Method> \ |
| 425 | static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) { \ |
| 426 | Schema::Param p; \ |
| 427 | if (Read(msg, &p)) { \ |
| 428 | DispatchToMethod(obj, func, p); \ |
| 429 | return true; \ |
| 430 | } \ |
| 431 | return false; \ |
| 432 | } |
| 433 | #define IPC_ASYNC_MESSAGE_METHODS_1 \ |
| 434 | IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
| 435 | template<class T, class S, typename TA> \ |
| 436 | static bool Dispatch(const Message* msg, T* obj, S* sender, \ |
| 437 | void (T::*func)(const Message&, TA)) { \ |
| 438 | Schema::Param p; \ |
| 439 | if (Read(msg, &p)) { \ |
| 440 | (obj->*func)(*msg, p.a); \ |
| 441 | return true; \ |
| 442 | } \ |
| 443 | return false; \ |
| 444 | } |
| 445 | #define IPC_ASYNC_MESSAGE_METHODS_2 \ |
| 446 | IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
| 447 | template<class T, class S, typename TA, typename TB> \ |
| 448 | static bool Dispatch(const Message* msg, T* obj, S* sender, \ |
| 449 | void (T::*func)(const Message&, TA, TB)) { \ |
| 450 | Schema::Param p; \ |
| 451 | if (Read(msg, &p)) { \ |
| 452 | (obj->*func)(*msg, p.a, p.b); \ |
| 453 | return true; \ |
| 454 | } \ |
| 455 | return false; \ |
| 456 | } \ |
| 457 | template<typename TA, typename TB> \ |
| 458 | static bool Read(const IPC::Message* msg, TA* a, TB* b) { \ |
| 459 | Schema::Param p; \ |
| 460 | if (!Read(msg, &p)) \ |
| 461 | return false; \ |
| 462 | *a = p.a; \ |
| 463 | *b = p.b; \ |
| 464 | return true; \ |
| 465 | } |
| 466 | #define IPC_ASYNC_MESSAGE_METHODS_3 \ |
| 467 | IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
| 468 | template<class T, class S, typename TA, typename TB, typename TC> \ |
| 469 | static bool Dispatch(const Message* msg, T* obj, S* sender, \ |
| 470 | void (T::*func)(const Message&, TA, TB, TC)) { \ |
| 471 | Schema::Param p; \ |
| 472 | if (Read(msg, &p)) { \ |
| 473 | (obj->*func)(*msg, p.a, p.b, p.c); \ |
| 474 | return true; \ |
| 475 | } \ |
| 476 | return false; \ |
| 477 | } \ |
| 478 | template<typename TA, typename TB, typename TC> \ |
| 479 | static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c) { \ |
| 480 | Schema::Param p; \ |
| 481 | if (!Read(msg, &p)) \ |
| 482 | return false; \ |
| 483 | *a = p.a; \ |
| 484 | *b = p.b; \ |
| 485 | *c = p.c; \ |
| 486 | return true; \ |
| 487 | } |
| 488 | #define IPC_ASYNC_MESSAGE_METHODS_4 \ |
| 489 | IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
| 490 | template<class T, class S, typename TA, typename TB, typename TC, \ |
| 491 | typename TD> \ |
| 492 | static bool Dispatch(const Message* msg, T* obj, S* sender, \ |
| 493 | void (T::*func)(const Message&, TA, TB, TC, TD)) { \ |
| 494 | Schema::Param p; \ |
| 495 | if (Read(msg, &p)) { \ |
| 496 | (obj->*func)(*msg, p.a, p.b, p.c, p.d); \ |
| 497 | return true; \ |
| 498 | } \ |
| 499 | return false; \ |
| 500 | } \ |
| 501 | template<typename TA, typename TB, typename TC, typename TD> \ |
| 502 | static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d) { \ |
| 503 | Schema::Param p; \ |
| 504 | if (!Read(msg, &p)) \ |
| 505 | return false; \ |
| 506 | *a = p.a; \ |
| 507 | *b = p.b; \ |
| 508 | *c = p.c; \ |
| 509 | *d = p.d; \ |
| 510 | return true; \ |
| 511 | } |
| 512 | #define IPC_ASYNC_MESSAGE_METHODS_5 \ |
| 513 | IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
| 514 | template<class T, class S, typename TA, typename TB, typename TC, \ |
| 515 | typename TD, typename TE> \ |
| 516 | static bool Dispatch(const Message* msg, T* obj, S* sender, \ |
| 517 | void (T::*func)(const Message&, TA, TB, TC, TD, TE)) { \ |
| 518 | Schema::Param p; \ |
| 519 | if (Read(msg, &p)) { \ |
| 520 | (obj->*func)(*msg, p.a, p.b, p.c, p.d, p.e); \ |
| 521 | return true; \ |
| 522 | } \ |
| 523 | return false; \ |
| 524 | } \ |
| 525 | template<typename TA, typename TB, typename TC, typename TD, typename TE> \ |
| 526 | static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d, \ |
| 527 | TE* e) { \ |
| 528 | Schema::Param p; \ |
| 529 | if (!Read(msg, &p)) \ |
| 530 | return false; \ |
| 531 | *a = p.a; \ |
| 532 | *b = p.b; \ |
| 533 | *c = p.c; \ |
| 534 | *d = p.d; \ |
| 535 | *e = p.e; \ |
| 536 | return true; \ |
| 537 | } |
| 538 | |
| 539 | // The following macros define the common set of methods provided by SYNC |
| 540 | // message classes. |
| 541 | #define IPC_SYNC_MESSAGE_METHODS_GENERIC \ |
| 542 | template<class T, class S, class Method> \ |
| 543 | static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) { \ |
| 544 | Schema::SendParam send_params; \ |
| 545 | bool ok = ReadSendParam(msg, &send_params); \ |
| 546 | return Schema::DispatchWithSendParams(ok, send_params, msg, obj, sender, \ |
| 547 | func); \ |
| 548 | } \ |
| 549 | template<class T, class Method> \ |
| 550 | static bool DispatchDelayReply(const Message* msg, T* obj, Method func) { \ |
| 551 | Schema::SendParam send_params; \ |
| 552 | bool ok = ReadSendParam(msg, &send_params); \ |
| 553 | return Schema::DispatchDelayReplyWithSendParams(ok, send_params, msg, \ |
| 554 | obj, func); \ |
| 555 | } |
| 556 | #define IPC_SYNC_MESSAGE_METHODS_0 \ |
| 557 | IPC_SYNC_MESSAGE_METHODS_GENERIC |
| 558 | #define IPC_SYNC_MESSAGE_METHODS_1 \ |
| 559 | IPC_SYNC_MESSAGE_METHODS_GENERIC \ |
| 560 | template<typename TA> \ |
| 561 | static void WriteReplyParams(Message* reply, TA a) { \ |
| 562 | Schema::WriteReplyParams(reply, a); \ |
| 563 | } |
| 564 | #define IPC_SYNC_MESSAGE_METHODS_2 \ |
| 565 | IPC_SYNC_MESSAGE_METHODS_GENERIC \ |
| 566 | template<typename TA, typename TB> \ |
| 567 | static void WriteReplyParams(Message* reply, TA a, TB b) { \ |
| 568 | Schema::WriteReplyParams(reply, a, b); \ |
| 569 | } |
| 570 | #define IPC_SYNC_MESSAGE_METHODS_3 \ |
| 571 | IPC_SYNC_MESSAGE_METHODS_GENERIC \ |
| 572 | template<typename TA, typename TB, typename TC> \ |
| 573 | static void WriteReplyParams(Message* reply, TA a, TB b, TC c) { \ |
| 574 | Schema::WriteReplyParams(reply, a, b, c); \ |
| 575 | } |
| 576 | #define IPC_SYNC_MESSAGE_METHODS_4 \ |
| 577 | IPC_SYNC_MESSAGE_METHODS_GENERIC \ |
| 578 | template<typename TA, typename TB, typename TC, typename TD> \ |
| 579 | static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d) { \ |
| 580 | Schema::WriteReplyParams(reply, a, b, c, d); \ |
| 581 | } |
| 582 | #define IPC_SYNC_MESSAGE_METHODS_5 \ |
| 583 | IPC_SYNC_MESSAGE_METHODS_GENERIC \ |
| 584 | template<typename TA, typename TB, typename TC, typename TD, typename TE> \ |
| 585 | static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d, TE e) { \ |
| 586 | Schema::WriteReplyParams(reply, a, b, c, d, e); \ |
| 587 | } |
| 588 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 589 | // Common message macro which dispatches into one of the 6 (sync x kind) |
| 590 | // routines. There is a way that these 6 cases can be lumped together, |
| 591 | // but the macros get very complicated in that case. |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 592 | // Note: intended be redefined to generate other information. |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 593 | #define IPC_MESSAGE_DECL(sync, kind, msg_class, \ |
| 594 | in_cnt, out_cnt, in_list, out_list) \ |
| 595 | IPC_##sync##_##kind##_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 596 | IPC_MESSAGE_EXTRA(sync, kind, msg_class, in_cnt, out_cnt, in_list, out_list) |
| 597 | |
| 598 | #define IPC_EMPTY_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
[email protected] | 7b60496 | 2011-10-27 01:45:58 | [diff] [blame] | 599 | class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 600 | public: \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 601 | typedef IPC::Message Schema; \ |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 602 | enum { ID = IPC_MESSAGE_ID() }; \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 603 | msg_class() : IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) {} \ |
[email protected] | 8bf55ca | 2011-10-17 22:15:27 | [diff] [blame] | 604 | static void Log(std::string* name, const Message* msg, std::string* l); \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 605 | }; |
| 606 | |
| 607 | #define IPC_EMPTY_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
[email protected] | 7b60496 | 2011-10-27 01:45:58 | [diff] [blame] | 608 | class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 609 | public: \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 610 | typedef IPC::Message Schema; \ |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 611 | enum { ID = IPC_MESSAGE_ID() }; \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 612 | msg_class(int32 routing_id) \ |
| 613 | : IPC::Message(routing_id, ID, PRIORITY_NORMAL) {} \ |
[email protected] | 8bf55ca | 2011-10-17 22:15:27 | [diff] [blame] | 614 | static void Log(std::string* name, const Message* msg, std::string* l); \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 615 | }; |
| 616 | |
| 617 | #define IPC_ASYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 618 | class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 619 | public: \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 620 | typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \ |
| 621 | typedef Schema::Param Param; \ |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 622 | enum { ID = IPC_MESSAGE_ID() }; \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 623 | msg_class(IPC_TYPE_IN_##in_cnt in_list); \ |
[email protected] | 3690ebe0 | 2011-05-25 09:08:19 | [diff] [blame] | 624 | virtual ~msg_class(); \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 625 | static bool Read(const Message* msg, Schema::Param* p); \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 626 | static void Log(std::string* name, const Message* msg, std::string* l); \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 627 | IPC_ASYNC_MESSAGE_METHODS_##in_cnt \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 628 | }; |
| 629 | |
| 630 | #define IPC_ASYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 631 | class IPC_MESSAGE_EXPORT msg_class : public IPC::Message { \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 632 | public: \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 633 | typedef IPC::MessageSchema<IPC_TUPLE_IN_##in_cnt in_list> Schema; \ |
| 634 | typedef Schema::Param Param; \ |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 635 | enum { ID = IPC_MESSAGE_ID() }; \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 636 | msg_class(int32 routing_id IPC_COMMA_##in_cnt \ |
| 637 | IPC_TYPE_IN_##in_cnt in_list); \ |
[email protected] | 3690ebe0 | 2011-05-25 09:08:19 | [diff] [blame] | 638 | virtual ~msg_class(); \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 639 | static bool Read(const Message* msg, Schema::Param* p); \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 640 | static void Log(std::string* name, const Message* msg, std::string* l); \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 641 | IPC_ASYNC_MESSAGE_METHODS_##in_cnt \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 642 | }; |
| 643 | |
| 644 | #define IPC_SYNC_CONTROL_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 645 | class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 646 | public: \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 647 | typedef IPC::SyncMessageSchema<IPC_TUPLE_IN_##in_cnt in_list, \ |
| 648 | IPC_TUPLE_OUT_##out_cnt out_list> Schema; \ |
| 649 | typedef Schema::ReplyParam ReplyParam; \ |
| 650 | typedef Schema::SendParam SendParam; \ |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 651 | enum { ID = IPC_MESSAGE_ID() }; \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 652 | msg_class(IPC_TYPE_IN_##in_cnt in_list \ |
| 653 | IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \ |
| 654 | IPC_TYPE_OUT_##out_cnt out_list); \ |
[email protected] | 3690ebe0 | 2011-05-25 09:08:19 | [diff] [blame] | 655 | virtual ~msg_class(); \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 656 | static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \ |
| 657 | static bool ReadReplyParam( \ |
| 658 | const Message* msg, \ |
| 659 | TupleTypes<ReplyParam>::ValueTuple* p); \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 660 | static void Log(std::string* name, const Message* msg, std::string* l); \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 661 | IPC_SYNC_MESSAGE_METHODS_##out_cnt \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 662 | }; |
| 663 | |
| 664 | #define IPC_SYNC_ROUTED_DECL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 665 | class IPC_MESSAGE_EXPORT msg_class : public IPC::SyncMessage { \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 666 | public: \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 667 | typedef IPC::SyncMessageSchema<IPC_TUPLE_IN_##in_cnt in_list, \ |
| 668 | IPC_TUPLE_OUT_##out_cnt out_list> Schema; \ |
| 669 | typedef Schema::ReplyParam ReplyParam; \ |
| 670 | typedef Schema::SendParam SendParam; \ |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 671 | enum { ID = IPC_MESSAGE_ID() }; \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 672 | msg_class(int32 routing_id \ |
| 673 | IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \ |
| 674 | IPC_TYPE_IN_##in_cnt in_list \ |
| 675 | IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \ |
| 676 | IPC_TYPE_OUT_##out_cnt out_list); \ |
[email protected] | 3690ebe0 | 2011-05-25 09:08:19 | [diff] [blame] | 677 | virtual ~msg_class(); \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 678 | static bool ReadSendParam(const Message* msg, Schema::SendParam* p); \ |
| 679 | static bool ReadReplyParam( \ |
| 680 | const Message* msg, \ |
| 681 | TupleTypes<ReplyParam>::ValueTuple* p); \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 682 | static void Log(std::string* name, const Message* msg, std::string* l); \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 683 | IPC_SYNC_MESSAGE_METHODS_##out_cnt \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 684 | }; |
| 685 | |
| 686 | #if defined(IPC_MESSAGE_IMPL) |
| 687 | |
| 688 | // "Implementation" inclusion produces constructors, destructors, and |
| 689 | // logging functions, except for the no-arg special cases, where the |
| 690 | // implementation occurs in the declaration, and there is no special |
| 691 | // logging function. |
| 692 | #define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \ |
| 693 | in_cnt, out_cnt, in_list, out_list) \ |
| 694 | IPC_##sync##_##kind##_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 695 | IPC_##sync##_MESSAGE_LOG(msg_class) |
| 696 | |
| 697 | #define IPC_EMPTY_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) |
| 698 | #define IPC_EMPTY_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) |
| 699 | |
| 700 | #define IPC_ASYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 701 | msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list) : \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 702 | IPC::Message(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL) { \ |
| 703 | Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \ |
| 704 | } \ |
| 705 | msg_class::~msg_class() {} \ |
| 706 | bool msg_class::Read(const Message* msg, Schema::Param* p) { \ |
| 707 | return Schema::Read(msg, p); \ |
| 708 | } |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 709 | |
| 710 | #define IPC_ASYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 711 | msg_class::msg_class(int32 routing_id IPC_COMMA_##in_cnt \ |
| 712 | IPC_TYPE_IN_##in_cnt in_list) : \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 713 | IPC::Message(routing_id, ID, PRIORITY_NORMAL) { \ |
| 714 | Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \ |
| 715 | } \ |
| 716 | msg_class::~msg_class() {} \ |
| 717 | bool msg_class::Read(const Message* msg, Schema::Param* p) { \ |
| 718 | return Schema::Read(msg, p); \ |
| 719 | } |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 720 | |
| 721 | #define IPC_SYNC_CONTROL_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 722 | msg_class::msg_class(IPC_TYPE_IN_##in_cnt in_list \ |
| 723 | IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \ |
| 724 | IPC_TYPE_OUT_##out_cnt out_list) : \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 725 | IPC::SyncMessage(MSG_ROUTING_CONTROL, ID, PRIORITY_NORMAL, \ |
| 726 | new IPC::ParamDeserializer<Schema::ReplyParam>( \ |
| 727 | IPC_NAME_OUT_##out_cnt out_list)) { \ |
| 728 | Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \ |
| 729 | } \ |
| 730 | msg_class::~msg_class() {} \ |
| 731 | bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \ |
| 732 | return Schema::ReadSendParam(msg, p); \ |
| 733 | } \ |
| 734 | bool msg_class::ReadReplyParam(const Message* msg, \ |
| 735 | TupleTypes<ReplyParam>::ValueTuple* p) { \ |
| 736 | return Schema::ReadReplyParam(msg, p); \ |
| 737 | } |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 738 | |
| 739 | #define IPC_SYNC_ROUTED_IMPL(msg_class, in_cnt, out_cnt, in_list, out_list) \ |
| 740 | msg_class::msg_class(int32 routing_id \ |
| 741 | IPC_COMMA_OR_##in_cnt(IPC_COMMA_##out_cnt) \ |
| 742 | IPC_TYPE_IN_##in_cnt in_list \ |
| 743 | IPC_COMMA_AND_##in_cnt(IPC_COMMA_##out_cnt) \ |
| 744 | IPC_TYPE_OUT_##out_cnt out_list) : \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 745 | IPC::SyncMessage(routing_id, ID, PRIORITY_NORMAL, \ |
| 746 | new IPC::ParamDeserializer<Schema::ReplyParam>( \ |
| 747 | IPC_NAME_OUT_##out_cnt out_list)) { \ |
| 748 | Schema::Write(this, IPC_NAME_IN_##in_cnt in_list); \ |
| 749 | } \ |
| 750 | msg_class::~msg_class() {} \ |
| 751 | bool msg_class::ReadSendParam(const Message* msg, Schema::SendParam* p) { \ |
| 752 | return Schema::ReadSendParam(msg, p); \ |
| 753 | } \ |
| 754 | bool msg_class::ReadReplyParam(const Message* msg, \ |
| 755 | TupleTypes<ReplyParam>::ValueTuple* p) { \ |
| 756 | return Schema::ReadReplyParam(msg, p); \ |
| 757 | } |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 758 | |
[email protected] | 8bf55ca | 2011-10-17 22:15:27 | [diff] [blame] | 759 | #define IPC_EMPTY_MESSAGE_LOG(msg_class) \ |
| 760 | void msg_class::Log(std::string* name, \ |
| 761 | const Message* msg, \ |
| 762 | std::string* l) { \ |
| 763 | if (name) \ |
| 764 | *name = #msg_class; \ |
| 765 | } |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 766 | |
| 767 | #define IPC_ASYNC_MESSAGE_LOG(msg_class) \ |
| 768 | void msg_class::Log(std::string* name, \ |
| 769 | const Message* msg, \ |
| 770 | std::string* l) { \ |
| 771 | if (name) \ |
| 772 | *name = #msg_class; \ |
| 773 | if (!msg || !l) \ |
| 774 | return; \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 775 | Schema::Param p; \ |
| 776 | if (Schema::Read(msg, &p)) \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 777 | IPC::LogParam(p, l); \ |
| 778 | } |
| 779 | |
| 780 | #define IPC_SYNC_MESSAGE_LOG(msg_class) \ |
| 781 | void msg_class::Log(std::string* name, \ |
| 782 | const Message* msg, \ |
| 783 | std::string* l) { \ |
| 784 | if (name) \ |
| 785 | *name = #msg_class; \ |
| 786 | if (!msg || !l) \ |
| 787 | return; \ |
| 788 | if (msg->is_sync()) { \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 789 | TupleTypes<Schema::SendParam>::ValueTuple p; \ |
| 790 | if (Schema::ReadSendParam(msg, &p)) \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 791 | IPC::LogParam(p, l); \ |
| 792 | AddOutputParamsToLog(msg, l); \ |
| 793 | } else { \ |
[email protected] | 1d4ecf4 | 2011-08-26 21:27:30 | [diff] [blame] | 794 | TupleTypes<Schema::ReplyParam>::ValueTuple p; \ |
| 795 | if (Schema::ReadReplyParam(msg, &p)) \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 796 | IPC::LogParam(p, l); \ |
| 797 | } \ |
| 798 | } |
| 799 | |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 800 | #elif defined(IPC_MESSAGE_MACROS_LOG_ENABLED) |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 801 | |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 802 | #ifndef IPC_LOG_TABLE_CREATED |
| 803 | #define IPC_LOG_TABLE_CREATED |
[email protected] | 82e5ee8 | 2009-04-03 02:29:45 | [diff] [blame] | 804 | |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 805 | #include "base/hash_tables.h" |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 806 | |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 807 | typedef void (*LogFunction)(std::string* name, |
| 808 | const IPC::Message* msg, |
| 809 | std::string* params); |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 810 | |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 811 | typedef base::hash_map<uint32, LogFunction > LogFunctionMap; |
| 812 | LogFunctionMap g_log_function_mapping; |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 813 | |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 814 | #endif // IPC_LOG_TABLE_CREATED |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 815 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 816 | // "Log table" inclusion produces extra logging registration code. |
| 817 | #define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \ |
| 818 | in_cnt, out_cnt, in_list, out_list) \ |
| 819 | class LoggerRegisterHelper##msg_class { \ |
| 820 | public: \ |
| 821 | LoggerRegisterHelper##msg_class() { \ |
[email protected] | 6fa21d0 | 2011-11-04 00:14:16 | [diff] [blame] | 822 | const uint32 msg_id = static_cast<uint32>(msg_class::ID); \ |
| 823 | g_log_function_mapping[msg_id] = msg_class::Log; \ |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 824 | } \ |
| 825 | }; \ |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 826 | LoggerRegisterHelper##msg_class g_LoggerRegisterHelper##msg_class; |
[email protected] | f91cb99 | 2009-02-04 20:10:12 | [diff] [blame] | 827 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 828 | #else |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 829 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 830 | // Normal inclusion produces nothing extra. |
| 831 | #define IPC_MESSAGE_EXTRA(sync, kind, msg_class, \ |
| 832 | in_cnt, out_cnt, in_list, out_list) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 833 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 834 | #endif // defined(IPC_MESSAGE_IMPL) |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 835 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 836 | // Handle variable sized argument lists. These are usually invoked by token |
| 837 | // pasting against the argument counts. |
| 838 | #define IPC_TYPE_IN_0() |
| 839 | #define IPC_TYPE_IN_1(t1) const t1& arg1 |
| 840 | #define IPC_TYPE_IN_2(t1, t2) const t1& arg1, const t2& arg2 |
| 841 | #define IPC_TYPE_IN_3(t1, t2, t3) const t1& arg1, const t2& arg2, const t3& arg3 |
| 842 | #define IPC_TYPE_IN_4(t1, t2, t3, t4) const t1& arg1, const t2& arg2, const t3& arg3, const t4& arg4 |
| 843 | #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] | 844 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 845 | #define IPC_TYPE_OUT_0() |
| 846 | #define IPC_TYPE_OUT_1(t1) t1* arg6 |
| 847 | #define IPC_TYPE_OUT_2(t1, t2) t1* arg6, t2* arg7 |
| 848 | #define IPC_TYPE_OUT_3(t1, t2, t3) t1* arg6, t2* arg7, t3* arg8 |
| 849 | #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] | 850 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 851 | #define IPC_TUPLE_IN_0() Tuple0 |
| 852 | #define IPC_TUPLE_IN_1(t1) Tuple1<t1> |
| 853 | #define IPC_TUPLE_IN_2(t1, t2) Tuple2<t1, t2> |
| 854 | #define IPC_TUPLE_IN_3(t1, t2, t3) Tuple3<t1, t2, t3> |
| 855 | #define IPC_TUPLE_IN_4(t1, t2, t3, t4) Tuple4<t1, t2, t3, t4> |
| 856 | #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] | 857 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 858 | #define IPC_TUPLE_OUT_0() Tuple0 |
| 859 | #define IPC_TUPLE_OUT_1(t1) Tuple1<t1&> |
| 860 | #define IPC_TUPLE_OUT_2(t1, t2) Tuple2<t1&, t2&> |
| 861 | #define IPC_TUPLE_OUT_3(t1, t2, t3) Tuple3<t1&, t2&, t3&> |
| 862 | #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] | 863 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 864 | #define IPC_NAME_IN_0() MakeTuple() |
| 865 | #define IPC_NAME_IN_1(t1) MakeRefTuple(arg1) |
| 866 | #define IPC_NAME_IN_2(t1, t2) MakeRefTuple(arg1, arg2) |
| 867 | #define IPC_NAME_IN_3(t1, t2, t3) MakeRefTuple(arg1, arg2, arg3) |
| 868 | #define IPC_NAME_IN_4(t1, t2, t3, t4) MakeRefTuple(arg1, arg2, arg3, arg4) |
| 869 | #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] | 870 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 871 | #define IPC_NAME_OUT_0() MakeTuple() |
| 872 | #define IPC_NAME_OUT_1(t1) MakeRefTuple(*arg6) |
| 873 | #define IPC_NAME_OUT_2(t1, t2) MakeRefTuple(*arg6, *arg7) |
| 874 | #define IPC_NAME_OUT_3(t1, t2, t3) MakeRefTuple(*arg6, *arg7, *arg8) |
| 875 | #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] | 876 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 877 | // There are places where the syntax requires a comma if there are input args, |
| 878 | // if there are input args and output args, or if there are input args or |
| 879 | // output args. These macros allow generation of the comma as needed; invoke |
| 880 | // by token pasting against the argument counts. |
| 881 | #define IPC_COMMA_0 |
| 882 | #define IPC_COMMA_1 , |
| 883 | #define IPC_COMMA_2 , |
| 884 | #define IPC_COMMA_3 , |
| 885 | #define IPC_COMMA_4 , |
| 886 | #define IPC_COMMA_5 , |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 887 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 888 | #define IPC_COMMA_AND_0(x) |
| 889 | #define IPC_COMMA_AND_1(x) x |
| 890 | #define IPC_COMMA_AND_2(x) x |
| 891 | #define IPC_COMMA_AND_3(x) x |
| 892 | #define IPC_COMMA_AND_4(x) x |
| 893 | #define IPC_COMMA_AND_5(x) x |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 894 | |
[email protected] | 8a8c9c7 | 2011-03-01 20:35:47 | [diff] [blame] | 895 | #define IPC_COMMA_OR_0(x) x |
| 896 | #define IPC_COMMA_OR_1(x) , |
| 897 | #define IPC_COMMA_OR_2(x) , |
| 898 | #define IPC_COMMA_OR_3(x) , |
| 899 | #define IPC_COMMA_OR_4(x) , |
| 900 | #define IPC_COMMA_OR_5(x) , |
[email protected] | 6d8ffc9f | 2010-03-12 18:27:53 | [diff] [blame] | 901 | |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 902 | // Message IDs |
| 903 | // Note: we currently use __LINE__ to give unique IDs to messages within |
| 904 | // a file. They're globally unique since each file defines its own |
[email protected] | 3b3ec721 | 2011-10-21 17:35:08 | [diff] [blame] | 905 | // IPC_MESSAGE_START. |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 906 | #define IPC_MESSAGE_ID() ((IPC_MESSAGE_START << 16) + __LINE__) |
| 907 | #define IPC_MESSAGE_ID_CLASS(id) ((id) >> 16) |
| 908 | #define IPC_MESSAGE_ID_LINE(id) ((id) & 0xffff) |
| 909 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 910 | // Message crackers and handlers. |
| 911 | // Prefer to use the IPC_BEGIN_MESSAGE_MAP_EX to the older macros since they |
| 912 | // allow you to detect when a message could not be de-serialized. Usage: |
| 913 | // |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 914 | // bool MyClass::OnMessageReceived(const IPC::Message& msg) { |
| 915 | // bool handled = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 916 | // bool msg_is_good = false; |
| 917 | // IPC_BEGIN_MESSAGE_MAP_EX(MyClass, msg, msg_is_good) |
| 918 | // IPC_MESSAGE_HANDLER(MsgClassOne, OnMsgClassOne) |
| 919 | // ...more handlers here ... |
| 920 | // IPC_MESSAGE_HANDLER(MsgClassTen, OnMsgClassTen) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 921 | // IPC_MESSAGE_UNHANDLED(handled = false) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 922 | // IPC_END_MESSAGE_MAP_EX() |
| 923 | // if (!msg_is_good) { |
| 924 | // // Signal error here or terminate offending process. |
| 925 | // } |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 926 | // return handled; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 927 | // } |
| 928 | |
[email protected] | 21fa3a1 | 2010-12-08 23:34:16 | [diff] [blame] | 929 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 930 | #define IPC_BEGIN_MESSAGE_MAP_EX(class_name, msg, msg_is_ok) \ |
| 931 | { \ |
| 932 | typedef class_name _IpcMessageHandlerClass; \ |
| 933 | const IPC::Message& ipc_message__ = msg; \ |
| 934 | bool& msg_is_ok__ = msg_is_ok; \ |
| 935 | switch (ipc_message__.type()) { \ |
| 936 | |
| 937 | #define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \ |
| 938 | { \ |
| 939 | typedef class_name _IpcMessageHandlerClass; \ |
| 940 | const IPC::Message& ipc_message__ = msg; \ |
| 941 | bool msg_is_ok__ = true; \ |
| 942 | switch (ipc_message__.type()) { \ |
| 943 | |
[email protected] | e86a255 | 2011-11-11 00:21:02 | [diff] [blame^] | 944 | #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \ |
| 945 | case msg_class::ID: { \ |
| 946 | /* TRACK_RUN_IN_IPC_HANDLER(member_func); TODO(jar) */ \ |
| 947 | msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, \ |
| 948 | &member_func); \ |
| 949 | } \ |
| 950 | break; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 951 | |
| 952 | #define IPC_MESSAGE_HANDLER(msg_class, member_func) \ |
| 953 | IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func) |
| 954 | |
[email protected] | e86a255 | 2011-11-11 00:21:02 | [diff] [blame^] | 955 | #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \ |
| 956 | case msg_class::ID: { \ |
| 957 | /* TRACK_RUN_IN_IPC_HANDLER(member_func); TODO(jar) */ \ |
| 958 | msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, \ |
| 959 | &member_func); \ |
| 960 | } \ |
| 961 | break; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 962 | |
[email protected] | e86a255 | 2011-11-11 00:21:02 | [diff] [blame^] | 963 | #define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \ |
| 964 | IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \ |
| 965 | _IpcMessageHandlerClass::member_func) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 966 | |
[email protected] | e86a255 | 2011-11-11 00:21:02 | [diff] [blame^] | 967 | #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \ |
| 968 | case msg_class::ID: { \ |
| 969 | /* TRACK_RUN_IN_IPC_HANDLER(code); TODO(jar) */ \ |
| 970 | code; \ |
| 971 | } \ |
| 972 | break; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 973 | |
[email protected] | e86a255 | 2011-11-11 00:21:02 | [diff] [blame^] | 974 | #define IPC_REPLY_HANDLER(func) \ |
| 975 | case IPC_REPLY_ID: { \ |
| 976 | /* TRACK_RUN_IN_IPC_HANDLER(func); TODO(jar) */ \ |
| 977 | func(ipc_message__); \ |
| 978 | } \ |
| 979 | break; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 980 | |
| 981 | |
[email protected] | e86a255 | 2011-11-11 00:21:02 | [diff] [blame^] | 982 | #define IPC_MESSAGE_UNHANDLED(code) \ |
| 983 | default: { \ |
| 984 | /* TRACK_RUN_IN_IPC_HANDLER(code); TODO(jar) */ \ |
| 985 | code; \ |
| 986 | } \ |
| 987 | break; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 988 | |
| 989 | #define IPC_MESSAGE_UNHANDLED_ERROR() \ |
| 990 | IPC_MESSAGE_UNHANDLED(NOTREACHED() << \ |
| 991 | "Invalid message with type = " << \ |
| 992 | ipc_message__.type()) |
| 993 | |
| 994 | #define IPC_END_MESSAGE_MAP() \ |
| 995 | DCHECK(msg_is_ok__); \ |
| 996 | } \ |
| 997 | } |
| 998 | |
| 999 | #define IPC_END_MESSAGE_MAP_EX() \ |
| 1000 | } \ |
[email protected] | 8d70d5f | 2010-12-08 23:41:08 | [diff] [blame] | 1001 | } |
[email protected] | 9f547bf | 2010-12-13 17:00:42 | [diff] [blame] | 1002 | |
| 1003 | // This corresponds to an enum value from IPCMessageStart. |
| 1004 | #define IPC_MESSAGE_CLASS(message) \ |
[email protected] | d7a5e3e | 2011-03-12 16:28:36 | [diff] [blame] | 1005 | IPC_MESSAGE_ID_CLASS(message.type()) |
[email protected] | 6476c72c | 2011-02-11 18:46:19 | [diff] [blame] | 1006 | |
| 1007 | #endif // IPC_IPC_MESSAGE_MACROS_H_ |
| 1008 | |
| 1009 | // Clean up IPC_MESSAGE_START in this unguarded section so that the |
| 1010 | // XXX_messages.h files need not do so themselves. This makes the |
| 1011 | // XXX_messages.h files easier to write. |
| 1012 | #undef IPC_MESSAGE_START |