Pepper_47_C++_interfaces
ppp_entrypoints.cc
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 // When used in conjunction with module_embedder.h, this gives a default
6 // implementation of ppp.h for clients of the ppapi C++ interface. Most
7 // plugin implementors can export their derivation of Module by just
8 // linking to this implementation.
9 
10 #include "ppapi/c/ppb.h"
11 #include "ppapi/c/ppp.h"
12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/cpp/module.h"
15 
17 static PP_GetInterface_Func g_broker_get_interface = NULL;
18 
19 namespace pp {
20 
21 // Give a default implementation of Module::Get(). See module.cc for details.
23  return g_module_singleton;
24 }
25 
26 void SetBrokerGetInterfaceFunc(PP_GetInterface_Func broker_get_interface) {
27  g_broker_get_interface = broker_get_interface;
28 }
29 
30 } // namespace pp
31 
32 // Global PPP functions --------------------------------------------------------
33 
34 PP_EXPORT int32_t PPP_InitializeModule(PP_Module module_id,
35  PPB_GetInterface get_browser_interface) {
36  pp::Module* module = pp::CreateModule();
37  if (!module)
38  return PP_ERROR_FAILED;
39 
40  if (!module->InternalInit(module_id, get_browser_interface)) {
41  delete module;
42  return PP_ERROR_FAILED;
43  }
44  g_module_singleton = module;
45  return PP_OK;
46 }
47 
48 PP_EXPORT void PPP_ShutdownModule() {
49  delete g_module_singleton;
50  g_module_singleton = NULL;
51 }
52 
53 PP_EXPORT const void* PPP_GetInterface(const char* interface_name) {
54  if (g_module_singleton)
55  return g_module_singleton->GetPluginInterface(interface_name);
57  return g_broker_get_interface(interface_name);
58  return NULL;
59 }
void SetBrokerGetInterfaceFunc(PP_GetInterface_Func broker_get_interface)
PP_EXPORT const void * PPP_GetInterface(const char *interface_name)
PP_EXPORT int32_t PPP_InitializeModule(PP_Module module_id, PPB_GetInterface get_browser_interface)
bool InternalInit(PP_Module mod, PPB_GetInterface get_browser_interface)
Definition: module.cc:204
PP_EXPORT void PPP_ShutdownModule()
pp::Module * CreateModule()
static pp::Module * g_module_singleton
static PP_GetInterface_Func g_broker_get_interface
static Module * Get()
const void * GetPluginInterface(const char *interface_name)
Definition: module.cc:162