Index: ppapi/host/dispatch_host_message.h |
diff --git a/ppapi/host/dispatch_host_message.h b/ppapi/host/dispatch_host_message.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3e60e577995811528325215c36fcc42acfae1f0a |
--- /dev/null |
+++ b/ppapi/host/dispatch_host_message.h |
@@ -0,0 +1,78 @@ |
+// 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. |
+ |
+#include "ipc/ipc_message_macros.h" |
+ |
+// This file provides infrastructure for dispatching host resource call |
+// messages. Normal IPC message handlers can't take extra parameters or |
+// return values. We want to take a HostMessageContext as a parameter and |
+// also return the int32_t return value to the caller. |
+ |
+#include "base/profiler/scoped_profile.h" // For TRACK_RUN_IN_IPC_HANDLER. |
+#include "ppapi/c/pp_errors.h" |
+ |
+namespace ppapi { |
+namespace host { |
+ |
+struct HostMessageContext; |
+ |
+template <class ObjT, class Method> |
+inline int32_t DispatchResourceCall(ObjT* obj, Method method, |
+ HostMessageContext* context, |
+ const Tuple0& arg) { |
+ return (obj->*method)(context); |
+} |
+ |
+template <class ObjT, class Method, class A> |
+inline int32_t DispatchResourceCall(ObjT* obj, Method method, |
+ HostMessageContext* context, |
+ const Tuple1<A>& arg) { |
+ return (obj->*method)(context, arg.a); |
+} |
+ |
+template<class ObjT, class Method, class A, class B> |
+inline int32_t DispatchResourceCall(ObjT* obj, Method method, |
+ HostMessageContext* context, |
+ const Tuple2<A, B>& arg) { |
+ return (obj->*method)(context, arg.a, arg.b); |
+} |
+ |
+template<class ObjT, class Method, class A, class B, class C> |
+inline int32_t DispatchResourceCall(ObjT* obj, Method method, |
+ HostMessageContext* context, |
+ const Tuple3<A, B, C>& arg) { |
+ return (obj->*method)(context, arg.a, arg.b, arg.c); |
+} |
+ |
+template<class ObjT, class Method, class A, class B, class C, class D> |
+inline int32_t DispatchResourceCall(ObjT* obj, Method method, |
+ HostMessageContext* context, |
+ const Tuple4<A, B, C, D>& arg) { |
+ return (obj->*method)(context, arg.a, arg.b, arg.c, arg.d); |
+} |
+ |
+template<class ObjT, class Method, class A, class B, class C, class D, class E> |
+inline int32_t DispatchResourceCall(ObjT* obj, Method method, |
+ HostMessageContext* context, |
+ const Tuple5<A, B, C, D, E>& arg) { |
+ return (obj->*method)(context, arg.a, arg.b, arg.c, arg.d, arg.e); |
+} |
+ |
+#define PPAPI_DISPATCH_HOST_RESOURCE_CALL(msg_class, member_func) \ |
+ case msg_class::ID: { \ |
+ TRACK_RUN_IN_IPC_HANDLER(member_func); \ |
+ msg_class::Schema::Param p; \ |
+ if (msg_class::Read(&ipc_message__, &p)) { \ |
+ return ppapi::host::DispatchResourceCall( \ |
+ this, \ |
+ &_IpcMessageHandlerClass::member_func, \ |
+ context, p); \ |
+ } else { \ |
+ return PP_ERROR_FAILED; \ |
+ } \ |
+ } \ |
+ break; |
+ |
+} // namespace host |
+} // namespace ppapi |