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

[acm] Fix Network.preferred() -> Network.prefer() #2717

Merged
merged 2 commits into from
Dec 14, 2023
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
2 changes: 1 addition & 1 deletion system/inc/system_dynalib_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ DYNALIB_FN(17, system_net, network_is_off, bool(network_handle_t, void*))
DYNALIB_FN(18, system_net, network_set_configuration, int(network_handle_t, const network_configuration_t*, void*))
DYNALIB_FN(19, system_net, network_get_configuration, int(network_handle_t, network_configuration_t**, size_t*, const char*, size_t, void*))
DYNALIB_FN(20, system_net, network_free_configuration, int(network_configuration_t*, size_t, void*))
DYNALIB_FN(21, system_net, network_preferred, network_handle_t(network_handle_t, bool, void*))
DYNALIB_FN(21, system_net, network_prefer, network_handle_t(network_handle_t, bool, void*))
DYNALIB_FN(22, system_net, network_is_preferred, bool(network_handle_t, void*))

DYNALIB_END(system_net)
Expand Down
2 changes: 1 addition & 1 deletion system/inc/system_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void network_off(network_handle_t network, uint32_t flags, uint32_t param1, void
bool network_is_on(network_handle_t network, void* reserved);
bool network_is_off(network_handle_t network, void* reserved);
int network_connect_cancel(network_handle_t network, uint32_t flags, uint32_t param1, void* reserved);
network_handle_t network_preferred(network_handle_t network, bool preferred, void* reserved);
network_handle_t network_prefer(network_handle_t network, bool prefer, void* reserved);
bool network_is_preferred(network_handle_t network, void* reserved);

#define NETWORK_LISTEN_EXIT (1<<0)
Expand Down
10 changes: 7 additions & 3 deletions system/src/system_connection_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ ConnectionManager* ConnectionManager::instance() {

void ConnectionManager::setPreferredNetwork(network_handle_t network, bool preferred) {
if (preferred) {
preferredNetwork_ = network;
} else if (network == preferredNetwork_) {
preferredNetwork_ = NETWORK_INTERFACE_ALL;
if (network != NETWORK_INTERFACE_ALL) {
preferredNetwork_ = network;
}
} else {
if (network == preferredNetwork_ || network == NETWORK_INTERFACE_ALL) {
preferredNetwork_ = NETWORK_INTERFACE_ALL;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion system/src/system_network_compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ int network_listen_command(network_handle_t network, network_listen_command_t co
return 0;
}

network_handle_t network_preferred(network_handle_t network, bool preferred, void* reserved) {
network_handle_t network_prefer(network_handle_t network, bool prefer, void* reserved) {
return network;
}

Expand Down
4 changes: 2 additions & 2 deletions system/src/system_network_manager_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ int network_listen_command(network_handle_t network, network_listen_command_t co
return ListeningModeHandler::instance()->enqueueCommand(command, arg);
}

network_handle_t network_preferred(network_handle_t network, bool preferred, void* reserved) {
ConnectionManager::instance()->setPreferredNetwork(network, preferred);
network_handle_t network_prefer(network_handle_t network, bool prefer, void* reserved) {
ConnectionManager::instance()->setPreferredNetwork(network, prefer);
return ConnectionManager::instance()->getPreferredNetwork();
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit_tests/stub/system_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int network_connect_cancel(network_handle_t network, uint32_t flags, uint32_t pa
return 0;
}

network_handle_t network_preferred(network_handle_t network, bool preferred, void* reserved) {
network_handle_t network_prefer(network_handle_t network, bool prefer, void* reserved) {
return network;
}

Expand Down
30 changes: 30 additions & 0 deletions user/tests/app/connection-manager/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,36 @@ void loop() {
// Run the internal connection test
system_internal(4, nullptr);
}
else if(c == '2') {
// Prefer wifi
WiFi.prefer();
// Confirm that we prefer wifi
if (Network.prefer() == WiFi) {
Log.info("Wifi is preferred");
}
// No longer prefer wifi, revert to default
WiFi.prefer(false);
if (Network.prefer() == Network) {
Log.info("Default is preferred");
}

// Prefer cellular
Cellular.prefer();
// Confirm cellular is preferred
if (Network.prefer() == Cellular) {
Log.info("Cellular is preferred");
}
// Confirm calling Network does not change preference
Network.prefer();
if (Network.prefer() == Cellular) {
Log.info("Cellular is still preferred");
}
// Clear any set network preference
Network.prefer(false);
if (Network.prefer() == Network) {
Log.info("Default is preferred");
}
}
else if(c == '3') {
Particle.disconnect(CloudDisconnectOptions().clearSession(true));
waitUntil(Particle.disconnected);
Expand Down
2 changes: 1 addition & 1 deletion wiring/inc/spark_wiring_network.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class NetworkClass
virtual void setListenTimeout(uint16_t timeout);
virtual uint16_t getListenTimeout();
virtual bool listening();
virtual NetworkClass& preferred(bool preferred = true);
virtual NetworkClass& prefer(bool prefer = true);
virtual bool isPreferred();

operator network_interface_t() const {
Expand Down
4 changes: 2 additions & 2 deletions wiring/src/spark_wiring_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ bool NetworkClass::listening() {
return network_listening(*this, 0, nullptr);
}

NetworkClass& NetworkClass::preferred(bool preferred) {
network_handle_t network = network_preferred(*this, preferred, nullptr);
NetworkClass& NetworkClass::prefer(bool prefer) {
network_handle_t network = network_prefer(*this, prefer, nullptr);
return Network.from(network);
}

Expand Down