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 // This file provides infrastructure for dispatching host resource call
6 // messages. Normal IPC message handlers can't take extra parameters or
7 // return values. We want to take a HostMessageContext as a parameter and
8 // also return the int32_t return value to the caller.
9
10 #ifndef PPAPI_HOST_DISPATCH_HOST_MESSAGE_H_
11 #define PPAPI_HOST_DISPATCH_HOST_MESSAGE_H_
12
13 #include "base/profiler/scoped_profile.h"
14 #include "ipc/ipc_message_macros.h"
15 #include "ppapi/c/pp_errors.h"
16
17 namespace ppapi {
18 namespace host {
19
20 struct HostMessageContext;
21
22 template <class ObjT, class Method>
DispatchResourceCall(ObjT * obj,Method method,HostMessageContext * context,Tuple0 & arg)23 inline int32_t DispatchResourceCall(ObjT* obj, Method method,
24 HostMessageContext* context,
25 Tuple0& arg) {
26 return (obj->*method)(context);
27 }
28
29 template <class ObjT, class Method, class A>
DispatchResourceCall(ObjT * obj,Method method,HostMessageContext * context,Tuple1<A> & arg)30 inline int32_t DispatchResourceCall(ObjT* obj, Method method,
31 HostMessageContext* context,
32 Tuple1<A>& arg) {
33 return (obj->*method)(context, arg.a);
34 }
35
36 template<class ObjT, class Method, class A, class B>
DispatchResourceCall(ObjT * obj,Method method,HostMessageContext * context,Tuple2<A,B> & arg)37 inline int32_t DispatchResourceCall(ObjT* obj, Method method,
38 HostMessageContext* context,
39 Tuple2<A, B>& arg) {
40 return (obj->*method)(context, arg.a, arg.b);
41 }
42
43 template<class ObjT, class Method, class A, class B, class C>
DispatchResourceCall(ObjT * obj,Method method,HostMessageContext * context,Tuple3<A,B,C> & arg)44 inline int32_t DispatchResourceCall(ObjT* obj, Method method,
45 HostMessageContext* context,
46 Tuple3<A, B, C>& arg) {
47 return (obj->*method)(context, arg.a, arg.b, arg.c);
48 }
49
50 template<class ObjT, class Method, class A, class B, class C, class D>
DispatchResourceCall(ObjT * obj,Method method,HostMessageContext * context,Tuple4<A,B,C,D> & arg)51 inline int32_t DispatchResourceCall(ObjT* obj, Method method,
52 HostMessageContext* context,
53 Tuple4<A, B, C, D>& arg) {
54 return (obj->*method)(context, arg.a, arg.b, arg.c, arg.d);
55 }
56
57 template<class ObjT, class Method, class A, class B, class C, class D, class E>
DispatchResourceCall(ObjT * obj,Method method,HostMessageContext * context,Tuple5<A,B,C,D,E> & arg)58 inline int32_t DispatchResourceCall(ObjT* obj, Method method,
59 HostMessageContext* context,
60 Tuple5<A, B, C, D, E>& arg) {
61 return (obj->*method)(context, arg.a, arg.b, arg.c, arg.d, arg.e);
62 }
63
64 // Note that this only works for message with 1 or more parameters. For
65 // 0-parameter messages you need to use the _0 version below (since there are
66 // no params in the message).
67 #define PPAPI_DISPATCH_HOST_RESOURCE_CALL(msg_class, member_func) \
68 case msg_class::ID: { \
69 TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \
70 msg_class::Schema::Param p; \
71 if (msg_class::Read(&ipc_message__, &p)) { \
72 return ppapi::host::DispatchResourceCall( \
73 this, \
74 &_IpcMessageHandlerClass::member_func, \
75 context, p); \
76 } \
77 return PP_ERROR_FAILED; \
78 }
79
80 #define PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(msg_class, member_func) \
81 case msg_class::ID: { \
82 TRACK_RUN_IN_THIS_SCOPED_REGION(member_func); \
83 return member_func(context); \
84 }
85
86 } // namespace host
87 } // namespace ppapi
88
89 #endif // PPAPI_HOST_DISPATCH_HOST_MESSAGE_H_
90