Skip to content

Commit

Permalink
Code Enhancements to the NetworkManager Plugin (#68)
Browse files Browse the repository at this point in the history
Reason for change: Code Enhancements to the NetworkManager Plugin
Test Procedure: Sanity Testing
Risks: Medium
Signed-off-by: Karunakaran A <[email protected]>
  • Loading branch information
karuna2git committed Dec 31, 2024
1 parent 95fe8d6 commit 293031c
Show file tree
Hide file tree
Showing 11 changed files with 393 additions and 332 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ find_package(${NAMESPACE}Core REQUIRED)
find_package(${NAMESPACE}Plugins REQUIRED)
find_package(CURL)

set(PLUGIN_NETWORKMANAGER_STARTUPORDER "55" CACHE STRING "To configure startup order of Unified NetworkManager plugin")
set(PLUGIN_LEGACY_NW_STARTUPORDER "56" CACHE STRING "To configure startup order of Legacy Network plugin")
set(PLUGIN_LEGACY_WIFI_STARTUPORDER "56" CACHE STRING "To configure startup order of Legacy WiFi plugin")
set(PLUGIN_NETWORKMANAGER_STARTUPORDER "25" CACHE STRING "To configure startup order of Unified NetworkManager plugin")
set(PLUGIN_LEGACY_NW_STARTUPORDER "35" CACHE STRING "To configure startup order of Legacy Network plugin")
set(PLUGIN_LEGACY_WIFI_STARTUPORDER "35" CACHE STRING "To configure startup order of Legacy WiFi plugin")

set(PLUGIN_BUILD_REFERENCE ${PROJECT_VERSION} CACHE STRING "To Set the Hash for the plugin")
add_definitions(-DPLUGIN_BUILD_REFERENCE=${PLUGIN_BUILD_REFERENCE})
Expand Down
10 changes: 5 additions & 5 deletions INetworkManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace WPEFramework
INTERNET_LIMITED /* @text: LIMITED_INTERNET */,
INTERNET_CAPTIVE_PORTAL /* @text: CAPTIVE_PORTAL */,
INTERNET_FULLY_CONNECTED /* @text: FULLY_CONNECTED */,
INTERNET_UNKNOWN /* @text: NO_INTERNET */,
INTERNET_UNKNOWN /* @text: UNKNOWN */,
};

enum WiFiWPS : uint8_t
Expand Down Expand Up @@ -237,9 +237,9 @@ namespace WPEFramework
/* @brief Get Authentication URL if the device is behind Captive Portal */
virtual uint32_t GetCaptivePortalURI(string &uri/* @out */) const = 0;

/* @brief Start The Internet Connectivity Monitoring */
/* @brief Start The Internet Connectivity Monitoring */
virtual uint32_t StartConnectivityMonitoring(const uint32_t interval /* @in */) = 0;
/* @brief Stop The Internet Connectivity Monitoring */
/* @brief Stop The Internet Connectivity Monitoring */
virtual uint32_t StopConnectivityMonitoring(void) const = 0;

/* @brief Get the Public IP used for external world communication */
Expand Down Expand Up @@ -275,8 +275,8 @@ namespace WPEFramework
virtual uint32_t SetLogLevel(const Logging& level /* @in */) = 0;
virtual uint32_t GetLogLevel(Logging& level /* @out */) = 0;

/* @brief configure network manager plugin */
virtual uint32_t Configure(const string& configLine /* @in */) = 0;
/* @brief Configure the Network Manager plugin */
virtual uint32_t Configure(PluginHost::IShell* service /* @in */) = 0;

/* @event */
struct EXTERNAL INotification : virtual public Core::IUnknown
Expand Down
25 changes: 14 additions & 11 deletions LegacyPlugin_NetworkAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "NetworkManagerLogger.h"
#include "NetworkManagerJsonEnum.h"


