1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com// Copyright (c) 2012 The Chromium Authors. All rights reserved. 28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// Use of this source code is governed by a BSD-style license that can be 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com// found in the LICENSE file. 48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com#ifndef LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_ 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com#define LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_ 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/pp_bool.h> 9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com#include <ppapi/c/pp_completion_callback.h> 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/pp_errors.h> 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/pp_file_info.h> 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/pp_instance.h> 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/pp_resource.h> 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/pp_var.h> 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_console.h> 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_core.h> 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_file_io.h> 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_file_ref.h> 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_file_system.h> 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_host_resolver.h> 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_messaging.h> 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_messaging.h> 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_net_address.h> 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_tcp_socket.h> 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_url_loader.h> 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_url_request_info.h> 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_url_response_info.h> 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_udp_socket.h> 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_var.h> 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_var_array.h> 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_var_array_buffer.h> 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <ppapi/c/ppb_var_dictionary.h> 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <sdk_util/macros.h> 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comnamespace nacl_io { 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// This class is the base interface for Pepper used by nacl_io. 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// We use #include and macro magic to simplify adding new interfaces. The 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// resulting PepperInterface basically looks like this: 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// class PepperInterface { 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// public: 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// virtual ~PepperInterface() {} 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// virtual PP_Instance GetInstance() = 0; 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// ... 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// // Interface getters. 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// ConsoleInterface* GetConsoleInterface() = 0; 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// CoreInterface* GetCoreInterface() = 0; 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// FileIoInterface* GetFileIoInterface() = 0; 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// ... etc. 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// }; 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// Note: To add a new interface: 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// 5904423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com// 1. Using one of the other interfaces as a template, add your interface to 6004423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com// all_interfaces.h. 6104423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com// 2. Add the necessary pepper header to the top of this file. 6204423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com// 3. Compile and cross your fingers! 6304423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com 6404423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com// Forward declare interface classes. 6504423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com#include "nacl_io/pepper/undef_macros.h" 6604423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com#include "nacl_io/pepper/define_empty_macros.h" 6704423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com#undef BEGIN_INTERFACE 6804423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com#define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \ 6904423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com class BaseClass; 7004423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com#include "nacl_io/pepper/all_interfaces.h" 7104423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com 7204423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.comint PPErrorToErrno(int32_t err); 7304423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com 7404423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.comclass PepperInterface { 7504423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com public: 7604423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com virtual ~PepperInterface() {} 7704423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com virtual PP_Instance GetInstance() = 0; 7804423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com 7904423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com // Convenience functions. These forward to 8004423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com // GetCoreInterface()->{AddRef,Release}Resource. 8104423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com void AddRefResource(PP_Resource resource); 8204423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com void ReleaseResource(PP_Resource resource); 8304423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com 8404423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com// Interface getters. 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// 868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// These macros expand to definitions like: 878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// 888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// CoreInterface* GetCoreInterface() = 0; 898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// 908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "nacl_io/pepper/undef_macros.h" 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "nacl_io/pepper/define_empty_macros.h" 928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#undef BEGIN_INTERFACE 938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \ 948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual BaseClass* Get##BaseClass() = 0; 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "nacl_io/pepper/all_interfaces.h" 968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 97b1277c96b0818550190be134fd5e9a971087120bbsalomon@google.com 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// Interface class definitions. 99b1277c96b0818550190be134fd5e9a971087120bbsalomon@google.com// 1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// Each class will be defined with all pure virtual methods, e.g: 1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// class CoreInterface { 1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// public: 1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// virtual ~CoreInterface() {} 1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// virtual void AddRefResource() = 0; 1068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// virtual void ReleaseResource() = 0; 1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// virtual PP_Bool IsMainThread() = 0; 1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// }; 1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// 1105c80ea17d4e4a795bfaeb260fc27e952ba471f1dreed@android.com#include "nacl_io/pepper/undef_macros.h" 1115c80ea17d4e4a795bfaeb260fc27e952ba471f1dreed@android.com#define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \ 1125c80ea17d4e4a795bfaeb260fc27e952ba471f1dreed@android.com class BaseClass { \ 1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: \ 1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~BaseClass() {} 1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define END_INTERFACE(BaseClass, PPInterface) \ 11616690af1c21dead3eedb25ebd0a4b9a091684ed4reed@android.com }; 11716690af1c21dead3eedb25ebd0a4b9a091684ed4reed@android.com#define METHOD0(Class, ReturnType, MethodName) \ 11816690af1c21dead3eedb25ebd0a4b9a091684ed4reed@android.com virtual ReturnType MethodName() = 0; 11916690af1c21dead3eedb25ebd0a4b9a091684ed4reed@android.com#define METHOD1(Class, ReturnType, MethodName, Type0) \ 12016690af1c21dead3eedb25ebd0a4b9a091684ed4reed@android.com virtual ReturnType MethodName(Type0) = 0; 12116690af1c21dead3eedb25ebd0a4b9a091684ed4reed@android.com#define METHOD2(Class, ReturnType, MethodName, Type0, Type1) \ 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ReturnType MethodName(Type0, Type1) = 0; 12316690af1c21dead3eedb25ebd0a4b9a091684ed4reed@android.com#define METHOD3(Class, ReturnType, MethodName, Type0, Type1, Type2) \ 12416690af1c21dead3eedb25ebd0a4b9a091684ed4reed@android.com virtual ReturnType MethodName(Type0, Type1, Type2) = 0; 12516690af1c21dead3eedb25ebd0a4b9a091684ed4reed@android.com#define METHOD4(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3) \ 12616690af1c21dead3eedb25ebd0a4b9a091684ed4reed@android.com virtual ReturnType MethodName(Type0, Type1, Type2, Type3) = 0; 1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define METHOD5(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3, \ 1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Type4) \ 12904423805455de868b1b468cfe4057cb77f74b6b0bsalomon@google.com virtual ReturnType MethodName(Type0, Type1, Type2, Type3, Type4) = 0; 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "nacl_io/pepper/all_interfaces.h" 131f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 132f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 133f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comclass ScopedResource { 134f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com public: 135f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com // Does not AddRef. 136f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com explicit ScopedResource(PepperInterface* ppapi); 137f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com ScopedResource(PepperInterface* ppapi, PP_Resource resource); 138f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com ~ScopedResource(); 1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PP_Resource pp_resource() const { return resource_; } 1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Set a new resource, releasing the old one. Does not AddRef the new 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // resource. 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void Reset(PP_Resource resource); 1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Return the resource without decrementing its refcount. 1478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PP_Resource Release(); 1488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PepperInterface* ppapi_; 1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PP_Resource resource_; 1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com DISALLOW_COPY_AND_ASSIGN(ScopedResource); 15427661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com}; 15527661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com 15627661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.comclass ScopedVar { 15727661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com public: 15827661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com // Does not AddRef. 15927661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com explicit ScopedVar(PepperInterface* ppapi); 16027661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com ScopedVar(PepperInterface* ppapi, PP_Var var); 16127661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com ~ScopedVar(); 16227661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com 16327661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com PP_Var pp_var() const { return var_; } 16427661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com 16527661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com // Set a new var, releasing the old one. Does not AddRef the new 16627661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com // resource. 16727661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com void Reset(PP_Var resource); 16827661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com 16927661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com // Return the var without decrementing its refcount. 17027661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com PP_Var Release(); 17127661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com 17227661181d757145d98f2dc3e02b88ee3fffce9e5bsalomon@google.com private: 1738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PepperInterface* ppapi_; 1748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PP_Var var_; 1758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com DISALLOW_COPY_AND_ASSIGN(ScopedVar); 1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 1788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} // namespace nacl_io 1808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif // LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_ 1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com