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>
30 #include <ppapi/c/ppb_var_array.h>
31 #include <ppapi/c/ppb_var_array_buffer.h>
32 #include <ppapi/c/ppb_var_dictionary.h>
34 #include <sdk_util/macros.h>
38 // This class is the base interface for Pepper used by nacl_io.
40 // We use #include and macro magic to simplify adding new interfaces. The
41 // resulting PepperInterface basically looks like this:
43 // class PepperInterface {
45 // virtual ~PepperInterface() {}
46 // virtual PP_Instance GetInstance() = 0;
49 // // Interface getters.
50 // ConsoleInterface* GetConsoleInterface() = 0;
51 // CoreInterface* GetCoreInterface() = 0;
52 // FileIoInterface* GetFileIoInterface() = 0;
57 // Note: To add a new interface:
59 // 1. Using one of the other interfaces as a template, add your interface to
61 // 2. Add the necessary pepper header to the top of this file.
62 // 3. Compile and cross your fingers!
64 // Forward declare interface classes.
65 #include "nacl_io/pepper/undef_macros.h"
66 #include "nacl_io/pepper/define_empty_macros.h"
67 #undef BEGIN_INTERFACE
68 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \
70 #include "nacl_io/pepper/all_interfaces.h"
72 int PPErrorToErrno(int32_t err
);
74 // Helper function to log real pepper error at call site.
77 #define PPERROR_TO_ERRNO(err) \
82 int PPErrorToErrnoLog(int32_t err
, const char* file
, int line
);
84 #define PPERROR_TO_ERRNO(err) \
85 PPErrorToErrnoLog(err, __FILE__, __LINE__)
89 class PepperInterface
{
91 virtual ~PepperInterface() {}
92 virtual PP_Instance
GetInstance() = 0;
94 // Convenience functions. These forward to
95 // GetCoreInterface()->{AddRef,Release}Resource.
96 void AddRefResource(PP_Resource resource
);
97 void ReleaseResource(PP_Resource resource
);
101 // These macros expand to definitions like:
103 // CoreInterface* GetCoreInterface() = 0;
105 #include "nacl_io/pepper/undef_macros.h"
106 #include "nacl_io/pepper/define_empty_macros.h"
107 #undef BEGIN_INTERFACE
108 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \
109 virtual BaseClass* Get##BaseClass() = 0;
110 #include "nacl_io/pepper/all_interfaces.h"
113 // Interface class definitions.
115 // Each class will be defined with all pure virtual methods, e.g:
117 // class CoreInterface {
119 // virtual ~CoreInterface() {}
120 // virtual void AddRefResource() = 0;
121 // virtual void ReleaseResource() = 0;
122 // virtual PP_Bool IsMainThread() = 0;
125 #include "nacl_io/pepper/undef_macros.h"
126 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \
129 virtual ~BaseClass() {}
130 #define END_INTERFACE(BaseClass, PPInterface) \
132 #define METHOD0(Class, ReturnType, MethodName) \
133 virtual ReturnType MethodName() = 0;
134 #define METHOD1(Class, ReturnType, MethodName, Type0) \
135 virtual ReturnType MethodName(Type0) = 0;
136 #define METHOD2(Class, ReturnType, MethodName, Type0, Type1) \
137 virtual ReturnType MethodName(Type0, Type1) = 0;
138 #define METHOD3(Class, ReturnType, MethodName, Type0, Type1, Type2) \
139 virtual ReturnType MethodName(Type0, Type1, Type2) = 0;
140 #define METHOD4(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3) \
141 virtual ReturnType MethodName(Type0, Type1, Type2, Type3) = 0;
142 #define METHOD5(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3, \
144 virtual ReturnType MethodName(Type0, Type1, Type2, Type3, Type4) = 0;
145 #include "nacl_io/pepper/all_interfaces.h"
148 class ScopedResource
{
151 explicit ScopedResource(PepperInterface
* ppapi
);
152 ScopedResource(PepperInterface
* ppapi
, PP_Resource resource
);
155 PP_Resource
pp_resource() const { return resource_
; }
157 // Set a new resource, releasing the old one. Does not AddRef the new
159 void Reset(PP_Resource resource
);
161 // Return the resource without decrementing its refcount.
162 PP_Resource
Release();
165 PepperInterface
* ppapi_
;
166 PP_Resource resource_
;
168 DISALLOW_COPY_AND_ASSIGN(ScopedResource
);
174 explicit ScopedVar(PepperInterface
* ppapi
);
175 ScopedVar(PepperInterface
* ppapi
, PP_Var var
);
178 PP_Var
pp_var() const { return var_
; }
180 // Set a new var, releasing the old one. Does not AddRef the new
182 void Reset(PP_Var resource
);
184 // Return the var without decrementing its refcount.
188 PepperInterface
* ppapi_
;
191 DISALLOW_COPY_AND_ASSIGN(ScopedVar
);
194 } // namespace nacl_io
196 #endif // LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_