Skip to content

Commit 3739ccd

Browse files
authored
Merge pull request #12488 from kjbracey-arm/override_ns
C++11-ify virtualisation in Nanostack classes
2 parents 981691f + 04580b7 commit 3739ccd

21 files changed

+134
-231
lines changed

features/nanostack/mbed-mesh-api/mbed-mesh-api/LoWPANNDInterface.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,15 @@
2323
*
2424
* Configure Nanostack to use 6LoWPAN-ND protocol.
2525
*/
26-
class LoWPANNDInterface : public MeshInterfaceNanostack {
26+
class LoWPANNDInterface final : public MeshInterfaceNanostack {
2727
public:
28-
29-
/** Create an uninitialized LoWPANNDInterface
30-
*
31-
* Must initialize to initialize the mesh on a phy.
32-
*/
33-
LoWPANNDInterface() { }
34-
35-
/** Create an initialized LoWPANNDInterface
36-
*
37-
*/
38-
LoWPANNDInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
28+
/** Inherit MeshInterfaceNanostack constructors */
29+
using MeshInterfaceNanostack::MeshInterfaceNanostack;
3930

4031
bool getRouterIpAddress(char *address, int8_t len);
4132
protected:
4233
Nanostack::LoWPANNDInterface *get_interface() const;
43-
virtual nsapi_error_t do_initialize();
34+
nsapi_error_t do_initialize() override;
4435
};
4536

4637
#endif

features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525

2626
class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed::NonCopyable<Nanostack::Interface> {
2727
public:
28-
virtual nsapi_error_t get_ip_address(SocketAddress *address);
29-
virtual char *get_mac_address(char *buf, nsapi_size_t buflen);
30-
virtual nsapi_error_t get_netmask(SocketAddress *address);
31-
virtual nsapi_error_t get_gateway(SocketAddress *address);
32-
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
33-
virtual nsapi_connection_status_t get_connection_status() const;
28+
nsapi_error_t get_ip_address(SocketAddress *address) final;
29+
char *get_mac_address(char *buf, nsapi_size_t buflen) final;
30+
nsapi_error_t get_netmask(SocketAddress *address) final;
31+
nsapi_error_t get_gateway(SocketAddress *address) override;
32+
void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) final;
33+
nsapi_connection_status_t get_connection_status() const final;
3434

3535
void get_mac_address(uint8_t *buf) const
3636
{
@@ -59,20 +59,20 @@ class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed
5959
NanostackPhy &interface_phy;
6060
protected:
6161
Interface(NanostackPhy &phy);
62-
virtual nsapi_error_t register_phy();
62+
nsapi_error_t register_phy();
6363
NanostackPhy &get_phy() const
6464
{
6565
return interface_phy;
6666
}
67-
int8_t interface_id;
68-
int8_t _device_id;
67+
int8_t interface_id = -1;
68+
int8_t _device_id = -1;
6969
rtos::Semaphore connect_semaphore;
7070
rtos::Semaphore disconnect_semaphore;
7171

7272
mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
73-
nsapi_connection_status_t _connect_status;
74-
nsapi_connection_status_t _previous_connection_status;
75-
bool _blocking;
73+
nsapi_connection_status_t _connect_status = NSAPI_STATUS_DISCONNECTED;
74+
nsapi_connection_status_t _previous_connection_status = NSAPI_STATUS_DISCONNECTED;
75+
bool _blocking = true;
7676
};
7777

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

9696
/** Stop the interface
9797
*
9898
* @return 0 on success, negative error code on failure
9999
*/
100-
virtual nsapi_error_t disconnect();
100+
nsapi_error_t disconnect() override;
101101

102102
/** @copydoc NetworkInterface::get_ip_address */
103-
virtual nsapi_error_t get_ip_address(SocketAddress *address);
103+
nsapi_error_t get_ip_address(SocketAddress *address) override;
104104

105105
/** Get the internally stored MAC address
106106
/return MAC address of the interface
107107
*/
108-
virtual const char *get_mac_address();
108+
const char *get_mac_address() override;
109109

110110
/** Register callback for status reporting
111111
*
@@ -115,20 +115,20 @@ class InterfaceNanostack : public virtual NetworkInterface {
115115
*
116116
* @param status_cb The callback for status changes
117117
*/
118-
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
118+
void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) override;
119119

