diff --git a/ppapi/PRESUBMIT.py b/ppapi/PRESUBMIT.py index 1a950034e4cf..72672e9d6615 100644 --- a/ppapi/PRESUBMIT.py +++ b/ppapi/PRESUBMIT.py @@ -65,6 +65,8 @@ def CheckTODO(input_api, output_api): # Only examine public stable interfaces. if name_parts[2] in ['dev', 'private', 'trusted']: continue + if name_parts[2] == 'extensions' and name_parts[3] == 'dev': + continue filepath = os.path.join('..', filename) if RE_TODO.search(open(filepath, 'rb').read()): diff --git a/ppapi/api/extensions/dev/ppb_ext_socket_dev.idl b/ppapi/api/extensions/dev/ppb_ext_socket_dev.idl new file mode 100644 index 000000000000..10051d788102 --- /dev/null +++ b/ppapi/api/extensions/dev/ppb_ext_socket_dev.idl @@ -0,0 +1,417 @@ +/* Copyright (c) 2013 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. + */ + +/** + * This file defines the Pepper equivalent of the chrome.socket + * extension API. + */ + +label Chrome { + M28 = 0.1 +}; + +/** + * A string PP_Var which has one of the following values: + * - "tcp" + * - "udp" + */ +typedef PP_Var PP_Ext_Socket_SocketType_Dev; + +/** + * A dictionary PP_Var. + */ +typedef PP_Var PP_Ext_Socket_CreateOptions_Dev; + +/** + * A dictionary PP_Var which contains + * - "socketId" : integer PP_Var + * The id of the newly created socket. + */ +typedef PP_Var PP_Ext_Socket_CreateInfo_Dev; + +/** + * A dictionary PP_Var which contains + * - "resultCode" : integer PP_Var + * - "socketId" : integer or undefined PP_Var + * The id of the accepted socket. + */ +typedef PP_Var PP_Ext_Socket_AcceptInfo_Dev; + +/** + * A dictionary PP_Var which contains + * - "resultCode" : integer PP_Var + * The resultCode returned from the underlying read() call. + * - "data" : array buffer PP_Var + */ +typedef PP_Var PP_Ext_Socket_ReadInfo_Dev; + +/** + * A dictionary PP_Var which contains + * - "bytesWritten" : integer PP_Var + * The number of bytes sent, or a negative error code. + */ +typedef PP_Var PP_Ext_Socket_WriteInfo_Dev; + +/** + * A dictionary PP_Var which contains + * - "resultCode" : integer PP_Var + * The resultCode returned from the underlying recvfrom() call. + * - "data": array buffer PP_Var + * - "address": string PP_Var + * The address of the remote machine. + * - "port": integer PP_Var + */ +typedef PP_Var PP_Ext_Socket_RecvFromInfo_Dev; + +/** + * A dictionary PP_Var which contains + * - "socketType" : string PP_Var which matches the description of + * PP_Ext_Socket_SocketType_Dev + * The type of the passed socket. This will be tcp or + * udp. + * - "connected" : boolean PP_Var + * Whether or not the underlying socket is connected. + * + * For tcp sockets, this will remain true even if the remote peer + * has disconnected. Reading or writing to the socket may then result in an + * error, hinting that this socket should be disconnected via + * Disconnect(). + * + * For udp sockets, this just represents whether a default remote + * address has been specified for reading and writing packets. + * - "peerAddress" : string or undefined PP_Var + * If the underlying socket is connected, contains the IPv4/6 address of the + * peer. + * - "peerPort" : integer or undefined PP_Var + * If the underlying socket is connected, contains the port of the connected + * peer. + * - "localAddress" : string or undefined PP_Var + * If the underlying socket is bound or connected, contains its local IPv4/6 + * address. + * - "localPort" : integer or undefined PP_Var + * If the underlying socket is bound or connected, contains its local port. + */ +typedef PP_Var PP_Ext_Socket_SocketInfo_Dev; + +/** + * A dictionary PP_Var which contains + * - "name" : string PP_Var + * The underlying name of the adapter. On *nix, this will typically be "eth0", + * "lo", etc. + * - "address": string PP_Var + * The available IPv4/6 address. + */ +typedef PP_Var PP_Ext_Socket_NetworkInterface_Dev; + +/** + * An array PP_Var which contains elements of + * PP_Ext_Socket_NetworkInterface_Dev. + */ +typedef PP_Var PP_Ext_Socket_NetworkInterface_Dev_Array; + +interface PPB_Ext_Socket_Dev { + /** + * Creates a socket of the specified type that will connect to the specified + * remote machine. + * + * @param[in] instance A PP_Instance. + * @param[in] type A PP_Ext_Socket_SocketType_Dev. The type of + * socket to create. Must be tcp or udp. + * @param[in] options An undefined PP_Var or + * PP_Ext_Socket_CreateOptions_Dev. The socket options. + * @param[out] create_info A PP_Ext_Socket_CreateInfo_Dev. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t Create( + [in] PP_Instance instance, + [in] PP_Ext_Socket_SocketType_Dev type, + [in] PP_Ext_Socket_CreateOptions_Dev options, + [out] PP_Ext_Socket_CreateInfo_Dev create_info, + [in] PP_CompletionCallback callback); + + /** + * Destroys the socket. Each socket created should be destroyed after use. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + */ + void Destroy( + [in] PP_Instance instance, + [in] PP_Var socket_id); + + /** + * Connects the socket to the remote machine (for a tcp socket). + * For a udp socket, this sets the default address which packets + * are sent to and read from for Read() and Write() + * calls. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] hostname A string PP_Var. The hostname or IP + * address of the remote machine. + * @param[in] port An integer PP_Var. The port of the remote + * machine. + * @param[out] result An integer PP_Var. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t Connect( + [in] PP_Instance instance, + [in] PP_Var socket_id, + [in] PP_Var hostname, + [in] PP_Var port, + [out] PP_Var result, + [in] PP_CompletionCallback callback); + + /** + * Binds the local address for socket. Currently, it does not support TCP + * socket. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] address A string PP_Var. The address of the local + * machine. + * @param[in] port An integer PP_Var. The port of the local + * machine. + * @param[out] result An integer PP_Var. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t Bind( + [in] PP_Instance instance, + [in] PP_Var socket_id, + [in] PP_Var address, + [in] PP_Var port, + [out] PP_Var result, + [in] PP_CompletionCallback callback); + + /** + * Disconnects the socket. For UDP sockets, Disconnect is a + * non-operation but is safe to call. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + */ + void Disconnect( + [in] PP_Instance instance, + [in] PP_Var socket_id); + + /** + * Reads data from the given connected socket. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] buffer_size An undefined or integer PP_Var. The + * read buffer size. + * @param[out] read_info A PP_Ext_Socket_ReadInfo_Dev. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t Read( + [in] PP_Instance instance, + [in] PP_Var socket_id, + [in] PP_Var buffer_size, + [out] PP_Ext_Socket_ReadInfo_Dev read_info, + [in] PP_CompletionCallback callback); + + /** + * Writes data on the given connected socket. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] data An array buffer PP_Var. The data to write. + * @param[out] write_info A PP_Ext_Socket_WriteInfo_Dev. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t Write( + [in] PP_Instance instance, + [in] PP_Var socket_id, + [in] PP_Var data, + [out] PP_Ext_Socket_WriteInfo_Dev write_info, + [in] PP_CompletionCallback callback); + + /** + * Receives data from the given UDP socket. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] buffer_size An undefined or integer PP_Var. The + * receive buffer size. + * @param[out] recv_from_info A PP_Ext_Socket_RecvFromInfo_Dev. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t RecvFrom( + [in] PP_Instance instance, + [in] PP_Var socket_id, + [in] PP_Var buffer_size, + [out] PP_Ext_Socket_RecvFromInfo_Dev recv_from_info, + [in] PP_CompletionCallback callback); + + /** + * Sends data on the given UDP socket to the given address and port. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] data An array buffer PP_Var. + * @param[in] address A string PP_Var. The address of the remote + * machine. + * @param[in] port An integer PP_Var. The port of the remote + * machine. + * @param[out] write_info A PP_Ext_Socket_WriteInfo_Dev. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t SendTo( + [in] PP_Instance instance, + [in] PP_Var socket_id, + [in] PP_Var data, + [in] PP_Var address, + [in] PP_Var port, + [out] PP_Ext_Socket_WriteInfo_Dev write_info, + [in] PP_CompletionCallback callback); + + /** + * This method applies to TCP sockets only. + * Listens for connections on the specified port and address. This effectively + * makes this a server socket, and client socket functions (Connect, Read, + * Write) can no longer be used on this socket. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] address A string PP_Var. The address of the local + * machine. + * @param[in] port An integer PP_Var. The port of the local + * machine. + * @param[in] backlog An undefined or integer PP_Var. Length of + * the socket's listen queue. + * @param[out] result An integer PP_Var. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t Listen( + [in] PP_Instance instance, + [in] PP_Var socket_id, + [in] PP_Var address, + [in] PP_Var port, + [in] PP_Var backlog, + [out] PP_Var result, + [in] PP_CompletionCallback callback); + + /** + * This method applies to TCP sockets only. + * Registers a callback function to be called when a connection is accepted on + * this listening server socket. Listen must be called first. + * If there is already an active accept callback, this callback will be + * invoked immediately with an error as the resultCode. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[out] accept_info A PP_Ext_Socket_AcceptInfo_Dev. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t Accept( + [in] PP_Instance instance, + [in] PP_Var socket_id, + [out] PP_Ext_Socket_AcceptInfo_Dev accept_info, + [in] PP_CompletionCallback callback); + + /** + * Enables or disables the keep-alive functionality for a TCP connection. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] enable A boolean PP_Var. If true, enable keep-alive + * functionality. + * @param[in] delay An undefined or integer PP_Var. Set the delay + * seconds between the last data packet received and the first keepalive + * probe. Default is 0. + * @param[out] result A boolean PP_Var. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t SetKeepAlive( + [in] PP_Instance instance, + [in] PP_Var socket_id, + [in] PP_Var enable, + [in] PP_Var delay, + [out] PP_Var result, + [in] PP_CompletionCallback callback); + + /** + * Sets or clears TCP_NODELAY for a TCP connection. Nagle's + * algorithm will be disabled when TCP_NODELAY is set. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] no_delay A boolean PP_Var. + * @param[out] result A boolean PP_Var. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t SetNoDelay( + [in] PP_Instance instance, + [in] PP_Var socket_id, + [in] PP_Var no_delay, + [out] PP_Var result, + [in] PP_CompletionCallback callback); + + /** + * Retrieves the state of the given socket. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[out] result A PP_Ext_Socket_SocketInfo_Dev. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t GetInfo( + [in] PP_Instance instance, + [in] PP_Var socket_id, + [out] PP_Ext_Socket_SocketInfo_Dev result, + [in] PP_CompletionCallback callback); + + /** + * Retrieves information about local adapters on this system. + * + * @param[in] instance A PP_Instance. + * @param[out] result A PP_Ext_Socket_NetworkInterface_Dev_Array. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t GetNetworkList( + [in] PP_Instance instance, + [out] PP_Ext_Socket_NetworkInterface_Dev_Array result, + [in] PP_CompletionCallback callback); +}; diff --git a/ppapi/c/extensions/dev/ppb_ext_socket_dev.h b/ppapi/c/extensions/dev/ppb_ext_socket_dev.h new file mode 100644 index 000000000000..b24e1290f2b4 --- /dev/null +++ b/ppapi/c/extensions/dev/ppb_ext_socket_dev.h @@ -0,0 +1,420 @@ +/* Copyright (c) 2013 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. + */ + +/* From extensions/dev/ppb_ext_socket_dev.idl, + * modified Tue Apr 02 16:04:00 2013. + */ + +#ifndef PPAPI_C_EXTENSIONS_DEV_PPB_EXT_SOCKET_DEV_H_ +#define PPAPI_C_EXTENSIONS_DEV_PPB_EXT_SOCKET_DEV_H_ + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_macros.h" +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/pp_var.h" + +#define PPB_EXT_SOCKET_DEV_INTERFACE_0_1 "PPB_Ext_Socket(Dev);0.1" +#define PPB_EXT_SOCKET_DEV_INTERFACE PPB_EXT_SOCKET_DEV_INTERFACE_0_1 + +/** + * @file + * This file defines the Pepper equivalent of the chrome.socket + * extension API. + */ + + +/** + * @addtogroup Typedefs + * @{ + */ +/** + * A string PP_Var which has one of the following values: + * - "tcp" + * - "udp" + */ +typedef struct PP_Var PP_Ext_Socket_SocketType_Dev; + +/** + * A dictionary PP_Var. + */ +typedef struct PP_Var PP_Ext_Socket_CreateOptions_Dev; + +/** + * A dictionary PP_Var which contains + * - "socketId" : integer PP_Var + * The id of the newly created socket. + */ +typedef struct PP_Var PP_Ext_Socket_CreateInfo_Dev; + +/** + * A dictionary PP_Var which contains + * - "resultCode" : integer PP_Var + * - "socketId" : integer or undefined PP_Var + * The id of the accepted socket. + */ +typedef struct PP_Var PP_Ext_Socket_AcceptInfo_Dev; + +/** + * A dictionary PP_Var which contains + * - "resultCode" : integer PP_Var + * The resultCode returned from the underlying read() call. + * - "data" : array buffer PP_Var + */ +typedef struct PP_Var PP_Ext_Socket_ReadInfo_Dev; + +/** + * A dictionary PP_Var which contains + * - "bytesWritten" : integer PP_Var + * The number of bytes sent, or a negative error code. + */ +typedef struct PP_Var PP_Ext_Socket_WriteInfo_Dev; + +/** + * A dictionary PP_Var which contains + * - "resultCode" : integer PP_Var + * The resultCode returned from the underlying recvfrom() call. + * - "data": array buffer PP_Var + * - "address": string PP_Var + * The address of the remote machine. + * - "port": integer PP_Var + */ +typedef struct PP_Var PP_Ext_Socket_RecvFromInfo_Dev; + +/** + * A dictionary PP_Var which contains + * - "socketType" : string PP_Var which matches the description of + * PP_Ext_Socket_SocketType_Dev + * The type of the passed socket. This will be tcp or + * udp. + * - "connected" : boolean PP_Var + * Whether or not the underlying socket is connected. + * + * For tcp sockets, this will remain true even if the remote peer + * has disconnected. Reading or writing to the socket may then result in an + * error, hinting that this socket should be disconnected via + * Disconnect(). + * + * For udp sockets, this just represents whether a default remote + * address has been specified for reading and writing packets. + * - "peerAddress" : string or undefined PP_Var + * If the underlying socket is connected, contains the IPv4/6 address of the + * peer. + * - "peerPort" : integer or undefined PP_Var + * If the underlying socket is connected, contains the port of the connected + * peer. + * - "localAddress" : string or undefined PP_Var + * If the underlying socket is bound or connected, contains its local IPv4/6 + * address. + * - "localPort" : integer or undefined PP_Var + * If the underlying socket is bound or connected, contains its local port. + */ +typedef struct PP_Var PP_Ext_Socket_SocketInfo_Dev; + +/** + * A dictionary PP_Var which contains + * - "name" : string PP_Var + * The underlying name of the adapter. On *nix, this will typically be "eth0", + * "lo", etc. + * - "address": string PP_Var + * The available IPv4/6 address. + */ +typedef struct PP_Var PP_Ext_Socket_NetworkInterface_Dev; + +/** + * An array PP_Var which contains elements of + * PP_Ext_Socket_NetworkInterface_Dev. + */ +typedef struct PP_Var PP_Ext_Socket_NetworkInterface_Dev_Array; +/** + * @} + */ + +/** + * @addtogroup Interfaces + * @{ + */ +struct PPB_Ext_Socket_Dev_0_1 { + /** + * Creates a socket of the specified type that will connect to the specified + * remote machine. + * + * @param[in] instance A PP_Instance. + * @param[in] type A PP_Ext_Socket_SocketType_Dev. The type of + * socket to create. Must be tcp or udp. + * @param[in] options An undefined PP_Var or + * PP_Ext_Socket_CreateOptions_Dev. The socket options. + * @param[out] create_info A PP_Ext_Socket_CreateInfo_Dev. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t (*Create)(PP_Instance instance, + PP_Ext_Socket_SocketType_Dev type, + PP_Ext_Socket_CreateOptions_Dev options, + PP_Ext_Socket_CreateInfo_Dev* create_info, + struct PP_CompletionCallback callback); + /** + * Destroys the socket. Each socket created should be destroyed after use. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + */ + void (*Destroy)(PP_Instance instance, struct PP_Var socket_id); + /** + * Connects the socket to the remote machine (for a tcp socket). + * For a udp socket, this sets the default address which packets + * are sent to and read from for Read() and Write() + * calls. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] hostname A string PP_Var. The hostname or IP + * address of the remote machine. + * @param[in] port An integer PP_Var. The port of the remote + * machine. + * @param[out] result An integer PP_Var. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t (*Connect)(PP_Instance instance, + struct PP_Var socket_id, + struct PP_Var hostname, + struct PP_Var port, + struct PP_Var* result, + struct PP_CompletionCallback callback); + /** + * Binds the local address for socket. Currently, it does not support TCP + * socket. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] address A string PP_Var. The address of the local + * machine. + * @param[in] port An integer PP_Var. The port of the local + * machine. + * @param[out] result An integer PP_Var. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t (*Bind)(PP_Instance instance, + struct PP_Var socket_id, + struct PP_Var address, + struct PP_Var port, + struct PP_Var* result, + struct PP_CompletionCallback callback); + /** + * Disconnects the socket. For UDP sockets, Disconnect is a + * non-operation but is safe to call. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + */ + void (*Disconnect)(PP_Instance instance, struct PP_Var socket_id); + /** + * Reads data from the given connected socket. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] buffer_size An undefined or integer PP_Var. The + * read buffer size. + * @param[out] read_info A PP_Ext_Socket_ReadInfo_Dev. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t (*Read)(PP_Instance instance, + struct PP_Var socket_id, + struct PP_Var buffer_size, + PP_Ext_Socket_ReadInfo_Dev* read_info, + struct PP_CompletionCallback callback); + /** + * Writes data on the given connected socket. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] data An array buffer PP_Var. The data to write. + * @param[out] write_info A PP_Ext_Socket_WriteInfo_Dev. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t (*Write)(PP_Instance instance, + struct PP_Var socket_id, + struct PP_Var data, + PP_Ext_Socket_WriteInfo_Dev* write_info, + struct PP_CompletionCallback callback); + /** + * Receives data from the given UDP socket. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] buffer_size An undefined or integer PP_Var. The + * receive buffer size. + * @param[out] recv_from_info A PP_Ext_Socket_RecvFromInfo_Dev. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t (*RecvFrom)(PP_Instance instance, + struct PP_Var socket_id, + struct PP_Var buffer_size, + PP_Ext_Socket_RecvFromInfo_Dev* recv_from_info, + struct PP_CompletionCallback callback); + /** + * Sends data on the given UDP socket to the given address and port. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] data An array buffer PP_Var. + * @param[in] address A string PP_Var. The address of the remote + * machine. + * @param[in] port An integer PP_Var. The port of the remote + * machine. + * @param[out] write_info A PP_Ext_Socket_WriteInfo_Dev. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t (*SendTo)(PP_Instance instance, + struct PP_Var socket_id, + struct PP_Var data, + struct PP_Var address, + struct PP_Var port, + PP_Ext_Socket_WriteInfo_Dev* write_info, + struct PP_CompletionCallback callback); + /** + * This method applies to TCP sockets only. + * Listens for connections on the specified port and address. This effectively + * makes this a server socket, and client socket functions (Connect, Read, + * Write) can no longer be used on this socket. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] address A string PP_Var. The address of the local + * machine. + * @param[in] port An integer PP_Var. The port of the local + * machine. + * @param[in] backlog An undefined or integer PP_Var. Length of + * the socket's listen queue. + * @param[out] result An integer PP_Var. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t (*Listen)(PP_Instance instance, + struct PP_Var socket_id, + struct PP_Var address, + struct PP_Var port, + struct PP_Var backlog, + struct PP_Var* result, + struct PP_CompletionCallback callback); + /** + * This method applies to TCP sockets only. + * Registers a callback function to be called when a connection is accepted on + * this listening server socket. Listen must be called first. + * If there is already an active accept callback, this callback will be + * invoked immediately with an error as the resultCode. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[out] accept_info A PP_Ext_Socket_AcceptInfo_Dev. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t (*Accept)(PP_Instance instance, + struct PP_Var socket_id, + PP_Ext_Socket_AcceptInfo_Dev* accept_info, + struct PP_CompletionCallback callback); + /** + * Enables or disables the keep-alive functionality for a TCP connection. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] enable A boolean PP_Var. If true, enable keep-alive + * functionality. + * @param[in] delay An undefined or integer PP_Var. Set the delay + * seconds between the last data packet received and the first keepalive + * probe. Default is 0. + * @param[out] result A boolean PP_Var. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t (*SetKeepAlive)(PP_Instance instance, + struct PP_Var socket_id, + struct PP_Var enable, + struct PP_Var delay, + struct PP_Var* result, + struct PP_CompletionCallback callback); + /** + * Sets or clears TCP_NODELAY for a TCP connection. Nagle's + * algorithm will be disabled when TCP_NODELAY is set. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[in] no_delay A boolean PP_Var. + * @param[out] result A boolean PP_Var. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t (*SetNoDelay)(PP_Instance instance, + struct PP_Var socket_id, + struct PP_Var no_delay, + struct PP_Var* result, + struct PP_CompletionCallback callback); + /** + * Retrieves the state of the given socket. + * + * @param[in] instance A PP_Instance. + * @param[in] socket_id An integer PP_Var. The socket ID. + * @param[out] result A PP_Ext_Socket_SocketInfo_Dev. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t (*GetInfo)(PP_Instance instance, + struct PP_Var socket_id, + PP_Ext_Socket_SocketInfo_Dev* result, + struct PP_CompletionCallback callback); + /** + * Retrieves information about local adapters on this system. + * + * @param[in] instance A PP_Instance. + * @param[out] result A PP_Ext_Socket_NetworkInterface_Dev_Array. + * @param[in] callback A PP_CompletionCallback to be called + * upon completion. + * + * @return An error code from pp_errors.h. + */ + int32_t (*GetNetworkList)(PP_Instance instance, + PP_Ext_Socket_NetworkInterface_Dev_Array* result, + struct PP_CompletionCallback callback); +}; + +typedef struct PPB_Ext_Socket_Dev_0_1 PPB_Ext_Socket_Dev; +/** + * @} + */ + +#endif /* PPAPI_C_EXTENSIONS_DEV_PPB_EXT_SOCKET_DEV_H_ */ + diff --git a/ppapi/cpp/extensions/dev/socket_dev.cc b/ppapi/cpp/extensions/dev/socket_dev.cc new file mode 100644 index 000000000000..a2e88301b062 --- /dev/null +++ b/ppapi/cpp/extensions/dev/socket_dev.cc @@ -0,0 +1,479 @@ +// Copyright (c) 2013 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/cpp/extensions/dev/socket_dev.h" + +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/extensions/optional.h" +#include "ppapi/cpp/extensions/to_var_converter.h" +#include "ppapi/cpp/logging.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name() { + return PPB_EXT_SOCKET_DEV_INTERFACE_0_1; +} + +} // namespace + +namespace ext { +namespace socket { + +const char* const SocketType_Dev::kTcp = "tcp"; +const char* const SocketType_Dev::kUdp = "udp"; + +SocketType_Dev::SocketType_Dev() : value(NONE) { +} + +SocketType_Dev::SocketType_Dev(ValueType in_value) : value(in_value) { +} + +SocketType_Dev::~SocketType_Dev() { +} + +bool SocketType_Dev::Populate(const PP_Var& var_value) { + if (var_value.type != PP_VARTYPE_STRING) + return false; + + std::string string_value = Var(var_value).AsString(); + if (string_value == kTcp) { + value = TCP; + } else if (string_value == kUdp) { + value = UDP; + } else { + value = NONE; + return false; + } + return true; +} + +Var SocketType_Dev::CreateVar() const { + switch (value) { + case TCP: + return Var(kTcp); + case UDP: + return Var(kUdp); + default: + PP_NOTREACHED(); + return Var(std::string()); + } +} + +const char* const CreateInfo_Dev::kSocketId = "socketId"; + +CreateInfo_Dev::CreateInfo_Dev() + : socket_id(kSocketId) { +} + +CreateInfo_Dev::~CreateInfo_Dev() { +} + +bool CreateInfo_Dev::Populate(const PP_Ext_Socket_CreateInfo_Dev& value) { + if (value.type != PP_VARTYPE_DICTIONARY) + return false; + + VarDictionary_Dev dict(value); + bool result = socket_id.Populate(dict); + + return result; +} + +Var CreateInfo_Dev::CreateVar() const { + VarDictionary_Dev dict; + + bool result = socket_id.AddTo(&dict); + // Suppress unused variable warnings. + static_cast(result); + PP_DCHECK(result); + + return dict; +} + +const char* const AcceptInfo_Dev::kResultCode = "resultCode"; +const char* const AcceptInfo_Dev::kSocketId = "socketId"; + +AcceptInfo_Dev::AcceptInfo_Dev() + : result_code(kResultCode), + socket_id(kSocketId) { +} + +AcceptInfo_Dev::~AcceptInfo_Dev() { +} + +bool AcceptInfo_Dev::Populate(const PP_Ext_Socket_AcceptInfo_Dev& value) { + if (value.type != PP_VARTYPE_DICTIONARY) + return false; + + VarDictionary_Dev dict(value); + bool result = result_code.Populate(dict); + result = socket_id.Populate(dict) && result; + + return result; +} + +Var AcceptInfo_Dev::CreateVar() const { + VarDictionary_Dev dict; + + bool result = result_code.AddTo(&dict); + result = socket_id.MayAddTo(&dict) && result; + PP_DCHECK(result); + + return dict; +} + +const char* const ReadInfo_Dev::kResultCode = "resultCode"; +const char* const ReadInfo_Dev::kData = "data"; + +ReadInfo_Dev::ReadInfo_Dev() + : result_code(kResultCode), + data(kData) { +} + +ReadInfo_Dev::~ReadInfo_Dev() { +} + +bool ReadInfo_Dev::Populate(const PP_Ext_Socket_ReadInfo_Dev& value) { + if (value.type != PP_VARTYPE_DICTIONARY) + return false; + + VarDictionary_Dev dict(value); + bool result = result_code.Populate(dict); + result = data.Populate(dict) && result; + + return result; +} + +Var ReadInfo_Dev::CreateVar() const { + VarDictionary_Dev dict; + + bool result = result_code.AddTo(&dict); + result = data.AddTo(&dict) && result; + PP_DCHECK(result); + + return dict; +} + +const char* const WriteInfo_Dev::kBytesWritten = "bytesWritten"; + +WriteInfo_Dev::WriteInfo_Dev() + : bytes_written(kBytesWritten) { +} + +WriteInfo_Dev::~WriteInfo_Dev() { +} + +bool WriteInfo_Dev::Populate(const PP_Ext_Socket_WriteInfo_Dev& value) { + if (value.type != PP_VARTYPE_DICTIONARY) + return false; + + VarDictionary_Dev dict(value); + bool result = bytes_written.Populate(dict); + + return result; +} + +Var WriteInfo_Dev::CreateVar() const { + VarDictionary_Dev dict; + + bool result = bytes_written.AddTo(&dict); + // Suppress unused variable warnings. + static_cast(result); + PP_DCHECK(result); + + return dict; +} + +const char* const RecvFromInfo_Dev::kResultCode = "resultCode"; +const char* const RecvFromInfo_Dev::kData = "data"; +const char* const RecvFromInfo_Dev::kAddress = "address"; +const char* const RecvFromInfo_Dev::kPort = "port"; + +RecvFromInfo_Dev::RecvFromInfo_Dev() + : result_code(kResultCode), + data(kData), + address(kAddress), + port(kPort) { +} + +RecvFromInfo_Dev::~RecvFromInfo_Dev() { +} + +bool RecvFromInfo_Dev::Populate(const PP_Ext_Socket_RecvFromInfo_Dev& value) { + if (value.type != PP_VARTYPE_DICTIONARY) + return false; + + VarDictionary_Dev dict(value); + bool result = result_code.Populate(dict); + result = data.Populate(dict) && result; + result = address.Populate(dict) && result; + result = port.Populate(dict) && result; + + return result; +} + +Var RecvFromInfo_Dev::CreateVar() const { + VarDictionary_Dev dict; + + bool result = result_code.AddTo(&dict); + result = data.AddTo(&dict) && result; + result = address.AddTo(&dict) && result; + result = port.AddTo(&dict) && result; + PP_DCHECK(result); + + return dict; +} + +const char* const SocketInfo_Dev::kSocketType = "socketType"; +const char* const SocketInfo_Dev::kConnected = "connected"; +const char* const SocketInfo_Dev::kPeerAddress = "peerAddress"; +const char* const SocketInfo_Dev::kPeerPort = "peerPort"; +const char* const SocketInfo_Dev::kLocalAddress = "localAddress"; +const char* const SocketInfo_Dev::kLocalPort = "localPort"; + +SocketInfo_Dev::SocketInfo_Dev() + : socket_type(kSocketType), + connected(kConnected), + peer_address(kPeerAddress), + peer_port(kPeerPort), + local_address(kLocalAddress), + local_port(kLocalPort) { +} + +SocketInfo_Dev::~SocketInfo_Dev() { +} + +bool SocketInfo_Dev::Populate(const PP_Ext_Socket_SocketInfo_Dev& value) { + if (value.type != PP_VARTYPE_DICTIONARY) + return false; + + VarDictionary_Dev dict(value); + bool result = socket_type.Populate(dict); + result = connected.Populate(dict) && result; + result = peer_address.Populate(dict) && result; + result = peer_port.Populate(dict) && result; + result = local_address.Populate(dict) && result; + result = local_port.Populate(dict) && result; + + return result; +} + +Var SocketInfo_Dev::CreateVar() const { + VarDictionary_Dev dict; + + bool result = socket_type.AddTo(&dict); + result = connected.AddTo(&dict) && result; + result = peer_address.MayAddTo(&dict) && result; + result = peer_port.MayAddTo(&dict) && result; + result = local_address.MayAddTo(&dict) && result; + result = local_port.MayAddTo(&dict) && result; + PP_DCHECK(result); + + return dict; +} + +const char* const NetworkInterface_Dev::kName = "name"; +const char* const NetworkInterface_Dev::kAddress = "address"; + +NetworkInterface_Dev::NetworkInterface_Dev() + : name(kName), + address(kAddress) { +} + +NetworkInterface_Dev::~NetworkInterface_Dev() { +} + +bool NetworkInterface_Dev::Populate( + const PP_Ext_Socket_NetworkInterface_Dev& value) { + if (value.type != PP_VARTYPE_DICTIONARY) + return false; + + VarDictionary_Dev dict(value); + bool result = name.Populate(dict); + result = address.Populate(dict) && result; + + return result; +} + +Var NetworkInterface_Dev::CreateVar() const { + VarDictionary_Dev dict; + + bool result = name.AddTo(&dict); + result = address.AddTo(&dict) && result; + PP_DCHECK(result); + + return dict; +} + +Socket_Dev::Socket_Dev(const InstanceHandle& instance) : instance_(instance) { +} + +Socket_Dev::~Socket_Dev() { +} + +int32_t Socket_Dev::Create( + const SocketType_Dev& type, + const Optional& options, + const CompletionCallbackWithOutput& callback) { + if (!has_interface()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + + internal::ToVarConverter type_var(type); + internal::ToVarConverter > options_var(options); + + return get_interface()->Create( + instance_.pp_instance(), + type_var.pp_var(), + options_var.pp_var(), + callback.output(), + callback.pp_completion_callback()); +} + +void Socket_Dev::Destroy(int32_t socket_id) { + if (!has_interface()) + return; + + internal::ToVarConverter socket_id_var(socket_id); + + return get_interface()->Destroy( + instance_.pp_instance(), + socket_id_var.pp_var()); +} + +void Socket_Dev::Disconnect(int32_t socket_id) { + if (!has_interface()) + return; + + internal::ToVarConverter socket_id_var(socket_id); + + return get_interface()->Disconnect( + instance_.pp_instance(), + socket_id_var.pp_var()); +} + +int32_t Socket_Dev::Read( + int32_t socket_id, + const Optional& buffer_size, + const CompletionCallbackWithOutput& callback) { + if (!has_interface()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + + internal::ToVarConverter socket_id_var(socket_id); + internal::ToVarConverter > buffer_size_var(buffer_size); + + return get_interface()->Read( + instance_.pp_instance(), + socket_id_var.pp_var(), + buffer_size_var.pp_var(), + callback.output(), + callback.pp_completion_callback()); +} + +int32_t Socket_Dev::Write( + int32_t socket_id, + const Var& data, + const CompletionCallbackWithOutput& callback) { + if (!has_interface()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + + internal::ToVarConverter socket_id_var(socket_id); + internal::ToVarConverter data_var(data); + + return get_interface()->Write( + instance_.pp_instance(), + socket_id_var.pp_var(), + data_var.pp_var(), + callback.output(), + callback.pp_completion_callback()); +} + +int32_t Socket_Dev::RecvFrom( + int32_t socket_id, + const Optional& buffer_size, + const CompletionCallbackWithOutput& callback) { + if (!has_interface()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + + internal::ToVarConverter socket_id_var(socket_id); + internal::ToVarConverter > buffer_size_var(buffer_size); + + return get_interface()->RecvFrom( + instance_.pp_instance(), + socket_id_var.pp_var(), + buffer_size_var.pp_var(), + callback.output(), + callback.pp_completion_callback()); +} + +int32_t Socket_Dev::SendTo( + int32_t socket_id, + const Var& data, + const std::string& address, + int32_t port, + const CompletionCallbackWithOutput& callback) { + if (!has_interface()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + + internal::ToVarConverter socket_id_var(socket_id); + internal::ToVarConverter data_var(data); + internal::ToVarConverter address_var(address); + internal::ToVarConverter port_var(port); + + return get_interface()->SendTo( + instance_.pp_instance(), + socket_id_var.pp_var(), + data_var.pp_var(), + address_var.pp_var(), + port_var.pp_var(), + callback.output(), + callback.pp_completion_callback()); +} + +int32_t Socket_Dev::Accept( + int32_t socket_id, + const CompletionCallbackWithOutput& callback) { + if (!has_interface()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + + internal::ToVarConverter socket_id_var(socket_id); + + return get_interface()->Accept( + instance_.pp_instance(), + socket_id_var.pp_var(), + callback.output(), + callback.pp_completion_callback()); +} + +int32_t Socket_Dev::GetInfo( + int32_t socket_id, + const CompletionCallbackWithOutput& callback) { + if (!has_interface()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + + internal::ToVarConverter socket_id_var(socket_id); + + return get_interface()->GetInfo( + instance_.pp_instance(), + socket_id_var.pp_var(), + callback.output(), + callback.pp_completion_callback()); +} + +int32_t Socket_Dev::GetNetworkList( + const CompletionCallbackWithOutput >& + callback) { + if (!has_interface()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + + return get_interface()->GetNetworkList( + instance_.pp_instance(), + callback.output(), + callback.pp_completion_callback()); +} + +} // namespace socket +} // namespace ext +} // namespace pp diff --git a/ppapi/cpp/extensions/dev/socket_dev.h b/ppapi/cpp/extensions/dev/socket_dev.h new file mode 100644 index 000000000000..5d2e5be4a990 --- /dev/null +++ b/ppapi/cpp/extensions/dev/socket_dev.h @@ -0,0 +1,243 @@ +// Copyright (c) 2013 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_CPP_EXTENSIONS_DEV_SOCKET_DEV_H_ +#define PPAPI_CPP_EXTENSIONS_DEV_SOCKET_DEV_H_ + +#include +#include + +#include "ppapi/c/extensions/dev/ppb_ext_socket_dev.h" +#include "ppapi/cpp/dev/var_dictionary_dev.h" +#include "ppapi/cpp/extensions/dict_field.h" +#include "ppapi/cpp/extensions/ext_output_traits.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/var.h" +#include "ppapi/cpp/var_array_buffer.h" + +namespace pp { + +template +class CompletionCallbackWithOutput; + +namespace ext { + +template +class Optional; + +namespace socket { + +// Data types ------------------------------------------------------------------ +class SocketType_Dev { + public: + enum ValueType { + NONE, + TCP, + UDP + }; + + SocketType_Dev(); + SocketType_Dev(ValueType in_value); + ~SocketType_Dev(); + + bool Populate(const PP_Var& var_value); + + Var CreateVar() const; + + ValueType value; + + static const char* const kTcp; + static const char* const kUdp; +}; + +typedef VarDictionary_Dev CreateOptions_Dev; + +class CreateInfo_Dev : public internal::OutputObjectBase { + public: + CreateInfo_Dev(); + ~CreateInfo_Dev(); + + bool Populate(const PP_Ext_Socket_CreateInfo_Dev& value); + + Var CreateVar() const; + + static const char* const kSocketId; + + DictField socket_id; +}; + +class AcceptInfo_Dev : public internal::OutputObjectBase { + public: + AcceptInfo_Dev(); + ~AcceptInfo_Dev(); + + bool Populate(const PP_Ext_Socket_AcceptInfo_Dev& value); + + Var CreateVar() const; + + static const char* const kResultCode; + static const char* const kSocketId; + + DictField result_code; + OptionalDictField socket_id; +}; + +class ReadInfo_Dev : public internal::OutputObjectBase { + public: + ReadInfo_Dev(); + ~ReadInfo_Dev(); + + bool Populate(const PP_Ext_Socket_ReadInfo_Dev& value); + + Var CreateVar() const; + + static const char* const kResultCode; + static const char* const kData; + + DictField result_code; + // TODO(yzshen): It is more natural to use VarArrayBuffer, but it doesn't have + // a default constructor currently. + DictField data; +}; + +class WriteInfo_Dev : public internal::OutputObjectBase { + public: + WriteInfo_Dev(); + ~WriteInfo_Dev(); + + bool Populate(const PP_Ext_Socket_WriteInfo_Dev& value); + + Var CreateVar() const; + + static const char* const kBytesWritten; + + DictField bytes_written; +}; + +class RecvFromInfo_Dev : public internal::OutputObjectBase { + public: + RecvFromInfo_Dev(); + ~RecvFromInfo_Dev(); + + bool Populate(const PP_Ext_Socket_RecvFromInfo_Dev& value); + + Var CreateVar() const; + + static const char* const kResultCode; + static const char* const kData; + static const char* const kAddress; + static const char* const kPort; + + DictField result_code; + DictField data; + DictField address; + DictField port; +}; + +class SocketInfo_Dev : public internal::OutputObjectBase { + public: + SocketInfo_Dev(); + ~SocketInfo_Dev(); + + bool Populate(const PP_Ext_Socket_SocketInfo_Dev& value); + + Var CreateVar() const; + + static const char* const kSocketType; + static const char* const kConnected; + static const char* const kPeerAddress; + static const char* const kPeerPort; + static const char* const kLocalAddress; + static const char* const kLocalPort; + + DictField socket_type; + DictField connected; + OptionalDictField peer_address; + OptionalDictField peer_port; + OptionalDictField local_address; + OptionalDictField local_port; +}; + +class NetworkInterface_Dev : public internal::OutputObjectBase { + public: + NetworkInterface_Dev(); + ~NetworkInterface_Dev(); + + bool Populate(const PP_Ext_Socket_NetworkInterface_Dev& value); + + Var CreateVar() const; + + static const char* const kName; + static const char* const kAddress; + + DictField name; + DictField address; +}; + +// Functions ------------------------------------------------------------------- +class Socket_Dev { + public: + explicit Socket_Dev(const InstanceHandle& instance); + ~Socket_Dev(); + + int32_t Create(const SocketType_Dev& type, + const Optional& options, + const CompletionCallbackWithOutput& callback); + void Destroy(int32_t socket_id); + // TODO(yzshen): Support more powerful traits. + //int32_t Connect(int32_t socket_id, + // const std::string& hostname, + // int32_t port, + // const CompletionCallbackWithOutput& callback); + //int32_t Bind(int32_t socket_id, + // const std::string& address, + // int32_t port, + // const CompletionCallbackWithOutput& callback); + void Disconnect(int32_t socket_id); + int32_t Read(int32_t socket_id, + const Optional& buffer_size, + const CompletionCallbackWithOutput& callback); + int32_t Write(int32_t socket_id, + const Var& data, + const CompletionCallbackWithOutput& callback); + int32_t RecvFrom( + int32_t socket_id, + const Optional& buffer_size, + const CompletionCallbackWithOutput& callback); + int32_t SendTo(int32_t socket_id, + const Var& data, + const std::string& address, + int32_t port, + const CompletionCallbackWithOutput& callback); + // TODO(yzshen): Support more powerful traits. + //int32_t Listen(int32_t socket_id, + // const std::string& address, + // int32_t port, + // const Optional& backlog, + // const CompletionCallbackWithOutput& callback); + int32_t Accept(int32_t socket_id, + const CompletionCallbackWithOutput& callback); + // TODO(yzshen): Support more powerful traits. + //int32_t SetKeepAlive(int32_t socket_id, + // bool enable, + // const Optional& delay, + // const CompletionCallbackWithOutput& callback); + //int32_t SetNoDelay(int32_t socket_id, + // bool no_delay, + // const CompletionCallbackWithOutput& callback); + int32_t GetInfo(int32_t socket_id, + const CompletionCallbackWithOutput& callback); + int32_t GetNetworkList( + const CompletionCallbackWithOutput >& + callback); + + private: + InstanceHandle instance_; +}; + +} // namespace socket +} // namespace ext +} // namespace pp + +#endif // PPAPI_CPP_EXTENSIONS_DEV_SOCKET_DEV_H_ diff --git a/ppapi/cpp/extensions/from_var_converter.h b/ppapi/cpp/extensions/from_var_converter.h index 6fb8a3257896..ddafe1db0121 100644 --- a/ppapi/cpp/extensions/from_var_converter.h +++ b/ppapi/cpp/extensions/from_var_converter.h @@ -8,6 +8,8 @@ #include #include "ppapi/c/pp_var.h" +#include "ppapi/cpp/dev/var_array_dev.h" +#include "ppapi/cpp/dev/var_dictionary_dev.h" #include "ppapi/cpp/extensions/optional.h" #include "ppapi/cpp/logging.h" #include "ppapi/cpp/var.h" @@ -80,7 +82,7 @@ class FromVarConverter > }; template <> -class FromVarConverter : public FromVarConverterBase { +class FromVarConverter : public FromVarConverterBase { public: FromVarConverter() { } @@ -93,7 +95,25 @@ class FromVarConverter : public FromVarConverterBase { } void Set(const PP_Var& var) { - FromVarConverterBase::value_ = Var(var).AsString(); + FromVarConverterBase::value_ = Var(var).AsBool(); + } +}; + +template <> +class FromVarConverter : public FromVarConverterBase { + public: + FromVarConverter() { + } + + FromVarConverter(const PP_Var& var) { + Set(var); + } + + ~FromVarConverter() { + } + + void Set(const PP_Var& var) { + FromVarConverterBase::value_ = Var(var).AsInt(); } }; @@ -115,6 +135,80 @@ class FromVarConverter : public FromVarConverterBase { } }; +template <> +class FromVarConverter : public FromVarConverterBase { + public: + FromVarConverter() { + } + + FromVarConverter(const PP_Var& var) { + Set(var); + } + + ~FromVarConverter() { + } + + void Set(const PP_Var& var) { + FromVarConverterBase::value_ = Var(var).AsString(); + } +}; + +template <> +class FromVarConverter : public FromVarConverterBase { + public: + FromVarConverter() { + } + + FromVarConverter(const PP_Var& var) { + Set(var); + } + + ~FromVarConverter() { + } + + void Set(const PP_Var& var) { + FromVarConverterBase::value_ = Var(var); + } +}; + +template <> +class FromVarConverter + : public FromVarConverterBase { + public: + FromVarConverter() { + } + + FromVarConverter(const PP_Var& var) { + Set(var); + } + + ~FromVarConverter() { + } + + void Set(const PP_Var& var) { + FromVarConverterBase::value_ = Var(var); + } +}; + +template <> +class FromVarConverter + : public FromVarConverterBase { + public: + FromVarConverter() { + } + + FromVarConverter(const PP_Var& var) { + Set(var); + } + + ~FromVarConverter() { + } + + void Set(const PP_Var& var) { + FromVarConverterBase::value_ = Var(var); + } +}; + } // namespace internal } // namespace ext } // namespace pp diff --git a/ppapi/cpp/extensions/to_var_converter.h b/ppapi/cpp/extensions/to_var_converter.h index ba05064ec8d7..591365290f72 100644 --- a/ppapi/cpp/extensions/to_var_converter.h +++ b/ppapi/cpp/extensions/to_var_converter.h @@ -8,8 +8,11 @@ #include #include "ppapi/c/pp_var.h" +#include "ppapi/cpp/dev/var_array_dev.h" +#include "ppapi/cpp/dev/var_dictionary_dev.h" #include "ppapi/cpp/extensions/optional.h" #include "ppapi/cpp/var.h" +#include "ppapi/cpp/var_array_buffer.h" namespace pp { namespace ext { @@ -65,6 +68,36 @@ class ToVarConverter > : public ToVarConverterBase { } }; +template <> +class ToVarConverter : public ToVarConverterBase { + public: + explicit ToVarConverter(bool object) : ToVarConverterBase(Var(object)) { + } + + ~ToVarConverter() { + } +}; + +template <> +class ToVarConverter : public ToVarConverterBase { + public: + explicit ToVarConverter(int32_t object) : ToVarConverterBase(Var(object)) { + } + + ~ToVarConverter() { + } +}; + +template <> +class ToVarConverter : public ToVarConverterBase { + public: + explicit ToVarConverter(double object) : ToVarConverterBase(Var(object)) { + } + + ~ToVarConverter() { + } +}; + template <> class ToVarConverter : public ToVarConverterBase { public: @@ -77,9 +110,39 @@ class ToVarConverter : public ToVarConverterBase { }; template <> -class ToVarConverter : public ToVarConverterBase { +class ToVarConverter : public ToVarConverterBase { public: - explicit ToVarConverter(double object) : ToVarConverterBase(Var(object)) { + explicit ToVarConverter(const Var& object) : ToVarConverterBase(object) { + } + + ~ToVarConverter() { + } +}; + +template <> +class ToVarConverter : public ToVarConverterBase { + public: + explicit ToVarConverter(const Var& object) : ToVarConverterBase(object) { + } + + ~ToVarConverter() { + } +}; + +template <> +class ToVarConverter : public ToVarConverterBase { + public: + explicit ToVarConverter(const Var& object) : ToVarConverterBase(object) { + } + + ~ToVarConverter() { + } +}; + +template <> +class ToVarConverter : public ToVarConverterBase { + public: + explicit ToVarConverter(const Var& object) : ToVarConverterBase(object) { } ~ToVarConverter() { diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c index 51a27c432460..430156e8912b 100644 --- a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c +++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c @@ -46,6 +46,7 @@ #include "ppapi/c/dev/ppp_zoom_dev.h" #include "ppapi/c/extensions/dev/ppb_ext_alarms_dev.h" #include "ppapi/c/extensions/dev/ppb_ext_events_dev.h" +#include "ppapi/c/extensions/dev/ppb_ext_socket_dev.h" #include "ppapi/c/ppb_audio.h" #include "ppapi/c/ppb_audio_config.h" #include "ppapi/c/ppb_console.h" @@ -280,6 +281,7 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPP_Flash_BrowserOperations_1 static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPP_Instance_Private_0_1; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Ext_Alarms_Dev_0_1; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Ext_Events_Dev_0_1; +static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1; /* END Declarations for all Wrapper Infos. */ /* Not generating wrapper methods for PPB_Audio_1_0 */ @@ -3946,6 +3948,100 @@ void Pnacl_M27_PPB_Ext_Events_Dev_RemoveListener(PP_Instance instance, uint32_t /* End wrapper methods for PPB_Ext_Events_Dev_0_1 */ +/* Begin wrapper methods for PPB_Ext_Socket_Dev_0_1 */ + +static __attribute__((pnaclcall)) +int32_t Pnacl_M28_PPB_Ext_Socket_Dev_Create(PP_Instance instance, PP_Ext_Socket_SocketType_Dev type, PP_Ext_Socket_CreateOptions_Dev options, PP_Ext_Socket_CreateInfo_Dev* create_info, struct PP_CompletionCallback callback) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + return iface->Create(instance, type, options, create_info, callback); +} + +static __attribute__((pnaclcall)) +void Pnacl_M28_PPB_Ext_Socket_Dev_Destroy(PP_Instance instance, struct PP_Var socket_id) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + iface->Destroy(instance, socket_id); +} + +static __attribute__((pnaclcall)) +int32_t Pnacl_M28_PPB_Ext_Socket_Dev_Connect(PP_Instance instance, struct PP_Var socket_id, struct PP_Var hostname, struct PP_Var port, struct PP_Var* result, struct PP_CompletionCallback callback) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + return iface->Connect(instance, socket_id, hostname, port, result, callback); +} + +static __attribute__((pnaclcall)) +int32_t Pnacl_M28_PPB_Ext_Socket_Dev_Bind(PP_Instance instance, struct PP_Var socket_id, struct PP_Var address, struct PP_Var port, struct PP_Var* result, struct PP_CompletionCallback callback) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + return iface->Bind(instance, socket_id, address, port, result, callback); +} + +static __attribute__((pnaclcall)) +void Pnacl_M28_PPB_Ext_Socket_Dev_Disconnect(PP_Instance instance, struct PP_Var socket_id) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + iface->Disconnect(instance, socket_id); +} + +static __attribute__((pnaclcall)) +int32_t Pnacl_M28_PPB_Ext_Socket_Dev_Read(PP_Instance instance, struct PP_Var socket_id, struct PP_Var buffer_size, PP_Ext_Socket_ReadInfo_Dev* read_info, struct PP_CompletionCallback callback) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + return iface->Read(instance, socket_id, buffer_size, read_info, callback); +} + +static __attribute__((pnaclcall)) +int32_t Pnacl_M28_PPB_Ext_Socket_Dev_Write(PP_Instance instance, struct PP_Var socket_id, struct PP_Var data, PP_Ext_Socket_WriteInfo_Dev* write_info, struct PP_CompletionCallback callback) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + return iface->Write(instance, socket_id, data, write_info, callback); +} + +static __attribute__((pnaclcall)) +int32_t Pnacl_M28_PPB_Ext_Socket_Dev_RecvFrom(PP_Instance instance, struct PP_Var socket_id, struct PP_Var buffer_size, PP_Ext_Socket_RecvFromInfo_Dev* recv_from_info, struct PP_CompletionCallback callback) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + return iface->RecvFrom(instance, socket_id, buffer_size, recv_from_info, callback); +} + +static __attribute__((pnaclcall)) +int32_t Pnacl_M28_PPB_Ext_Socket_Dev_SendTo(PP_Instance instance, struct PP_Var socket_id, struct PP_Var data, struct PP_Var address, struct PP_Var port, PP_Ext_Socket_WriteInfo_Dev* write_info, struct PP_CompletionCallback callback) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + return iface->SendTo(instance, socket_id, data, address, port, write_info, callback); +} + +static __attribute__((pnaclcall)) +int32_t Pnacl_M28_PPB_Ext_Socket_Dev_Listen(PP_Instance instance, struct PP_Var socket_id, struct PP_Var address, struct PP_Var port, struct PP_Var backlog, struct PP_Var* result, struct PP_CompletionCallback callback) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + return iface->Listen(instance, socket_id, address, port, backlog, result, callback); +} + +static __attribute__((pnaclcall)) +int32_t Pnacl_M28_PPB_Ext_Socket_Dev_Accept(PP_Instance instance, struct PP_Var socket_id, PP_Ext_Socket_AcceptInfo_Dev* accept_info, struct PP_CompletionCallback callback) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + return iface->Accept(instance, socket_id, accept_info, callback); +} + +static __attribute__((pnaclcall)) +int32_t Pnacl_M28_PPB_Ext_Socket_Dev_SetKeepAlive(PP_Instance instance, struct PP_Var socket_id, struct PP_Var enable, struct PP_Var delay, struct PP_Var* result, struct PP_CompletionCallback callback) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + return iface->SetKeepAlive(instance, socket_id, enable, delay, result, callback); +} + +static __attribute__((pnaclcall)) +int32_t Pnacl_M28_PPB_Ext_Socket_Dev_SetNoDelay(PP_Instance instance, struct PP_Var socket_id, struct PP_Var no_delay, struct PP_Var* result, struct PP_CompletionCallback callback) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + return iface->SetNoDelay(instance, socket_id, no_delay, result, callback); +} + +static __attribute__((pnaclcall)) +int32_t Pnacl_M28_PPB_Ext_Socket_Dev_GetInfo(PP_Instance instance, struct PP_Var socket_id, PP_Ext_Socket_SocketInfo_Dev* result, struct PP_CompletionCallback callback) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + return iface->GetInfo(instance, socket_id, result, callback); +} + +static __attribute__((pnaclcall)) +int32_t Pnacl_M28_PPB_Ext_Socket_Dev_GetNetworkList(PP_Instance instance, PP_Ext_Socket_NetworkInterface_Dev_Array* result, struct PP_CompletionCallback callback) { + const struct PPB_Ext_Socket_Dev_0_1 *iface = Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1.real_iface; + return iface->GetNetworkList(instance, result, callback); +} + +/* End wrapper methods for PPB_Ext_Socket_Dev_0_1 */ + /* Not generating wrapper interface for PPB_Audio_1_0 */ /* Not generating wrapper interface for PPB_AudioConfig_1_0 */ @@ -4858,6 +4954,24 @@ struct PPB_Ext_Events_Dev_0_1 Pnacl_Wrappers_PPB_Ext_Events_Dev_0_1 = { .RemoveListener = (void (*)(PP_Instance instance, uint32_t listener_id))&Pnacl_M27_PPB_Ext_Events_Dev_RemoveListener }; +struct PPB_Ext_Socket_Dev_0_1 Pnacl_Wrappers_PPB_Ext_Socket_Dev_0_1 = { + .Create = (int32_t (*)(PP_Instance instance, PP_Ext_Socket_SocketType_Dev type, PP_Ext_Socket_CreateOptions_Dev options, PP_Ext_Socket_CreateInfo_Dev* create_info, struct PP_CompletionCallback callback))&Pnacl_M28_PPB_Ext_Socket_Dev_Create, + .Destroy = (void (*)(PP_Instance instance, struct PP_Var socket_id))&Pnacl_M28_PPB_Ext_Socket_Dev_Destroy, + .Connect = (int32_t (*)(PP_Instance instance, struct PP_Var socket_id, struct PP_Var hostname, struct PP_Var port, struct PP_Var* result, struct PP_CompletionCallback callback))&Pnacl_M28_PPB_Ext_Socket_Dev_Connect, + .Bind = (int32_t (*)(PP_Instance instance, struct PP_Var socket_id, struct PP_Var address, struct PP_Var port, struct PP_Var* result, struct PP_CompletionCallback callback))&Pnacl_M28_PPB_Ext_Socket_Dev_Bind, + .Disconnect = (void (*)(PP_Instance instance, struct PP_Var socket_id))&Pnacl_M28_PPB_Ext_Socket_Dev_Disconnect, + .Read = (int32_t (*)(PP_Instance instance, struct PP_Var socket_id, struct PP_Var buffer_size, PP_Ext_Socket_ReadInfo_Dev* read_info, struct PP_CompletionCallback callback))&Pnacl_M28_PPB_Ext_Socket_Dev_Read, + .Write = (int32_t (*)(PP_Instance instance, struct PP_Var socket_id, struct PP_Var data, PP_Ext_Socket_WriteInfo_Dev* write_info, struct PP_CompletionCallback callback))&Pnacl_M28_PPB_Ext_Socket_Dev_Write, + .RecvFrom = (int32_t (*)(PP_Instance instance, struct PP_Var socket_id, struct PP_Var buffer_size, PP_Ext_Socket_RecvFromInfo_Dev* recv_from_info, struct PP_CompletionCallback callback))&Pnacl_M28_PPB_Ext_Socket_Dev_RecvFrom, + .SendTo = (int32_t (*)(PP_Instance instance, struct PP_Var socket_id, struct PP_Var data, struct PP_Var address, struct PP_Var port, PP_Ext_Socket_WriteInfo_Dev* write_info, struct PP_CompletionCallback callback))&Pnacl_M28_PPB_Ext_Socket_Dev_SendTo, + .Listen = (int32_t (*)(PP_Instance instance, struct PP_Var socket_id, struct PP_Var address, struct PP_Var port, struct PP_Var backlog, struct PP_Var* result, struct PP_CompletionCallback callback))&Pnacl_M28_PPB_Ext_Socket_Dev_Listen, + .Accept = (int32_t (*)(PP_Instance instance, struct PP_Var socket_id, PP_Ext_Socket_AcceptInfo_Dev* accept_info, struct PP_CompletionCallback callback))&Pnacl_M28_PPB_Ext_Socket_Dev_Accept, + .SetKeepAlive = (int32_t (*)(PP_Instance instance, struct PP_Var socket_id, struct PP_Var enable, struct PP_Var delay, struct PP_Var* result, struct PP_CompletionCallback callback))&Pnacl_M28_PPB_Ext_Socket_Dev_SetKeepAlive, + .SetNoDelay = (int32_t (*)(PP_Instance instance, struct PP_Var socket_id, struct PP_Var no_delay, struct PP_Var* result, struct PP_CompletionCallback callback))&Pnacl_M28_PPB_Ext_Socket_Dev_SetNoDelay, + .GetInfo = (int32_t (*)(PP_Instance instance, struct PP_Var socket_id, PP_Ext_Socket_SocketInfo_Dev* result, struct PP_CompletionCallback callback))&Pnacl_M28_PPB_Ext_Socket_Dev_GetInfo, + .GetNetworkList = (int32_t (*)(PP_Instance instance, PP_Ext_Socket_NetworkInterface_Dev_Array* result, struct PP_CompletionCallback callback))&Pnacl_M28_PPB_Ext_Socket_Dev_GetNetworkList +}; + static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Audio_1_0 = { .iface_macro = PPB_AUDIO_INTERFACE_1_0, .wrapped_iface = NULL /* Still need slot for real_iface */, @@ -5734,6 +5848,12 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Ext_Events_Dev_0_1 = { .real_iface = NULL }; +static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1 = { + .iface_macro = PPB_EXT_SOCKET_DEV_INTERFACE_0_1, + .wrapped_iface = (void *) &Pnacl_Wrappers_PPB_Ext_Socket_Dev_0_1, + .real_iface = NULL +}; + static struct __PnaclWrapperInfo *s_ppb_wrappers[] = { &Pnacl_WrapperInfo_PPB_Audio_1_0, &Pnacl_WrapperInfo_PPB_AudioConfig_1_0, @@ -5858,6 +5978,7 @@ static struct __PnaclWrapperInfo *s_ppb_wrappers[] = { &Pnacl_WrapperInfo_PPB_X509Certificate_Private_0_1, &Pnacl_WrapperInfo_PPB_Ext_Alarms_Dev_0_1, &Pnacl_WrapperInfo_PPB_Ext_Events_Dev_0_1, + &Pnacl_WrapperInfo_PPB_Ext_Socket_Dev_0_1, NULL }; diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi index b8e9ef5a0685..016bcb48b377 100644 --- a/ppapi/ppapi_sources.gypi +++ b/ppapi/ppapi_sources.gypi @@ -138,6 +138,7 @@ # Extensions dev interfaces. 'c/extensions/dev/ppb_ext_alarms_dev.h', 'c/extensions/dev/ppb_ext_events_dev.h', + 'c/extensions/dev/ppb_ext_socket_dev.h', ], 'cpp_source_files': [ 'cpp/array_output.cc', @@ -342,6 +343,8 @@ 'cpp/extensions/dev/alarms_dev.h', 'cpp/extensions/dev/events_dev.cc', 'cpp/extensions/dev/events_dev.h', + 'cpp/extensions/dev/socket_dev.cc', + 'cpp/extensions/dev/socket_dev.h', # Utility sources. 'utility/completion_callback_factory.h', diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h index a48fdb70a939..9f9757e0e271 100644 --- a/ppapi/tests/all_c_includes.h +++ b/ppapi/tests/all_c_includes.h @@ -49,6 +49,7 @@ #include "ppapi/c/dev/ppp_zoom_dev.h" #include "ppapi/c/extensions/dev/ppb_ext_alarms_dev.h" #include "ppapi/c/extensions/dev/ppb_ext_events_dev.h" +#include "ppapi/c/extensions/dev/ppb_ext_socket_dev.h" #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" diff --git a/ppapi/tests/all_cpp_includes.h b/ppapi/tests/all_cpp_includes.h index 75ea7235b940..c9e0a6b081e6 100644 --- a/ppapi/tests/all_cpp_includes.h +++ b/ppapi/tests/all_cpp_includes.h @@ -37,6 +37,7 @@ #include "ppapi/cpp/dev/widget_dev.h" #include "ppapi/cpp/dev/zoom_dev.h" #include "ppapi/cpp/extensions/dev/alarms_dev.h" +#include "ppapi/cpp/extensions/dev/socket_dev.h" #include "ppapi/cpp/file_io.h" #include "ppapi/cpp/file_ref.h" #include "ppapi/cpp/file_system.h"