using namespace std;
using namespace WPEFramework::Plugin;
#define API_VERSION_NUMBER_MAJOR 2
Expand Down Expand Up @@ -84,7 +83,6 @@ namespace WPEFramework
, m_subsInternetChange(false)
{
_gNWInstance = this;
m_defaultInterface = "wlan0";
m_timer.connect(std::bind(&Network::subscribeToEvents, this));
registerLegacyMethods();
}
Expand Down Expand Up @@ -167,7 +165,13 @@ namespace WPEFramework

void Network::Deinitialize(PluginHost::IShell* /* service */)
{
m_timer.stop();
unregisterLegacyMethods();

if (m_networkmanager)
m_networkmanager.reset();

m_networkmanager = NULL;
m_service->Release();
m_service = nullptr;
_gNWInstance = nullptr;
Expand Down Expand Up @@ -204,7 +208,7 @@ namespace WPEFramework
Register("getInternetConnectionState", &Network::getInternetConnectionState, this);
Register("ping", &Network::doPing, this);
Register("isConnectedToInternet", &Network::isConnectedToInternet, this);
Register("setStunEndPoint", &Network::setStunEndPoint, this);
Register("setStunEndPoint", &Network::setStunEndpoint, this);
Register("trace", &Network::doTrace, this);
Register("setConnectivityTestEndpoints", &Network::setConnectivityTestEndpoints, this);
Register("startConnectivityMonitoring", &Network::startConnectivityMonitoring, this);
Expand All @@ -219,6 +223,8 @@ namespace WPEFramework
*/
void Network::unregisterLegacyMethods(void)
{
Unregister("getStbIp");
Unregister("getSTBIPFamily");
Unregister("getInterfaces");
Unregister("isInterfaceEnabled");
Unregister("getPublicIP");
Expand All @@ -230,6 +236,8 @@ namespace WPEFramework
Unregister("getInternetConnectionState");
Unregister("ping");
Unregister("isConnectedToInternet");
Unregister("setStunEndPoint");
Unregister("trace");
Unregister("setConnectivityTestEndpoints");
Unregister("startConnectivityMonitoring");
Unregister("getCaptivePortalURI");
Expand Down Expand Up @@ -319,19 +327,19 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {
returnJson(rc);
}

uint32_t Network::setStunEndPoint(const JsonObject& parameters, JsonObject& response)
uint32_t Network::setStunEndpoint(const JsonObject& parameters, JsonObject& response)
{
LOG_INPARAM();
uint32_t rc = Core::ERROR_GENERAL;
string endPoint = parameters["server"].String();
string endpoint = parameters["server"].String();
uint32_t port = parameters["port"].Number();
uint32_t bindTimeout = parameters["timeout"].Number();
uint32_t cacheTimeout = parameters["cache_timeout"].Number();

auto _nwmgr = m_service->QueryInterfaceByCallsign<Exchange::INetworkManager>(NETWORK_MANAGER_CALLSIGN);
if (_nwmgr)
{
rc = _nwmgr->SetStunEndpoint(endPoint, port, bindTimeout, cacheTimeout);
rc = _nwmgr->SetStunEndpoint(endpoint, port, bindTimeout, cacheTimeout);
_nwmgr->Release();
}
else
Expand Down Expand Up @@ -1017,8 +1025,6 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {
legacyParams["oldInterfaceName"] = getInterfaceNameToType(parameters["prevActiveInterface"].String());
legacyParams["newInterfaceName"] = getInterfaceNameToType(parameters["currentActiveInterface"].String());

m_defaultInterface = parameters["currentActiveInterface"].String();

string json;
legacyParams.ToString(json);

Expand Down Expand Up @@ -1049,9 +1055,6 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {

Notify("onIPAddressStatusChanged", legacyParams);

// if ("ACQUIRED" == parameters["status"].String())
// m_defaultInterface = parameters["interface"].String();

return;
}

Expand Down
3 changes: 1 addition & 2 deletions LegacyPlugin_NetworkAPIs.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace WPEFramework {
uint32_t getCaptivePortalURI(const JsonObject& parameters, JsonObject& response);
uint32_t stopConnectivityMonitoring(const JsonObject& parameters, JsonObject& response);
uint32_t getPublicIP(const JsonObject& parameters, JsonObject& response);
uint32_t setStunEndPoint(const JsonObject& parameters, JsonObject& response);
uint32_t setStunEndpoint(const JsonObject& parameters, JsonObject& response);
uint32_t getStbIp(const JsonObject& parameters, JsonObject& response);
uint32_t getSTBIPFamily(const JsonObject& parameters, JsonObject& response);

Expand Down Expand Up @@ -88,7 +88,6 @@ namespace WPEFramework {
PluginHost::IShell* m_service;
std::shared_ptr<WPEFramework::JSONRPC::SmartLinkType<WPEFramework::Core::JSON::IElement>> m_networkmanager;
//WPEFramework::Exchange::INetworkManager* m_nwmgr;
string m_defaultInterface;
NetworkManagerTimer m_timer;

bool m_subsIfaceStateChange;
Expand Down
6 changes: 6 additions & 0 deletions LegacyPlugin_WiFiManagerAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ namespace WPEFramework

void WiFiManager::Deinitialize(PluginHost::IShell* /* service */)
{
m_timer.stop();
unregisterLegacyMethods();

if (m_networkmanager)
m_networkmanager.reset();

m_networkmanager = NULL;
m_service->Release();
m_service = nullptr;
_gWiFiInstance = nullptr;
Expand Down
19 changes: 12 additions & 7 deletions NetworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace WPEFramework
*/
const string NetworkManager::Initialize(PluginHost::IShell *service)
{
string message{};
// Make sure everything is null as we expect
ASSERT(_service == nullptr);
ASSERT(_networkManager == nullptr);
Expand All @@ -84,20 +85,24 @@ namespace WPEFramework
// Still running inside the main WPEFramework process - the child process will have now been spawned and registered if necessary
if (_networkManager != nullptr)
{
// set the plugin configuration
Exchange::INetworkManager::Logging _loglevel;
_networkManager->Configure(_service->ConfigLine());
if (_networkManager->Configure(service) != Core::ERROR_NONE)
{
SYSLOG(Logging::Startup, (_T("Configuring NetworkManager")));
message = _T("NetworkManager failed to configure");
}

// configure loglevel in libWPEFrameworkNetworkManager.so
// Set the plugin log level
Exchange::INetworkManager::Logging _loglevel;
_networkManager->GetLogLevel(_loglevel);
NetworkManagerLogger::SetLevel(static_cast <NetworkManagerLogger::LogLevel>(_loglevel));


// Register Notifications
_networkManager->Register(&_notification);

// Register all custom JSON-RPC methods
RegisterAllMethods();


// Get IPlugin interface for this plugin
_networkManagerImpl = _networkManager->QueryInterface<PluginHost::IPlugin>();
}
Expand All @@ -109,11 +114,11 @@ namespace WPEFramework
_service = nullptr;

// Returning a string signals that we failed to initialize - WPEFramework will print this as an error message
return "Failed to initialize NetworkManager";
message = _T("Failed to initialize NetworkManager");
}

// Success
return "";
return message;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion NetworkManager.json
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@
}
},
"GetWiFiSignalStrength":{
"summary": "Get WiFiSignalStrength of connected SSID. The signal quality is identifed based on the signal strength. The possible states are \n* 'Excellent' \n* 'Good' \n* 'Fair' \n* 'Weak' \n* 'Disconnected' \n",
"summary": "Get WiFiSignalStrength of connected SSID. The signal quality is identifed based on the signal strength. The possible states are\n* 'Excellent'\n* 'Good'\n* 'Fair'\n* 'Weak'\n* 'Disconnected'\n",
"events":{
"onWiFiSignalStrengthChange" : "Triggered when Wifi signal strength switches between Excellent, Good, Fair, Weak."
},
Expand Down
Loading

0 comments on commit 293031c

Please sign in to comment.