C++11-ify virtualisation in Nanostack classes

Use `override` and `final` where appropriate, and eliminate unnecessary
`virtual`.

Some other C++11 simplifications.

Eliminate two unused header files (with no corresponding source files).

Reduces code size.
pull/12488/head
Kevin Bracey 2020-02-21 13:49:26 +02:00
parent 8f1bf967d3
commit 04580b73d8
21 changed files with 134 additions and 231 deletions

View File

@ -23,24 +23,15 @@
* *
* Configure Nanostack to use 6LoWPAN-ND protocol. * Configure Nanostack to use 6LoWPAN-ND protocol.
*/ */
class LoWPANNDInterface : public MeshInterfaceNanostack { class LoWPANNDInterface final : public MeshInterfaceNanostack {
public: public:
/** Inherit MeshInterfaceNanostack constructors */
/** Create an uninitialized LoWPANNDInterface using MeshInterfaceNanostack::MeshInterfaceNanostack;
*
* Must initialize to initialize the mesh on a phy.
*/
LoWPANNDInterface() { }
/** Create an initialized LoWPANNDInterface
*
*/
LoWPANNDInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
bool getRouterIpAddress(char *address, int8_t len); bool getRouterIpAddress(char *address, int8_t len);
protected: protected:
Nanostack::LoWPANNDInterface *get_interface() const; Nanostack::LoWPANNDInterface *get_interface() const;
virtual nsapi_error_t do_initialize(); nsapi_error_t do_initialize() override;
}; };
#endif #endif

View File

