Separate Stack/Interface concept into two distinct classes

Christopher Haster 2016-04-20 14:39:13 -05:00 committed by Russ Butler
parent 49ba2be3a7
commit d17fa4faad
9 changed files with 50 additions and 32 deletions

View File

@ -17,7 +17,7 @@
#ifndef ESP8266_INTERFACE_H
#define ESP8266_INTERFACE_H
#include "WiFiStack.h"
#include "WiFiInterface.h"
#include "ESP8266.h"
#define ESP8266_SOCKET_COUNT 5
@ -25,7 +25,7 @@
/** ESP8266Interface class
* Implementation of the NetworkStack for the ESP8266
*/
class ESP8266Interface : public WiFiStack
class ESP8266Interface : public NetworkStack, public WiFiInterface
{
public:
/** ESP8266Interface lifetime

View File

@ -17,7 +17,7 @@
#ifndef LWIP_INTERFACE_H
#define LWIP_INTERFACE_H
#include "EthernetStack.h"
#include "EthernetInterface.h"
#include "rtos.h"
#include "lwip/netif.h"
@ -25,7 +25,7 @@
/** LWIPInterface class
* Implementation of the NetworkStack for LWIP
*/
class LWIPInterface : public EthernetStack
class LWIPInterface : public NetworkStack, public EthernetInterface
{
public:
/** Start the interface

View File

@ -1,4 +1,4 @@
/* CellularStack
/* CellularInterface
* Copyright (c) 2015 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -19,11 +19,11 @@
#include "NetworkStack.h"
/** CellularStack class
/** CellularInterface class
*
* Common interface that is shared between ethernet hardware
*/
class CellularStack : public NetworkStack
class CellularInterface
{
public:
/** Start the interface
@ -40,6 +40,12 @@ public:
* @return 0 on success, negative error code on failure
*/
virtual int disconnect() = 0;
/** Get the local MAC address
*
* @return Null-terminated representation of the local MAC address
*/
virtual const char *get_mac_address() = 0;
};
#endif

View File

@ -1,4 +1,4 @@
/* EthernetStack
/* EthernetInterface
* Copyright (c) 2015 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -19,11 +19,11 @@
#include "NetworkStack.h"
/** EthernetStack class
/** EthernetInterface class
*
* Common interface that is shared between ethernet hardware.
*/
class EthernetStack : public NetworkStack
class EthernetInterface
{
public:
/** Start the interface
@ -37,6 +37,12 @@ public:
* @return 0 on success, negative error code on failure
*/
virtual int disconnect() = 0;
/** Get the local MAC address
*
* @return Null-terminated representation of the local MAC address
*/
virtual const char *get_mac_address() = 0;
};
#endif

View File

@ -1,4 +1,4 @@
/* MeshStack
/* MeshInterface
* Copyright (c) 2015 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -19,11 +19,11 @@
#include "NetworkStack.h"
/** MeshStack class
/** MeshInterface class
*
* Common interface that is shared between mesh hardware
*/
class MeshStack : public NetworkStack
class MeshInterface
{
public:
/** Start the interface
@ -37,6 +37,12 @@ public:
* @return 0 on success, negative on failure
*/
virtual int disconnect() = 0;
/** Get the local MAC address
*
* @return Null-terminated representation of the local MAC address
*/
virtual const char *get_mac_address() = 0;
};
#endif

View File

@ -77,14 +77,6 @@ enum nsapi_option_t {
NSAPI_RCVBUF, /*!< Sets recv buffer size */
};
/** Maximum size of MAC address representation
*/
#define NSAPI_MAC_SIZE 18
/** Maximum number of bytes for MAC address
*/
#define NSAPI_MAC_BYTES 6
/** NetworkStack class
*
@ -105,12 +97,6 @@ public:
*/
virtual const char *get_ip_address() = 0;
/** Get the local MAC address
*
* @return Null-terminated representation of the local MAC address
*/
virtual const char *get_mac_address() = 0;
/** Translates a hostname to an IP address
*
* The hostname may be either a domain name or an IP address. If the

View File

@ -52,9 +52,9 @@ int Socket::close()
if (!_socket) {
return 0;
}
_iface->socket_attach(_socket, 0, 0);
void *volatile socket = _socket;
_socket = 0;
return _iface->socket_close(socket);

View File

@ -28,6 +28,14 @@
*/
#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.

View File

@ -1,4 +1,4 @@
/* WiFiStack
/* WiFiInterface
* Copyright (c) 2015 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -33,11 +33,11 @@ enum nsapi_security_t {
NSAPI_SECURITY_WPA2, /*!< phrase conforms to WPA2 */
};
/** WiFiStack class
/** WiFiInterface class
*
* Common interface that is shared between WiFi devices
*/
class WiFiStack : public NetworkStack
class WiFiInterface
{
public:
/** Start the interface
@ -57,6 +57,12 @@ public:
* @return 0 on success, negative error code on failure
*/
virtual int disconnect() = 0;
/** Get the local MAC address
*
* @return Null-terminated representation of the local MAC address
*/
virtual const char *get_mac_address() = 0;
};
#endif