blob: 6ffe1e68a45efe7a8b86d0af4b5ab5d575661bc5 [file] [log] [blame]
Ben Murdochca12bfa2013-07-23 11:17:05 +01001// 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)2a99a7e2013-03-28 15:31:22 +00005#ifndef LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_
6#define LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_
7
Ben Murdochbb1529c2013-08-08 10:24:53 +01008#include <ppapi/c/pp_bool.h>
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00009#include <ppapi/c/pp_completion_callback.h>
Ben Murdochbb1529c2013-08-08 10:24:53 +010010#include <ppapi/c/pp_errors.h>
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000011#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 Murdochbb1529c2013-08-08 10:24:53 +010019#include <ppapi/c/ppb_host_resolver.h>
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000020#include <ppapi/c/ppb_messaging.h>
21#include <ppapi/c/ppb_messaging.h>
Ben Murdochbb1529c2013-08-08 10:24:53 +010022#include <ppapi/c/ppb_net_address.h>
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000023#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)868fa2f2013-06-11 10:57:03 +010028#include <sdk_util/macros.h>
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000029
Ben Murdochca12bfa2013-07-23 11:17:05 +010030namespace nacl_io {
31
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000032// 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)c2e0dbd2013-05-09 18:35:53 +010041#include "nacl_io/pepper/undef_macros.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000042#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)2a99a7e2013-03-28 15:31:22 +000047
48int PPErrorToErrno(int32_t err);
49
50class 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)c2e0dbd2013-05-09 18:35:53 +010056 virtual bool IsMainThread() = 0;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000057
58// Interface getters.
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010059#include "nacl_io/pepper/undef_macros.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000060#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)2a99a7e2013-03-28 15:31:22 +000065};
66
67// Interface class definitions.
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010068#include "nacl_io/pepper/undef_macros.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000069#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)2a99a7e2013-03-28 15:31:22 +000087
88
89class 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 Murdochca12bfa2013-07-23 11:17:05 +0100107} // namespace nacl_io
108
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000109#endif // LIBRARIES_NACL_IO_PEPPER_INTERFACE_H_