Restructured nsapi headers

- Provide nsapi.h as central entry point
- Provide nsapi_types.h as c-compatible destination for nsapi types
- Standardize include paths
pull/2216/head^2
Christopher Haster 2016-07-19 17:12:22 -05:00
parent 04e4d9f450
commit 97380a75c6
13 changed files with 237 additions and 134 deletions

View File

@ -17,13 +17,14 @@
#ifndef CELLULAR_INTERFACE_H
#define CELLULAR_INTERFACE_H
#include "NetworkStack.h"
#include "NetworkSocketAPI/NetworkInterface.h"
/** CellularInterface class
*
* Common interface that is shared between ethernet hardware
*/
class CellularInterface
class CellularInterface : public NetworkInterface
{
public:
/** Start the interface
@ -47,5 +48,6 @@ public:
*/
virtual const char *get_mac_address() = 0;
};
#endif

View File

@ -17,7 +17,8 @@
#ifndef ETH_INTERFACE_H
#define ETH_INTERFACE_H
#include "NetworkInterface.h"
#include "NetworkSocketAPI/NetworkInterface.h"
/** EthInterface class
*
@ -45,4 +46,5 @@ public:
virtual const char *get_mac_address() = 0;
};
#endif

View File

@ -17,7 +17,8 @@
#ifndef MESH_INTERFACE_H
#define MESH_INTERFACE_H
#include "NetworkInterface.h"
#include "NetworkSocketAPI/NetworkInterface.h"
/** MeshInterface class
*
@ -45,4 +46,5 @@ public:
virtual const char *get_mac_address() = 0;
};
#endif

View File

@ -17,8 +17,8 @@
#ifndef NETWORK_INTERFACE_H
#define NETWORK_INTERFACE_H
#include "mbed.h"
#include "SocketAddress.h"
#include "NetworkSocketAPI/NetworkStack.h"
class NetworkInterface {
public:
@ -38,4 +38,5 @@ protected:
virtual NetworkStack * get_stack(void) = 0;
};
#endif

View File

@ -17,68 +17,8 @@
#ifndef NETWORK_STACK_H
#define NETWORK_STACK_H
#include "mbed.h"
#include "SocketAddress.h"
/** Enum of standardized error codes
*
* Valid error codes have negative values and may
* be returned by any network operation.
*
* @enum nsapi_error_t
*/
enum nsapi_error_t {
NSAPI_ERROR_WOULD_BLOCK = -3001, /*!< no data is not available but call is non-blocking */
NSAPI_ERROR_UNSUPPORTED = -3002, /*!< unsupported functionality */
NSAPI_ERROR_PARAMETER = -3003, /*!< invalid configuration */
NSAPI_ERROR_NO_CONNECTION = -3004, /*!< not connected to a network */
NSAPI_ERROR_NO_SOCKET = -3005, /*!< socket not available for use */
NSAPI_ERROR_NO_ADDRESS = -3006, /*!< IP address is not known */
NSAPI_ERROR_NO_MEMORY = -3007, /*!< memory resource not available */
NSAPI_ERROR_DNS_FAILURE = -3008, /*!< DNS failed to complete successfully */
NSAPI_ERROR_DHCP_FAILURE = -3009, /*!< DHCP failed to complete successfully */
NSAPI_ERROR_AUTH_FAILURE = -3010, /*!< connection to access point faield */
NSAPI_ERROR_DEVICE_ERROR = -3011, /*!< failure interfacing with the network procesor */
};
/** Enum of socket protocols
*
* The socket protocol specifies a particular protocol to
* be used with a newly created socket.
*
* @enum nsapi_protocol_t
*/
enum nsapi_protocol_t {
NSAPI_TCP, /*!< Socket is of TCP type */
NSAPI_UDP, /*!< Socket is of UDP type */
};
/* Enum of standardized stack option levels
*
* @enum nsapi_level_t
*/
enum nsapi_level_t {
NSAPI_STACK, /*!< Stack option level */
NSAPI_SOCKET, /*!< Socket option level */
};
/* Enum of standardized stack options
*
* These options may not be supported on all stacks, in which
* case NSAPI_ERROR_UNSUPPORTED may be returned from setsockopt.
*
* @enum nsapi_option_t
*/
enum nsapi_option_t {
NSAPI_REUSEADDR, /*!< Allow bind to reuse local addresses */
NSAPI_KEEPALIVE, /*!< Enables sending of keepalive messages */
NSAPI_KEEPIDLE, /*!< Sets timeout value to initiate keepalive */
NSAPI_KEEPINTVL, /*!< Sets timeout value for keepalive */
NSAPI_LINGER, /*!< Keeps close from returning until queues empty */
NSAPI_SNDBUF, /*!< Sets send buffer size */
NSAPI_RCVBUF, /*!< Sets recv buffer size */
};
#include "nsapi_types.h"
#include "NetworkSocketAPI/SocketAddress.h"
/** NetworkStack class
@ -337,4 +277,5 @@ protected:
virtual int getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen);
};
#endif

View File

@ -17,9 +17,15 @@
#ifndef SOCKET_H
#define SOCKET_H
#include "SocketAddress.h"
#include "NetworkStack.h"
#include "Mutex.h"
#include "NetworkSocketAPI/SocketAddress.h"
#include "NetworkSocketAPI/NetworkStack.h"
#include "rtos/Mutex.h"
#include "Callback.h"
#ifndef NSAPI_NO_INCLUDE_MBED
#include "mbed.h" // needed for backwards compatability
#endif
/** Abstract socket class
*/
@ -147,7 +153,7 @@ public:
*
* @param func Function to call on state change
*/
void attach(Callback<void()> func);
void attach(mbed::Callback<void()> func);
/** Register a callback on state change of the socket
*
@ -163,7 +169,7 @@ public:
*/
template <typename T, typename M>
void attach(T *obj, M method) {
attach(Callback<void()>(obj, method));
attach(mbed::Callback<void()>(obj, method));
}
protected:
@ -174,9 +180,10 @@ protected:
NetworkStack *_iface;
void *_socket;
uint32_t _timeout;
Callback<void()> _event;
Callback<void()> _callback;
mbed::Callback<void()> _event;
mbed::Callback<void()> _callback;
rtos::Mutex _lock;
};
#endif