@ -25,12 +25,12 @@
class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed::NonCopyable<Nanostack::Interface> { class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed::NonCopyable<Nanostack::Interface> {
public: public:
virtual nsapi_error_t get_ip_address(SocketAddress *address); nsapi_error_t get_ip_address(SocketAddress *address) final;
virtual char *get_mac_address(char *buf, nsapi_size_t buflen); char *get_mac_address(char *buf, nsapi_size_t buflen) final;
virtual nsapi_error_t get_netmask(SocketAddress *address); nsapi_error_t get_netmask(SocketAddress *address) final;
virtual nsapi_error_t get_gateway(SocketAddress *address); nsapi_error_t get_gateway(SocketAddress *address) override;
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) final;
virtual nsapi_connection_status_t get_connection_status() const; nsapi_connection_status_t get_connection_status() const final;
void get_mac_address(uint8_t *buf) const void get_mac_address(uint8_t *buf) const
{ {
@ -59,20 +59,20 @@ private:
NanostackPhy &interface_phy; NanostackPhy &interface_phy;
protected: protected:
Interface(NanostackPhy &phy); Interface(NanostackPhy &phy);
virtual nsapi_error_t register_phy(); nsapi_error_t register_phy();
NanostackPhy &get_phy() const NanostackPhy &get_phy() const
{ {
return interface_phy; return interface_phy;
} }
int8_t interface_id; int8_t interface_id = -1;
int8_t _device_id; int8_t _device_id = -1;
rtos::Semaphore connect_semaphore; rtos::Semaphore connect_semaphore;
rtos::Semaphore disconnect_semaphore; rtos::Semaphore disconnect_semaphore;
mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb; mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
nsapi_connection_status_t _connect_status; nsapi_connection_status_t _connect_status = NSAPI_STATUS_DISCONNECTED;
nsapi_connection_status_t _previous_connection_status; nsapi_connection_status_t _previous_connection_status = NSAPI_STATUS_DISCONNECTED;
bool _blocking; bool _blocking = true;
}; };
class Nanostack::MeshInterface : public Nanostack::Interface { class Nanostack::MeshInterface : public Nanostack::Interface {
@ -91,21 +91,21 @@ public:
* *
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t connect(); nsapi_error_t connect() override;
/** Stop the interface /** Stop the interface
* *
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t disconnect(); nsapi_error_t disconnect() override;
/** @copydoc NetworkInterface::get_ip_address */ /** @copydoc NetworkInterface::get_ip_address */
virtual nsapi_error_t get_ip_address(SocketAddress *address); nsapi_error_t get_ip_address(SocketAddress *address) override;
/** Get the internally stored MAC address /** Get the internally stored MAC address
/return MAC address of the interface /return MAC address of the interface
*/ */
virtual const char *get_mac_address(); const char *get_mac_address() override;
/** Register callback for status reporting /** Register callback for status reporting
* *
@ -115,20 +115,20 @@ public:
* *
* @param status_cb The callback for status changes * @param status_cb The callback for status changes
*/ */
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb); void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) override;
/** Get the connection status /** Get the connection status
* *
* @return The connection status according to ConnectionStatusType * @return The connection status according to ConnectionStatusType
*/ */
virtual nsapi_connection_status_t get_connection_status() const; nsapi_connection_status_t get_connection_status() const override;
/** Set blocking status of connect() which by default should be blocking /** Set blocking status of connect() which by default should be blocking
* *
* @param blocking true if connect is blocking * @param blocking true if connect is blocking
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t set_blocking(bool blocking); nsapi_error_t set_blocking(bool blocking) override;
/** Set file system root path. /** Set file system root path.
* *
@ -138,7 +138,7 @@ public:
* @param root_path Address to NUL-terminated root-path string or NULL to disable file system usage. * @param root_path Address to NUL-terminated root-path string or NULL to disable file system usage.
* @return MESH_ERROR_NONE on success, MESH_ERROR_MEMORY in case of memory failure, MESH_ERROR_UNKNOWN in case of other error. * @return MESH_ERROR_NONE on success, MESH_ERROR_MEMORY in case of memory failure, MESH_ERROR_UNKNOWN in case of other error.
*/ */
virtual nsapi_error_t set_file_system_root_path(const char *root_path); nsapi_error_t set_file_system_root_path(const char *root_path);
/** Get the interface ID /** Get the interface ID
* @return Interface identifier * @return Interface identifier
@ -149,20 +149,20 @@ public:
} }
protected: protected:
InterfaceNanostack(); InterfaceNanostack() = default;
virtual Nanostack *get_stack(void); Nanostack *get_stack(void) override;
Nanostack::Interface *get_interface() const Nanostack::Interface *get_interface() const
{ {
return _interface; return _interface;
} }
virtual nsapi_error_t do_initialize() = 0; virtual nsapi_error_t do_initialize() = 0;
Nanostack::Interface *_interface; Nanostack::Interface *_interface = nullptr;
SocketAddress ip_addr; SocketAddress ip_addr;
char mac_addr_str[24]; char mac_addr_str[24] {};
mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb; mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
bool _blocking; bool _blocking = true;
}; };
class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface, private mbed::NonCopyable<MeshInterfaceNanostack> { class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface, private mbed::NonCopyable<MeshInterfaceNanostack> {
@ -178,13 +178,13 @@ public:
nsapi_error_t initialize(NanostackRfPhy *phy); nsapi_error_t initialize(NanostackRfPhy *phy);
protected: protected:
MeshInterfaceNanostack() : _phy(NULL) { } MeshInterfaceNanostack() = default;
MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { } MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
Nanostack::MeshInterface *get_interface() const Nanostack::MeshInterface *get_interface() const
{ {
return static_cast<Nanostack::MeshInterface *>(_interface); return static_cast<Nanostack::MeshInterface *>(_interface);
} }
NanostackRfPhy *_phy; NanostackRfPhy *_phy = nullptr;
}; };
#endif /* MESHINTERFACENANOSTACK_H */ #endif /* MESHINTERFACENANOSTACK_H */

View File

@ -1,29 +0,0 @@
/*
* Copyright (c) 2016 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* 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 NANOSTACKEMACINTERFACE_H
#define NANOSTACKEMACINTERFACE_H
#include "MeshInterfaceNanostack.h"
#include "NanostackEthernetPhy.h"
class NanostackEMACInterface : public Nanostack::Interface {
public:
NanostackEMACInterface(EMAC &emac);
};
#endif // NANOSTACKEMACINTERFACE_H

View File

@ -21,13 +21,13 @@
#include "MeshInterfaceNanostack.h" #include "MeshInterfaceNanostack.h"
#include "NanostackEthernetPhy.h" #include "NanostackEthernetPhy.h"
class Nanostack::EthernetInterface : public Nanostack::Interface { class Nanostack::EthernetInterface final : public Nanostack::Interface {
public: public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip, nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw, const char *netmask, const char *gw,
nsapi_ip_stack_t stack = DEFAULT_STACK, nsapi_ip_stack_t stack = DEFAULT_STACK,
bool blocking = true); bool blocking = true) override;
virtual nsapi_error_t bringdown(); nsapi_error_t bringdown() override;
private: private:
friend class Nanostack; friend class Nanostack;
@ -47,8 +47,7 @@ protected:
*/ */
class NanostackEthernetInterface : public InterfaceNanostack, public EthInterface, private mbed::NonCopyable<NanostackEthernetInterface> { class NanostackEthernetInterface : public InterfaceNanostack, public EthInterface, private mbed::NonCopyable<NanostackEthernetInterface> {
public: public:
NanostackEthernetInterface() { } NanostackEthernetInterface() = default;
//NanostackEthernetInterface(NanostackEthernetPhy *phy);
nsapi_error_t initialize(NanostackEthernetPhy *phy); nsapi_error_t initialize(NanostackEthernetPhy *phy);
@ -57,7 +56,7 @@ protected:
{ {
return static_cast<Nanostack::EthernetInterface *>(_interface); return static_cast<Nanostack::EthernetInterface *>(_interface);
} }
virtual nsapi_error_t do_initialize(); nsapi_error_t do_initialize() override;
}; };

View File

@ -21,26 +21,26 @@
#include "PPPInterface.h" #include "PPPInterface.h"
#include "NanostackPPPPhy.h" #include "NanostackPPPPhy.h"
class Nanostack::PPPInterface : public Nanostack::Interface { class Nanostack::PPPInterface final : public Nanostack::Interface {
public: public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip, nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw, const char *netmask, const char *gw,
nsapi_ip_stack_t stack = DEFAULT_STACK, nsapi_ip_stack_t stack = DEFAULT_STACK,
bool blocking = true); bool blocking = true) override;
virtual nsapi_error_t bringdown(); nsapi_error_t bringdown() override;
typedef mbed::Callback<void (uint8_t up, int8_t device_id)> link_state_cb_t; typedef mbed::Callback<void (uint8_t up, int8_t device_id)> link_state_cb_t;
virtual void set_link_state_changed_callback(link_state_cb_t link_state_cb); void set_link_state_changed_callback(link_state_cb_t link_state_cb);
private: private:
friend class Nanostack; friend class Nanostack;
PPPInterface(NanostackPhy &phy) : Interface(phy), link_state_up(false), enet_tasklet_connected(false) {} PPPInterface(NanostackPPPPhy &phy) : Interface(phy) {}
nsapi_error_t initialize(); nsapi_error_t initialize();
void link_state_changed(bool up); void link_state_changed(bool up);
nsapi_error_t connect_enet_tasklet(); nsapi_error_t connect_enet_tasklet();
link_state_cb_t link_state_cb; link_state_cb_t link_state_cb = nullptr;
bool link_state_up; bool link_state_up = false;
bool enet_tasklet_connected; bool enet_tasklet_connected = false;
}; };
#endif #endif

