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 #ifndef LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_
6 #define LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_
8 #include <ppapi/c/pp_bool.h>
9 #include <ppapi/c/pp_completion_callback.h>
10 #include <ppapi/c/pp_errors.h>
11 #include <ppapi/c/pp_file_info.h>
12 #include <ppapi/c/pp_instance.h>
13 #include <ppapi/c/pp_resource.h>
14 #include <ppapi/c/pp_var.h>
15 #include <ppapi/c/ppb_console.h>
16 #include <ppapi/c/ppb_core.h>
17 #include <ppapi/c/ppb_file_io.h>
18 #include <ppapi/c/ppb_file_ref.h>
19 #include <ppapi/c/ppb_file_system.h>
20 #include <ppapi/c/ppb_host_resolver.h>
21 #include <ppapi/c/ppb_messaging.h>
22 #include <ppapi/c/ppb_messaging.h>
23 #include <ppapi/c/ppb_net_address.h>
24 #include <ppapi/c/ppb_tcp_socket.h>
25 #include <ppapi/c/ppb_url_loader.h>
26 #include <ppapi/c/ppb_url_request_info.h>
27 #include <ppapi/c/ppb_url_response_info.h>
28 #include <ppapi/c/ppb_udp_socket.h>
29 #include <ppapi/c/ppb_var.h>
31 #include <sdk_util/macros.h>
35 // This class is the base interface for Pepper used by nacl_io.
37 // We use #include and macro magic to simplify adding new interfaces. The
38 // resulting PepperInterface basically looks like this:
40 // class PepperInterface {
42 // virtual ~PepperInterface() {}
43 // virtual PP_Instance GetInstance() = 0;
46 // // Interface getters.
47 // ConsoleInterface* GetConsoleInterface() = 0;
48 // CoreInterface* GetCoreInterface() = 0;
49 // FileIoInterface* GetFileIoInterface() = 0;
54 // Note: To add a new interface:
56 // 1. Using one of the other interfaces as a template, add your interface to
58 // 2. Add the necessary pepper header to the top of this file.
59 // 3. Compile and cross your fingers!
62 // Forward declare interface classes.
63 #include "nacl_io/pepper/undef_macros.h"
64 #include "nacl_io/pepper/define_empty_macros.h"
65 #undef BEGIN_INTERFACE
66 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \
68 #include "nacl_io/pepper/all_interfaces.h"
70 int PPErrorToErrno(int32_t err);
72 class PepperInterface {
74 virtual ~PepperInterface() {}
75 virtual PP_Instance GetInstance() = 0;
77 // Convenience functions. These forward to
78 // GetCoreInterface()->{AddRef,Release}Resource.
79 void AddRefResource(PP_Resource resource);
80 void ReleaseResource(PP_Resource resource);
84 // These macros expand to definitions like:
86 // CoreInterface* GetCoreInterface() = 0;
88 #include "nacl_io/pepper/undef_macros.h"
89 #include "nacl_io/pepper/define_empty_macros.h"
90 #undef BEGIN_INTERFACE
91 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \
92 virtual BaseClass* Get##BaseClass() = 0;
93 #include "nacl_io/pepper/all_interfaces.h"
96 // Interface class definitions.
98 // Each class will be defined with all pure virtual methods, e.g:
100 // class CoreInterface {
102 // virtual ~CoreInterface() {}
103 // virtual void AddRefResource() = 0;
104 // virtual void ReleaseResource() = 0;
105 // virtual PP_Bool IsMainThread() = 0;
108 #include "nacl_io/pepper/undef_macros.h"
109 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \
112 virtual ~BaseClass() {}
113 #define END_INTERFACE(BaseClass, PPInterface) \
115 #define METHOD0(Class, ReturnType, MethodName) \
116 virtual ReturnType MethodName() = 0;
117 #define METHOD1(Class, ReturnType, MethodName, Type0) \
118 virtual ReturnType MethodName(Type0) = 0;
119 #define METHOD2(Class, ReturnType, MethodName, Type0, Type1) \
120 virtual ReturnType MethodName(Type0, Type1) = 0;
121 #define METHOD3(Class, ReturnType, MethodName, Type0, Type1, Type2) \
122 virtual ReturnType MethodName(Type0, Type1, Type2) = 0;
123 #define METHOD4(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3) \
124 virtual ReturnType MethodName(Type0, Type1, Type2, Type3) = 0;
125 #define METHOD5(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3, \
127 virtual ReturnType MethodName(Type0, Type1, Type2, Type3, Type4) = 0;
128 #include "nacl_io/pepper/all_interfaces.h"
131 class ScopedResource {
133 // Does not AddRef by default.
134 ScopedResource(PepperInterface* ppapi, PP_Resource resource);
137 PP_Resource pp_resource() { return resource_; }
139 // Return the resource without decrementing its refcount.
140 PP_Resource Release();
143 PepperInterface* ppapi_;
144 PP_Resource resource_;
146 DISALLOW_COPY_AND_ASSIGN(ScopedResource);
149 } // namespace nacl_io
151 #endif // LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_