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 class PepperInterface
{
76 virtual ~PepperInterface() {}
77 virtual PP_Instance
GetInstance() = 0;
79 // Convenience functions. These forward to
80 // GetCoreInterface()->{AddRef,Release}Resource.
81 void AddRefResource(PP_Resource resource
);
82 void ReleaseResource(PP_Resource resource
);
86 // These macros expand to definitions like:
88 // CoreInterface* GetCoreInterface() = 0;
90 #include "nacl_io/pepper/undef_macros.h"
91 #include "nacl_io/pepper/define_empty_macros.h"
92 #undef BEGIN_INTERFACE
93 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \
94 virtual BaseClass* Get##BaseClass() = 0;
95 #include "nacl_io/pepper/all_interfaces.h"
98 // Interface class definitions.
100 // Each class will be defined with all pure virtual methods, e.g:
102 // class CoreInterface {
104 // virtual ~CoreInterface() {}
105 // virtual void AddRefResource() = 0;
106 // virtual void ReleaseResource() = 0;
107 // virtual PP_Bool IsMainThread() = 0;
110 #include "nacl_io/pepper/undef_macros.h"
111 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \
114 virtual ~BaseClass() {}
115 #define END_INTERFACE(BaseClass, PPInterface) \
117 #define METHOD0(Class, ReturnType, MethodName) \
118 virtual ReturnType MethodName() = 0;
119 #define METHOD1(Class, ReturnType, MethodName, Type0) \
120 virtual ReturnType MethodName(Type0) = 0;
121 #define METHOD2(Class, ReturnType, MethodName, Type0, Type1) \
122 virtual ReturnType MethodName(Type0, Type1) = 0;
123 #define METHOD3(Class, ReturnType, MethodName, Type0, Type1, Type2) \
124 virtual ReturnType MethodName(Type0, Type1, Type2) = 0;
125 #define METHOD4(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3) \
126 virtual ReturnType MethodName(Type0, Type1, Type2, Type3) = 0;
127 #define METHOD5(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3, \
129 virtual ReturnType MethodName(Type0, Type1, Type2, Type3, Type4) = 0;
130 #include "nacl_io/pepper/all_interfaces.h"
133 class ScopedResource
{
136 explicit ScopedResource(PepperInterface
* ppapi
);
137 ScopedResource(PepperInterface
* ppapi
, PP_Resource resource
);
140 PP_Resource
pp_resource() const { return resource_
; }
142 // Set a new resource, releasing the old one. Does not AddRef the new
144 void Reset(PP_Resource resource
);
146 // Return the resource without decrementing its refcount.
147 PP_Resource
Release();
150 PepperInterface
* ppapi_
;
151 PP_Resource resource_
;
153 DISALLOW_COPY_AND_ASSIGN(ScopedResource
);
159 explicit ScopedVar(PepperInterface
* ppapi
);
160 ScopedVar(PepperInterface
* ppapi
, PP_Var var
);
163 PP_Var
pp_var() const { return var_
; }
165 // Set a new var, releasing the old one. Does not AddRef the new
167 void Reset(PP_Var resource
);
169 // Return the var without decrementing its refcount.
173 PepperInterface
* ppapi_
;
176 DISALLOW_COPY_AND_ASSIGN(ScopedVar
);
179 } // namespace nacl_io
181 #endif // LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_