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 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 #define IPC_COMMA_OR_5(x) , | 869 #define IPC_COMMA_OR_5(x) , |
870 | 870 |
871 // Message IDs | 871 // Message IDs |
872 // Note: we currently use __LINE__ to give unique IDs to messages within | 872 // Note: we currently use __LINE__ to give unique IDs to messages within |
873 // a file. They're globally unique since each file defines its own | 873 // a file. They're globally unique since each file defines its own |
874 // IPC_MESSAGE_START. | 874 // IPC_MESSAGE_START. |
875 #define IPC_MESSAGE_ID() ((IPC_MESSAGE_START << 16) + __LINE__) | 875 #define IPC_MESSAGE_ID() ((IPC_MESSAGE_START << 16) + __LINE__) |
876 #define IPC_MESSAGE_ID_CLASS(id) ((id) >> 16) | 876 #define IPC_MESSAGE_ID_CLASS(id) ((id) >> 16) |
877 #define IPC_MESSAGE_ID_LINE(id) ((id) & 0xffff) | 877 #define IPC_MESSAGE_ID_LINE(id) ((id) & 0xffff) |
878 | 878 |
879 // Message crackers and handlers. | 879 // Message crackers and handlers. Usage: |
880 // Prefer to use the IPC_BEGIN_MESSAGE_MAP_EX to the older macros since they | |
881 // allow you to detect when a message could not be de-serialized. Usage: | |
882 // | 880 // |
883 // bool MyClass::OnMessageReceived(const IPC::Message& msg) { | 881 // bool MyClass::OnMessageReceived(const IPC::Message& msg) { |
884 // bool handled = true; | 882 // bool handled = true; |
885 // bool msg_is_good = false; | 883 // IPC_BEGIN_MESSAGE_MAP(MyClass, msg) |
886 // IPC_BEGIN_MESSAGE_MAP_EX(MyClass, msg, msg_is_good) | |
887 // IPC_MESSAGE_HANDLER(MsgClassOne, OnMsgClassOne) | 884 // IPC_MESSAGE_HANDLER(MsgClassOne, OnMsgClassOne) |
888 // ...more handlers here ... | 885 // ...more handlers here ... |
889 // IPC_MESSAGE_HANDLER(MsgClassTen, OnMsgClassTen) | 886 // IPC_MESSAGE_HANDLER(MsgClassTen, OnMsgClassTen) |
890 // IPC_MESSAGE_UNHANDLED(handled = false) | 887 // IPC_MESSAGE_UNHANDLED(handled = false) |
891 // IPC_END_MESSAGE_MAP_EX() | 888 // IPC_END_MESSAGE_MAP() |
892 // if (!msg_is_good) { | |
893 // // Signal error here or terminate offending process. | |
894 // } | |
895 // return handled; | 889 // return handled; |
896 // } | 890 // } |
897 | 891 |
898 | 892 |
899 #define IPC_BEGIN_MESSAGE_MAP_EX(class_name, msg, msg_is_ok) \ | |
900 { \ | |
901 typedef class_name _IpcMessageHandlerClass; \ | |
902 void* param__ = NULL; \ | |
903 const IPC::Message& ipc_message__ = msg; \ | |
904 bool& msg_is_ok__ = msg_is_ok; \ | |
905 switch (ipc_message__.type()) { | |
906 | |
907 #define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \ | 893 #define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \ |
908 { \ | 894 { \ |
909 typedef class_name _IpcMessageHandlerClass; \ | 895 typedef class_name _IpcMessageHandlerClass; \ |
910 void* param__ = NULL; \ | 896 void* param__ = NULL; \ |
911 const IPC::Message& ipc_message__ = msg; \ | 897 const IPC::Message& ipc_message__ = msg; \ |
912 bool msg_is_ok__ = true; \ | |
913 switch (ipc_message__.type()) { | 898 switch (ipc_message__.type()) { |
914 | 899 |
915 // gcc gives the following error now when using decltype so type typeof there: | 900 // gcc gives the following error now when using decltype so type typeof there: |
916 // error: identifier 'decltype' will become a keyword in C++0x [-Werror=c++0x-
compat] | 901 // error: identifier 'decltype' will become a keyword in C++0x [-Werror=c++0x-
compat] |
917 #if defined(OS_WIN) | 902 #if defined(OS_WIN) |
918 #define IPC_DECLTYPE decltype | 903 #define IPC_DECLTYPE decltype |
919 #else | 904 #else |
920 #define IPC_DECLTYPE typeof | 905 #define IPC_DECLTYPE typeof |
921 #endif | 906 #endif |
922 | 907 |
923 #define IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(class_name, msg, msg_is_ok, param) \ | 908 #define IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(class_name, msg, param) \ |
924 { \ | 909 { \ |
925 typedef class_name _IpcMessageHandlerClass; \ | 910 typedef class_name _IpcMessageHandlerClass; \ |
926 IPC_DECLTYPE(param) param__ = param; \ | 911 IPC_DECLTYPE(param) param__ = param; \ |
927 const IPC::Message& ipc_message__ = msg; \ | 912 const IPC::Message& ipc_message__ = msg; \ |
928 bool& msg_is_ok__ = msg_is_ok; \ | |
929 switch (ipc_message__.type()) { | 913 switch (ipc_message__.type()) { |
930 | 914 |
931 #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \ | 915 #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \ |
932 case msg_class::ID: { \ | 916 case msg_class::ID: { \ |
933 TRACK_RUN_IN_IPC_HANDLER(member_func); \ | 917 TRACK_RUN_IN_IPC_HANDLER(member_func); \ |
934 msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, \ | 918 if (!msg_class::Dispatch(&ipc_message__, obj, this, param__, \ |
935 param__, &member_func); \ | 919 &member_func)) \ |
936 if (!msg_is_ok__) \ | |
937 ipc_message__.set_dispatch_error(); \ | 920 ipc_message__.set_dispatch_error(); \ |
938 } \ | 921 } \ |
939 break; | 922 break; |
940 | 923 |
941 #define IPC_MESSAGE_HANDLER(msg_class, member_func) \ | 924 #define IPC_MESSAGE_HANDLER(msg_class, member_func) \ |
942 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func) | 925 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func) |
943 | 926 |
944 #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \ | 927 #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \ |
945 case msg_class::ID: { \ | 928 case msg_class::ID: { \ |
946 TRACK_RUN_IN_IPC_HANDLER(member_func); \ | 929 TRACK_RUN_IN_IPC_HANDLER(member_func); \ |
947 msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, \ | 930 if (!msg_class::DispatchDelayReply(&ipc_message__, obj, param__, \ |
948 param__, &member_func); \ | 931 &member_func)) \ |
949 if (!msg_is_ok__) \ | |
950 ipc_message__.set_dispatch_error(); \ | 932 ipc_message__.set_dispatch_error(); \ |
951 } \ | 933 } \ |
952 break; | 934 break; |
953 | 935 |
954 #define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \ | 936 #define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \ |
955 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \ | 937 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \ |
956 _IpcMessageHandlerClass::member_func) | 938 _IpcMessageHandlerClass::member_func) |
957 | 939 |
958 // TODO(jar): fix chrome frame to always supply |code| argument. | 940 // TODO(jar): fix chrome frame to always supply |code| argument. |
959 #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \ | 941 #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \ |
(...skipping 17 matching lines...) Expand all Loading... |
977 } \ | 959 } \ |
978 break; | 960 break; |
979 | 961 |
980 #define IPC_MESSAGE_UNHANDLED_ERROR() \ | 962 #define IPC_MESSAGE_UNHANDLED_ERROR() \ |
981 IPC_MESSAGE_UNHANDLED(NOTREACHED() << \ | 963 IPC_MESSAGE_UNHANDLED(NOTREACHED() << \ |
982 "Invalid message with type = " << \ | 964 "Invalid message with type = " << \ |
983 ipc_message__.type()) | 965 ipc_message__.type()) |
984 | 966 |
985 #define IPC_END_MESSAGE_MAP() \ | 967 #define IPC_END_MESSAGE_MAP() \ |
986 } \ | 968 } \ |
987 DCHECK(msg_is_ok__); \ | |
988 } | |
989 | |
990 #define IPC_END_MESSAGE_MAP_EX() \ | |
991 } \ | |
992 } | 969 } |
993 | 970 |
994 // This corresponds to an enum value from IPCMessageStart. | 971 // This corresponds to an enum value from IPCMessageStart. |
995 #define IPC_MESSAGE_CLASS(message) \ | 972 #define IPC_MESSAGE_CLASS(message) \ |
996 IPC_MESSAGE_ID_CLASS(message.type()) | 973 IPC_MESSAGE_ID_CLASS(message.type()) |
997 | 974 |
998 #endif // IPC_IPC_MESSAGE_MACROS_H_ | 975 #endif // IPC_IPC_MESSAGE_MACROS_H_ |
999 | 976 |
1000 // The following #ifdef cannot be removed. Although the code is semantically | 977 // The following #ifdef cannot be removed. Although the code is semantically |
1001 // equivalent without the #ifdef, VS2013 contains a bug where it is | 978 // equivalent without the #ifdef, VS2013 contains a bug where it is |
1002 // over-aggressive in optimizing out #includes. Putting the #ifdef is a | 979 // over-aggressive in optimizing out #includes. Putting the #ifdef is a |
1003 // workaround for this bug. See http://goo.gl/eGt2Fb for more details. | 980 // workaround for this bug. See http://goo.gl/eGt2Fb for more details. |
1004 // This can be removed once VS2013 is fixed. | 981 // This can be removed once VS2013 is fixed. |
1005 #ifdef IPC_MESSAGE_START | 982 #ifdef IPC_MESSAGE_START |
1006 // Clean up IPC_MESSAGE_START in this unguarded section so that the | 983 // Clean up IPC_MESSAGE_START in this unguarded section so that the |
1007 // XXX_messages.h files need not do so themselves. This makes the | 984 // XXX_messages.h files need not do so themselves. This makes the |
1008 // XXX_messages.h files easier to write. | 985 // XXX_messages.h files easier to write. |
1009 #undef IPC_MESSAGE_START | 986 #undef IPC_MESSAGE_START |
1010 #endif | 987 #endif |
OLD | NEW |