Skip to content

Commit 804d1e6

Browse files
authored
Merge pull request #12489 from kjbracey-arm/override_lwip
C++11-ify virtualisation in lwIP classes
2 parents 6677249 + aa9058a commit 804d1e6

File tree

3 files changed

+68
-95
lines changed

3 files changed

+68
-95
lines changed

features/lwipstack/LWIPMemoryManager.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "EMACMemoryManager.h"
2020

2121

22-
class LWIPMemoryManager : public EMACMemoryManager {
22+
class LWIPMemoryManager final : public EMACMemoryManager {
2323
public:
2424

2525
/**
@@ -31,7 +31,7 @@ class LWIPMemoryManager : public EMACMemoryManager {
3131
* @param align Memory alignment requirement in bytes
3232
* @return Allocated memory buffer, or NULL in case of error
3333
*/
34-
virtual net_stack_mem_buf_t *alloc_heap(uint32_t size, uint32_t align);
34+
net_stack_mem_buf_t *alloc_heap(uint32_t size, uint32_t align) override;
3535

3636
/**
3737
* Allocates memory buffer chain from a pool
@@ -44,7 +44,7 @@ class LWIPMemoryManager : public EMACMemoryManager {
4444
* @param align Memory alignment requirement for each buffer in bytes
4545
* @return Allocated memory buffer chain, or NULL in case of error
4646
*/
47-
virtual net_stack_mem_buf_t *alloc_pool(uint32_t size, uint32_t align);
47+
net_stack_mem_buf_t *alloc_pool(uint32_t size, uint32_t align) override;
4848

4949
/**
5050
* Get memory buffer pool allocation unit
@@ -54,7 +54,7 @@ class LWIPMemoryManager : public EMACMemoryManager {
5454
* @param align Memory alignment requirement in bytes
5555
* @return Contiguous memory size
5656
*/
57-
virtual uint32_t get_pool_alloc_unit(uint32_t align) const;
57+
uint32_t get_pool_alloc_unit(uint32_t align) const override;
5858

5959
/**
6060
* Free memory buffer chain
@@ -64,7 +64,7 @@ class LWIPMemoryManager : public EMACMemoryManager {
6464
*
6565
* @param buf Memory buffer chain to be freed.
6666
*/
67-
virtual void free(net_stack_mem_buf_t *buf);
67+
void free(net_stack_mem_buf_t *buf) override;
6868

6969
/**
7070
* Return total length of a memory buffer chain
@@ -74,7 +74,7 @@ class LWIPMemoryManager : public EMACMemoryManager {
7474
* @param buf Memory buffer chain
7575
* @return Total length in bytes
7676
*/
77-
virtual uint32_t get_total_len(const net_stack_mem_buf_t *buf) const;
77+
uint32_t get_total_len(const net_stack_mem_buf_t *buf) const override;
7878

7979
/**
8080
* Copy a memory buffer chain
@@ -85,7 +85,7 @@ class LWIPMemoryManager : public EMACMemoryManager {
8585
* @param to_buf Memory buffer chain to copy to
8686
* @param from_buf Memory buffer chain to copy from
8787
*/
88-
virtual void copy(net_stack_mem_buf_t *to_buf, const net_stack_mem_buf_t *from_buf);
88+
void copy(net_stack_mem_buf_t *to_buf, const net_stack_mem_buf_t *from_buf) override;
8989

9090
/**
9191
* Copy to a memory buffer chain
@@ -98,7 +98,7 @@ class LWIPMemoryManager : public EMACMemoryManager {
9898
* @param ptr Pointer to data
9999
* @param len Data length
100100
*/
101-
virtual void copy_to_buf(net_stack_mem_buf_t *to_buf, const void *ptr, uint32_t len);
101+
void copy_to_buf(net_stack_mem_buf_t *to_buf, const void *ptr, uint32_t len) override;
102102

103103
/**
104104
* Copy from a memory buffer chain
@@ -110,7 +110,7 @@ class LWIPMemoryManager : public EMACMemoryManager {
110110
* @param from_buf Memory buffer chain to copy from
111111
* @return Length of the data that was copied
112112
*/
113-
virtual uint32_t copy_from_buf(void *ptr, uint32_t len, const net_stack_mem_buf_t *from_buf) const;
113+
uint32_t copy_from_buf(void *ptr, uint32_t len, const net_stack_mem_buf_t *from_buf) const override;
114114

115115
/**
116116
* Concatenate two memory buffer chains
@@ -122,7 +122,7 @@ class LWIPMemoryManager : public EMACMemoryManager {
122122
* @param to_buf Memory buffer chain to concatenate to
123123
* @param cat_buf Memory buffer chain to concatenate
124124
*/
125-
virtual void cat(net_stack_mem_buf_t *to_buf, net_stack_mem_buf_t *cat_buf);
125+
void cat(net_stack_mem_buf_t *to_buf, net_stack_mem_buf_t *cat_buf) override;
126126

127127
/**
128128
* Returns the next buffer
@@ -132,23 +132,23 @@ class LWIPMemoryManager : public EMACMemoryManager {
132132
* @param buf Memory buffer
133133
* @return The next memory buffer, or NULL if last
134134
*/
135-
virtual net_stack_mem_buf_t *get_next(const net_stack_mem_buf_t *buf) const;
135+
net_stack_mem_buf_t *get_next(const net_stack_mem_buf_t *buf) const override;
136136

137137
/**
138138
* Return pointer to the payload of the buffer
139139
*
140140
* @param buf Memory buffer
141141
* @return Pointer to the payload
142142
*/
143-
virtual void *get_ptr(const net_stack_mem_buf_t *buf) const;
143+
void *get_ptr(const net_stack_mem_buf_t *buf) const override;
144144

145145
/**
146146
* Return payload size of the buffer
147147
*
148148
* @param buf Memory buffer
149149
* @return Size in bytes
150150
*/
151-
virtual uint32_t get_len(const net_stack_mem_buf_t *buf) const;
151+
uint32_t get_len(const net_stack_mem_buf_t *buf) const override;
152152

153153
/**
154154
* Sets the payload size of the buffer
@@ -159,7 +159,7 @@ class LWIPMemoryManager : public EMACMemoryManager {
159159
* @param buf Memory buffer
160160
* @param len Payload size, must be less or equal allocated size
161161
*/
162-
virtual void set_len(net_stack_mem_buf_t *buf, uint32_t len);
162+
void set_len(net_stack_mem_buf_t *buf, uint32_t len) override;
163163

164164
private:
165165

features/lwipstack/LWIPStack.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -191,30 +191,13 @@ LWIP::call_in_callback_cb_t LWIP::get_call_in_callback()
191191
return cb;
192192
}
193193

194-
const char *LWIP::get_ip_address()
194+
nsapi_error_t LWIP::get_ip_address(SocketAddress *address)
195195
{
196196
if (!default_interface) {
197-
return NULL;
197+
return NSAPI_ERROR_NO_ADDRESS;
198198
}
199199

200-
const ip_addr_t *addr = get_ip_addr(true, &default_interface->netif);
201-
202-
if (!addr) {
203-
return NULL;
204-
}
205-
#if LWIP_IPV6
206-
if (IP_IS_V6(addr)) {
207-
return ip6addr_ntoa_r(ip_2_ip6(addr), ip_address, sizeof(ip_address));
208-
}
209-
#endif
210-
#if LWIP_IPV4
211-
if (IP_IS_V4(addr)) {
212-
return ip4addr_ntoa_r(ip_2_ip4(addr), ip_address, sizeof(ip_address));
213-
}
214-
#endif
215-
#if LWIP_IPV6 && LWIP_IPV4
216-
return NULL;
217-
#endif
200+
return get_ip_address_if(address, nullptr);
218201
}
219202

220203
nsapi_error_t LWIP::get_ip_address_if(SocketAddress *address, const char *interface_name)

0 commit comments

Comments
 (0)