| 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 #ifndef IPC_IPC_MESSAGE_UTILS_H_ | 5 #ifndef IPC_IPC_MESSAGE_UTILS_H_ |
| 6 #define IPC_IPC_MESSAGE_UTILS_H_ | 6 #define IPC_IPC_MESSAGE_UTILS_H_ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 | 496 |
| 497 template <> | 497 template <> |
| 498 struct IPC_EXPORT ParamTraits<base::TimeTicks> { | 498 struct IPC_EXPORT ParamTraits<base::TimeTicks> { |
| 499 typedef base::TimeTicks param_type; | 499 typedef base::TimeTicks param_type; |
| 500 static void Write(Message* m, const param_type& p); | 500 static void Write(Message* m, const param_type& p); |
| 501 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 501 static bool Read(const Message* m, PickleIterator* iter, param_type* r); |
| 502 static void Log(const param_type& p, std::string* l); | 502 static void Log(const param_type& p, std::string* l); |
| 503 }; | 503 }; |
| 504 | 504 |
| 505 template <> | 505 template <> |
| 506 struct ParamTraits<Tuple<>> { | 506 struct ParamTraits<base::Tuple<>> { |
| 507 typedef Tuple<> param_type; | 507 typedef base::Tuple<> param_type; |
| 508 static void Write(Message* m, const param_type& p) { | 508 static void Write(Message* m, const param_type& p) { |
| 509 } | 509 } |
| 510 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 510 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
| 511 return true; | 511 return true; |
| 512 } | 512 } |
| 513 static void Log(const param_type& p, std::string* l) { | 513 static void Log(const param_type& p, std::string* l) { |
| 514 } | 514 } |
| 515 }; | 515 }; |
| 516 | 516 |
| 517 template <class A> | 517 template <class A> |
| 518 struct ParamTraits<Tuple<A>> { | 518 struct ParamTraits<base::Tuple<A>> { |
| 519 typedef Tuple<A> param_type; | 519 typedef base::Tuple<A> param_type; |
| 520 static void Write(Message* m, const param_type& p) { | 520 static void Write(Message* m, const param_type& p) { |
| 521 WriteParam(m, get<0>(p)); | 521 WriteParam(m, base::get<0>(p)); |
| 522 } | 522 } |
| 523 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 523 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
| 524 return ReadParam(m, iter, &get<0>(*r)); | 524 return ReadParam(m, iter, &base::get<0>(*r)); |
| 525 } | 525 } |
| 526 static void Log(const param_type& p, std::string* l) { | 526 static void Log(const param_type& p, std::string* l) { |
| 527 LogParam(get<0>(p), l); | 527 LogParam(base::get<0>(p), l); |
| 528 } | 528 } |
| 529 }; | 529 }; |
| 530 | 530 |
| 531 template <class A, class B> | 531 template <class A, class B> |
| 532 struct ParamTraits< Tuple<A, B> > { | 532 struct ParamTraits<base::Tuple<A, B>> { |
| 533 typedef Tuple<A, B> param_type; | 533 typedef base::Tuple<A, B> param_type; |
| 534 static void Write(Message* m, const param_type& p) { | 534 static void Write(Message* m, const param_type& p) { |
| 535 WriteParam(m, get<0>(p)); | 535 WriteParam(m, base::get<0>(p)); |
| 536 WriteParam(m, get<1>(p)); | 536 WriteParam(m, base::get<1>(p)); |
| 537 } | 537 } |
| 538 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 538 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
| 539 return (ReadParam(m, iter, &get<0>(*r)) && | 539 return (ReadParam(m, iter, &base::get<0>(*r)) && |
| 540 ReadParam(m, iter, &get<1>(*r))); | 540 ReadParam(m, iter, &base::get<1>(*r))); |
| 541 } | 541 } |
| 542 static void Log(const param_type& p, std::string* l) { | 542 static void Log(const param_type& p, std::string* l) { |
| 543 LogParam(get<0>(p), l); | 543 LogParam(base::get<0>(p), l); |
| 544 l->append(", "); | 544 l->append(", "); |
| 545 LogParam(get<1>(p), l); | 545 LogParam(base::get<1>(p), l); |
| 546 } | 546 } |
| 547 }; | 547 }; |
| 548 | 548 |
| 549 template <class A, class B, class C> | 549 template <class A, class B, class C> |
| 550 struct ParamTraits< Tuple<A, B, C> > { | 550 struct ParamTraits<base::Tuple<A, B, C>> { |
| 551 typedef Tuple<A, B, C> param_type; | 551 typedef base::Tuple<A, B, C> param_type; |
| 552 static void Write(Message* m, const param_type& p) { | 552 static void Write(Message* m, const param_type& p) { |
| 553 WriteParam(m, get<0>(p)); | 553 WriteParam(m, base::get<0>(p)); |
| 554 WriteParam(m, get<1>(p)); | 554 WriteParam(m, base::get<1>(p)); |
| 555 WriteParam(m, get<2>(p)); | 555 WriteParam(m, base::get<2>(p)); |
| 556 } | 556 } |
| 557 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 557 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
| 558 return (ReadParam(m, iter, &get<0>(*r)) && | 558 return (ReadParam(m, iter, &base::get<0>(*r)) && |
| 559 ReadParam(m, iter, &get<1>(*r)) && | 559 ReadParam(m, iter, &base::get<1>(*r)) && |
| 560 ReadParam(m, iter, &get<2>(*r))); | 560 ReadParam(m, iter, &base::get<2>(*r))); |
| 561 } | 561 } |
| 562 static void Log(const param_type& p, std::string* l) { | 562 static void Log(const param_type& p, std::string* l) { |
| 563 LogParam(get<0>(p), l); | 563 LogParam(base::get<0>(p), l); |
| 564 l->append(", "); | 564 l->append(", "); |
| 565 LogParam(get<1>(p), l); | 565 LogParam(base::get<1>(p), l); |
| 566 l->append(", "); | 566 l->append(", "); |
| 567 LogParam(get<2>(p), l); | 567 LogParam(base::get<2>(p), l); |
| 568 } | 568 } |
| 569 }; | 569 }; |
| 570 | 570 |
| 571 template <class A, class B, class C, class D> | 571 template <class A, class B, class C, class D> |
| 572 struct ParamTraits< Tuple<A, B, C, D> > { | 572 struct ParamTraits<base::Tuple<A, B, C, D>> { |
| 573 typedef Tuple<A, B, C, D> param_type; | 573 typedef base::Tuple<A, B, C, D> param_type; |
| 574 static void Write(Message* m, const param_type& p) { | 574 static void Write(Message* m, const param_type& p) { |
| 575 WriteParam(m, get<0>(p)); | 575 WriteParam(m, base::get<0>(p)); |
| 576 WriteParam(m, get<1>(p)); | 576 WriteParam(m, base::get<1>(p)); |
| 577 WriteParam(m, get<2>(p)); | 577 WriteParam(m, base::get<2>(p)); |
| 578 WriteParam(m, get<3>(p)); | 578 WriteParam(m, base::get<3>(p)); |
| 579 } | 579 } |
| 580 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 580 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
| 581 return (ReadParam(m, iter, &get<0>(*r)) && | 581 return (ReadParam(m, iter, &base::get<0>(*r)) && |
| 582 ReadParam(m, iter, &get<1>(*r)) && | 582 ReadParam(m, iter, &base::get<1>(*r)) && |
| 583 ReadParam(m, iter, &get<2>(*r)) && | 583 ReadParam(m, iter, &base::get<2>(*r)) && |
| 584 ReadParam(m, iter, &get<3>(*r))); | 584 ReadParam(m, iter, &base::get<3>(*r))); |
| 585 } | 585 } |
| 586 static void Log(const param_type& p, std::string* l) { | 586 static void Log(const param_type& p, std::string* l) { |
| 587 LogParam(get<0>(p), l); | 587 LogParam(base::get<0>(p), l); |
| 588 l->append(", "); | 588 l->append(", "); |
| 589 LogParam(get<1>(p), l); | 589 LogParam(base::get<1>(p), l); |
| 590 l->append(", "); | 590 l->append(", "); |
| 591 LogParam(get<2>(p), l); | 591 LogParam(base::get<2>(p), l); |
| 592 l->append(", "); | 592 l->append(", "); |
| 593 LogParam(get<3>(p), l); | 593 LogParam(base::get<3>(p), l); |
| 594 } | 594 } |
| 595 }; | 595 }; |
| 596 | 596 |
| 597 template <class A, class B, class C, class D, class E> | 597 template <class A, class B, class C, class D, class E> |
| 598 struct ParamTraits< Tuple<A, B, C, D, E> > { | 598 struct ParamTraits<base::Tuple<A, B, C, D, E>> { |
| 599 typedef Tuple<A, B, C, D, E> param_type; | 599 typedef base::Tuple<A, B, C, D, E> param_type; |
| 600 static void Write(Message* m, const param_type& p) { | 600 static void Write(Message* m, const param_type& p) { |
| 601 WriteParam(m, get<0>(p)); | 601 WriteParam(m, base::get<0>(p)); |
| 602 WriteParam(m, get<1>(p)); | 602 WriteParam(m, base::get<1>(p)); |
| 603 WriteParam(m, get<2>(p)); | 603 WriteParam(m, base::get<2>(p)); |
| 604 WriteParam(m, get<3>(p)); | 604 WriteParam(m, base::get<3>(p)); |
| 605 WriteParam(m, get<4>(p)); | 605 WriteParam(m, base::get<4>(p)); |
| 606 } | 606 } |
| 607 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 607 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
| 608 return (ReadParam(m, iter, &get<0>(*r)) && | 608 return (ReadParam(m, iter, &base::get<0>(*r)) && |
| 609 ReadParam(m, iter, &get<1>(*r)) && | 609 ReadParam(m, iter, &base::get<1>(*r)) && |
| 610 ReadParam(m, iter, &get<2>(*r)) && | 610 ReadParam(m, iter, &base::get<2>(*r)) && |
| 611 ReadParam(m, iter, &get<3>(*r)) && | 611 ReadParam(m, iter, &base::get<3>(*r)) && |
| 612 ReadParam(m, iter, &get<4>(*r))); | 612 ReadParam(m, iter, &base::get<4>(*r))); |
| 613 } | 613 } |
| 614 static void Log(const param_type& p, std::string* l) { | 614 static void Log(const param_type& p, std::string* l) { |
| 615 LogParam(get<0>(p), l); | 615 LogParam(base::get<0>(p), l); |
| 616 l->append(", "); | 616 l->append(", "); |
| 617 LogParam(get<1>(p), l); | 617 LogParam(base::get<1>(p), l); |
| 618 l->append(", "); | 618 l->append(", "); |
| 619 LogParam(get<2>(p), l); | 619 LogParam(base::get<2>(p), l); |
| 620 l->append(", "); | 620 l->append(", "); |
| 621 LogParam(get<3>(p), l); | 621 LogParam(base::get<3>(p), l); |
| 622 l->append(", "); | 622 l->append(", "); |
| 623 LogParam(get<4>(p), l); | 623 LogParam(base::get<4>(p), l); |
| 624 } | 624 } |
| 625 }; | 625 }; |
| 626 | 626 |
| 627 template<class P> | 627 template<class P> |
| 628 struct ParamTraits<ScopedVector<P> > { | 628 struct ParamTraits<ScopedVector<P> > { |
| 629 typedef ScopedVector<P> param_type; | 629 typedef ScopedVector<P> param_type; |
| 630 static void Write(Message* m, const param_type& p) { | 630 static void Write(Message* m, const param_type& p) { |
| 631 WriteParam(m, static_cast<int>(p.size())); | 631 WriteParam(m, static_cast<int>(p.size())); |
| 632 for (size_t i = 0; i < p.size(); i++) | 632 for (size_t i = 0; i < p.size(); i++) |
| 633 WriteParam(m, *p[i]); | 633 WriteParam(m, *p[i]); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 #endif // defined(OS_WIN) | 781 #endif // defined(OS_WIN) |
| 782 | 782 |
| 783 //----------------------------------------------------------------------------- | 783 //----------------------------------------------------------------------------- |
| 784 // Generic message subclasses | 784 // Generic message subclasses |
| 785 | 785 |
| 786 // Used for asynchronous messages. | 786 // Used for asynchronous messages. |
| 787 template <class ParamType> | 787 template <class ParamType> |
| 788 class MessageSchema { | 788 class MessageSchema { |
| 789 public: | 789 public: |
| 790 typedef ParamType Param; | 790 typedef ParamType Param; |
| 791 typedef typename TupleTypes<ParamType>::ParamTuple RefParam; | 791 typedef typename base::TupleTypes<ParamType>::ParamTuple RefParam; |
| 792 | 792 |
| 793 static void Write(Message* msg, const RefParam& p) IPC_MSG_NOINLINE; | 793 static void Write(Message* msg, const RefParam& p) IPC_MSG_NOINLINE; |
| 794 static bool Read(const Message* msg, Param* p) IPC_MSG_NOINLINE; | 794 static bool Read(const Message* msg, Param* p) IPC_MSG_NOINLINE; |
| 795 }; | 795 }; |
| 796 | 796 |
| 797 // defined in ipc_logging.cc | 797 // defined in ipc_logging.cc |
| 798 IPC_EXPORT void GenerateLogData(const std::string& channel, | 798 IPC_EXPORT void GenerateLogData(const std::string& channel, |
| 799 const Message& message, | 799 const Message& message, |
| 800 LogData* data, bool get_params); | 800 LogData* data, bool get_params); |
| 801 | 801 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 } | 854 } |
| 855 | 855 |
| 856 RefTuple out_; | 856 RefTuple out_; |
| 857 }; | 857 }; |
| 858 | 858 |
| 859 // Used for synchronous messages. | 859 // Used for synchronous messages. |
| 860 template <class SendParamType, class ReplyParamType> | 860 template <class SendParamType, class ReplyParamType> |
| 861 class SyncMessageSchema { | 861 class SyncMessageSchema { |
| 862 public: | 862 public: |
| 863 typedef SendParamType SendParam; | 863 typedef SendParamType SendParam; |
| 864 typedef typename TupleTypes<SendParam>::ParamTuple RefSendParam; | 864 typedef typename base::TupleTypes<SendParam>::ParamTuple RefSendParam; |
| 865 typedef ReplyParamType ReplyParam; | 865 typedef ReplyParamType ReplyParam; |
| 866 | 866 |
| 867 static void Write(Message* msg, const RefSendParam& send) IPC_MSG_NOINLINE; | 867 static void Write(Message* msg, const RefSendParam& send) IPC_MSG_NOINLINE; |
| 868 static bool ReadSendParam(const Message* msg, SendParam* p) IPC_MSG_NOINLINE; | 868 static bool ReadSendParam(const Message* msg, SendParam* p) IPC_MSG_NOINLINE; |
| 869 static bool ReadReplyParam( | 869 static bool ReadReplyParam( |
| 870 const Message* msg, | 870 const Message* msg, |
| 871 typename TupleTypes<ReplyParam>::ValueTuple* p) IPC_MSG_NOINLINE; | 871 typename base::TupleTypes<ReplyParam>::ValueTuple* p) IPC_MSG_NOINLINE; |
| 872 | 872 |
| 873 template<class T, class S, class Method> | 873 template<class T, class S, class Method> |
| 874 static bool DispatchWithSendParams(bool ok, const SendParam& send_params, | 874 static bool DispatchWithSendParams(bool ok, const SendParam& send_params, |
| 875 const Message* msg, T* obj, S* sender, | 875 const Message* msg, T* obj, S* sender, |
| 876 Method func) { | 876 Method func) { |
| 877 Message* reply = SyncMessage::GenerateReply(msg); | 877 Message* reply = SyncMessage::GenerateReply(msg); |
| 878 if (ok) { | 878 if (ok) { |
| 879 typename TupleTypes<ReplyParam>::ValueTuple reply_params; | 879 typename base::TupleTypes<ReplyParam>::ValueTuple reply_params; |
| 880 DispatchToMethod(obj, func, send_params, &reply_params); | 880 DispatchToMethod(obj, func, send_params, &reply_params); |
| 881 WriteParam(reply, reply_params); | 881 WriteParam(reply, reply_params); |
| 882 LogReplyParamsToMessage(reply_params, msg); | 882 LogReplyParamsToMessage(reply_params, msg); |
| 883 } else { | 883 } else { |
| 884 NOTREACHED() << "Error deserializing message " << msg->type(); | 884 NOTREACHED() << "Error deserializing message " << msg->type(); |
| 885 reply->set_reply_error(); | 885 reply->set_reply_error(); |
| 886 } | 886 } |
| 887 sender->Send(reply); | 887 sender->Send(reply); |
| 888 return ok; | 888 return ok; |
| 889 } | 889 } |
| 890 | 890 |
| 891 template<class T, class Method> | 891 template<class T, class Method> |
| 892 static bool DispatchDelayReplyWithSendParams(bool ok, | 892 static bool DispatchDelayReplyWithSendParams(bool ok, |
| 893 const SendParam& send_params, | 893 const SendParam& send_params, |
| 894 const Message* msg, T* obj, | 894 const Message* msg, T* obj, |
| 895 Method func) { | 895 Method func) { |
| 896 Message* reply = SyncMessage::GenerateReply(msg); | 896 Message* reply = SyncMessage::GenerateReply(msg); |
| 897 if (ok) { | 897 if (ok) { |
| 898 Tuple<Message&> t = MakeRefTuple(*reply); | 898 base::Tuple<Message&> t = base::MakeRefTuple(*reply); |
| 899 ConnectMessageAndReply(msg, reply); | 899 ConnectMessageAndReply(msg, reply); |
| 900 DispatchToMethod(obj, func, send_params, &t); | 900 DispatchToMethod(obj, func, send_params, &t); |
| 901 } else { | 901 } else { |
| 902 NOTREACHED() << "Error deserializing message " << msg->type(); | 902 NOTREACHED() << "Error deserializing message " << msg->type(); |
| 903 reply->set_reply_error(); | 903 reply->set_reply_error(); |
| 904 obj->Send(reply); | 904 obj->Send(reply); |
| 905 } | 905 } |
| 906 return ok; | 906 return ok; |
| 907 } | 907 } |
| 908 | 908 |
| 909 template <typename... Ts> | 909 template <typename... Ts> |
| 910 static void WriteReplyParams(Message* reply, Ts... args) { | 910 static void WriteReplyParams(Message* reply, Ts... args) { |
| 911 ReplyParam p(args...); | 911 ReplyParam p(args...); |
| 912 WriteParam(reply, p); | 912 WriteParam(reply, p); |
| 913 } | 913 } |
| 914 }; | 914 }; |
| 915 | 915 |
| 916 } // namespace IPC | 916 } // namespace IPC |
| 917 | 917 |
| 918 #endif // IPC_IPC_MESSAGE_UTILS_H_ | 918 #endif // IPC_IPC_MESSAGE_UTILS_H_ |
| OLD | NEW |