OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 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 |
11 // implemation file as well. | 11 // implemation file as well. |
12 // | 12 // |
13 // The senders of your messages will include your XXX_messages.h file to | 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. | 14 // get the full set of definitions they need to send your messages. |
15 // | 15 // |
16 // Each XXX_messages.h file must be registered with the IPC system. This | 16 // Each XXX_messages.h file must be registered with the IPC system. This |
17 // requires adding two things: | 17 // requires adding two things: |
18 // - An XXXMsgStart value to the IPCMessageStart enum in ipc_message_utils.h | 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 | 19 // - An inclusion of XXX_messages.h file in a message generator .h file |
20 // | 20 // |
21 // The XXXMsgStart value is an enumeration that ensures uniqueness for | 21 // The XXXMsgStart value is an enumeration that ensures uniqueness for |
22 // each different message file. Later, you will use this inside your | 22 // each different message file. Later, you will use this inside your |
23 // XXX_messages.h file before invoking message declaration macros: | 23 // XXX_messages.h file before invoking message declatation macros: |
24 // #define IPC_MESSAGE_START XXXMsgStart | 24 // #define IPC_MESSAGE_START XXXMsgStart |
25 // ( ... your macro invocations go here ... ) | 25 // ( ... your macro invocations go here ... ) |
26 // | 26 // |
27 // Message Generator Files | 27 // Message Generator Files |
28 // | 28 // |
29 // A message generator .h header file pulls in all other message-declaring | 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 | 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, | 31 // .cc file, which is where all the generated code will wind up. Typically, |
32 // you will use an existing generator (e.g. common_message_generator.cc | 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 | 33 // in /chrome/common), but there are circumstances where you may add a |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // The handler function will look like: | 169 // The handler function will look like: |
170 // void OnSyncMessageName(const type1& in1, IPC::Message* reply_msg); | 170 // void OnSyncMessageName(const type1& in1, IPC::Message* reply_msg); |
171 // | 171 // |
172 // Receiver stashes the IPC::Message* pointer, and when it's ready, it does: | 172 // Receiver stashes the IPC::Message* pointer, and when it's ready, it does: |
173 // ViewHostMsg_SyncMessageName::WriteReplyParams(reply_msg, out1, out2); | 173 // ViewHostMsg_SyncMessageName::WriteReplyParams(reply_msg, out1, out2); |
174 // Send(reply_msg); | 174 // Send(reply_msg); |
175 | 175 |
176 #ifndef IPC_IPC_MESSAGE_MACROS_H_ | 176 #ifndef IPC_IPC_MESSAGE_MACROS_H_ |
177 #define IPC_IPC_MESSAGE_MACROS_H_ | 177 #define IPC_IPC_MESSAGE_MACROS_H_ |
178 | 178 |
179 #include "base/profiler/scoped_profile.h" | |
180 #include "ipc/ipc_message_utils.h" | 179 #include "ipc/ipc_message_utils.h" |
181 #include "ipc/param_traits_macros.h" | 180 #include "ipc/param_traits_macros.h" |
182 | 181 |
183 #if defined(IPC_MESSAGE_IMPL) | 182 #if defined(IPC_MESSAGE_IMPL) |
184 #include "ipc/ipc_message_utils_impl.h" | 183 #include "ipc/ipc_message_utils_impl.h" |
185 #endif | 184 #endif |
186 | 185 |
187 // Override this to force message classes to be exported. | 186 // Override this to force message classes to be exported. |
188 #ifndef IPC_MESSAGE_EXPORT | 187 #ifndef IPC_MESSAGE_EXPORT |
189 #define IPC_MESSAGE_EXPORT | 188 #define IPC_MESSAGE_EXPORT |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 bool& msg_is_ok__ = msg_is_ok; \ | 933 bool& msg_is_ok__ = msg_is_ok; \ |
935 switch (ipc_message__.type()) { \ | 934 switch (ipc_message__.type()) { \ |
936 | 935 |
937 #define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \ | 936 #define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \ |
938 { \ | 937 { \ |
939 typedef class_name _IpcMessageHandlerClass; \ | 938 typedef class_name _IpcMessageHandlerClass; \ |
940 const IPC::Message& ipc_message__ = msg; \ | 939 const IPC::Message& ipc_message__ = msg; \ |
941 bool msg_is_ok__ = true; \ | 940 bool msg_is_ok__ = true; \ |
942 switch (ipc_message__.type()) { \ | 941 switch (ipc_message__.type()) { \ |
943 | 942 |
944 #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \ | 943 #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \ |
945 case msg_class::ID: { \ | 944 case msg_class::ID: \ |
946 TRACK_RUN_IN_IPC_HANDLER(member_func); \ | 945 msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, \ |
947 msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, \ | 946 &member_func); \ |
948 &member_func); \ | 947 break; |
949 } \ | |
950 break; | |
951 | 948 |
952 #define IPC_MESSAGE_HANDLER(msg_class, member_func) \ | 949 #define IPC_MESSAGE_HANDLER(msg_class, member_func) \ |
953 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func) | 950 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func) |
954 | 951 |
955 #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \ | 952 #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \ |
956 case msg_class::ID: { \ | 953 case msg_class::ID: \ |
957 TRACK_RUN_IN_IPC_HANDLER(member_func); \ | 954 msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, \ |
958 msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, \ | 955 &member_func); \ |
959 &member_func); \ | 956 break; |
960 } \ | |
961 break; | |
962 | 957 |
963 #define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \ | 958 #define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \ |
964 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \ | 959 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \ |
965 _IpcMessageHandlerClass::member_func) | 960 _IpcMessageHandlerClass::member_func) |
966 | 961 |
967 #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \ | 962 #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \ |
968 case msg_class::ID: \ | 963 case msg_class::ID: \ |
969 code; \ | 964 code; \ |
970 break; | 965 break; |
971 | 966 |
972 #define IPC_REPLY_HANDLER(func) \ | 967 #define IPC_REPLY_HANDLER(func) \ |
973 case IPC_REPLY_ID: { \ | 968 case IPC_REPLY_ID: \ |
974 TRACK_RUN_IN_IPC_HANDLER(func); \ | 969 func(ipc_message__); \ |
975 func(ipc_message__); \ | |
976 } \ | |
977 break; | 970 break; |
978 | 971 |
979 | 972 |
980 #define IPC_MESSAGE_UNHANDLED(code) \ | 973 #define IPC_MESSAGE_UNHANDLED(code) \ |
981 default: \ | 974 default: \ |
982 code; \ | 975 code; \ |
983 break; | 976 break; |
984 | 977 |
985 #define IPC_MESSAGE_UNHANDLED_ERROR() \ | 978 #define IPC_MESSAGE_UNHANDLED_ERROR() \ |
986 IPC_MESSAGE_UNHANDLED(NOTREACHED() << \ | 979 IPC_MESSAGE_UNHANDLED(NOTREACHED() << \ |
(...skipping 12 matching lines...) Expand all Loading... |
999 // This corresponds to an enum value from IPCMessageStart. | 992 // This corresponds to an enum value from IPCMessageStart. |
1000 #define IPC_MESSAGE_CLASS(message) \ | 993 #define IPC_MESSAGE_CLASS(message) \ |
1001 IPC_MESSAGE_ID_CLASS(message.type()) | 994 IPC_MESSAGE_ID_CLASS(message.type()) |
1002 | 995 |
1003 #endif // IPC_IPC_MESSAGE_MACROS_H_ | 996 #endif // IPC_IPC_MESSAGE_MACROS_H_ |
1004 | 997 |
1005 // Clean up IPC_MESSAGE_START in this unguarded section so that the | 998 // Clean up IPC_MESSAGE_START in this unguarded section so that the |
1006 // XXX_messages.h files need not do so themselves. This makes the | 999 // XXX_messages.h files need not do so themselves. This makes the |
1007 // XXX_messages.h files easier to write. | 1000 // XXX_messages.h files easier to write. |
1008 #undef IPC_MESSAGE_START | 1001 #undef IPC_MESSAGE_START |
OLD | NEW |