OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 #include <map> | 10 #include <map> |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 93 } |
94 } | 94 } |
95 private: | 95 private: |
96 const Message& msg_; | 96 const Message& msg_; |
97 mutable void* iter_; | 97 mutable void* iter_; |
98 }; | 98 }; |
99 | 99 |
100 //----------------------------------------------------------------------------- | 100 //----------------------------------------------------------------------------- |
101 // ParamTraits specializations, etc. | 101 // ParamTraits specializations, etc. |
102 | 102 |
103 template <class P> struct ParamTraits {}; | 103 template <class P> struct ParamTraits { |
| 104 }; |
| 105 |
| 106 template <class P> |
| 107 struct SimilarTypeTraits { |
| 108 typedef P Type; |
| 109 }; |
104 | 110 |
105 template <class P> | 111 template <class P> |
106 static inline void WriteParam(Message* m, const P& p) { | 112 static inline void WriteParam(Message* m, const P& p) { |
107 ParamTraits<P>::Write(m, p); | 113 typedef typename SimilarTypeTraits<P>::Type Type; |
| 114 ParamTraits<Type>::Write(m, static_cast<const Type& >(p)); |
108 } | 115 } |
109 | 116 |
110 template <class P> | 117 template <class P> |
111 static inline bool WARN_UNUSED_RESULT ReadParam(const Message* m, void** iter, | 118 static inline bool WARN_UNUSED_RESULT ReadParam(const Message* m, void** iter, |
112 P* p) { | 119 P* p) { |
113 return ParamTraits<P>::Read(m, iter, p); | 120 typedef typename SimilarTypeTraits<P>::Type Type; |
| 121 return ParamTraits<Type>::Read(m, iter, reinterpret_cast<Type* >(p)); |
114 } | 122 } |
115 | 123 |
116 template <class P> | 124 template <class P> |
117 static inline void LogParam(const P& p, std::wstring* l) { | 125 static inline void LogParam(const P& p, std::wstring* l) { |
118 ParamTraits<P>::Log(p, l); | 126 typedef typename SimilarTypeTraits<P>::Type Type; |
| 127 ParamTraits<Type>::Log(static_cast<const Type& >(p), l); |
119 } | 128 } |
120 | 129 |
121 template <> | 130 template <> |
122 struct ParamTraits<bool> { | 131 struct ParamTraits<bool> { |
123 typedef bool param_type; | 132 typedef bool param_type; |
124 static void Write(Message* m, const param_type& p) { | 133 static void Write(Message* m, const param_type& p) { |
125 m->WriteBool(p); | 134 m->WriteBool(p); |
126 } | 135 } |
127 static bool Read(const Message* m, void** iter, param_type* r) { | 136 static bool Read(const Message* m, void** iter, param_type* r) { |
128 return m->ReadBool(iter, r); | 137 return m->ReadBool(iter, r); |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 ReadParam(m, iter, &r->dispatch) && | 790 ReadParam(m, iter, &r->dispatch) && |
782 ReadParam(m, iter, &r->params); | 791 ReadParam(m, iter, &r->params); |
783 r->type = static_cast<uint16>(type); | 792 r->type = static_cast<uint16>(type); |
784 return result; | 793 return result; |
785 } | 794 } |
786 static void Log(const param_type& p, std::wstring* l) { | 795 static void Log(const param_type& p, std::wstring* l) { |
787 // Doesn't make sense to implement this! | 796 // Doesn't make sense to implement this! |
788 } | 797 } |
789 }; | 798 }; |
790 | 799 |
791 | |
792 template <> | 800 template <> |
793 struct ParamTraits<Message> { | 801 struct ParamTraits<Message> { |
794 static void Write(Message* m, const Message& p) { | 802 static void Write(Message* m, const Message& p) { |
795 m->WriteInt(p.size()); | 803 m->WriteInt(p.size()); |
796 m->WriteData(reinterpret_cast<const char*>(p.data()), p.size()); | 804 m->WriteData(reinterpret_cast<const char*>(p.data()), p.size()); |
797 } | 805 } |
798 static bool Read(const Message* m, void** iter, Message* r) { | 806 static bool Read(const Message* m, void** iter, Message* r) { |
799 int size; | 807 int size; |
800 if (!m->ReadInt(iter, &size)) | 808 if (!m->ReadInt(iter, &size)) |
801 return false; | 809 return false; |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 ReplyParam p(a, b, c, d, e); | 1233 ReplyParam p(a, b, c, d, e); |
1226 WriteParam(reply, p); | 1234 WriteParam(reply, p); |
1227 } | 1235 } |
1228 }; | 1236 }; |
1229 | 1237 |
1230 //----------------------------------------------------------------------------- | 1238 //----------------------------------------------------------------------------- |
1231 | 1239 |
1232 } // namespace IPC | 1240 } // namespace IPC |
1233 | 1241 |
1234 #endif // IPC_IPC_MESSAGE_UTILS_H_ | 1242 #endif // IPC_IPC_MESSAGE_UTILS_H_ |
OLD | NEW |