| 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 PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_ | 5 #ifndef PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_ |
| 6 #define PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_ | 6 #define PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
| 10 #include "base/tuple.h" | 10 #include "base/tuple.h" |
| 11 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
| 12 #include "ipc/ipc_message_utils.h" | 12 #include "ipc/ipc_message_utils.h" |
| 13 | 13 |
| 14 namespace ppapi { | 14 namespace ppapi { |
| 15 | 15 |
| 16 namespace internal { | 16 namespace internal { |
| 17 | 17 |
| 18 // TupleTypeMatch* check whether a tuple type contains elements of the specified | 18 // TupleTypeMatch* check whether a tuple type contains elements of the specified |
| 19 // types. They are used to make sure the output parameters of UnpackMessage() | 19 // types. They are used to make sure the output parameters of UnpackMessage() |
| 20 // match the corresponding message type. | 20 // match the corresponding message type. |
| 21 template <class TupleType, class A> | 21 template <class TupleType, class A> |
| 22 struct TupleTypeMatch1 { | 22 struct TupleTypeMatch1 { |
| 23 static const bool kValue = false; | 23 static const bool kValue = false; |
| 24 }; | 24 }; |
| 25 template <class A> | 25 template <class A> |
| 26 struct TupleTypeMatch1<Tuple1<A>, A> { | 26 struct TupleTypeMatch1<Tuple<A>, A> { |
| 27 static const bool kValue = true; | 27 static const bool kValue = true; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 template <class TupleType, class A, class B> | 30 template <class TupleType, class A, class B> |
| 31 struct TupleTypeMatch2 { | 31 struct TupleTypeMatch2 { |
| 32 static const bool kValue = false; | 32 static const bool kValue = false; |
| 33 }; | 33 }; |
| 34 template <class A, class B> | 34 template <class A, class B> |
| 35 struct TupleTypeMatch2<Tuple2<A, B>, A, B> { | 35 struct TupleTypeMatch2<Tuple<A, B>, A, B> { |
| 36 static const bool kValue = true; | 36 static const bool kValue = true; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 template <class TupleType, class A, class B, class C> | 39 template <class TupleType, class A, class B, class C> |
| 40 struct TupleTypeMatch3 { | 40 struct TupleTypeMatch3 { |
| 41 static const bool kValue = false; | 41 static const bool kValue = false; |
| 42 }; | 42 }; |
| 43 template <class A, class B, class C> | 43 template <class A, class B, class C> |
| 44 struct TupleTypeMatch3<Tuple3<A, B, C>, A, B, C> { | 44 struct TupleTypeMatch3<Tuple<A, B, C>, A, B, C> { |
| 45 static const bool kValue = true; | 45 static const bool kValue = true; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 template <class TupleType, class A, class B, class C, class D> | 48 template <class TupleType, class A, class B, class C, class D> |
| 49 struct TupleTypeMatch4 { | 49 struct TupleTypeMatch4 { |
| 50 static const bool kValue = false; | 50 static const bool kValue = false; |
| 51 }; | 51 }; |
| 52 template <class A, class B, class C, class D> | 52 template <class A, class B, class C, class D> |
| 53 struct TupleTypeMatch4<Tuple4<A, B, C, D>, A, B, C, D> { | 53 struct TupleTypeMatch4<Tuple<A, B, C, D>, A, B, C, D> { |
| 54 static const bool kValue = true; | 54 static const bool kValue = true; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 template <class TupleType, class A, class B, class C, class D, class E> | 57 template <class TupleType, class A, class B, class C, class D, class E> |
| 58 struct TupleTypeMatch5 { | 58 struct TupleTypeMatch5 { |
| 59 static const bool kValue = false; | 59 static const bool kValue = false; |
| 60 }; | 60 }; |
| 61 template <class A, class B, class C, class D, class E> | 61 template <class A, class B, class C, class D, class E> |
| 62 struct TupleTypeMatch5<Tuple5<A, B, C, D, E>, A, B, C, D, E> { | 62 struct TupleTypeMatch5<Tuple<A, B, C, D, E>, A, B, C, D, E> { |
| 63 static const bool kValue = true; | 63 static const bool kValue = true; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 } // namespace internal | 66 } // namespace internal |
| 67 | 67 |
| 68 template <class MsgClass, class A> | 68 template <class MsgClass, class A> |
| 69 bool UnpackMessage(const IPC::Message& msg, A* a) { | 69 bool UnpackMessage(const IPC::Message& msg, A* a) { |
| 70 COMPILE_ASSERT( | 70 COMPILE_ASSERT( |
| 71 (internal::TupleTypeMatch1<typename MsgClass::Param, A>::kValue), | 71 (internal::TupleTypeMatch1<typename MsgClass::Param, A>::kValue), |
| 72 tuple_types_dont_match); | 72 tuple_types_dont_match); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 return IPC::ReadParam(&msg, &iter, a) && | 121 return IPC::ReadParam(&msg, &iter, a) && |
| 122 IPC::ReadParam(&msg, &iter, b) && | 122 IPC::ReadParam(&msg, &iter, b) && |
| 123 IPC::ReadParam(&msg, &iter, c) && | 123 IPC::ReadParam(&msg, &iter, c) && |
| 124 IPC::ReadParam(&msg, &iter, d) && | 124 IPC::ReadParam(&msg, &iter, d) && |
| 125 IPC::ReadParam(&msg, &iter, e); | 125 IPC::ReadParam(&msg, &iter, e); |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace ppapi | 128 } // namespace ppapi |
| 129 | 129 |
| 130 #endif // PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_ | 130 #endif // PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_ |
| 131 | |
| OLD | NEW |