Skip to content

IPCore String-based API removal #11942

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

Merged
merged 4 commits into from
Feb 21, 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
43 changes: 25 additions & 18 deletions UNITTESTS/features/netsocket/PPPInterface/test_PPPInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,21 @@ TEST_F(TestPPPInterface, disconnect)

TEST_F(TestPPPInterface, set_network)
{
char ipAddress[NSAPI_IPv4_SIZE] = "127.0.0.1";
char netmask[NSAPI_IPv4_SIZE] = "255.255.0.0";
char gateway[NSAPI_IPv4_SIZE] = "127.0.0.2";
SocketAddress ipAddress("127.0.0.1");
SocketAddress netmask("255.255.0.0");
SocketAddress gateway("127.0.0.2");

const char *ipAddressArg;
const char *netmaskArg;
const char *gatewayArg;

EXPECT_EQ(0, iface->get_ip_address());
EXPECT_EQ(0, iface->get_netmask());
EXPECT_EQ(0, iface->get_gateway());
SocketAddress ipAddr;
SocketAddress netmaskAddr;
SocketAddress gatewayAddr;

EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_ip_address(&ipAddr));
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_netmask(&netmaskAddr));
EXPECT_EQ(NSAPI_ERROR_NO_CONNECTION, iface->get_gateway(&gatewayAddr));

EXPECT_CALL(*pppMock, set_stream(_));
EXPECT_CALL(*pppMock, set_ip_stack(_));
Expand All @@ -213,25 +217,28 @@ TEST_F(TestPPPInterface, set_network)
Return(NSAPI_ERROR_OK)));
EXPECT_EQ(NSAPI_ERROR_OK, iface->connect());
// Check the contents of the stored pointer arguments.
EXPECT_TRUE(0 == strcmp(ipAddress, ipAddressArg));
EXPECT_TRUE(0 == strcmp(netmask, netmaskArg));
EXPECT_TRUE(0 == strcmp(gateway, gatewayArg));
EXPECT_TRUE(0 == strcmp(ipAddress.get_ip_address(), ipAddressArg));
EXPECT_TRUE(0 == strcmp(netmask.get_ip_address(), netmaskArg));
EXPECT_TRUE(0 == strcmp(gateway.get_ip_address(), gatewayArg));

// Testing the getters makes sense now.
EXPECT_CALL(*netStackIface, get_ip_address(_, _))
EXPECT_CALL(*netStackIface, get_ip_address(_))
.Times(1)
.WillOnce(DoAll(SetArgPointee<0>(*ipAddress), Return(ipAddress)));
EXPECT_EQ(std::string(ipAddress), std::string(iface->get_ip_address()));
.WillOnce(DoAll(SetArgPointee<0>(ipAddress), Return(NSAPI_ERROR_OK)));
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_ip_address(&ipAddr));
EXPECT_EQ(ipAddress, ipAddr);

EXPECT_CALL(*netStackIface, get_netmask(_, _))
EXPECT_CALL(*netStackIface, get_netmask(_))
.Times(1)
.WillOnce(DoAll(SetArgPointee<0>(*netmask), Return(netmask)));
EXPECT_EQ(std::string(netmask), std::string(iface->get_netmask()));
.WillOnce(DoAll(SetArgPointee<0>(netmask), Return(NSAPI_ERROR_OK)));
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_netmask(&netmaskAddr));
EXPECT_EQ(netmask, netmaskAddr);

EXPECT_CALL(*netStackIface, get_gateway(_, _))
EXPECT_CALL(*netStackIface, get_gateway(_))
.Times(1)
.WillOnce(DoAll(SetArgPointee<0>(*gateway), Return(gateway)));
EXPECT_EQ(std::string(gateway), std::string(iface->get_gateway()));
.WillOnce(DoAll(SetArgPointee<0>(gateway), Return(NSAPI_ERROR_OK)));
EXPECT_EQ(NSAPI_ERROR_OK, iface->get_gateway(&gatewayAddr));
EXPECT_EQ(gateway, gatewayAddr);
}

TEST_F(TestPPPInterface, get_connection_status)
Expand Down
2 changes: 0 additions & 2 deletions UNITTESTS/features/netsocket/PPPInterface/unittest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ set(unittest-test-sources
stubs/mbed_shared_queues_stub.cpp
stubs/nsapi_dns_stub.cpp
stubs/EventFlags_stub.cpp
stubs/stoip4_stub.c
stubs/ip4tos_stub.c
stubs/NetworkStack_stub.cpp
stubs/NetworkInterfaceDefaults_stub.cpp
stubs/SocketStats_Stub.cpp
Expand Down
5 changes: 0 additions & 5 deletions UNITTESTS/stubs/AT_CellularContext_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ nsapi_error_t AT_CellularContext::get_ip_address(SocketAddress *address)
return NSAPI_ERROR_UNSUPPORTED;
}

const char *AT_CellularContext::get_ip_address()
{
return NULL;
}

