Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 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 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 5 | #ifndef LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_ |
| 6 | #define LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_ |
| 7 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 8 | #include <ppapi/c/pp_bool.h> |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 9 | #include <ppapi/c/pp_completion_callback.h> |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 10 | #include <ppapi/c/pp_errors.h> |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 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_file_io.h> |
| 17 | #include <ppapi/c/ppb_file_ref.h> |
| 18 | #include <ppapi/c/ppb_file_system.h> |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 19 | #include <ppapi/c/ppb_host_resolver.h> |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 20 | #include <ppapi/c/ppb_messaging.h> |
| 21 | #include <ppapi/c/ppb_messaging.h> |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 22 | #include <ppapi/c/ppb_net_address.h> |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 23 | #include <ppapi/c/ppb_url_loader.h> |
| 24 | #include <ppapi/c/ppb_url_request_info.h> |
| 25 | #include <ppapi/c/ppb_url_response_info.h> |
| 26 | #include <ppapi/c/ppb_var.h> |
| 27 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 28 | #include <sdk_util/macros.h> |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 29 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 30 | namespace nacl_io { |
| 31 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 32 | // Note: To add a new interface: |
| 33 | // |
| 34 | // 1. Using one of the other interfaces as a template, add your interface to |
| 35 | // all_interfaces.h. |
| 36 | // 2. Add the necessary pepper header to the top of this file. |
| 37 | // 3. Compile and cross your fingers! |
| 38 | |
| 39 | |
| 40 | // Forward declare interface classes. |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 41 | #include "nacl_io/pepper/undef_macros.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 42 | #include "nacl_io/pepper/define_empty_macros.h" |
| 43 | #undef BEGIN_INTERFACE |
| 44 | #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \ |
| 45 | class BaseClass; |
| 46 | #include "nacl_io/pepper/all_interfaces.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 47 | |
| 48 | int PPErrorToErrno(int32_t err); |
| 49 | |
| 50 | class PepperInterface { |
| 51 | public: |
| 52 | virtual ~PepperInterface() {} |
| 53 | virtual PP_Instance GetInstance() = 0; |
| 54 | virtual void AddRefResource(PP_Resource) = 0; |
| 55 | virtual void ReleaseResource(PP_Resource) = 0; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 56 | virtual bool IsMainThread() = 0; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 57 | |
| 58 | // Interface getters. |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 59 | #include "nacl_io/pepper/undef_macros.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 60 | #include "nacl_io/pepper/define_empty_macros.h" |
| 61 | #undef BEGIN_INTERFACE |
| 62 | #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \ |
| 63 | virtual BaseClass* Get##BaseClass() = 0; |
| 64 | #include "nacl_io/pepper/all_interfaces.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | // Interface class definitions. |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 68 | #include "nacl_io/pepper/undef_macros.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 69 | #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \ |
| 70 | class BaseClass { \ |
| 71 | public: \ |
| 72 | virtual ~BaseClass() {} |
| 73 | #define END_INTERFACE(BaseClass, PPInterface) \ |
| 74 | }; |
| 75 | #define METHOD1(Class, ReturnType, MethodName, Type0) \ |
| 76 | virtual ReturnType MethodName(Type0) = 0; |
| 77 | #define METHOD2(Class, ReturnType, MethodName, Type0, Type1) \ |
| 78 | virtual ReturnType MethodName(Type0, Type1) = 0; |
| 79 | #define METHOD3(Class, ReturnType, MethodName, Type0, Type1, Type2) \ |
| 80 | virtual ReturnType MethodName(Type0, Type1, Type2) = 0; |
| 81 | #define METHOD4(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3) \ |
| 82 | virtual ReturnType MethodName(Type0, Type1, Type2, Type3) = 0; |
| 83 | #define METHOD5(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3, \ |
| 84 | Type4) \ |
| 85 | virtual ReturnType MethodName(Type0, Type1, Type2, Type3, Type4) = 0; |
| 86 | #include "nacl_io/pepper/all_interfaces.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 87 | |
| 88 | |
| 89 | class ScopedResource { |
| 90 | public: |
| 91 | // Does not AddRef by default. |
| 92 | ScopedResource(PepperInterface* ppapi, PP_Resource resource); |
| 93 | ~ScopedResource(); |
| 94 | |
| 95 | PP_Resource pp_resource() { return resource_; } |
| 96 | |
| 97 | // Return the resource without decrementing its refcount. |
| 98 | PP_Resource Release(); |
| 99 | |
| 100 | private: |
| 101 | PepperInterface* ppapi_; |
| 102 | PP_Resource resource_; |
| 103 | |
| 104 | DISALLOW_COPY_AND_ASSIGN(ScopedResource); |
| 105 | }; |
| 106 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 107 | } // namespace nacl_io |
| 108 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 109 | #endif // LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_ |