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