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.
5 #include "nacl_io/real_pepper_interface.h"
9 #include <ppapi/c/pp_errors.h>
11 #include "nacl_io/log.h"
15 #include "nacl_io/pepper/undef_macros.h"
16 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \
17 class Real##BaseClass : public BaseClass { \
19 explicit Real##BaseClass(const PPInterface* interface);
20 #define END_INTERFACE(BaseClass, PPInterface) \
22 const PPInterface* interface_; \
24 #define METHOD0(Class, ReturnType, MethodName) \
25 virtual ReturnType MethodName();
26 #define METHOD1(Class, ReturnType, MethodName, Type0) \
27 virtual ReturnType MethodName(Type0);
28 #define METHOD2(Class, ReturnType, MethodName, Type0, Type1) \
29 virtual ReturnType MethodName(Type0, Type1);
30 #define METHOD3(Class, ReturnType, MethodName, Type0, Type1, Type2) \
31 virtual ReturnType MethodName(Type0, Type1, Type2);
32 #define METHOD4(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3) \
33 virtual ReturnType MethodName(Type0, Type1, Type2, Type3);
34 #define METHOD5(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3, \
36 virtual ReturnType MethodName(Type0, Type1, Type2, Type3, Type4);
37 #include "nacl_io/pepper/all_interfaces.h"
40 #include "nacl_io/pepper/undef_macros.h"
41 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \
42 Real##BaseClass::Real##BaseClass(const PPInterface* interface) \
43 : interface_(interface) {}
45 #define END_INTERFACE(BaseClass, PPInterface)
47 #define METHOD0(BaseClass, ReturnType, MethodName) \
48 ReturnType Real##BaseClass::MethodName() { \
49 return interface_->MethodName(); \
51 #define METHOD1(BaseClass, ReturnType, MethodName, Type0) \
52 ReturnType Real##BaseClass::MethodName(Type0 arg0) { \
53 return interface_->MethodName(arg0); \
55 #define METHOD2(BaseClass, ReturnType, MethodName, Type0, Type1) \
56 ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1) { \
57 return interface_->MethodName(arg0, arg1); \
59 #define METHOD3(BaseClass, ReturnType, MethodName, Type0, Type1, Type2) \
60 ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1, \
62 return interface_->MethodName(arg0, arg1, arg2); \
64 #define METHOD4(BaseClass, ReturnType, MethodName, Type0, Type1, Type2, Type3) \
65 ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1, Type2 arg2, \
67 return interface_->MethodName(arg0, arg1, arg2, arg3); \
69 #define METHOD5(BaseClass, ReturnType, MethodName, Type0, Type1, Type2, Type3, \
71 ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1, Type2 arg2, \
72 Type3 arg3, Type4 arg4) { \
73 return interface_->MethodName(arg0, arg1, arg2, arg3, arg4); \
75 #include "nacl_io/pepper/all_interfaces.h"
78 RealPepperInterface::RealPepperInterface(PP_Instance instance
,
79 PPB_GetInterface get_browser_interface
)
80 : instance_(instance
) {
81 #include "nacl_io/pepper/undef_macros.h"
82 #include "nacl_io/pepper/define_empty_macros.h"
83 #undef BEGIN_INTERFACE
84 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) { \
85 const PPInterface* iface = static_cast<const PPInterface*>( \
86 get_browser_interface(InterfaceString)); \
87 BaseClass##interface_ = NULL; \
89 BaseClass##interface_ = new Real##BaseClass(iface); \
91 LOG_ERROR("interface missing: %s\n", InterfaceString); \
93 #include "nacl_io/pepper/all_interfaces.h"
96 PP_Instance
RealPepperInterface::GetInstance() {
100 // Define getter function.
101 #include "nacl_io/pepper/undef_macros.h"
102 #include "nacl_io/pepper/define_empty_macros.h"
103 #undef BEGIN_INTERFACE
104 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \
105 BaseClass* RealPepperInterface::Get##BaseClass() { \
106 return BaseClass##interface_; \
108 #include "nacl_io/pepper/all_interfaces.h"
110 } // namespace nacl_io