- add sources.
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / libraries / nacl_io / real_pepper_interface.cc
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 #include "nacl_io/real_pepper_interface.h"
6
7 #include <assert.h>
8 #include <stdio.h>
9 #include <ppapi/c/pp_errors.h>
10
11 #include "nacl_io/dbgprint.h"
12
13 namespace nacl_io {
14
15 #include "nacl_io/pepper/undef_macros.h"
16 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \
17     class Real##BaseClass : public BaseClass { \
18      public: \
19       explicit Real##BaseClass(const PPInterface* interface);
20 #define END_INTERFACE(BaseClass, PPInterface) \
21      private: \
22       const PPInterface* interface_; \
23     };
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, \
35                 Type4) \
36     virtual ReturnType MethodName(Type0, Type1, Type2, Type3, Type4);
37 #include "nacl_io/pepper/all_interfaces.h"
38
39
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) {}
44
45 #define END_INTERFACE(BaseClass, PPInterface)
46
47 #define METHOD0(BaseClass, ReturnType, MethodName) \
48     ReturnType Real##BaseClass::MethodName() { \
49       return interface_->MethodName(); \
50     }
51 #define METHOD1(BaseClass, ReturnType, MethodName, Type0) \
52     ReturnType Real##BaseClass::MethodName(Type0 arg0) { \
53       return interface_->MethodName(arg0); \
54     }
55 #define METHOD2(BaseClass, ReturnType, MethodName, Type0, Type1) \
56     ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1) { \
57       return interface_->MethodName(arg0, arg1); \
58     }
59 #define METHOD3(BaseClass, ReturnType, MethodName, Type0, Type1, Type2) \
60     ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1, \
61                                            Type2 arg2) { \
62       return interface_->MethodName(arg0, arg1, arg2); \
63     }
64 #define METHOD4(BaseClass, ReturnType, MethodName, Type0, Type1, Type2, Type3) \
65     ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1, Type2 arg2, \
66                                            Type3 arg3) { \
67       return interface_->MethodName(arg0, arg1, arg2, arg3); \
68     }
69 #define METHOD5(BaseClass, ReturnType, MethodName, Type0, Type1, Type2, Type3, \
70                 Type4) \
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); \
74     }
75 #include "nacl_io/pepper/all_interfaces.h"
76
77
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; \
88     if (iface) \
89       BaseClass##interface_ = new Real##BaseClass(iface); \
90     else \
91       dbgprintf("nacl_io: interface missing: %s\n", InterfaceString); \
92   }
93 #include "nacl_io/pepper/all_interfaces.h"
94 }
95
96 PP_Instance RealPepperInterface::GetInstance() {
97   return instance_;
98 }
99
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_; \
107     }
108 #include "nacl_io/pepper/all_interfaces.h"
109
110 }  // namespace nacl_io
111