void AT_CellularContext::attach(Callback<void(nsapi_event_t, intptr_t)> status_cb)
{
}
Expand Down
5 changes: 0 additions & 5 deletions UNITTESTS/stubs/AT_CellularStack_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ nsapi_error_t AT_CellularStack::get_ip_address(SocketAddress* address)
return NSAPI_ERROR_UNSUPPORTED;
}

const char *AT_CellularStack::get_ip_address()
{
return NULL;
}

nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
{
return NSAPI_ERROR_OK;
Expand Down
19 changes: 0 additions & 19 deletions UNITTESTS/stubs/NetworkInterface_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ nsapi_error_t NetworkInterface::get_ip_address(SocketAddress *)
return NSAPI_ERROR_UNSUPPORTED;
}

const char *NetworkInterface::get_ip_address()
{
return nullptr;
}
nsapi_error_t NetworkInterface::get_ipv6_link_local_address(SocketAddress *address)
{
return NSAPI_ERROR_UNSUPPORTED;
Expand All @@ -45,31 +41,16 @@ nsapi_error_t NetworkInterface::get_netmask(SocketAddress *)
return NSAPI_ERROR_UNSUPPORTED;
}

const char *NetworkInterface::get_netmask()
{
return nullptr;
}

nsapi_error_t NetworkInterface::get_gateway(SocketAddress *)
{
return NSAPI_ERROR_UNSUPPORTED;
}

const char *NetworkInterface::get_gateway()
{
return nullptr;
}

nsapi_error_t NetworkInterface::set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway)
{
return NSAPI_ERROR_UNSUPPORTED;
}

nsapi_error_t NetworkInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
{
return NSAPI_ERROR_UNSUPPORTED;
}

nsapi_error_t NetworkInterface::set_dhcp(bool dhcp)
{
return NSAPI_ERROR_UNSUPPORTED;
Expand Down
10 changes: 0 additions & 10 deletions UNITTESTS/stubs/NetworkStack_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ nsapi_error_t NetworkStack::get_ip_address(SocketAddress* address)
return NSAPI_ERROR_UNSUPPORTED;
}

const char *NetworkStack::get_ip_address()
{
return NULL;
}