120120
/** Get the connection status
121121
*
122122
* @return The connection status according to ConnectionStatusType
123123
*/
124-
virtual nsapi_connection_status_t get_connection_status() const;
124+
nsapi_connection_status_t get_connection_status() const override;
125125

126126
/** Set blocking status of connect() which by default should be blocking
127127
*
128128
* @param blocking true if connect is blocking
129129
* @return 0 on success, negative error code on failure
130130
*/
131-
virtual nsapi_error_t set_blocking(bool blocking);
131+
nsapi_error_t set_blocking(bool blocking) override;
132132

133133
/** Set file system root path.
134134
*
@@ -138,7 +138,7 @@ class InterfaceNanostack : public virtual NetworkInterface {
138138
* @param root_path Address to NUL-terminated root-path string or NULL to disable file system usage.
139139
* @return MESH_ERROR_NONE on success, MESH_ERROR_MEMORY in case of memory failure, MESH_ERROR_UNKNOWN in case of other error.
140140
*/
141-
virtual nsapi_error_t set_file_system_root_path(const char *root_path);
141+
nsapi_error_t set_file_system_root_path(const char *root_path);
142142

143143
/** Get the interface ID
144144
* @return Interface identifier
@@ -149,20 +149,20 @@ class InterfaceNanostack : public virtual NetworkInterface {
149149
}
150150

151151
protected:
152-
InterfaceNanostack();
153-
virtual Nanostack *get_stack(void);
152+
InterfaceNanostack() = default;
153+
Nanostack *get_stack(void) override;
154154
Nanostack::Interface *get_interface() const
155155
{
156156
return _interface;
157157
}
158158
virtual nsapi_error_t do_initialize() = 0;
159159

160-
Nanostack::Interface *_interface;
160+
Nanostack::Interface *_interface = nullptr;
161161

162162
SocketAddress ip_addr;
163-
char mac_addr_str[24];
163+
char mac_addr_str[24] {};
164164
mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
165-
bool _blocking;
165+
bool _blocking = true;
166166
};
167167

168168
class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface, private mbed::NonCopyable<MeshInterfaceNanostack> {
@@ -178,13 +178,13 @@ class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface,
178178
nsapi_error_t initialize(NanostackRfPhy *phy);
179179

180180
protected:
181-
MeshInterfaceNanostack() : _phy(NULL) { }
181+
MeshInterfaceNanostack() = default;
182182
MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
183183
Nanostack::MeshInterface *get_interface() const
184184
{
185185
return static_cast<Nanostack::MeshInterface *>(_interface);
186186
}
187-
NanostackRfPhy *_phy;
187+
NanostackRfPhy *_phy = nullptr;
188188
};
189189

190190
#endif /* MESHINTERFACENANOSTACK_H */

features/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackEMACInterface.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

features/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackEthernetInterface.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
#include "MeshInterfaceNanostack.h"
2222
#include "NanostackEthernetPhy.h"
2323

