Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Unified Diff: ppapi/proxy/ppapi_message_utils.h

Issue 11028104: Add template SyncCall() to PluginResource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync & resolve Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/proxy/plugin_resource.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/proxy/ppapi_message_utils.h
diff --git a/ppapi/proxy/ppapi_message_utils.h b/ppapi/proxy/ppapi_message_utils.h
new file mode 100644
index 0000000000000000000000000000000000000000..68667ddebd58fb693a8a2f518c75acf724659214
--- /dev/null
+++ b/ppapi/proxy/ppapi_message_utils.h
@@ -0,0 +1,131 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_
+#define PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_
+
+#include "base/basictypes.h"
+#include "base/pickle.h"
+#include "base/tuple.h"
+#include "ipc/ipc_message.h"
+#include "ipc/ipc_message_utils.h"
+
+namespace ppapi {
+
+namespace internal {
+
+// TupleTypeMatch* check whether a tuple type contains elements of the specified
+// types. They are used to make sure the output parameters of UnpackMessage()
+// match the corresponding message type.
+template <class TupleType, class A>
+struct TupleTypeMatch1 {
+ static const bool kValue = false;
+};
+template <class A>
+struct TupleTypeMatch1<Tuple1<A>, A> {
+ static const bool kValue = true;
+};
+
+template <class TupleType, class A, class B>
+struct TupleTypeMatch2 {
+ static const bool kValue = false;
+};
+template <class A, class B>
+struct TupleTypeMatch2<Tuple2<A, B>, A, B> {
+ static const bool kValue = true;
+};
+
+template <class TupleType, class A, class B, class C>
+struct TupleTypeMatch3 {
+ static const bool kValue = false;
+};
+template <class A, class B, class C>
+struct TupleTypeMatch3<Tuple3<A, B, C>, A, B, C> {
+ static const bool kValue = true;
+};
+
+template <class TupleType, class A, class B, class C, class D>
+struct TupleTypeMatch4 {
+ static const bool kValue = false;
+};
+template <class A, class B, class C, class D>
+struct TupleTypeMatch4<Tuple4<A, B, C, D>, A, B, C, D> {
+ static const bool kValue = true;
+};
+
+template <class TupleType, class A, class B, class C, class D, class E>
+struct TupleTypeMatch5 {
+ static const bool kValue = false;
+};
+template <class A, class B, class C, class D, class E>
+struct TupleTypeMatch5<Tuple5<A, B, C, D, E>, A, B, C, D, E> {
+ static const bool kValue = true;
+};
+
+} // namespace internal
+
+template <class MsgClass, class A>
+bool UnpackMessage(const IPC::Message& msg, A* a) {
+ COMPILE_ASSERT(
+ (internal::TupleTypeMatch1<typename MsgClass::Param, A>::kValue),
+ tuple_types_dont_match);
+
+ PickleIterator iter(msg);
+ return IPC::ReadParam(&msg, &iter, a);
+}
+
+template <class MsgClass, class A, class B>
+bool UnpackMessage(const IPC::Message& msg, A* a, B* b) {
+ COMPILE_ASSERT(
+ (internal::TupleTypeMatch2<typename MsgClass::Param, A, B>::kValue),
+ tuple_types_dont_match);
+
+ PickleIterator iter(msg);
+ return IPC::ReadParam(&msg, &iter, a) && IPC::ReadParam(&msg, &iter, b);
+}
+
+template <class MsgClass, class A, class B, class C>
+bool UnpackMessage(const IPC::Message& msg, A* a, B* b, C* c) {
+ COMPILE_ASSERT(
+ (internal::TupleTypeMatch3<typename MsgClass::Param, A, B, C>::kValue),
+ tuple_types_dont_match);
+
+ PickleIterator iter(msg);
+ return IPC::ReadParam(&msg, &iter, a) &&
+ IPC::ReadParam(&msg, &iter, b) &&
+ IPC::ReadParam(&msg, &iter, c);
+}
+
+template <class MsgClass, class A, class B, class C, class D>
+bool UnpackMessage(const IPC::Message& msg, A* a, B* b, C* c, D* d) {
+ COMPILE_ASSERT(
+ (internal::TupleTypeMatch4<typename MsgClass::Param, A, B, C, D>::kValue),
+ tuple_types_dont_match);
+
+ PickleIterator iter(msg);
+ return IPC::ReadParam(&msg, &iter, a) &&
+ IPC::ReadParam(&msg, &iter, b) &&
+ IPC::ReadParam(&msg, &iter, c) &&
+ IPC::ReadParam(&msg, &iter, d);
+}
+
+template <class MsgClass, class A, class B, class C, class D, class E>
+bool UnpackMessage(const IPC::Message& msg, A* a, B* b, C* c, D* d, E* e) {
+ COMPILE_ASSERT(
+ (internal::TupleTypeMatch5<
+ typename MsgClass::Param, A, B, C, D, E>::kValue),
+ tuple_types_dont_match);
+
+ PickleIterator iter(msg);
+ return IPC::ReadParam(&msg, &iter, a) &&
+ IPC::ReadParam(&msg, &iter, b) &&
+ IPC::ReadParam(&msg, &iter, c) &&
+ IPC::ReadParam(&msg, &iter, d) &&
+ IPC::ReadParam(&msg, &iter, e);
+}
+
+} // namespace ppapi
+
+#endif // PPAPI_PROXY_PPAPI_MESSAGE_UTILS_H_
+
« no previous file with comments | « ppapi/proxy/plugin_resource.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698