Pepper_56_C++_interfaces
Pepper_56_C++_interfaces
 All Classes Namespaces Files Functions Typedefs Enumerations Macros Groups
module.h
Go to the documentation of this file.
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 PPAPI_CPP_MODULE_H_
6 #define PPAPI_CPP_MODULE_H_
7 
8 #include <map>
9 #include <string>
10 
11 #include "ppapi/c/pp_instance.h"
12 #include "ppapi/c/pp_module.h"
13 #include "ppapi/c/pp_stdint.h"
14 #include "ppapi/c/ppb.h"
15 #include "ppapi/c/ppb_core.h"
16 #include "ppapi/cpp/core.h"
17 
18 
21 namespace pp {
22 
23 class Instance;
24 
29 class Module {
30  public:
31  typedef std::map<PP_Instance, Instance*> InstanceMap;
32 
33  // You may not call any other PP functions from the constructor, put them
34  // in Init instead. Various things will not be set up until the constructor
35  // completes.
36  Module();
37  virtual ~Module();
38 
43  static Module* Get();
44 
50  virtual bool Init();
51 
55  PP_Module pp_module() const { return pp_module_; }
56 
61  // TODO(sehr): This should be removed once the NaCl browser plugin no longer
62  // needs it.
63  PPB_GetInterface get_browser_interface() const {
64  return get_browser_interface_;
65  }
66 
74  Core* core() { return core_; }
75 
81  const void* GetPluginInterface(const char* interface_name);
82 
86  const void* GetBrowserInterface(const char* interface_name);
87 
98  Instance* InstanceForPPInstance(PP_Instance instance);
99 
117  void AddPluginInterface(const std::string& interface_name,
118  const void* vtable);
119 
120  // InternalInit() sets the browser interface and calls the regular Init()
127  // TODO(brettw) make this private when I can figure out how to make the
128  // initialize function a friend.
129  bool InternalInit(PP_Module mod,
130  PPB_GetInterface get_browser_interface);
131 
136  const InstanceMap& current_instances() const { return current_instances_; }
137 
138  protected:
144  virtual Instance* CreateInstance(PP_Instance instance) = 0;
145 
146  // Instance tracking.
147  InstanceMap current_instances_;
148 
149  private:
150  friend PP_Bool Instance_DidCreate(PP_Instance pp_instance,
151  uint32_t argc,
152  const char* argn[],
153  const char* argv[]);
154  friend void Instance_DidDestroy(PP_Instance instance);
155 
156  // Unimplemented (disallow copy and assign).
157  Module(const Module&);
158  Module& operator=(const Module&);
159 
160  PP_Module pp_module_;
161  PPB_GetInterface get_browser_interface_;
162 
163  Core* core_;
164 
165  // All additional interfaces this plugin can handle as registered by
166  // AddPluginInterface.
167  typedef std::map<std::string, const void*> InterfaceMap;
168  InterfaceMap additional_interfaces_;
169 };
170 
171 } // namespace pp
172 
173 #endif // PPAPI_CPP_MODULE_H_
virtual Instance * CreateInstance(PP_Instance instance)=0
const InstanceMap & current_instances() const
Definition: module.h:136
virtual bool Init()
Core * core()
Definition: module.h:74
const void * GetPluginInterface(const char *interface_name)
static Module * Get()
Instance * InstanceForPPInstance(PP_Instance instance)
void AddPluginInterface(const std::string &interface_name, const void *vtable)
bool InternalInit(PP_Module mod, PPB_GetInterface get_browser_interface)
Definition: module.h:29
const void * GetBrowserInterface(const char *interface_name)
PPB_GetInterface get_browser_interface() const
Definition: module.h:63
Definition: instance.h:42
APIs related to memory management, time, and threads.
Definition: core.h:21
PP_Module pp_module() const
Definition: module.h:55