nsapi_error_t NetworkStack::get_ipv6_link_local_address(SocketAddress *address)
{
return NSAPI_ERROR_UNSUPPORTED;
Expand All @@ -118,8 +113,3 @@ nsapi_error_t NetworkStack::get_ip_address_if(SocketAddress* address, const char
{
return NSAPI_ERROR_UNSUPPORTED;
}

const char *NetworkStack::get_ip_address_if(const char *interface_name)
{
return NULL;
}
4 changes: 0 additions & 4 deletions UNITTESTS/stubs/NetworkStack_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ class NetworkStackstub : public NetworkStack {
{
}

virtual const char *get_ip_address()
{
return "127.0.0.1";
}
virtual nsapi_error_t get_ip_address(SocketAddress* address)
{
address->set_ip_address("127.0.0.1");
Expand Down
1 change: 0 additions & 1 deletion UNITTESTS/stubs/OnboardNetworkStack_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class OnboardNetworkStackMock : public OnboardNetworkStack {
MOCK_CONST_METHOD0(get_connection_status, nsapi_connection_status_t());
MOCK_METHOD1(get_interface_name, char *(char *buf));
MOCK_METHOD2(get_mac_address, char *(char *buf, nsapi_size_t buflen));
MOCK_METHOD2(get_ip_address, char *(char *buf, nsapi_size_t buflen));
MOCK_METHOD1(get_ip_address, nsapi_error_t (SocketAddress *address));
MOCK_METHOD1(get_ipv6_link_local_address, nsapi_error_t(SocketAddress *address));
MOCK_METHOD2(get_netmask, char *(char *buf, nsapi_size_t buflen));
Expand Down
16 changes: 0 additions & 16 deletions components/wifi/esp8266-driver/ESP8266Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,22 +507,6 @@ int ESP8266Interface::disconnect()
}
}

const char *ESP8266Interface::get_ip_address()
{
if (_software_conn_stat == IFACE_STATUS_DISCONNECTED) {
_esp.uart_enable_input(true);
}

const char *ip_buff = _esp.ip_addr();
if (!ip_buff || strcmp(ip_buff, "0.0.0.0") == 0) {
ip_buff = NULL;
}
if (_software_conn_stat == IFACE_STATUS_DISCONNECTED) {
_esp.uart_enable_input(false);
}
return ip_buff;
}

nsapi_error_t ESP8266Interface::get_ip_address(SocketAddress *address)
{
if (_software_conn_stat == IFACE_STATUS_DISCONNECTED) {
Expand Down
3 changes: 0 additions & 3 deletions components/wifi/esp8266-driver/ESP8266Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface {
*/
virtual nsapi_error_t get_ip_address(SocketAddress *address);

MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual const char *get_ip_address();

/** Get the internally stored MAC address
* @return MAC address of the interface
*/
Expand Down
2 changes: 0 additions & 2 deletions features/cellular/framework/API/CellularContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ class CellularContext : public CellularInterface {
virtual nsapi_error_t set_blocking(bool blocking) = 0;
virtual NetworkStack *get_stack() = 0;
virtual nsapi_error_t get_ip_address(SocketAddress *address) = 0;
MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual const char *get_ip_address() = 0;

/** Register callback for status reporting.
*
Expand Down
15 changes: 0 additions & 15 deletions features/cellular/framework/AT/AT_CellularContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,6 @@ nsapi_error_t AT_CellularContext::get_ip_address(SocketAddress *address)
#endif
}

const char *AT_CellularContext::get_ip_address()
{
#if NSAPI_PPP_AVAILABLE
return nsapi_ppp_get_ip_addr(_at.get_file_handle());
#else
if (!_stack) {
_stack = get_stack();
}
if (_stack) {
return _stack->get_ip_address();
}
return NULL;
#endif
}

char *AT_CellularContext::get_interface_name(char *interface_name)
{
if (_cid < 0) {
Expand Down
1 change: 0 additions & 1 deletion features/cellular/framework/AT/AT_CellularContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class AT_CellularContext : public CellularContext {
virtual nsapi_error_t set_blocking(bool blocking);
virtual NetworkStack *get_stack();
virtual nsapi_error_t get_ip_address(SocketAddress *address);
virtual const char *get_ip_address();
virtual char *get_interface_name(char *interface_name);
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
virtual nsapi_error_t connect();
Expand Down
43 changes: 0 additions & 43 deletions features/cellular/framework/AT/AT_CellularStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,49 +104,6 @@ nsapi_error_t AT_CellularStack::get_ip_address(SocketAddress *address)
return (ipv4 || ipv6) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_ADDRESS;
}

const char *AT_CellularStack::get_ip_address()
{
_at.lock();

bool ipv4 = false, ipv6 = false;

_at.cmd_start_stop("+CGPADDR", "=", "%d", _cid);
_at.resp_start("+CGPADDR:");

if (_at.info_resp()) {
_at.skip_param();

if (_at.read_string(_ip, PDP_IPV6_SIZE) != -1) {
convert_ipv6(_ip);
SocketAddress address;
address.set_ip_address(_ip);

ipv4 = (address.get_ip_version() == NSAPI_IPv4);
ipv6 = (address.get_ip_version() == NSAPI_IPv6);

// Try to look for second address ONLY if modem has support for dual stack(can handle both IPv4 and IPv6 simultaneously).
// Otherwise assumption is that second address is not reliable, even if network provides one.
if ((_device.get_property(AT_CellularDevice::PROPERTY_IPV4V6_PDP_TYPE) && (_at.read_string(_ip, PDP_IPV6_SIZE) != -1))) {
convert_ipv6(_ip);
address.set_ip_address(_ip);
ipv6 = (address.get_ip_version() == NSAPI_IPv6);
}
}
}
_at.resp_stop();
_at.unlock();

if (ipv4 && ipv6) {
_stack_type = IPV4V6_STACK;
} else if (ipv4) {
_stack_type = IPV4_STACK;
} else if (ipv6) {
_stack_type = IPV6_STACK;
}

return (ipv4 || ipv6) ? _ip : NULL;
}

void AT_CellularStack::set_cid(int cid)
{
_cid = cid;
Expand Down
3 changes: 0 additions & 3 deletions features/cellular/framework/AT/AT_CellularStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class AT_CellularStack : public NetworkStack {

virtual nsapi_error_t get_ip_address(SocketAddress *address);

MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
virtual const char *get_ip_address();

/**
* Set PDP context ID for this stack
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,6 @@ void UBLOX_AT_CellularContext::get_next_credentials(char **config)
}
}

const char *UBLOX_AT_CellularContext::get_gateway()
{
return get_ip_address();
}

nsapi_error_t UBLOX_AT_CellularContext::get_gateway(SocketAddress *addr)
{
return get_ip_address(addr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class UBLOX_AT_CellularContext: public AT_CellularContext {
virtual ~UBLOX_AT_CellularContext();

virtual void do_connect();
virtual const char *get_gateway();
virtual nsapi_error_t get_gateway(SocketAddress *addr);

const char *get_apn(void);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,6 @@ void UBLOX_AT_CellularStack::clear_socket(CellularSocket *socket)
}

#ifndef UBX_MDM_SARA_R41XM
const char *UBLOX_AT_CellularStack::get_ip_address()
{
SocketAddress address;

get_ip_address(&address);

return (address.get_ip_version()) ? (address.get_ip_address()) : NULL;
}

nsapi_error_t UBLOX_AT_CellularStack::get_ip_address(SocketAddress *address)
{
if (!address) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class UBLOX_AT_CellularStack : public AT_CellularStack {
virtual ~UBLOX_AT_CellularStack();

#ifndef UBX_MDM_SARA_R41XM
virtual const char *get_ip_address();

virtual nsapi_error_t get_ip_address(SocketAddress *address);
#endif

Expand Down
Loading