View File

@ -17,51 +17,7 @@
#ifndef SOCKET_ADDRESS_H
#define SOCKET_ADDRESS_H
#include <stdint.h>
/** Maximum size of IP address representation
*/
#define NSAPI_IP_SIZE NSAPI_IPv6_SIZE
/** Maximum number of bytes for IP address
*/
#define NSAPI_IP_BYTES NSAPI_IPv6_BYTES
/** Maximum size of MAC address representation
*/
#define NSAPI_MAC_SIZE 18
/** Maximum number of bytes for MAC address
*/
#define NSAPI_MAC_BYTES 6
/** Enum of IP address versions
*
* The IP version specifies the type of an IP address.
*
* @enum nsapi_version_t
*/
enum nsapi_version_t {
NSAPI_IPv4, /*!< Address is IPv4 */
NSAPI_IPv6, /*!< Address is IPv6 */
};
/** Size of IPv4 representation
*/
#define NSAPI_IPv4_SIZE 16
/** Number of bytes in IPv4 address
*/
#define NSAPI_IPv4_BYTES 4
/** Size of IPv6 representation
*/
#define NSAPI_IPv6_SIZE 40
/** Number of bytes in IPv6 address
*/
#define NSAPI_IPv6_BYTES 16
#include "nsapi_types.h"
// Predeclared classes
class NetworkStack;
@ -178,4 +134,5 @@ private:
uint16_t _port;
};
#endif

View File

@ -17,11 +17,12 @@
#ifndef TCPSERVER_H
#define TCPSERVER_H
#include "Socket.h"
#include "TCPSocket.h"
#include "NetworkInterface.h"
#include "NetworkStack.h"
#include "Semaphore.h"
#include "NetworkSocketAPI/Socket.h"
#include "NetworkSocketAPI/TCPSocket.h"
#include "NetworkSocketAPI/NetworkStack.h"
#include "NetworkSocketAPI/NetworkInterface.h"
#include "rtos/Semaphore.h"
/** TCP socket server
*/
@ -108,4 +109,5 @@ protected:
rtos::Semaphore _accept_sem;
};
#endif

View File

@ -17,10 +17,11 @@
#ifndef TCPSOCKET_H
#define TCPSOCKET_H
#include "Socket.h"
#include "NetworkInterface.h"
#include "NetworkStack.h"
#include "Semaphore.h"
#include "NetworkSocketAPI/Socket.h"
#include "NetworkSocketAPI/NetworkStack.h"
#include "NetworkSocketAPI/NetworkInterface.h"
#include "rtos/Semaphore.h"
/** TCP socket connection
*/
@ -139,4 +140,5 @@ protected:
friend class TCPServer;
};
#endif

View File

@ -17,10 +17,11 @@
#ifndef UDPSOCKET_H
#define UDPSOCKET_H
#include "Socket.h"
#include "NetworkInterface.h"
#include "NetworkStack.h"
#include "Semaphore.h"
#include "NetworkSocketAPI/Socket.h"
#include "NetworkSocketAPI/NetworkStack.h"
#include "NetworkSocketAPI/NetworkInterface.h"
#include "rtos/Semaphore.h"
/** UDP socket
*/
@ -137,4 +138,5 @@ protected:
bool _write_in_progress;
};
#endif

View File

