diff options
Diffstat (limited to 'ppapi/thunk')
-rw-r--r-- | ppapi/thunk/ppb_flash_tcp_socket_api.h | 38 | ||||
-rw-r--r-- | ppapi/thunk/ppb_flash_tcp_socket_thunk.cc | 121 | ||||
-rw-r--r-- | ppapi/thunk/resource_creation_api.h | 1 | ||||
-rw-r--r-- | ppapi/thunk/thunk.h | 2 |
4 files changed, 162 insertions, 0 deletions
diff --git a/ppapi/thunk/ppb_flash_tcp_socket_api.h b/ppapi/thunk/ppb_flash_tcp_socket_api.h new file mode 100644 index 0000000..d18eb6e --- /dev/null +++ b/ppapi/thunk/ppb_flash_tcp_socket_api.h @@ -0,0 +1,38 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_THUNK_PPB_FLASH_TCP_SOCKET_API_H_ +#define PPAPI_THUNK_PPB_FLASH_TCP_SOCKET_API_H_ + +#include "ppapi/c/private/ppb_flash_tcp_socket.h" + +namespace ppapi { +namespace thunk { + +class PPB_Flash_TCPSocket_API { + public: + virtual ~PPB_Flash_TCPSocket_API() {} + + virtual int32_t Connect(const char* host, + uint16_t port, + PP_CompletionCallback callback) = 0; + virtual int32_t ConnectWithNetAddress(const PP_Flash_NetAddress* addr, + PP_CompletionCallback callback) = 0; + virtual PP_Bool GetLocalAddress(PP_Flash_NetAddress* local_addr) = 0; + virtual PP_Bool GetRemoteAddress(PP_Flash_NetAddress* remote_addr) = 0; + virtual int32_t InitiateSSL(const char* server_name, + PP_CompletionCallback callback) = 0; + virtual int32_t Read(char* buffer, + int32_t bytes_to_read, + PP_CompletionCallback callback) = 0; + virtual int32_t Write(const char* buffer, + int32_t bytes_to_write, + PP_CompletionCallback callback) = 0; + virtual void Disconnect() = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_FLASH_TCP_SOCKET_API_H_ diff --git a/ppapi/thunk/ppb_flash_tcp_socket_thunk.cc b/ppapi/thunk/ppb_flash_tcp_socket_thunk.cc new file mode 100644 index 0000000..815dd53 --- /dev/null +++ b/ppapi/thunk/ppb_flash_tcp_socket_thunk.cc @@ -0,0 +1,121 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/private/ppb_flash_tcp_socket.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_flash_tcp_socket_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource Create(PP_Instance instance) { + EnterFunction<ResourceCreationAPI> enter(instance, true); + if (enter.failed()) + return 0; + return enter.functions()->CreateFlashTCPSocket(instance); +} + +PP_Bool IsFlashTCPSocket(PP_Resource resource) { + EnterResource<PPB_Flash_TCPSocket_API> enter(resource, false); + return PP_FromBool(enter.succeeded()); +} + +int32_t Connect(PP_Resource tcp_socket, + const char* host, + uint16_t port, + PP_CompletionCallback callback) { + EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Connect(host, port, callback); +} + +int32_t ConnectWithNetAddress(PP_Resource tcp_socket, + const PP_Flash_NetAddress* addr, + PP_CompletionCallback callback) { + EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->ConnectWithNetAddress(addr, callback); +} + +PP_Bool GetLocalAddress(PP_Resource tcp_socket, + PP_Flash_NetAddress* local_addr) { + EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true); + if (enter.failed()) + return PP_FALSE; + return enter.object()->GetLocalAddress(local_addr); +} + +PP_Bool GetRemoteAddress(PP_Resource tcp_socket, + PP_Flash_NetAddress* remote_addr) { + EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true); + if (enter.failed()) + return PP_FALSE; + return enter.object()->GetRemoteAddress(remote_addr); +} + +int32_t InitiateSSL(PP_Resource tcp_socket, + const char* server_name, + PP_CompletionCallback callback) { + EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->InitiateSSL(server_name, callback); +} + +int32_t Read(PP_Resource tcp_socket, + char* buffer, + int32_t bytes_to_read, + PP_CompletionCallback callback) { + EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Read(buffer, bytes_to_read, callback); +} + +int32_t Write(PP_Resource tcp_socket, + const char* buffer, + int32_t bytes_to_write, + PP_CompletionCallback callback) { + EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Write(buffer, bytes_to_write, callback); +} + +void Disconnect(PP_Resource tcp_socket) { + EnterResource<PPB_Flash_TCPSocket_API> enter(tcp_socket, true); + if (enter.succeeded()) + enter.object()->Disconnect(); +} + +const PPB_Flash_TCPSocket g_ppb_flash_tcp_socket_thunk = { + &Create, + &IsFlashTCPSocket, + &Connect, + &ConnectWithNetAddress, + &GetLocalAddress, + &GetRemoteAddress, + &InitiateSSL, + &Read, + &Write, + &Disconnect +}; + +} // namespace + +const PPB_Flash_TCPSocket* GetPPB_Flash_TCPSocket_Thunk() { + return &g_ppb_flash_tcp_socket_thunk; +} + +} // namespace thunk +} // namespace ppapi + diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h index c998b56..e2e5ba1 100644 --- a/ppapi/thunk/resource_creation_api.h +++ b/ppapi/thunk/resource_creation_api.h @@ -63,6 +63,7 @@ class ResourceCreationAPI { virtual PP_Resource CreateFlashMenu(PP_Instance instance, const PP_Flash_Menu* menu_data) = 0; virtual PP_Resource CreateFlashNetConnector(PP_Instance instance) = 0; + virtual PP_Resource CreateFlashTCPSocket(PP_Instance instace) = 0; // Note: can't be called CreateFont due to Windows #defines. virtual PP_Resource CreateFontObject( PP_Instance instance, diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h index 645c5c6..9fb84b3 100644 --- a/ppapi/thunk/thunk.h +++ b/ppapi/thunk/thunk.h @@ -24,6 +24,7 @@ struct PPB_FileSystem_Dev; struct PPB_Find_Dev; struct PPB_Flash_Menu; struct PPB_Flash_NetConnector; +struct PPB_Flash_TCPSocket; struct PPB_Font_Dev; struct PPB_Fullscreen_Dev; struct PPB_GLESChromiumTextureMapping_Dev; @@ -75,6 +76,7 @@ const PPB_FileSystem_Dev* GetPPB_FileSystem_Thunk(); const PPB_Find_Dev* GetPPB_Find_Thunk(); const PPB_Flash_Menu* GetPPB_Flash_Menu_Thunk(); const PPB_Flash_NetConnector* GetPPB_Flash_NetConnector_Thunk(); +const PPB_Flash_TCPSocket* GetPPB_Flash_TCPSocket_Thunk(); const PPB_Font_Dev* GetPPB_Font_Thunk(); const PPB_Fullscreen_Dev* GetPPB_Fullscreen_Thunk(); const PPB_GLESChromiumTextureMapping_Dev* |