| 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 IPC_MESSAGE_DECL(SYNC, ROUTED, msg_class, 5, 1, (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 | 428 |
| 429 #define IPC_SYNC_MESSAGE_ROUTED5_2(msg_class, type1_in, type2_in, type3_in, type
4_in, type5_in, type1_out, type2_out) \ | 429 #define IPC_SYNC_MESSAGE_ROUTED5_2(msg_class, type1_in, type2_in, type3_in, type
4_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)) | 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 | 431 |
| 432 #define IPC_SYNC_MESSAGE_ROUTED5_3(msg_class, type1_in, type2_in, type3_in, type
4_in, type5_in, type1_out, type2_out, type3_out) \ | 432 #define IPC_SYNC_MESSAGE_ROUTED5_3(msg_class, type1_in, type2_in, type3_in, type
4_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)) | 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)) |
| 434 | 434 |
| 435 // The following macros define the common set of methods provided by ASYNC | 435 // The following macros define the common set of methods provided by ASYNC |
| 436 // message classes. | 436 // message classes. |
| 437 // This macro is for all the async IPCs that don't pass an extra parameter using |
| 438 // IPC_BEGIN_MESSAGE_MAP_WITH_PARAM. |
| 437 #define IPC_ASYNC_MESSAGE_METHODS_GENERIC \ | 439 #define IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
| 438 template<class T, class S, class Method> \ | 440 template<class T, class S, class P, class Method> \ |
| 439 static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) { \ | 441 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \ |
| 442 Method func) { \ |
| 440 Schema::Param p; \ | 443 Schema::Param p; \ |
| 441 if (Read(msg, &p)) { \ | 444 if (Read(msg, &p)) { \ |
| 442 DispatchToMethod(obj, func, p); \ | 445 DispatchToMethod(obj, func, p); \ |
| 443 return true; \ | 446 return true; \ |
| 444 } \ | 447 } \ |
| 445 return false; \ | 448 return false; \ |
| 446 } | 449 } |
| 450 |
| 451 // The following macros are for for async IPCs which have a dispatcher with an |
| 452 // extra parameter specified using IPC_BEGIN_MESSAGE_MAP_WITH_PARAM. |
| 447 #define IPC_ASYNC_MESSAGE_METHODS_1 \ | 453 #define IPC_ASYNC_MESSAGE_METHODS_1 \ |
| 448 IPC_ASYNC_MESSAGE_METHODS_GENERIC \ | 454 IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
| 449 template<class T, class S, typename TA> \ | 455 template<class T, class S, class P, typename TA> \ |
| 450 static bool Dispatch(const Message* msg, T* obj, S* sender, \ | 456 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \ |
| 451 void (T::*func)(const Message&, TA)) { \ | 457 void (T::*func)(P*, TA)) { \ |
| 452 Schema::Param p; \ | 458 Schema::Param p; \ |
| 453 if (Read(msg, &p)) { \ | 459 if (Read(msg, &p)) { \ |
| 454 (obj->*func)(*msg, p.a); \ | 460 (obj->*func)(parameter, p.a); \ |
| 455 return true; \ | 461 return true; \ |
| 456 } \ | 462 } \ |
| 457 return false; \ | 463 return false; \ |
| 458 } | 464 } |
| 459 #define IPC_ASYNC_MESSAGE_METHODS_2 \ | 465 #define IPC_ASYNC_MESSAGE_METHODS_2 \ |
| 460 IPC_ASYNC_MESSAGE_METHODS_GENERIC \ | 466 IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
| 461 template<class T, class S, typename TA, typename TB> \ | 467 template<class T, class S, class P, typename TA, typename TB> \ |
| 462 static bool Dispatch(const Message* msg, T* obj, S* sender, \ | 468 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \ |
| 463 void (T::*func)(const Message&, TA, TB)) { \ | 469 void (T::*func)(P*, TA, TB)) { \ |
| 464 Schema::Param p; \ | 470 Schema::Param p; \ |
| 465 if (Read(msg, &p)) { \ | 471 if (Read(msg, &p)) { \ |
| 466 (obj->*func)(*msg, p.a, p.b); \ | 472 (obj->*func)(parameter, p.a, p.b); \ |
| 467 return true; \ | 473 return true; \ |
| 468 } \ | 474 } \ |
| 469 return false; \ | 475 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 } | 476 } |
| 480 #define IPC_ASYNC_MESSAGE_METHODS_3 \ | 477 #define IPC_ASYNC_MESSAGE_METHODS_3 \ |
| 481 IPC_ASYNC_MESSAGE_METHODS_GENERIC \ | 478 IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
| 482 template<class T, class S, typename TA, typename TB, typename TC> \ | 479 template<class T, class S, class P, typename TA, typename TB, typename TC> \ |
| 483 static bool Dispatch(const Message* msg, T* obj, S* sender, \ | 480 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \ |
| 484 void (T::*func)(const Message&, TA, TB, TC)) { \ | 481 void (T::*func)(P*, TA, TB, TC)) { \ |
| 485 Schema::Param p; \ | 482 Schema::Param p; \ |
| 486 if (Read(msg, &p)) { \ | 483 if (Read(msg, &p)) { \ |
| 487 (obj->*func)(*msg, p.a, p.b, p.c); \ | 484 (obj->*func)(parameter, p.a, p.b, p.c); \ |
| 488 return true; \ | 485 return true; \ |
| 489 } \ | 486 } \ |
| 490 return false; \ | 487 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 } | 488 } |
| 502 #define IPC_ASYNC_MESSAGE_METHODS_4 \ | 489 #define IPC_ASYNC_MESSAGE_METHODS_4 \ |
| 503 IPC_ASYNC_MESSAGE_METHODS_GENERIC \ | 490 IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
| 504 template<class T, class S, typename TA, typename TB, typename TC, \ | 491 template<class T, class S, class P, typename TA, typename TB, typename TC, \ |
| 505 typename TD> \ | 492 typename TD> \ |
| 506 static bool Dispatch(const Message* msg, T* obj, S* sender, \ | 493 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \ |
| 507 void (T::*func)(const Message&, TA, TB, TC, TD)) { \ | 494 void (T::*func)(P*, TA, TB, TC, TD)) { \ |
| 508 Schema::Param p; \ | 495 Schema::Param p; \ |
| 509 if (Read(msg, &p)) { \ | 496 if (Read(msg, &p)) { \ |
| 510 (obj->*func)(*msg, p.a, p.b, p.c, p.d); \ | 497 (obj->*func)(parameter, p.a, p.b, p.c, p.d); \ |
| 511 return true; \ | 498 return true; \ |
| 512 } \ | 499 } \ |
| 513 return false; \ | 500 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 } | 501 } |
| 526 #define IPC_ASYNC_MESSAGE_METHODS_5 \ | 502 #define IPC_ASYNC_MESSAGE_METHODS_5 \ |
| 527 IPC_ASYNC_MESSAGE_METHODS_GENERIC \ | 503 IPC_ASYNC_MESSAGE_METHODS_GENERIC \ |
| 528 template<class T, class S, typename TA, typename TB, typename TC, \ | 504 template<class T, class S, class P, typename TA, typename TB, typename TC, \ |
| 529 typename TD, typename TE> \ | 505 typename TD, typename TE> \ |
| 530 static bool Dispatch(const Message* msg, T* obj, S* sender, \ | 506 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \ |
| 531 void (T::*func)(const Message&, TA, TB, TC, TD, TE)) { \ | 507 void (T::*func)(P*, TA, TB, TC, TD, TE)) { \ |
| 532 Schema::Param p; \ | 508 Schema::Param p; \ |
| 533 if (Read(msg, &p)) { \ | 509 if (Read(msg, &p)) { \ |
| 534 (obj->*func)(*msg, p.a, p.b, p.c, p.d, p.e); \ | 510 (obj->*func)(parameter, p.a, p.b, p.c, p.d, p.e); \ |
| 535 return true; \ | 511 return true; \ |
| 536 } \ | 512 } \ |
| 537 return false; \ | 513 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 } | 514 } |
| 552 | 515 |
| 553 // The following macros define the common set of methods provided by SYNC | 516 // The following macros define the common set of methods provided by SYNC |
| 554 // message classes. | 517 // message classes. |
| 555 #define IPC_SYNC_MESSAGE_METHODS_GENERIC \ | 518 #define IPC_SYNC_MESSAGE_METHODS_GENERIC \ |
| 556 template<class T, class S, class Method> \ | 519 template<class T, class S, class P, class Method> \ |
| 557 static bool Dispatch(const Message* msg, T* obj, S* sender, Method func) { \ | 520 static bool Dispatch(const Message* msg, T* obj, S* sender, P* parameter, \ |
| 521 Method func) { \ |
| 558 Schema::SendParam send_params; \ | 522 Schema::SendParam send_params; \ |
| 559 bool ok = ReadSendParam(msg, &send_params); \ | 523 bool ok = ReadSendParam(msg, &send_params); \ |
| 560 return Schema::DispatchWithSendParams(ok, send_params, msg, obj, sender, \ | 524 return Schema::DispatchWithSendParams(ok, send_params, msg, obj, sender, \ |
| 561 func); \ | 525 func); \ |
| 562 } \ | 526 } \ |
| 563 template<class T, class Method> \ | 527 template<class T, class P, class Method> \ |
| 564 static bool DispatchDelayReply(const Message* msg, T* obj, Method func) { \ | 528 static bool DispatchDelayReply(const Message* msg, T* obj, P* parameter, \ |
| 529 Method func) { \ |
| 565 Schema::SendParam send_params; \ | 530 Schema::SendParam send_params; \ |
| 566 bool ok = ReadSendParam(msg, &send_params); \ | 531 bool ok = ReadSendParam(msg, &send_params); \ |
| 567 return Schema::DispatchDelayReplyWithSendParams(ok, send_params, msg, \ | 532 return Schema::DispatchDelayReplyWithSendParams(ok, send_params, msg, \ |
| 568 obj, func); \ | 533 obj, func); \ |
| 569 } | 534 } |
| 570 #define IPC_SYNC_MESSAGE_METHODS_0 \ | 535 #define IPC_SYNC_MESSAGE_METHODS_0 \ |
| 571 IPC_SYNC_MESSAGE_METHODS_GENERIC | 536 IPC_SYNC_MESSAGE_METHODS_GENERIC |
| 572 #define IPC_SYNC_MESSAGE_METHODS_1 \ | 537 #define IPC_SYNC_MESSAGE_METHODS_1 \ |
| 573 IPC_SYNC_MESSAGE_METHODS_GENERIC \ | 538 IPC_SYNC_MESSAGE_METHODS_GENERIC \ |
| 574 template<typename TA> \ | 539 template<typename TA> \ |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 // IPC_MESSAGE_UNHANDLED(handled = false) | 890 // IPC_MESSAGE_UNHANDLED(handled = false) |
| 926 // IPC_END_MESSAGE_MAP_EX() | 891 // IPC_END_MESSAGE_MAP_EX() |
| 927 // if (!msg_is_good) { | 892 // if (!msg_is_good) { |
| 928 // // Signal error here or terminate offending process. | 893 // // Signal error here or terminate offending process. |
| 929 // } | 894 // } |
| 930 // return handled; | 895 // return handled; |
| 931 // } | 896 // } |
| 932 | 897 |
| 933 | 898 |
| 934 #define IPC_BEGIN_MESSAGE_MAP_EX(class_name, msg, msg_is_ok) \ | 899 #define IPC_BEGIN_MESSAGE_MAP_EX(class_name, msg, msg_is_ok) \ |
| 935 { \ | 900 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(class_name, msg, msg_is_ok, void, NULL) |
| 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 | 901 |
| 941 #define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \ | 902 #define IPC_BEGIN_MESSAGE_MAP(class_name, msg) \ |
| 942 { \ | 903 { \ |
| 943 typedef class_name _IpcMessageHandlerClass; \ | 904 typedef class_name _IpcMessageHandlerClass; \ |
| 905 typedef void _ParamClass; \ |
| 906 _ParamClass* param__ = NULL; \ |
| 944 const IPC::Message& ipc_message__ = msg; \ | 907 const IPC::Message& ipc_message__ = msg; \ |
| 945 bool msg_is_ok__ = true; \ | 908 bool msg_is_ok__ = true; \ |
| 946 switch (ipc_message__.type()) { \ | 909 switch (ipc_message__.type()) { \ |
| 947 | 910 |
| 911 #define IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(class_name, msg, msg_is_ok, \ |
| 912 param_type, param) \ |
| 913 { \ |
| 914 typedef class_name _IpcMessageHandlerClass; \ |
| 915 typedef param_type _ParamClass; \ |
| 916 _ParamClass* param__ = param; \ |
| 917 const IPC::Message& ipc_message__ = msg; \ |
| 918 bool& msg_is_ok__ = msg_is_ok; \ |
| 919 switch (ipc_message__.type()) { \ |
| 920 |
| 948 #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \ | 921 #define IPC_MESSAGE_FORWARD(msg_class, obj, member_func) \ |
| 949 case msg_class::ID: { \ | 922 case msg_class::ID: { \ |
| 950 TRACK_RUN_IN_IPC_HANDLER(member_func); \ | 923 TRACK_RUN_IN_IPC_HANDLER(member_func); \ |
| 951 msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, \ | 924 msg_is_ok__ = msg_class::Dispatch(&ipc_message__, obj, this, \ |
| 952 &member_func); \ | 925 param__, &member_func); \ |
| 953 } \ | 926 } \ |
| 954 break; | 927 break; |
| 955 | 928 |
| 956 #define IPC_MESSAGE_HANDLER(msg_class, member_func) \ | 929 #define IPC_MESSAGE_HANDLER(msg_class, member_func) \ |
| 957 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func) | 930 IPC_MESSAGE_FORWARD(msg_class, this, _IpcMessageHandlerClass::member_func) |
| 958 | 931 |
| 959 #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \ | 932 #define IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, obj, member_func) \ |
| 960 case msg_class::ID: { \ | 933 case msg_class::ID: { \ |
| 961 TRACK_RUN_IN_IPC_HANDLER(member_func); \ | 934 TRACK_RUN_IN_IPC_HANDLER(member_func); \ |
| 962 msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, \ | 935 msg_is_ok__ = msg_class::DispatchDelayReply(&ipc_message__, obj, \ |
| 963 &member_func); \ | 936 param__, &member_func); \ |
| 964 } \ | 937 } \ |
| 965 break; | 938 break; |
| 966 | 939 |
| 967 #define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \ | 940 #define IPC_MESSAGE_HANDLER_DELAY_REPLY(msg_class, member_func) \ |
| 968 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \ | 941 IPC_MESSAGE_FORWARD_DELAY_REPLY(msg_class, this, \ |
| 969 _IpcMessageHandlerClass::member_func) | 942 _IpcMessageHandlerClass::member_func) |
| 970 | 943 |
| 971 // TODO(jar): fix chrome frame to always supply |code| argument. | 944 // TODO(jar): fix chrome frame to always supply |code| argument. |
| 972 #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \ | 945 #define IPC_MESSAGE_HANDLER_GENERIC(msg_class, code) \ |
| 973 case msg_class::ID: { \ | 946 case msg_class::ID: { \ |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 // equivalent without the #ifdef, VS2013 contains a bug where it is | 987 // equivalent without the #ifdef, VS2013 contains a bug where it is |
| 1015 // over-aggressive in optimizing out #includes. Putting the #ifdef is a | 988 // over-aggressive in optimizing out #includes. Putting the #ifdef is a |
| 1016 // workaround for this bug. See http://goo.gl/eGt2Fb for more details. | 989 // workaround for this bug. See http://goo.gl/eGt2Fb for more details. |
| 1017 // This can be removed once VS2013 is fixed. | 990 // This can be removed once VS2013 is fixed. |
| 1018 #ifdef IPC_MESSAGE_START | 991 #ifdef IPC_MESSAGE_START |
| 1019 // Clean up IPC_MESSAGE_START in this unguarded section so that the | 992 // 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 | 993 // XXX_messages.h files need not do so themselves. This makes the |
| 1021 // XXX_messages.h files easier to write. | 994 // XXX_messages.h files easier to write. |
| 1022 #undef IPC_MESSAGE_START | 995 #undef IPC_MESSAGE_START |
| 1023 #endif | 996 #endif |
| OLD | NEW |