24-
class Nanostack::EthernetInterface : public Nanostack::Interface {
24+
class Nanostack::EthernetInterface final : public Nanostack::Interface {
2525
public:
26-
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
27-
const char *netmask, const char *gw,
28-
nsapi_ip_stack_t stack = DEFAULT_STACK,
29-
bool blocking = true);
30-
virtual nsapi_error_t bringdown();
26+
nsapi_error_t bringup(bool dhcp, const char *ip,
27+
const char *netmask, const char *gw,
28+
nsapi_ip_stack_t stack = DEFAULT_STACK,
29+
bool blocking = true) override;
30+
nsapi_error_t bringdown() override;
3131

3232
private:
3333
friend class Nanostack;
@@ -47,8 +47,7 @@ class Nanostack::EthernetInterface : public Nanostack::Interface {
4747
*/
4848
class NanostackEthernetInterface : public InterfaceNanostack, public EthInterface, private mbed::NonCopyable<NanostackEthernetInterface> {
4949
public:
50-
NanostackEthernetInterface() { }
51-
//NanostackEthernetInterface(NanostackEthernetPhy *phy);
50+
NanostackEthernetInterface() = default;
5251

5352
nsapi_error_t initialize(NanostackEthernetPhy *phy);
5453

@@ -57,7 +56,7 @@ class NanostackEthernetInterface : public InterfaceNanostack, public EthInterfac
5756
{
5857
return static_cast<Nanostack::EthernetInterface *>(_interface);
5958
}
60-
virtual nsapi_error_t do_initialize();
59+
nsapi_error_t do_initialize() override;
6160

6261
};
6362

features/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackPPPInterface.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@
2121
#include "PPPInterface.h"
2222
#include "NanostackPPPPhy.h"
2323

24-
class Nanostack::PPPInterface : public Nanostack::Interface {
24+
class Nanostack::PPPInterface final : public Nanostack::Interface {
2525
public:
26-
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
27-
const char *netmask, const char *gw,
28-
nsapi_ip_stack_t stack = DEFAULT_STACK,
29-
bool blocking = true);
30-
virtual nsapi_error_t bringdown();
26+
nsapi_error_t bringup(bool dhcp, const char *ip,
27+
const char *netmask, const char *gw,
28+
nsapi_ip_stack_t stack = DEFAULT_STACK,
29+
bool blocking = true) override;
30+
nsapi_error_t bringdown() override;
3131

3232
typedef mbed::Callback<void (uint8_t up, int8_t device_id)> link_state_cb_t;
33-
virtual void set_link_state_changed_callback(link_state_cb_t link_state_cb);
33+
void set_link_state_changed_callback(link_state_cb_t link_state_cb);
3434

3535
private:
3636
friend class Nanostack;
37-
PPPInterface(NanostackPhy &phy) : Interface(phy), link_state_up(false), enet_tasklet_connected(false) {}
37+
PPPInterface(NanostackPPPPhy &phy) : Interface(phy) {}
3838
nsapi_error_t initialize();
3939
void link_state_changed(bool up);
4040
nsapi_error_t connect_enet_tasklet();
41-
link_state_cb_t link_state_cb;
42-
bool link_state_up;
43-
bool enet_tasklet_connected;
41+
link_state_cb_t link_state_cb = nullptr;
42+
bool link_state_up = false;
43+
bool enet_tasklet_connected = false;
4444
};
4545

4646
#endif

features/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackRfInterface.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

features/nanostack/mbed-mesh-api/mbed-mesh-api/ThreadInterface.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,11 @@
2323
*
2424
* Configure Nanostack to use Thread protocol.
2525
*/
26-
class ThreadInterface : public MeshInterfaceNanostack {
26+
class ThreadInterface final : public MeshInterfaceNanostack {
2727
public:
2828

29-
/** Create an uninitialized ThreadInterface
30-
*
31-
* Must initialize to initialize the mesh on a phy.
32-
*/
33-
ThreadInterface() { }
34-
35-
/** Create an initialized ThreadInterface
36-
*
37-
*/
38-
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
29+
/** Inherit MeshInterfaceNanostack constructors */
30+
using MeshInterfaceNanostack::MeshInterfaceNanostack;
3931

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

6557
protected:
6658
Nanostack::ThreadInterface *get_interface() const;
67-
virtual nsapi_error_t do_initialize();
59+
nsapi_error_t do_initialize() override;
6860
};
6961

7062
#endif // THREADINTERFACE_H

features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,10 @@
2323
*
2424
* Configure Nanostack to use Wi-SUN protocol.
2525
*/
26-
class WisunInterface : public MeshInterfaceNanostack {
26+
class WisunInterface final : public MeshInterfaceNanostack {
2727
public:
28-
29-
/** Create an uninitialized WisunInterface
30-
*
31-
* Must initialize to initialize the mesh on a phy.
32-
*/
33-
WisunInterface() { }
34-
35-
/** Create an initialized WisunInterface
36-
*
37-
*/
38-
WisunInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
28+
/** Inherit MeshInterfaceNanostack constructors */
29+
using MeshInterfaceNanostack::MeshInterfaceNanostack;
3930

4031
/**
4132
* \brief Set Wi-SUN network name.
@@ -133,7 +124,7 @@ class WisunInterface : public MeshInterfaceNanostack {
133124
bool getRouterIpAddress(char *address, int8_t len);
134125
protected:
135126
Nanostack::WisunInterface *get_interface() const;
136-
virtual nsapi_error_t do_initialize();
127+
nsapi_error_t do_initialize() override;
137128
};
138129

139130
#endif

0 commit comments

Comments
 (0)