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 declatation macros: | 23 // XXX_messages.h file before invoking message declaration 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" |
179 #include "ipc/ipc_message_utils.h" | 180 #include "ipc/ipc_message_utils.h" |
180 #include "ipc/param_traits_macros.h" | 181 #include "ipc/param_traits_macros.h" |
181 | 182 |
182 #if defined(IPC_MESSAGE_IMPL) | 183 #if defined(IPC_MESSAGE_IMPL) |
183 #include "ipc/ipc_message_utils_impl.h" | 184 #include "ipc/ipc_message_utils_impl.h" |
184 #endif | 185 #endif |
185 | 186 |
186 // Override this to force message classes to be exported. | 187 // Override this to force message classes to be exported. |
187 #ifndef IPC_MESSAGE_EXPORT | 188 #ifndef IPC_MESSAGE_EXPORT |
188 #define IPC_MESSAGE_EXPORT | 189 #define IPC_MESSAGE_EXPORT |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 bool& msg_is_ok__ = msg_is_ok; \ | 934 bool& msg_is_ok__ = msg_is_ok; \ |
934 switch (ipc_message__.type()) { \ | 935 switch (ipc_message__.type()) { \ |
935 | 936 |
936 #define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \ | 937 #define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \ |
937 { \ | 938 { \ |
938 typedef class_name _IpcMessageHandlerClass; \ | 939 typedef class_name _IpcMessageHandlerClass; \ |
939 const IPC::Message& ipc_message__ = msg; \ | 940 const IPC::Message& ipc_message__ = msg; \ |
940 bool msg_is_ok__ = true; \ | 941 bool msg_is_ok__ = true; \ |
941 switch (ipc_message__.type()) { \ | 942 switch (ipc_message__.type()) { \ |
942 | 943 |
943 #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \ | 944 #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \ |
944 case msg_class::ID: \ | 945 case msg_class::ID: { \ |
945 msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, \ | 946 TRACK_RUN_IN_IPC_HANDLER(member_func); \ |
946 &member_func); \ | 947 msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, \ |
947 break; | 948 &member_func); \ |
| 949 } \ |
| 950 break; |
948 | 951 |
949 #define IPC_MESSAGE_HANDLER(msg_class, member_func) \ | 952 #define IPC_MESSAGE_HANDLER(msg_class, member_func) \ |
950 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func) | 953 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func) |
951 | 954 |
952 #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \ | 955 #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \ |
953 case msg_class::ID: \ | 956 case msg_class::ID: { \ |
954 msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, \ | 957 TRACK_RUN_IN_IPC_HANDLER(member_func); \ |
955 &member_func); \ | 958 msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, \ |
956 break; | 959 &member_func); \ |
| 960 } \ |
| 961 break; |
957 | 962 |
958 #define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \ | 963 #define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \ |
959 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \ | 964 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \ |
960 _IpcMessageHandlerClass::member_func) | 965 _IpcMessageHandlerClass::member_func) |
961 | 966 |
962 #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \ | 967 #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \ |
963 case msg_class::ID: \ | 968 case msg_class::ID: \ |
964 code; \ | 969 code; \ |
965 break; | 970 break; |
966 | 971 |
967 #define IPC_REPLY_HANDLER(func) \ | 972 #define IPC_REPLY_HANDLER(func) \ |
968 case IPC_REPLY_ID: \ | 973 case IPC_REPLY_ID: { \ |
969 func(ipc_message__); \ | 974 TRACK_RUN_IN_IPC_HANDLER(func); \ |
| 975 func(ipc_message__); \ |
| 976 } \ |
970 break; | 977 break; |
971 | 978 |
972 | 979 |
973 #define IPC_MESSAGE_UNHANDLED(code) \ | 980 #define IPC_MESSAGE_UNHANDLED(code) \ |
974 default: \ | 981 default: \ |
975 code; \ | 982 code; \ |
976 break; | 983 break; |
977 | 984 |
978 #define IPC_MESSAGE_UNHANDLED_ERROR() \ | 985 #define IPC_MESSAGE_UNHANDLED_ERROR() \ |
979 IPC_MESSAGE_UNHANDLED(NOTREACHED() << \ | 986 IPC_MESSAGE_UNHANDLED(NOTREACHED() << \ |
(...skipping 12 matching lines...) Expand all Loading... |
992 // This corresponds to an enum value from IPCMessageStart. | 999 // This corresponds to an enum value from IPCMessageStart. |
993 #define IPC_MESSAGE_CLASS(message) \ | 1000 #define IPC_MESSAGE_CLASS(message) \ |
994 IPC_MESSAGE_ID_CLASS(message.type()) | 1001 IPC_MESSAGE_ID_CLASS(message.type()) |
995 | 1002 |
996 #endif // IPC_IPC_MESSAGE_MACROS_H_ | 1003 #endif // IPC_IPC_MESSAGE_MACROS_H_ |
997 | 1004 |
998 // Clean up IPC_MESSAGE_START in this unguarded section so that the | 1005 // Clean up IPC_MESSAGE_START in this unguarded section so that the |
999 // XXX_messages.h files need not do so themselves. This makes the | 1006 // XXX_messages.h files need not do so themselves. This makes the |
1000 // XXX_messages.h files easier to write. | 1007 // XXX_messages.h files easier to write. |
1001 #undef IPC_MESSAGE_START | 1008 #undef IPC_MESSAGE_START |
OLD | NEW |