1ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// Use of this source code is governed by a BSD-style license that can be 3ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "nacl_io/real_pepper_interface.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <assert.h> 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <stdio.h> 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <ppapi/c/pp_errors.h> 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochnamespace nacl_io { 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "nacl_io/pepper/undef_macros.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \ 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) class Real##BaseClass : public BaseClass { \ 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: \ 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) explicit Real##BaseClass(const PPInterface* interface); 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define END_INTERFACE(BaseClass, PPInterface) \ 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: \ 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const PPInterface* interface_; \ 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }; 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define METHOD1(Class, ReturnType, MethodName, Type0) \ 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ReturnType MethodName(Type0); 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define METHOD2(Class, ReturnType, MethodName, Type0, Type1) \ 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ReturnType MethodName(Type0, Type1); 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define METHOD3(Class, ReturnType, MethodName, Type0, Type1, Type2) \ 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ReturnType MethodName(Type0, Type1, Type2); 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define METHOD4(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3) \ 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ReturnType MethodName(Type0, Type1, Type2, Type3); 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define METHOD5(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3, \ 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Type4) \ 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ReturnType MethodName(Type0, Type1, Type2, Type3, Type4); 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "nacl_io/pepper/all_interfaces.h" 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "nacl_io/pepper/undef_macros.h" 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \ 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Real##BaseClass::Real##BaseClass(const PPInterface* interface) \ 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : interface_(interface) {} 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define END_INTERFACE(BaseClass, PPInterface) 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define METHOD1(BaseClass, ReturnType, MethodName, Type0) \ 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ReturnType Real##BaseClass::MethodName(Type0 arg0) { \ 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return interface_->MethodName(arg0); \ 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define METHOD2(BaseClass, ReturnType, MethodName, Type0, Type1) \ 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1) { \ 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return interface_->MethodName(arg0, arg1); \ 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define METHOD3(BaseClass, ReturnType, MethodName, Type0, Type1, Type2) \ 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1, \ 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Type2 arg2) { \ 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return interface_->MethodName(arg0, arg1, arg2); \ 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define METHOD4(BaseClass, ReturnType, MethodName, Type0, Type1, Type2, Type3) \ 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1, Type2 arg2, \ 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Type3 arg3) { \ 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return interface_->MethodName(arg0, arg1, arg2, arg3); \ 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define METHOD5(BaseClass, ReturnType, MethodName, Type0, Type1, Type2, Type3, \ 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Type4) \ 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1, Type2 arg2, \ 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Type3 arg3, Type4 arg4) { \ 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return interface_->MethodName(arg0, arg1, arg2, arg3, arg4); \ 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "nacl_io/pepper/all_interfaces.h" 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)RealPepperInterface::RealPepperInterface(PP_Instance instance, 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PPB_GetInterface get_browser_interface) 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : instance_(instance), 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) core_interface_(NULL), 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) message_loop_interface_(NULL) { 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) core_interface_ = static_cast<const PPB_Core*>( 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) get_browser_interface(PPB_CORE_INTERFACE)); 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) message_loop_interface_ = static_cast<const PPB_MessageLoop*>( 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) get_browser_interface(PPB_MESSAGELOOP_INTERFACE)); 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) assert(core_interface_); 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) assert(message_loop_interface_); 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "nacl_io/pepper/undef_macros.h" 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "nacl_io/pepper/define_empty_macros.h" 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#undef BEGIN_INTERFACE 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \ 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BaseClass##interface_ = new Real##BaseClass( \ 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static_cast<const PPInterface*>( \ 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) get_browser_interface(InterfaceString))); 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "nacl_io/pepper/all_interfaces.h" 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)PP_Instance RealPepperInterface::GetInstance() { 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return instance_; 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RealPepperInterface::AddRefResource(PP_Resource resource) { 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (resource) 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) core_interface_->AddRefResource(resource); 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void RealPepperInterface::ReleaseResource(PP_Resource resource) { 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (resource) 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) core_interface_->ReleaseResource(resource); 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool RealPepperInterface::IsMainThread() { 108c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return core_interface_->IsMainThread(); 109c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Define getter function. 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "nacl_io/pepper/undef_macros.h" 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "nacl_io/pepper/define_empty_macros.h" 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#undef BEGIN_INTERFACE 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \ 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BaseClass* RealPepperInterface::Get##BaseClass() { \ 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return BaseClass##interface_; \ 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "nacl_io/pepper/all_interfaces.h" 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int32_t RealPepperInterface::InitializeMessageLoop() { 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int32_t result; 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PP_Resource message_loop = 0; 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (core_interface_->IsMainThread()) { 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(binji): Spin up the main thread's ppapi work thread. 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) assert(0); 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) message_loop = message_loop_interface_->GetCurrent(); 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!message_loop) { 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) message_loop = message_loop_interface_->Create(instance_); 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) result = message_loop_interface_->AttachToCurrentThread(message_loop); 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) assert(result == PP_OK); 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return PP_OK; 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 139eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 140ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch} // namespace nacl_io 141ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 142