Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_ | |
|
raymes
2012/10/11 04:45:54
Optional: combine this with ppapi/proxy/dispatch_r
yzshen1
2012/10/12 16:47:03
I think it is better to keep it as a separate file
| |
| 6 #define PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/pickle.h" | |
| 10 #include "base/tuple.h" | |
| 11 #include "ipc/ipc_message.h" | |
| 12 #include "ipc/ipc_message_utils.h" | |
| 13 | |
| 14 namespace ppapi { | |
| 15 | |
| 16 // TupleTypeMatch* check whether a tuple type contains elements of the specified | |
|
brettw
2012/10/10 21:58:23
Can you put the TupleTypeMatch in a nested "intern
yzshen1
2012/10/10 22:24:22
Done.
yzshen1
2012/10/10 22:24:22
Done.
| |
| 17 // types. They are used to make sure the output parameters of UnpackMessage() | |
| 18 // match the corresponding message type. | |
| 19 template <class TupleType, class A> | |
| 20 struct TupleTypeMatch1 { | |
| 21 static const bool kValue = false; | |
| 22 }; | |
| 23 template <class A> | |
| 24 struct TupleTypeMatch1<Tuple1<A>, A> { | |
| 25 static const bool kValue = true; | |
| 26 }; | |
| 27 | |
| 28 template <class TupleType, class A, class B> | |
| 29 struct TupleTypeMatch2 { | |
| 30 static const bool kValue = false; | |
| 31 }; | |
| 32 template <class A, class B> | |
| 33 struct TupleTypeMatch2<Tuple2<A, B>, A, B> { | |
| 34 static const bool kValue = true; | |
| 35 }; | |
| 36 | |
| 37 template <class TupleType, class A, class B, class C> | |
| 38 struct TupleTypeMatch3 { | |
| 39 static const bool kValue = false; | |
| 40 }; | |
| 41 template <class A, class B, class C> | |
| 42 struct TupleTypeMatch3<Tuple3<A, B, C>, A, B, C> { | |
| 43 static const bool kValue = true; | |
| 44 }; | |
| 45 | |
| 46 template <class TupleType, class A, class B, class C, class D> | |
| 47 struct TupleTypeMatch4 { | |
| 48 static const bool kValue = false; | |
| 49 }; | |
| 50 template <class A, class B, class C, class D> | |
| 51 struct TupleTypeMatch4<Tuple4<A, B, C, D>, A, B, C, D> { | |
| 52 static const bool kValue = true; | |
| 53 }; | |
| 54 | |
| 55 template <class TupleType, class A, class B, class C, class D, class E> | |
| 56 struct TupleTypeMatch5 { | |
| 57 static const bool kValue = false; | |
| 58 }; | |
| 59 template <class A, class B, class C, class D, class E> | |
| 60 struct TupleTypeMatch5<Tuple5<A, B, C, D, E>, A, B, C, D, E> { | |
| 61 static const bool kValue = true; | |
| 62 }; | |
| 63 | |
| 64 template <class MsgClass, class A> | |
| 65 bool UnpackMessage(const IPC::Message& msg, A* a) { | |
| 66 COMPILE_ASSERT((TupleTypeMatch1<typename MsgClass::Param, A>::kValue), | |
| 67 tuple_type_not_match); | |
| 68 | |
| 69 PickleIterator iter(msg); | |
| 70 return IPC::ReadParam(&msg, &iter, a); | |
| 71 } | |
| 72 | |
| 73 template <class MsgClass, class A, class B> | |
| 74 bool UnpackMessage(const IPC::Message& msg, A* a, B* b) { | |
| 75 COMPILE_ASSERT((TupleTypeMatch2<typename MsgClass::Param, A, B>::kValue), | |
| 76 tuple_type_not_match); | |
| 77 | |
| 78 PickleIterator iter(msg); | |
| 79 return IPC::ReadParam(&msg, &iter, a) && IPC::ReadParam(&msg, &iter, b); | |
| 80 } | |
| 81 | |
| 82 template <class MsgClass, class A, class B, class C> | |
| 83 bool UnpackMessage(const IPC::Message& msg, A* a, B* b, C* c) { | |
| 84 COMPILE_ASSERT((TupleTypeMatch3<typename MsgClass::Param, A, B, C>::kValue), | |
| 85 tuple_type_not_match); | |
| 86 | |
| 87 PickleIterator iter(msg); | |
| 88 return IPC::ReadParam(&msg, &iter, a) && | |
| 89 IPC::ReadParam(&msg, &iter, b) && | |
| 90 IPC::ReadParam(&msg, &iter, c); | |
| 91 } | |
| 92 | |
| 93 template <class MsgClass, class A, class B, class C, class D> | |
| 94 bool UnpackMessage(const IPC::Message& msg, A* a, B* b, C* c, D* d) { | |
| 95 COMPILE_ASSERT( | |
| 96 (TupleTypeMatch4<typename MsgClass::Param, A, B, C, D>::kValue), | |
| 97 tuple_type_not_match); | |
| 98 | |
| 99 PickleIterator iter(msg); | |
| 100 return IPC::ReadParam(&msg, &iter, a) && | |
| 101 IPC::ReadParam(&msg, &iter, b) && | |
| 102 IPC::ReadParam(&msg, &iter, c) && | |
| 103 IPC::ReadParam(&msg, &iter, d); | |
| 104 } | |
| 105 | |
| 106 template <class MsgClass, class A, class B, class C, class D, class E> | |
| 107 bool UnpackMessage(const IPC::Message& msg, A* a, B* b, C* c, D* d, E* e) { | |
| 108 COMPILE_ASSERT( | |
| 109 (TupleTypeMatch5<typename MsgClass::Param, A, B, C, D, E>::kValue), | |
| 110 tuple_type_not_match); | |
| 111 | |
| 112 PickleIterator iter(msg); | |
| 113 return IPC::ReadParam(&msg, &iter, a) && | |
| 114 IPC::ReadParam(&msg, &iter, b) && | |
| 115 IPC::ReadParam(&msg, &iter, c) && | |
| 116 IPC::ReadParam(&msg, &iter, d) && | |
| 117 IPC::ReadParam(&msg, &iter, e); | |
| 118 } | |
| 119 | |
| 120 } // namespace ppapi | |
| 121 | |
| 122 #endif // PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_ | |
| 123 | |
| OLD | NEW |