@ -17,7 +17,8 @@
#ifndef WIFI_INTERFACE_H
#define WIFI_INTERFACE_H
#include "NetworkInterface.h"
#include "NetworkSocketAPI/NetworkInterface.h"
/** Enum of WiFi encryption types
*
@ -65,4 +66,5 @@ public:
virtual const char *get_mac_address() = 0;
};
#endif

47
nsapi.h Normal file
View File

@ -0,0 +1,47 @@
/* nsapi.h - The network socket API
* Copyright (c) 2015 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NSAPI_H
#define NSAPI_H
// entry point for nsapi types
#include "nsapi_types.h"
// disable bug-compatible mbed inclusion
#define NSAPI_NO_INCLUDE_MBED
#ifdef __cplusplus
// entry point for C++ api
#include "NetworkSocketAPI/SocketAddress.h"
#include "NetworkSocketAPI/NetworkStack.h"
#include "NetworkSocketAPI/NetworkInterface.h"
#include "NetworkSocketAPI/EthInterface.h"
#include "NetworkSocketAPI/WiFiInterface.h"
#include "NetworkSocketAPI/CellularInterface.h"
#include "NetworkSocketAPI/MeshInterface.h"
#include "NetworkSocketAPI/Socket.h"
#include "NetworkSocketAPI/UDPSocket.h"
#include "NetworkSocketAPI/TCPSocket.h"
#include "NetworkSocketAPI/TCPServer.h"
#endif
#endif

136
nsapi_types.h Normal file
View File

@ -0,0 +1,136 @@
/* nsapi.h - The network socket API
* Copyright (c) 2015 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NSAPI_TYPES_H
#define NSAPI_TYPES_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Enum of standardized error codes
*
* Valid error codes have negative values and may
* be returned by any network operation.
*
* @enum nsapi_error_t
*/
typedef enum nsapi_error {
NSAPI_ERROR_WOULD_BLOCK = -3001, /*!< no data is not available but call is non-blocking */
NSAPI_ERROR_UNSUPPORTED = -3002, /*!< unsupported functionality */
NSAPI_ERROR_PARAMETER = -3003, /*!< invalid configuration */
NSAPI_ERROR_NO_CONNECTION = -3004, /*!< not connected to a network */
NSAPI_ERROR_NO_SOCKET = -3005, /*!< socket not available for use */
NSAPI_ERROR_NO_ADDRESS = -3006, /*!< IP address is not known */
NSAPI_ERROR_NO_MEMORY = -3007, /*!< memory resource not available */
NSAPI_ERROR_DNS_FAILURE = -3008, /*!< DNS failed to complete successfully */
NSAPI_ERROR_DHCP_FAILURE = -3009, /*!< DHCP failed to complete successfully */
NSAPI_ERROR_AUTH_FAILURE = -3010, /*!< connection to access point faield */
NSAPI_ERROR_DEVICE_ERROR = -3011, /*!< failure interfacing with the network procesor */
} nsapi_error_t;
/** Maximum size of IP address representation
*/
#define NSAPI_IP_SIZE NSAPI_IPv6_SIZE
/** Maximum number of bytes for IP address
*/
#define NSAPI_IP_BYTES NSAPI_IPv6_BYTES
/** Maximum size of MAC address representation
*/
#define NSAPI_MAC_SIZE 18
/** Maximum number of bytes for MAC address
*/
#define NSAPI_MAC_BYTES 6
/** Size of IPv4 representation
*/
#define NSAPI_IPv4_SIZE 16
/** Number of bytes in IPv4 address
*/
#define NSAPI_IPv4_BYTES 4
/** Size of IPv6 representation
*/
#define NSAPI_IPv6_SIZE 40
/** Number of bytes in IPv6 address
*/
#define NSAPI_IPv6_BYTES 16
/** Enum of IP address versions
*
* The IP version specifies the type of an IP address.
*
* @enum nsapi_version_t
*/
typedef enum nsapi_version {
NSAPI_IPv4, /*!< Address is IPv4 */
NSAPI_IPv6, /*!< Address is IPv6 */
} nsapi_version_t;
/** Enum of socket protocols
*
* The socket protocol specifies a particular protocol to
* be used with a newly created socket.
*
* @enum nsapi_protocol_t
*/
typedef enum nsapi_protocol {
NSAPI_TCP, /*!< Socket is of TCP type */
NSAPI_UDP, /*!< Socket is of UDP type */
} nsapi_protocol_t;
/* Enum of standardized stack option levels
*
* @enum nsapi_level_t
*/
typedef enum nsapi_level {
NSAPI_STACK, /*!< Stack option level */
NSAPI_SOCKET, /*!< Socket option level */
} nsapi_level_t;
/* Enum of standardized stack options
*
* These options may not be supported on all stacks, in which
* case NSAPI_ERROR_UNSUPPORTED may be returned from setsockopt.
*
* @enum nsapi_option_t
*/
typedef enum nsapi_option {
NSAPI_REUSEADDR, /*!< Allow bind to reuse local addresses */
NSAPI_KEEPALIVE, /*!< Enables sending of keepalive messages */
NSAPI_KEEPIDLE, /*!< Sets timeout value to initiate keepalive */
NSAPI_KEEPINTVL, /*!< Sets timeout value for keepalive */
NSAPI_LINGER, /*!< Keeps close from returning until queues empty */
NSAPI_SNDBUF, /*!< Sets send buffer size */
NSAPI_RCVBUF, /*!< Sets recv buffer size */
} nsapi_option_t;
#ifdef __cplusplus
}
#endif
#endif