OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Defining IPC Messages | 5 // Defining IPC Messages |
6 // | 6 // |
7 // Your IPC messages will be defined by macros inside of an XXX_messages.h | 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 | 8 // header file. Most of the time, the system can automatically generate all |
9 // of messaging mechanism from these definitions, but sometimes some manual | 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 | 10 // coding is required. In these cases, you will also have an XXX_messages.cc |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // You will use IPC message macro invocations for three things: | 123 // You will use IPC message macro invocations for three things: |
124 // - New struct definitions for IPC | 124 // - New struct definitions for IPC |
125 // - Registering existing struct and enum definitions with IPC | 125 // - Registering existing struct and enum definitions with IPC |
126 // - Defining the messages themselves | 126 // - Defining the messages themselves |
127 // | 127 // |
128 // New structs are defined with IPC_STRUCT_BEGIN(), IPC_STRUCT_MEMBER(), | 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 | 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 | 130 // to proclaim equivalent struct declarations for use by callers, as well |
131 // as later registering the type with the message generation. Note that | 131 // as later registering the type with the message generation. Note that |
132 // IPC_STRUCT_MEMBER() is only permitted inside matching calls to | 132 // IPC_STRUCT_MEMBER() is only permitted inside matching calls to |
133 // IPC_STRUCT_BEGIN() / IPC_STRUCT_END(). | 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. |
134 // | 136 // |
135 // Externally-defined structs are registered with IPC_STRUCT_TRAITS_BEGIN(), | 137 // Externally-defined structs are registered with IPC_STRUCT_TRAITS_BEGIN(), |
136 // IPC_STRUCT_TRAITS_MEMBER(), and IPC_STRUCT_TRAITS_END() macros. These | 138 // IPC_STRUCT_TRAITS_MEMBER(), and IPC_STRUCT_TRAITS_END() macros. These |
137 // cause registration of the types with message generation only. | 139 // cause registration of the types with message generation only. |
138 // There's also IPC_STRUCT_TRAITS_PARENT, which is used to register a parent | 140 // There's also IPC_STRUCT_TRAITS_PARENT, which is used to register a parent |
139 // class (whose own traits are already defined). Note that | 141 // class (whose own traits are already defined). Note that |
140 // IPC_STRUCT_TRAITS_MEMBER() and IPC_STRUCT_TRAITS_PARENT are only permitted | 142 // IPC_STRUCT_TRAITS_MEMBER() and IPC_STRUCT_TRAITS_PARENT are only permitted |
141 // inside matching calls to IPC_STRUCT_TRAITS_BEGIN() / | 143 // inside matching calls to IPC_STRUCT_TRAITS_BEGIN() / |
142 // IPC_STRUCT_TRAITS_END(). | 144 // IPC_STRUCT_TRAITS_END(). |
143 // | 145 // |
144 // Enum types are registered with a single IPC_ENUM_TRAITS() macro. There | 146 // Enum types are registered with a single IPC_ENUM_TRAITS_VALIDATE() macro. |
145 // is no need to enumerate each value to the IPC mechanism. | 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. |
146 // | 156 // |
147 // Do not place semicolons following these IPC_ macro invocations. There | 157 // Do not place semicolons following these IPC_ macro invocations. There |
148 // is no reason to expect that their expansion corresponds one-to-one with | 158 // is no reason to expect that their expansion corresponds one-to-one with |
149 // C++ statements. | 159 // C++ statements. |
150 // | 160 // |
151 // Once the types have been declared / registered, message definitions follow. | 161 // Once the types have been declared / registered, message definitions follow. |
152 // "Sync" messages are just synchronous calls, the Send() call doesn't return | 162 // "Sync" messages are just synchronous calls, the Send() call doesn't return |
153 // until a reply comes back. To declare a sync message, use the IPC_SYNC_ | 163 // 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 | 164 // 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 | 165 // are (i.e. 1_2 is 1 in, 2 out). Input parameters are first, followed by |
(...skipping 29 matching lines...) Expand all Loading... |
185 #define IPC_IPC_MESSAGE_MACROS_H_ | 195 #define IPC_IPC_MESSAGE_MACROS_H_ |
186 | 196 |
187 #include "base/profiler/scoped_profile.h" | 197 #include "base/profiler/scoped_profile.h" |
188 #include "ipc/ipc_message_utils.h" | 198 #include "ipc/ipc_message_utils.h" |
189 #include "ipc/param_traits_macros.h" | 199 #include "ipc/param_traits_macros.h" |
190 | 200 |
191 #if defined(IPC_MESSAGE_IMPL) | 201 #if defined(IPC_MESSAGE_IMPL) |
192 #include "ipc/ipc_message_utils_impl.h" | 202 #include "ipc/ipc_message_utils_impl.h" |
193 #endif | 203 #endif |
194 | 204 |
195 // Macros for defining structs. May be subsequently redefined. | 205 // Convenience macro for defining structs without inheritence. Should not need |
| 206 // to be subsequently redefined. |
196 #define IPC_STRUCT_BEGIN(struct_name) \ | 207 #define IPC_STRUCT_BEGIN(struct_name) \ |
197 IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, IPC::NoParams) | 208 IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, IPC::NoParams) |
| 209 |
| 210 // Macros for defining structs. Will be subsequently redefined. |
198 #define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \ | 211 #define IPC_STRUCT_BEGIN_WITH_PARENT(struct_name, parent) \ |
199 struct struct_name; \ | 212 struct struct_name; \ |
200 IPC_STRUCT_TRAITS_BEGIN(struct_name) \ | 213 IPC_STRUCT_TRAITS_BEGIN(struct_name) \ |
201 IPC_STRUCT_TRAITS_END() \ | 214 IPC_STRUCT_TRAITS_END() \ |
202 struct IPC_MESSAGE_EXPORT struct_name : parent { \ | 215 struct IPC_MESSAGE_EXPORT struct_name : parent { \ |
203 struct_name(); \ | 216 struct_name(); \ |
204 ~struct_name(); | 217 ~struct_name(); |
205 // Optional variadic parameters specify the default value for this struct | 218 // Optional variadic parameters specify the default value for this struct |
206 // member. They are passed through to the constructor for |type|. | 219 // member. They are passed through to the constructor for |type|. |
207 #define IPC_STRUCT_MEMBER(type, name, ...) type name; | 220 #define IPC_STRUCT_MEMBER(type, name, ...) type name; |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 // This corresponds to an enum value from IPCMessageStart. | 1007 // This corresponds to an enum value from IPCMessageStart. |
995 #define IPC_MESSAGE_CLASS(message) \ | 1008 #define IPC_MESSAGE_CLASS(message) \ |
996 IPC_MESSAGE_ID_CLASS(message.type()) | 1009 IPC_MESSAGE_ID_CLASS(message.type()) |
997 | 1010 |
998 #endif // IPC_IPC_MESSAGE_MACROS_H_ | 1011 #endif // IPC_IPC_MESSAGE_MACROS_H_ |
999 | 1012 |
1000 // Clean up IPC_MESSAGE_START in this unguarded section so that the | 1013 // Clean up IPC_MESSAGE_START in this unguarded section so that the |
1001 // XXX_messages.h files need not do so themselves. This makes the | 1014 // XXX_messages.h files need not do so themselves. This makes the |
1002 // XXX_messages.h files easier to write. | 1015 // XXX_messages.h files easier to write. |
1003 #undef IPC_MESSAGE_START | 1016 #undef IPC_MESSAGE_START |
OLD | NEW |