mirror of https://github.com/ARMmbed/mbed-os.git
nsapi - Adopted standardized return types in the Nanostack interfaces
parent
b045c8ba00
commit
00458c391c
|
@ -110,7 +110,7 @@ private:
|
|||
|
||||
static NanostackSocket * socket_tbl[NS_INTERFACE_SOCKETS_MAX];
|
||||
|
||||
static int map_mesh_error(mesh_error_t err)
|
||||
static nsapi_error_t map_mesh_error(mesh_error_t err)
|
||||
{
|
||||
switch (err) {
|
||||
case MESH_ERROR_NONE: return 0;
|
||||
|
@ -167,7 +167,7 @@ NanostackSocket::~NanostackSocket()
|
|||
close();
|
||||
}
|
||||
if (socket_id >= 0) {
|
||||
int ret = socket_free(socket_id);
|
||||
nsapi_error_t ret = socket_free(socket_id);
|
||||
MBED_ASSERT(0 == ret);
|
||||
MBED_ASSERT(socket_tbl[socket_id] == this);
|
||||
socket_tbl[socket_id] = NULL;
|
||||
|
@ -209,7 +209,7 @@ void NanostackSocket::close()
|
|||
MBED_ASSERT(mode != SOCKET_MODE_CLOSED);
|
||||
|
||||
if (socket_id >= 0) {
|
||||
int ret = socket_close(socket_id, (addr_valid ? &ns_address : NULL));
|
||||
nsapi_error_t ret = socket_close(socket_id, (addr_valid ? &ns_address : NULL));
|
||||
MBED_ASSERT(0 == ret);
|
||||
} else {
|
||||
MBED_ASSERT(SOCKET_MODE_UNOPENED == mode);
|
||||
|
@ -466,7 +466,7 @@ MeshInterfaceNanostack::MeshInterfaceNanostack(NanostackRfPhy *phy)
|
|||
// Nothing to do
|
||||
}
|
||||
|
||||
int MeshInterfaceNanostack::initialize(NanostackRfPhy *phy)
|
||||
nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy)
|
||||
{
|
||||
if (this->phy != NULL) {
|
||||
error("Phy already set");
|
||||
|
@ -486,7 +486,7 @@ void MeshInterfaceNanostack::mesh_network_handler(mesh_connection_status_t statu
|
|||
nanostack_unlock();
|
||||
}
|
||||
|
||||
int MeshInterfaceNanostack::register_rf()
|
||||
nsapi_error_t MeshInterfaceNanostack::register_rf()
|
||||
{
|
||||
nanostack_lock();
|
||||
|
||||
|
@ -504,7 +504,7 @@ int MeshInterfaceNanostack::register_rf()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int MeshInterfaceNanostack::actual_connect()
|
||||
nsapi_error_t MeshInterfaceNanostack::actual_connect()
|
||||
{
|
||||
nanostack_assert_locked();
|
||||
|
||||
|
@ -532,7 +532,7 @@ NetworkStack * MeshInterfaceNanostack::get_stack()
|
|||
return NanostackInterface::get_stack();
|
||||
}
|
||||
|
||||
int MeshInterfaceNanostack::disconnect()
|
||||
nsapi_error_t MeshInterfaceNanostack::disconnect()
|
||||
{
|
||||
nanostack_lock();
|
||||
|
||||
|
@ -562,7 +562,7 @@ const char *MeshInterfaceNanostack::get_mac_address()
|
|||
return mac_addr_str;
|
||||
}
|
||||
|
||||
int ThreadInterface::connect()
|
||||
nsapi_error_t ThreadInterface::connect()
|
||||
{
|
||||
// initialize mesh networking resources, memory, timers, etc...
|
||||
mesh_system_init();
|
||||
|
@ -586,14 +586,14 @@ int ThreadInterface::connect()
|
|||
nanostack_unlock();
|
||||
return map_mesh_error(status);
|
||||
}
|
||||
int ret = this->actual_connect();
|
||||
nsapi_error_t ret = this->actual_connect();
|
||||
|
||||
nanostack_unlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LoWPANNDInterface::connect()
|
||||
nsapi_error_t LoWPANNDInterface::connect()
|
||||
{
|
||||
// initialize mesh networking resources, memory, timers, etc...
|
||||
mesh_system_init();
|
||||
|
@ -617,7 +617,7 @@ int LoWPANNDInterface::connect()
|
|||
nanostack_unlock();
|
||||
return map_mesh_error(status);
|
||||
}
|
||||
int ret = this->actual_connect();
|
||||
nsapi_error_t ret = this->actual_connect();
|
||||
|
||||
nanostack_unlock();
|
||||
|
||||
|
@ -646,7 +646,7 @@ const char * NanostackInterface::get_ip_address()
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int NanostackInterface::socket_open(void **handle, nsapi_protocol_t protocol)
|
||||
nsapi_error_t NanostackInterface::socket_open(void **handle, nsapi_protocol_t protocol)
|
||||
{
|
||||
// Validate parameters
|
||||
if (NULL == handle) {
|
||||
|
@ -687,7 +687,7 @@ int NanostackInterface::socket_open(void **handle, nsapi_protocol_t protocol)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int NanostackInterface::socket_close(void *handle)
|
||||
nsapi_error_t NanostackInterface::socket_close(void *handle)
|
||||
{
|
||||
// Validate parameters
|
||||
NanostackSocket * socket = static_cast<NanostackSocket *>(handle);
|
||||
|
@ -707,7 +707,7 @@ int NanostackInterface::socket_close(void *handle)
|
|||
|
||||
}
|
||||
|
||||
int NanostackInterface::socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned int size)
|
||||
nsapi_size_or_error_t NanostackInterface::socket_sendto(void *handle, const SocketAddress &address, const void *data, nsapi_size_t size)
|
||||
{
|
||||
// Validate parameters
|
||||
NanostackSocket * socket = static_cast<NanostackSocket *>(handle);
|
||||
|
@ -718,7 +718,7 @@ int NanostackInterface::socket_sendto(void *handle, const SocketAddress &address
|
|||
|
||||
nanostack_lock();
|
||||
|
||||
int ret;
|
||||
nsapi_size_or_error_t ret;
|
||||
if (socket->closed()) {
|
||||
ret = NSAPI_ERROR_NO_CONNECTION;
|
||||
} else if (NANOSTACK_SOCKET_TCP == socket->proto) {
|
||||
|
@ -758,7 +758,7 @@ int NanostackInterface::socket_sendto(void *handle, const SocketAddress &address
|
|||
return ret;
|
||||
}
|
||||
|
||||
int NanostackInterface::socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size)
|
||||
nsapi_size_or_error_t NanostackInterface::socket_recvfrom(void *handle, SocketAddress *address, void *buffer, nsapi_size_t size)
|
||||
{
|
||||
// Validate parameters
|
||||
NanostackSocket * socket = static_cast<NanostackSocket *>(handle);
|
||||
|
@ -777,7 +777,7 @@ int NanostackInterface::socket_recvfrom(void *handle, SocketAddress *address, vo
|
|||
|
||||
nanostack_lock();
|
||||
|
||||
int ret;
|
||||
nsapi_size_or_error_t ret;
|
||||
if (socket->closed()) {
|
||||
ret = NSAPI_ERROR_NO_CONNECTION;
|
||||
} else if (NANOSTACK_SOCKET_TCP == socket->proto) {
|
||||
|
@ -796,7 +796,7 @@ int NanostackInterface::socket_recvfrom(void *handle, SocketAddress *address, vo
|
|||
return ret;
|
||||
}
|
||||
|
||||
int NanostackInterface::socket_bind(void *handle, const SocketAddress &address)
|
||||
nsapi_error_t NanostackInterface::socket_bind(void *handle, const SocketAddress &address)
|
||||
{
|
||||
// Validate parameters
|
||||
NanostackSocket * socket = static_cast<NanostackSocket *>(handle);
|
||||
|
@ -812,7 +812,7 @@ int NanostackInterface::socket_bind(void *handle, const SocketAddress &address)
|
|||
ns_address.type = ADDRESS_IPV6;
|
||||
memset(ns_address.address, 0, sizeof ns_address.address);
|
||||
ns_address.identifier = address.get_port();
|
||||
int ret = NSAPI_ERROR_DEVICE_ERROR;
|
||||
nsapi_error_t ret = NSAPI_ERROR_DEVICE_ERROR;
|
||||
if (0 == ::socket_bind(socket->socket_id, &ns_address)) {
|
||||
socket->set_bound();
|
||||
ret = 0;
|
||||
|
@ -825,22 +825,22 @@ int NanostackInterface::socket_bind(void *handle, const SocketAddress &address)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int NanostackInterface::setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen)
|
||||
nsapi_error_t NanostackInterface::setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen)
|
||||
{
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int NanostackInterface::getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen)
|
||||
nsapi_error_t NanostackInterface::getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen)
|
||||
{
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int NanostackInterface::socket_listen(void *handle, int backlog)
|
||||
nsapi_error_t NanostackInterface::socket_listen(void *handle, int backlog)
|
||||
{
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int NanostackInterface::socket_connect(void *handle, const SocketAddress &addr)
|
||||
nsapi_error_t NanostackInterface::socket_connect(void *handle, const SocketAddress &addr)
|
||||
{
|
||||
// Validate parameters
|
||||
NanostackSocket * socket = static_cast<NanostackSocket *>(handle);
|
||||
|
@ -851,7 +851,7 @@ int NanostackInterface::socket_connect(void *handle, const SocketAddress &addr)
|
|||
|
||||
nanostack_lock();
|
||||
|
||||
int ret;
|
||||
nsapi_error_t ret;
|
||||
ns_address_t ns_addr;
|
||||
int random_port = socket->is_bound() ? 0 : 1;
|
||||
convert_mbed_addr_to_ns(&ns_addr, &addr);
|
||||
|
@ -869,12 +869,12 @@ int NanostackInterface::socket_connect(void *handle, const SocketAddress &addr)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int NanostackInterface::socket_accept(void *server, void **handle, SocketAddress *address)
|
||||
nsapi_error_t NanostackInterface::socket_accept(void *server, void **handle, SocketAddress *address)
|
||||
{
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int NanostackInterface::socket_send(void *handle, const void *p, unsigned size)
|
||||
nsapi_size_or_error_t NanostackInterface::socket_send(void *handle, const void *p, nsapi_size_t size)
|
||||
{
|
||||
// Validate parameters
|
||||
NanostackSocket * socket = static_cast<NanostackSocket *>(handle);
|
||||
|
@ -885,7 +885,7 @@ int NanostackInterface::socket_send(void *handle, const void *p, unsigned size)
|
|||
|
||||
nanostack_lock();
|
||||
|
||||
int ret;
|
||||
nsapi_size_or_error_t ret;
|
||||
if (socket->closed()) {
|
||||
ret = NSAPI_ERROR_NO_CONNECTION;
|
||||
} else if (socket->is_connecting()) {
|
||||
|
@ -918,7 +918,7 @@ int NanostackInterface::socket_send(void *handle, const void *p, unsigned size)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int NanostackInterface::socket_recv(void *handle, void *data, unsigned size)
|
||||
nsapi_size_or_error_t NanostackInterface::socket_recv(void *handle, void *data, nsapi_size_t size)
|
||||
{
|
||||
// Validate parameters
|
||||
NanostackSocket * socket = static_cast<NanostackSocket *>(handle);
|
||||
|
@ -929,7 +929,7 @@ int NanostackInterface::socket_recv(void *handle, void *data, unsigned size)
|
|||
|
||||
nanostack_lock();
|
||||
|
||||
int ret;
|
||||
nsapi_size_or_error_t ret;
|
||||
if (socket->closed()) {
|
||||
ret = NSAPI_ERROR_NO_CONNECTION;
|
||||
} else if (socket->data_available()) {
|
||||
|
|
|
@ -37,7 +37,7 @@ protected:
|
|||
* @param proto Protocol of socket to open, NSAPI_TCP or NSAPI_UDP
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int socket_open(void **handle, nsapi_protocol_t proto);
|
||||
virtual nsapi_error_t socket_open(void **handle, nsapi_protocol_t proto);
|
||||
|
||||
/** Close the socket
|
||||
*
|
||||
|
@ -47,7 +47,7 @@ protected:
|
|||
* @param handle Socket handle
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int socket_close(void *handle);
|
||||
virtual nsapi_error_t socket_close(void *handle);
|
||||
|
||||
/** Bind a specific address to a socket
|
||||
*
|
||||
|
@ -58,7 +58,7 @@ protected:
|
|||
* @param address Local address to bind
|
||||
* @return 0 on success, negative error code on failure.
|
||||
*/
|
||||
virtual int socket_bind(void *handle, const SocketAddress &address);
|
||||
virtual nsapi_error_t socket_bind(void *handle, const SocketAddress &address);
|
||||
|
||||
/** Listen for connections on a TCP socket
|
||||
*
|
||||
|
@ -70,7 +70,7 @@ protected:
|
|||
* simultaneously
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int socket_listen(void *handle, int backlog);
|
||||
virtual nsapi_error_t socket_listen(void *handle, int backlog);
|
||||
|
||||
/** Connects TCP socket to a remote host
|
||||
*
|
||||
|
@ -81,7 +81,7 @@ protected:
|
|||
* @param address The SocketAddress of the remote host
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int socket_connect(void *handle, const SocketAddress &address);
|
||||
virtual nsapi_error_t socket_connect(void *handle, const SocketAddress &address);
|
||||
|
||||
/** Accepts a connection on a TCP socket
|
||||
*
|
||||
|
@ -101,7 +101,7 @@ protected:
|
|||
* @param address Destination for the remote address or NULL
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int socket_accept(void *handle, void **server, SocketAddress *address);
|
||||
virtual nsapi_error_t socket_accept(void *handle, void **server, SocketAddress *address);
|
||||
|
||||
/** Send data over a TCP socket
|
||||
*
|
||||
|
@ -117,7 +117,7 @@ protected:
|
|||
* @return Number of sent bytes on success, negative error
|
||||
* code on failure
|
||||
*/
|
||||
virtual int socket_send(void *handle, const void *data, unsigned size);
|
||||
virtual nsapi_size_or_error_t socket_send(void *handle, const void *data, nsapi_size_t size);
|
||||
|
||||
/** Receive data over a TCP socket
|
||||
*
|
||||
|
@ -133,7 +133,7 @@ protected:
|
|||
* @return Number of received bytes on success, negative error
|
||||
* code on failure
|
||||
*/
|
||||
virtual int socket_recv(void *handle, void *data, unsigned size);
|
||||
virtual nsapi_size_or_error_t socket_recv(void *handle, void *data, nsapi_size_t size);
|
||||
|
||||
/** Send a packet over a UDP socket
|
||||
*
|
||||
|
@ -150,7 +150,7 @@ protected:
|
|||
* @return Number of sent bytes on success, negative error
|
||||
* code on failure
|
||||
*/
|
||||
virtual int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size);
|
||||
virtual nsapi_size_or_error_t socket_sendto(void *handle, const SocketAddress &address, const void *data, nsapi_size_t size);
|
||||
|
||||
/** Receive a packet over a UDP socket
|
||||
*
|
||||
|
@ -167,7 +167,7 @@ protected:
|
|||
* @return Number of received bytes on success, negative error
|
||||
* code on failure
|
||||
*/
|
||||
virtual int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size);
|
||||
virtual nsapi_size_or_error_t socket_recvfrom(void *handle, SocketAddress *address, void *buffer, nsapi_size_t size);
|
||||
|
||||
/** Register a callback on state change of the socket
|
||||
*
|
||||
|
@ -197,7 +197,7 @@ protected:
|
|||
* @param optlen Length of the option value
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen);
|
||||
virtual nsapi_error_t setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen);
|
||||
|
||||
/* Get stack-specific socket options
|
||||
*
|
||||
|
@ -212,7 +212,7 @@ protected:
|
|||
* @param optlen Length of the option value
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen);
|
||||
virtual nsapi_error_t getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen);
|
||||
|
||||
private:
|
||||
static NanostackInterface * _ns_interface;
|
||||
|
@ -228,19 +228,19 @@ public:
|
|||
*
|
||||
* @return 0 on success, negative on failure
|
||||
*/
|
||||
virtual int initialize(NanostackRfPhy *phy);
|
||||
virtual nsapi_error_t initialize(NanostackRfPhy *phy);
|
||||
|
||||
/** Start the interface
|
||||
*
|
||||
* @return 0 on success, negative on failure
|
||||
*/
|
||||
virtual int connect() = 0;
|
||||
virtual nsapi_error_t connect() = 0;
|
||||
|
||||
/** Stop the interface
|
||||
*
|
||||
* @return 0 on success, negative on failure
|
||||
*/
|
||||
virtual int disconnect();
|
||||
virtual nsapi_error_t disconnect();
|
||||
|
||||
/** Get the internally stored IP address
|
||||
/return IP address of the interface or null if not yet connected
|
||||
|
@ -255,8 +255,8 @@ public:
|
|||
protected:
|
||||
MeshInterfaceNanostack();
|
||||
MeshInterfaceNanostack(NanostackRfPhy *phy);
|
||||
int register_rf();
|
||||
int actual_connect();
|
||||
nsapi_error_t register_rf();
|
||||
nsapi_error_t actual_connect();
|
||||
virtual NetworkStack * get_stack(void);
|
||||
|
||||
void mesh_network_handler(mesh_connection_status_t status);
|
||||
|
@ -287,7 +287,7 @@ public:
|
|||
|
||||
}
|
||||
|
||||
int connect();
|
||||
nsapi_error_t connect();
|
||||
protected:
|
||||
Mesh6LoWPAN_ND *get_mesh_api() const { return static_cast<Mesh6LoWPAN_ND *>(mesh_api); }
|
||||
private:
|
||||
|
@ -312,7 +312,7 @@ public:
|
|||
|
||||
}
|
||||
|
||||
int connect();
|
||||
nsapi_error_t connect();
|
||||
protected:
|
||||
MeshThread *get_mesh_api() const { return static_cast<MeshThread *>(mesh_api); }
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue