Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++11-ify virtualisation in Nanostack classes #12488

Merged
merged 1 commit into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions features/nanostack/mbed-mesh-api/mbed-mesh-api/LoWPANNDInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,15 @@
*
* Configure Nanostack to use 6LoWPAN-ND protocol.
*/
class LoWPANNDInterface : public MeshInterfaceNanostack {
class LoWPANNDInterface final : public MeshInterfaceNanostack {
public:

/** Create an uninitialized LoWPANNDInterface
*
* Must initialize to initialize the mesh on a phy.
*/
LoWPANNDInterface() { }

/** Create an initialized LoWPANNDInterface
*
*/
LoWPANNDInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
/** Inherit MeshInterfaceNanostack constructors */
using MeshInterfaceNanostack::MeshInterfaceNanostack;

bool getRouterIpAddress(char *address, int8_t len);
protected:
Nanostack::LoWPANNDInterface *get_interface() const;
virtual nsapi_error_t do_initialize();
nsapi_error_t do_initialize() override;
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed::NonCopyable<Nanostack::Interface> {
public:
virtual nsapi_error_t get_ip_address(SocketAddress *address);
virtual char *get_mac_address(char *buf, nsapi_size_t buflen);
virtual nsapi_error_t get_netmask(SocketAddress *address);
virtual nsapi_error_t get_gateway(SocketAddress *address);
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
virtual nsapi_connection_status_t get_connection_status() const;
nsapi_error_t get_ip_address(SocketAddress *address) final;
char *get_mac_address(char *buf, nsapi_size_t buflen) final;
nsapi_error_t get_netmask(SocketAddress *address) final;
nsapi_error_t get_gateway(SocketAddress *address) override;
void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) final;
nsapi_connection_status_t get_connection_status() const final;

void get_mac_address(uint8_t *buf) const
{
Expand Down Expand Up @@ -59,20 +59,20 @@ class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed
NanostackPhy &interface_phy;
protected:
Interface(NanostackPhy &phy);
virtual nsapi_error_t register_phy();
nsapi_error_t register_phy();
NanostackPhy &get_phy() const
{
return interface_phy;
}
int8_t interface_id;
int8_t _device_id;
int8_t interface_id = -1;
int8_t _device_id = -1;
rtos::Semaphore connect_semaphore;
rtos::Semaphore disconnect_semaphore;

mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
nsapi_connection_status_t _connect_status;
nsapi_connection_status_t _previous_connection_status;
bool _blocking;
nsapi_connection_status_t _connect_status = NSAPI_STATUS_DISCONNECTED;
nsapi_connection_status_t _previous_connection_status = NSAPI_STATUS_DISCONNECTED;
bool _blocking = true;
};

class Nanostack::MeshInterface : public Nanostack::Interface {
Expand All @@ -91,21 +91,21 @@ class InterfaceNanostack : public virtual NetworkInterface {
*
* @return 0 on success, negative error code on failure
*/
virtual nsapi_error_t connect();
nsapi_error_t connect() override;

/** Stop the interface
*
* @return 0 on success, negative error code on failure
*/
virtual nsapi_error_t disconnect();
nsapi_error_t disconnect() override;

/** @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
/return MAC address of the interface
*/
virtual const char *get_mac_address();
const char *get_mac_address() override;

/** Register callback for status reporting
*
Expand All @@ -115,20 +115,20 @@ class InterfaceNanostack : public virtual NetworkInterface {
*
* @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
*
* @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
*
* @param blocking true if connect is blocking
* @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.
*
Expand All @@ -138,7 +138,7 @@ class InterfaceNanostack : public virtual NetworkInterface {
* @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.
*/
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
* @return Interface identifier
Expand All @@ -149,20 +149,20 @@ class InterfaceNanostack : public virtual NetworkInterface {
}

protected:
InterfaceNanostack();
virtual Nanostack *get_stack(void);
InterfaceNanostack() = default;
Nanostack *get_stack(void) override;
Nanostack::Interface *get_interface() const
{
return _interface;
}
virtual nsapi_error_t do_initialize() = 0;

Nanostack::Interface *_interface;
Nanostack::Interface *_interface = nullptr;

SocketAddress ip_addr;
char mac_addr_str[24];
char mac_addr_str[24] {};
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> {
Expand All @@ -178,13 +178,13 @@ class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface,
nsapi_error_t initialize(NanostackRfPhy *phy);

protected:
MeshInterfaceNanostack() : _phy(NULL) { }
MeshInterfaceNanostack() = default;
MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
Nanostack::MeshInterface *get_interface() const
{
return static_cast<Nanostack::MeshInterface *>(_interface);
}
NanostackRfPhy *_phy;
NanostackRfPhy *_phy = nullptr;
};

#endif /* MESHINTERFACENANOSTACK_H */

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
#include "MeshInterfaceNanostack.h"
#include "NanostackEthernetPhy.h"

class Nanostack::EthernetInterface : public Nanostack::Interface {
class Nanostack::EthernetInterface final : public Nanostack::Interface {
public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,
nsapi_ip_stack_t stack = DEFAULT_STACK,
bool blocking = true);
virtual nsapi_error_t bringdown();
nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,
nsapi_ip_stack_t stack = DEFAULT_STACK,
bool blocking = true) override;
nsapi_error_t bringdown() override;

private:
friend class Nanostack;
Expand All @@ -47,8 +47,7 @@ class Nanostack::EthernetInterface : public Nanostack::Interface {
*/
class NanostackEthernetInterface : public InterfaceNanostack, public EthInterface, private mbed::NonCopyable<NanostackEthernetInterface> {
public:
NanostackEthernetInterface() { }
//NanostackEthernetInterface(NanostackEthernetPhy *phy);
NanostackEthernetInterface() = default;

nsapi_error_t initialize(NanostackEthernetPhy *phy);

Expand All @@ -57,7 +56,7 @@ class NanostackEthernetInterface : public InterfaceNanostack, public EthInterfac
{
return static_cast<Nanostack::EthernetInterface *>(_interface);
}
virtual nsapi_error_t do_initialize();
nsapi_error_t do_initialize() override;

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@
#include "PPPInterface.h"
#include "NanostackPPPPhy.h"

class Nanostack::PPPInterface : public Nanostack::Interface {
class Nanostack::PPPInterface final : public Nanostack::Interface {
public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,
nsapi_ip_stack_t stack = DEFAULT_STACK,
bool blocking = true);
virtual nsapi_error_t bringdown();
nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,
nsapi_ip_stack_t stack = DEFAULT_STACK,
bool blocking = true) override;
nsapi_error_t bringdown() override;

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:
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();
void link_state_changed(bool up);
nsapi_error_t connect_enet_tasklet();
link_state_cb_t link_state_cb;
bool link_state_up;
bool enet_tasklet_connected;
link_state_cb_t link_state_cb = nullptr;
bool link_state_up = false;
bool enet_tasklet_connected = false;
};

#endif

This file was deleted.

16 changes: 4 additions & 12 deletions features/nanostack/mbed-mesh-api/mbed-mesh-api/ThreadInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,11 @@
*
* Configure Nanostack to use Thread protocol.
*/
class ThreadInterface : public MeshInterfaceNanostack {
class ThreadInterface final : public MeshInterfaceNanostack {
public:

/** Create an uninitialized ThreadInterface
*
* Must initialize to initialize the mesh on a phy.
*/
ThreadInterface() { }

/** Create an initialized ThreadInterface
*
*/
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
/** Inherit MeshInterfaceNanostack constructors */
using MeshInterfaceNanostack::MeshInterfaceNanostack;

/**
* \brief Sets the eui64 for the device configuration.
Expand Down Expand Up @@ -64,7 +56,7 @@ class ThreadInterface : public MeshInterfaceNanostack {

protected:
Nanostack::ThreadInterface *get_interface() const;
virtual nsapi_error_t do_initialize();
nsapi_error_t do_initialize() override;
};

#endif // THREADINTERFACE_H
17 changes: 4 additions & 13 deletions features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,10 @@
*
* Configure Nanostack to use Wi-SUN protocol.
*/
class WisunInterface : public MeshInterfaceNanostack {
class WisunInterface final : public MeshInterfaceNanostack {
public:

/** Create an uninitialized WisunInterface
*
* Must initialize to initialize the mesh on a phy.
*/
WisunInterface() { }

/** Create an initialized WisunInterface
*
*/
WisunInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
/** Inherit MeshInterfaceNanostack constructors */
using MeshInterfaceNanostack::MeshInterfaceNanostack;

/**
* \brief Set Wi-SUN network name.
Expand Down Expand Up @@ -133,7 +124,7 @@ class WisunInterface : public MeshInterfaceNanostack {
bool getRouterIpAddress(char *address, int8_t len);
protected:
Nanostack::WisunInterface *get_interface() const;
virtual nsapi_error_t do_initialize();
nsapi_error_t do_initialize() override;
};

#endif
Loading