View File

@ -1,29 +0,0 @@
/*
* Copyright (c) 2016 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* 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 NANOSTACKRFINTERFACE_H
#define NANOSTACKRFINTERFACE_H
#include "MeshInterfaceNanostack.h"
#include "NanostackRfPhy.h"
class NanostackRfInterface : public Nanostack::Interface {
public:
NanostackRfInterface(NanostackRfPhy &phy);
};
#endif // NANOSTACKRFINTERFACE_H

View File

@ -23,19 +23,11 @@
* *
* Configure Nanostack to use Thread protocol. * Configure Nanostack to use Thread protocol.
*/ */
class ThreadInterface : public MeshInterfaceNanostack { class ThreadInterface final : public MeshInterfaceNanostack {
public: public:
/** Create an uninitialized ThreadInterface /** Inherit MeshInterfaceNanostack constructors */
* using MeshInterfaceNanostack::MeshInterfaceNanostack;
* Must initialize to initialize the mesh on a phy.
*/
ThreadInterface() { }
/** Create an initialized ThreadInterface
*
*/
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
/** /**
* \brief Sets the eui64 for the device configuration. * \brief Sets the eui64 for the device configuration.
@ -64,7 +56,7 @@ public:
protected: protected:
Nanostack::ThreadInterface *get_interface() const; Nanostack::ThreadInterface *get_interface() const;
virtual nsapi_error_t do_initialize(); nsapi_error_t do_initialize() override;
}; };
#endif // THREADINTERFACE_H #endif // THREADINTERFACE_H

View File

@ -23,19 +23,10 @@
* *
* Configure Nanostack to use Wi-SUN protocol. * Configure Nanostack to use Wi-SUN protocol.
*/ */
class WisunInterface : public MeshInterfaceNanostack { class WisunInterface final : public MeshInterfaceNanostack {
public: public:
/** Inherit MeshInterfaceNanostack constructors */
/** Create an uninitialized WisunInterface using MeshInterfaceNanostack::MeshInterfaceNanostack;
*
* Must initialize to initialize the mesh on a phy.
*/
WisunInterface() { }
/** Create an initialized WisunInterface
*
*/
WisunInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
/** /**
* \brief Set Wi-SUN network name. * \brief Set Wi-SUN network name.
@ -133,7 +124,7 @@ public:
bool getRouterIpAddress(char *address, int8_t len); bool getRouterIpAddress(char *address, int8_t len);
protected: protected:
Nanostack::WisunInterface *get_interface() const; Nanostack::WisunInterface *get_interface() const;
virtual nsapi_error_t do_initialize(); nsapi_error_t do_initialize() override;
}; };
#endif #endif

View File

@ -24,19 +24,19 @@
#include "ns_trace.h" #include "ns_trace.h"
#define TRACE_GROUP "nslp" #define TRACE_GROUP "nslp"
class Nanostack::LoWPANNDInterface : public Nanostack::MeshInterface { class Nanostack::LoWPANNDInterface final : public Nanostack::MeshInterface {
public: public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip, nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw, const char *netmask, const char *gw,
nsapi_ip_stack_t stack = IPV6_STACK, nsapi_ip_stack_t stack = IPV6_STACK,
bool blocking = true); bool blocking = true) override;
virtual nsapi_error_t bringdown(); nsapi_error_t bringdown() override;
virtual nsapi_error_t get_gateway(SocketAddress *sockAddr); nsapi_error_t get_gateway(SocketAddress *sockAddr) override;
friend class Nanostack; friend class Nanostack;
friend class ::LoWPANNDInterface; friend class ::LoWPANNDInterface;
private: private:
LoWPANNDInterface(NanostackRfPhy &phy) : MeshInterface(phy) { } using MeshInterface::MeshInterface;
mesh_error_t init(); mesh_error_t init();
mesh_error_t mesh_connect(); mesh_error_t mesh_connect();
mesh_error_t mesh_disconnect(); mesh_error_t mesh_disconnect();

View File

@ -69,20 +69,11 @@ void Nanostack::Interface::attach(
_connection_status_cb = status_cb; _connection_status_cb = status_cb;
} }
Nanostack::Interface::Interface(NanostackPhy &phy) : interface_phy(phy), interface_id(-1), _device_id(-1), Nanostack::Interface::Interface(NanostackPhy &phy) : interface_phy(phy)
_connect_status(NSAPI_STATUS_DISCONNECTED), _previous_connection_status(NSAPI_STATUS_DISCONNECTED), _blocking(true)
{ {
mesh_system_init(); mesh_system_init();
} }
InterfaceNanostack::InterfaceNanostack()
: _interface(NULL),
ip_addr(), mac_addr_str(), _blocking(true)
{
// Nothing to do
}
int InterfaceNanostack::connect() int InterfaceNanostack::connect()
{ {
nsapi_error_t error = do_initialize(); nsapi_error_t error = do_initialize();

View File

@ -13,9 +13,9 @@
class EMACPhy : public NanostackEthernetPhy { class EMACPhy : public NanostackEthernetPhy {
public: public:
EMACPhy(NanostackMemoryManager &mem, EMAC &m); EMACPhy(NanostackMemoryManager &mem, EMAC &m);
virtual int8_t phy_register(); int8_t phy_register() override;
virtual void get_mac_address(uint8_t *mac); void get_mac_address(uint8_t *mac) override;
virtual void set_mac_address(uint8_t *mac); void set_mac_address(uint8_t *mac) override;
int8_t address_write(phy_address_type_e, uint8_t *); int8_t address_write(phy_address_type_e, uint8_t *);
int8_t tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow); int8_t tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow);
@ -26,7 +26,7 @@ private:
NanostackMemoryManager &memory_manager; NanostackMemoryManager &memory_manager;
EMAC &emac; EMAC &emac;
uint8_t mac_addr[6]; uint8_t mac_addr[6];
int8_t device_id; int8_t device_id = -1;
phy_device_driver_s phy; phy_device_driver_s phy;
}; };
@ -50,7 +50,7 @@ extern "C"
return single_phy->tx(data_ptr, data_len, tx_handle, data_flow); return single_phy->tx(data_ptr, data_len, tx_handle, data_flow);
} }
EMACPhy::EMACPhy(NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), emac(m), device_id(-1) EMACPhy::EMACPhy(NanostackMemoryManager &mem, EMAC &m) : memory_manager(mem), emac(m)
{ {
/* Same default address logic as lwIP glue uses */ /* Same default address logic as lwIP glue uses */
#if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE) #if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)

View File

@ -29,15 +29,15 @@
class PPPPhy : public NanostackPPPPhy { class PPPPhy : public NanostackPPPPhy {
public: public:
PPPPhy(NanostackMemoryManager &mem, PPP &m); PPPPhy(NanostackMemoryManager &mem, PPP &m);
virtual int8_t phy_register(); int8_t phy_register() override;
virtual void phy_power_on(); void phy_power_on();
virtual void phy_power_off(); void phy_power_off();
virtual void get_iid64(uint8_t *iid64); void get_iid64(uint8_t *iid64) override;
virtual uint16_t get_mtu(); uint16_t get_mtu() override;
virtual void set_link_state_change_cb(link_state_change_cb_t cb); void set_link_state_change_cb(link_state_change_cb_t cb) override;
int8_t tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow); int8_t tx(uint8_t *data_ptr, uint16_t data_len, uint8_t tx_handle, data_protocol_e data_flow);
@ -48,10 +48,10 @@ private:
NanostackMemoryManager &memory_manager; NanostackMemoryManager &memory_manager;
PPP &ppp; PPP &ppp;
uint8_t iid64[8]; uint8_t iid64[8];
link_state_change_cb_t link_state_change_cb; link_state_change_cb_t link_state_change_cb = nullptr;
bool active; bool active = false;
bool powered_up; bool powered_up = false;
int8_t device_id; int8_t device_id = -1;
phy_device_driver_s phy; phy_device_driver_s phy;
}; };
@ -196,7 +196,7 @@ extern "C"
return single_phy->tx(data_ptr, data_len, tx_handle, data_flow); return single_phy->tx(data_ptr, data_len, tx_handle, data_flow);
} }
PPPPhy::PPPPhy(NanostackMemoryManager &mem, PPP &m) : memory_manager(mem), ppp(m), link_state_change_cb(NULL), active(false), powered_up(false), device_id(-1) PPPPhy::PPPPhy(NanostackMemoryManager &mem, PPP &m) : memory_manager(mem), ppp(m)
{ {
} }

View File

@ -25,11 +25,11 @@
class Nanostack::ThreadInterface : public Nanostack::MeshInterface { class Nanostack::ThreadInterface : public Nanostack::MeshInterface {
public: public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip, nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw, const char *netmask, const char *gw,
nsapi_ip_stack_t stack = IPV6_STACK, nsapi_ip_stack_t stack = IPV6_STACK,
bool blocking = true); bool blocking = true) override;
virtual nsapi_error_t bringdown(); nsapi_error_t bringdown() override;
friend class Nanostack; friend class Nanostack;
friend class ::ThreadInterface; friend class ::ThreadInterface;
private: private:

View File

@ -25,14 +25,14 @@
#include "ns_trace.h" #include "ns_trace.h"
#define TRACE_GROUP "WSIn" #define TRACE_GROUP "WSIn"
class Nanostack::WisunInterface : public Nanostack::MeshInterface { class Nanostack::WisunInterface final : public Nanostack::MeshInterface {
public: public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip, nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw, const char *netmask, const char *gw,
nsapi_ip_stack_t stack = IPV6_STACK, nsapi_ip_stack_t stack = IPV6_STACK,
bool blocking = true); bool blocking = true) override;
virtual nsapi_error_t bringdown(); nsapi_error_t bringdown() override;
virtual nsapi_error_t get_gateway(SocketAddress *address); nsapi_error_t get_gateway(SocketAddress *address) override;
friend class Nanostack; friend class Nanostack;
friend class ::WisunInterface; friend class ::WisunInterface;

View File

@ -18,7 +18,7 @@
#include "EMACMemoryManager.h" #include "EMACMemoryManager.h"
class NanostackMemoryManager : public EMACMemoryManager { class NanostackMemoryManager final : public EMACMemoryManager {
public: public:
/** /**
@ -30,7 +30,7 @@ public:
* @param align Memory alignment requirement in bytes * @param align Memory alignment requirement in bytes
* @return Allocated memory buffer, or NULL in case of error * @return Allocated memory buffer, or NULL in case of error
*/ */
virtual emac_mem_buf_t *alloc_heap(uint32_t size, uint32_t align); emac_mem_buf_t *alloc_heap(uint32_t size, uint32_t align) override;
/** /**
* Allocates memory buffer chain from a pool * Allocates memory buffer chain from a pool
@ -43,7 +43,7 @@ public:
* @param align Memory alignment requirement for each buffer in bytes * @param align Memory alignment requirement for each buffer in bytes
* @return Allocated memory buffer chain, or NULL in case of error * @return Allocated memory buffer chain, or NULL in case of error
*/ */
virtual emac_mem_buf_t *alloc_pool(uint32_t size, uint32_t align); emac_mem_buf_t *alloc_pool(uint32_t size, uint32_t align) override;
/** /**
* Get memory buffer pool allocation unit * Get memory buffer pool allocation unit
@ -53,7 +53,7 @@ public:
* @param align Memory alignment requirement in bytes * @param align Memory alignment requirement in bytes
* @return Contiguous memory size * @return Contiguous memory size
*/ */
virtual uint32_t get_pool_alloc_unit(uint32_t align) const; uint32_t get_pool_alloc_unit(uint32_t align) const override;
/** /**
* Free memory buffer chain * Free memory buffer chain
@ -63,7 +63,7 @@ public:
* *
* @param buf Memory buffer chain to be freed. * @param buf Memory buffer chain to be freed.
*/ */
virtual void free(emac_mem_buf_t *buf); void free(emac_mem_buf_t *buf) override;
/** /**
* Return total length of a memory buffer chain * Return total length of a memory buffer chain
@ -73,9 +73,7 @@ public:
* @param buf Memory buffer chain * @param buf Memory buffer chain
* @return Total length in bytes * @return Total length in bytes
*/ */
virtual uint32_t get_total_len(const emac_mem_buf_t *buf) const; uint32_t get_total_len(const emac_mem_buf_t *buf) const override;
virtual void set_align_preference(uint32_t align) { }
/** /**
* Copy a memory buffer chain * Copy a memory buffer chain
@ -86,7 +84,7 @@ public:
* @param to_buf Memory buffer chain to copy to * @param to_buf Memory buffer chain to copy to
* @param from_buf Memory buffer chain to copy from * @param from_buf Memory buffer chain to copy from
*/ */
virtual void copy(emac_mem_buf_t *to_buf, const emac_mem_buf_t *from_buf); void copy(emac_mem_buf_t *to_buf, const emac_mem_buf_t *from_buf) override;
@ -100,7 +98,7 @@ public:
* @param to_buf Memory buffer chain to concatenate to * @param to_buf Memory buffer chain to concatenate to
* @param cat_buf Memory buffer chain to concatenate * @param cat_buf Memory buffer chain to concatenate
*/ */
virtual void cat(emac_mem_buf_t *to_buf, emac_mem_buf_t *cat_buf); void cat(emac_mem_buf_t *to_buf, emac_mem_buf_t *cat_buf) override;
/** /**
* Returns the next buffer * Returns the next buffer
@ -110,7 +108,7 @@ public:
* @param buf Memory buffer * @param buf Memory buffer
* @return The next memory buffer, or NULL if last * @return The next memory buffer, or NULL if last
*/ */
virtual emac_mem_buf_t *get_next(const emac_mem_buf_t *buf) const; emac_mem_buf_t *get_next(const emac_mem_buf_t *buf) const override;
/** /**
* Return pointer to the payload of the buffer * Return pointer to the payload of the buffer
@ -118,7 +116,7 @@ public:
* @param buf Memory buffer * @param buf Memory buffer
* @return Pointer to the payload * @return Pointer to the payload
*/ */
virtual void *get_ptr(const emac_mem_buf_t *buf) const; void *get_ptr(const emac_mem_buf_t *buf) const override;
/** /**
* Return payload size of the buffer * Return payload size of the buffer
@ -126,7 +124,7 @@ public:
* @param buf Memory buffer * @param buf Memory buffer
* @return Size in bytes * @return Size in bytes
*/ */
virtual uint32_t get_len(const emac_mem_buf_t *buf) const; uint32_t get_len(const emac_mem_buf_t *buf) const override;
/** /**
* Sets the payload size of the buffer * Sets the payload size of the buffer
@ -137,7 +135,7 @@ public:
* @param buf Memory buffer * @param buf Memory buffer
* @param len Payload size, must be less or equal allocated size * @param len Payload size, must be less or equal allocated size
*/ */
virtual void set_len(emac_mem_buf_t *buf, uint32_t len); void set_len(emac_mem_buf_t *buf, uint32_t len) override;
}; };
#endif /* NANOSTACK_MEMORY_MANAGER_H */ #endif /* NANOSTACK_MEMORY_MANAGER_H */

View File

@ -40,12 +40,12 @@ public:
class PPPInterface; class PPPInterface;
/* Implement OnboardNetworkStack method */ /* Implement OnboardNetworkStack method */
virtual nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out); nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out) override;
/* Local variant with stronger typing and manual address specification */ /* Local variant with stronger typing and manual address specification */
nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, Nanostack::EthernetInterface **interface_out, const uint8_t *mac_addr = NULL); nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, Nanostack::EthernetInterface **interface_out, const uint8_t *mac_addr = NULL);
virtual nsapi_error_t add_ppp_interface(PPP &ppp, bool default_if, OnboardNetworkStack::Interface **interface_out); nsapi_error_t add_ppp_interface(PPP &ppp, bool default_if, OnboardNetworkStack::Interface **interface_out) override;
/* Local variant with stronger typing and manual address specification */ /* Local variant with stronger typing and manual address specification */
nsapi_error_t add_ppp_interface(PPP &ppp, bool default_if, Nanostack::PPPInterface **interface_out); nsapi_error_t add_ppp_interface(PPP &ppp, bool default_if, Nanostack::PPPInterface **interface_out);
@ -57,7 +57,7 @@ protected:
Nanostack(); Nanostack();
/** @copydoc NetworkStack::get_ip_address */ /** @copydoc NetworkStack::get_ip_address */
virtual nsapi_error_t get_ip_address(SocketAddress *sockAddr); nsapi_error_t get_ip_address(SocketAddress *sockAddr) override;
/** Opens a socket /** Opens a socket
* *
@ -71,7 +71,7 @@ protected:
* @param proto Protocol of socket to open, NSAPI_TCP or NSAPI_UDP * @param proto Protocol of socket to open, NSAPI_TCP or NSAPI_UDP
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t socket_open(void **handle, nsapi_protocol_t proto); nsapi_error_t socket_open(void **handle, nsapi_protocol_t proto) override;
/** Close the socket /** Close the socket
* *
@ -81,7 +81,7 @@ protected:
* @param handle Socket handle * @param handle Socket handle
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t socket_close(void *handle); nsapi_error_t socket_close(void *handle) override;
/** Bind a specific address to a socket /** Bind a specific address to a socket
* *
@ -92,7 +92,7 @@ protected:
* @param address Local address to bind * @param address Local address to bind
* @return 0 on success, negative error code on failure. * @return 0 on success, negative error code on failure.
*/ */
virtual nsapi_error_t socket_bind(void *handle, const SocketAddress &address); nsapi_error_t socket_bind(void *handle, const SocketAddress &address) override;
/** Listen for connections on a TCP socket /** Listen for connections on a TCP socket
* *
@ -104,7 +104,7 @@ protected:
* simultaneously * simultaneously
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t socket_listen(void *handle, int backlog); nsapi_error_t socket_listen(void *handle, int backlog) override;
/** Connects TCP socket to a remote host /** Connects TCP socket to a remote host
* *
@ -115,7 +115,7 @@ protected:
* @param address The SocketAddress of the remote host * @param address The SocketAddress of the remote host
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t socket_connect(void *handle, const SocketAddress &address); nsapi_error_t socket_connect(void *handle, const SocketAddress &address) override;
/** Accepts a connection on a TCP socket /** Accepts a connection on a TCP socket
* *
@ -135,7 +135,7 @@ protected:
* @param address Destination for the remote address or NULL * @param address Destination for the remote address or NULL
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t socket_accept(void *handle, void **server, SocketAddress *address); nsapi_error_t socket_accept(void *handle, void **server, SocketAddress *address) override;
/** Send data over a TCP socket /** Send data over a TCP socket
* *
@ -151,7 +151,7 @@ protected:
* @return Number of sent bytes on success, negative error * @return Number of sent bytes on success, negative error
* code on failure * code on failure
*/ */
virtual nsapi_size_or_error_t socket_send(void *handle, const void *data, nsapi_size_t size); nsapi_size_or_error_t socket_send(void *handle, const void *data, nsapi_size_t size) override;
/** Receive data over a TCP socket /** Receive data over a TCP socket
* *
@ -167,7 +167,7 @@ protected:
* @return Number of received bytes on success, negative error * @return Number of received bytes on success, negative error
* code on failure * code on failure
*/ */
virtual nsapi_size_or_error_t socket_recv(void *handle, void *data, nsapi_size_t size); nsapi_size_or_error_t socket_recv(void *handle, void *data, nsapi_size_t size) override;
/** Send a packet over a UDP socket /** Send a packet over a UDP socket
* *
@ -184,7 +184,7 @@ protected:
* @return Number of sent bytes on success, negative error * @return Number of sent bytes on success, negative error
* code on failure * code on failure
*/ */
virtual nsapi_size_or_error_t socket_sendto(void *handle, const SocketAddress &address, const void *data, nsapi_size_t size); nsapi_size_or_error_t socket_sendto(void *handle, const SocketAddress &address, const void *data, nsapi_size_t size) override;
/** Receive a packet over a UDP socket /** Receive a packet over a UDP socket
* *
@ -201,7 +201,7 @@ protected:
* @return Number of received bytes on success, negative error * @return Number of received bytes on success, negative error
* code on failure * code on failure
*/ */
virtual nsapi_size_or_error_t socket_recvfrom(void *handle, SocketAddress *address, void *buffer, nsapi_size_t size); nsapi_size_or_error_t socket_recvfrom(void *handle, SocketAddress *address, void *buffer, nsapi_size_t size) override;
/** Register a callback on state change of the socket /** Register a callback on state change of the socket
* *
@ -216,7 +216,7 @@ protected:
* @param callback Function to call on state change * @param callback Function to call on state change
* @param data Argument to pass to callback * @param data Argument to pass to callback
*/ */
virtual void socket_attach(void *handle, void (*callback)(void *), void *data); void socket_attach(void *handle, void (*callback)(void *), void *data) override;
/* Set stack-specific socket options /* Set stack-specific socket options
* *
@ -231,7 +231,7 @@ protected:
* @param optlen Length of the option value * @param optlen Length of the option value
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen); nsapi_error_t setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen) override;
/* Get stack-specific socket options /* Get stack-specific socket options
* *
@ -246,7 +246,7 @@ protected:
* @param optlen Length of the option value * @param optlen Length of the option value
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen); nsapi_error_t getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen) override;
private: private:
@ -268,7 +268,7 @@ private:
* *
* @return Call in callback * @return Call in callback
*/ */
virtual call_in_callback_cb_t get_call_in_callback(); call_in_callback_cb_t get_call_in_callback() override;
/** Call a callback after a delay /** Call a callback after a delay
* *
@ -279,7 +279,7 @@ private:
* @param func Callback to be called * @param func Callback to be called
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t call_in(int delay, mbed::Callback<void()> func); nsapi_error_t call_in(int delay, mbed::Callback<void()> func) override;
struct nanostack_callback { struct nanostack_callback {
mbed::Callback<void()> callback; mbed::Callback<void()> callback;

View File

@ -37,9 +37,8 @@ public:
eventOS_scheduler_mutex_release(); eventOS_scheduler_mutex_release();
} }
private: NanostackLockGuard(const NanostackLockGuard &) = delete;
NanostackLockGuard(const NanostackLockGuard &); NanostackLockGuard &operator=(const NanostackLockGuard &) = delete;
NanostackLockGuard &operator=(const NanostackLockGuard &);
}; };
#endif /* NANOSTACK_LOCK_GUARD_H_ */ #endif /* NANOSTACK_LOCK_GUARD_H_ */

