Home | History | Annotate | Download | only in nacl_io
      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 
      5 #ifndef LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_
      6 #define LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_
      7 
      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_file_io.h>
     17 #include <ppapi/c/ppb_file_ref.h>
     18 #include <ppapi/c/ppb_file_system.h>
     19 #include <ppapi/c/ppb_host_resolver.h>
     20 #include <ppapi/c/ppb_messaging.h>
     21 #include <ppapi/c/ppb_messaging.h>
     22 #include <ppapi/c/ppb_net_address.h>
     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 
     28 #include <sdk_util/macros.h>
     29 
     30 namespace nacl_io {
     31 
     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.
     41 #include "nacl_io/pepper/undef_macros.h"
     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"
     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;
     56   virtual bool IsMainThread() = 0;
     57 
     58 // Interface getters.
     59 #include "nacl_io/pepper/undef_macros.h"
     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"
     65 };
     66 
     67 // Interface class definitions.
     68 #include "nacl_io/pepper/undef_macros.h"
     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"
     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 
    107 }  // namespace nacl_io
    108 
    109 #endif  // LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_
    110