View File

@ -42,7 +42,7 @@ public:
* *
* @return NanostackMACPhy * @return NanostackMACPhy
*/ */
virtual NanostackMACPhy *nanostack_mac_phy() NanostackMACPhy *nanostack_mac_phy() final
{ {
return this; return this;
} }

View File

@ -50,7 +50,7 @@ public:
* *
* @return NanostackPPPPhy * @return NanostackPPPPhy
*/ */
virtual NanostackPPPPhy *nanostack_ppp_phy() NanostackPPPPhy *nanostack_ppp_phy() final
{ {
return this; return this;
} }

View File

@ -39,7 +39,7 @@ public:
*/ */
virtual NanostackMACPhy *nanostack_mac_phy() virtual NanostackMACPhy *nanostack_mac_phy()
{ {
return 0; return nullptr;
} }
/** Return pointer to a NanostackPPPPhy. /** Return pointer to a NanostackPPPPhy.
@ -49,12 +49,12 @@ public:
*/ */
virtual NanostackPPPPhy *nanostack_ppp_phy() virtual NanostackPPPPhy *nanostack_ppp_phy()
{ {
return 0; return nullptr;
} }
protected: protected:
NanostackPhy() {} NanostackPhy() = default;
virtual ~NanostackPhy() {} virtual ~NanostackPhy() = default;
}; };
#endif /* NANOSTACK_INTERFACE_H_ */ #endif /* NANOSTACK_INTERFACE_H_ */

View File

@ -48,7 +48,7 @@ public:
* @return Device driver ID or a negative error * @return Device driver ID or a negative error
* code on failure * code on failure
*/ */
virtual int8_t phy_register() int8_t phy_register() override
{ {
return rf_register(); return rf_register();
} }