Skip to content

Commit

Permalink
NetworkManger connectivitymonitor static class removed. (rdkcentral#5016
Browse files Browse the repository at this point in the history
)

* connectivity monitor singleton class removed

* wifisignal strength logic update

* connectivity monitor call backfunction removed

* RDK proxy error fix
  • Loading branch information
cmuhammedrafi authored Mar 13, 2024
1 parent 16d3aa5 commit 9ecef91
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 63 deletions.
16 changes: 4 additions & 12 deletions NetworkManager/service/NetworkConnectivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
#include <curl/curl.h>
#include "Module.h"
#include "NetworkConnectivity.h"

#include "NetworkManagerImplementation.h"

namespace WPEFramework {
namespace Plugin {

ConnectivityMonitor* ConnectivityMonitor::connectivityMonitor = nullptr;
extern NetworkManagerImplementation* _instance;

bool EndpointCache::isEndpointCashFileExist()
{
Expand Down Expand Up @@ -438,14 +438,6 @@ namespace WPEFramework {
return InternetConnectionState;
}

void ConnectivityMonitor::registerConnectivityMonitorCallback(NetworkManagerImplementation * impl)
{
if(impl != nullptr)
networkManagerImpl = impl;
else
NMLOG_ERROR("NetworkManagerImplementation pointer null");
}

bool ConnectivityMonitor::doContinuousConnectivityMonitoring(int timeoutInSeconds)
{
if(!isConnectivityMonitorEndpointSet())
Expand Down Expand Up @@ -591,11 +583,11 @@ namespace WPEFramework {
InternetConnectionState = testConnectivity(getConnectivityMonitorEndpoints(), TEST_CONNECTIVITY_DEFAULT_TIMEOUT_MS, NSM_IPRESOLVE_WHATEVER);
if(g_internetState.load() != InternetConnectionState)
{
if(networkManagerImpl != nullptr)
if(_instance != nullptr)
{
Exchange::INetworkManager::InternetStatus oldState = static_cast<Exchange::INetworkManager::InternetStatus>(g_internetState.load());
Exchange::INetworkManager::InternetStatus newstate = static_cast<Exchange::INetworkManager::InternetStatus>(InternetConnectionState);
networkManagerImpl->ReportInternetStatusChangedEvent(oldState , newstate);
_instance->ReportInternetStatusChangedEvent(oldState , newstate);
NMLOG_TRACE("ReportInternetStatusChangedEvent called");
}
else
Expand Down
17 changes: 2 additions & 15 deletions NetworkManager/service/NetworkConnectivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <mutex>
#include "Module.h"
#include "NetworkManagerLogger.h"
#include "NetworkManagerImplementation.h"

#define CAPTIVEPORTAL_MAX_LEN 512
#define DEFAULT_MONITOR_TIMEOUT 60 // in seconds
Expand Down Expand Up @@ -102,16 +101,6 @@ namespace WPEFramework {

class ConnectivityMonitor : public Connectivity {
public:
static ConnectivityMonitor* getInstance()
{
if (connectivityMonitor == nullptr) {
static ConnectivityMonitor instance;
connectivityMonitor = &instance;
}
return connectivityMonitor;
}

void registerConnectivityMonitorCallback(NetworkManagerImplementation * impl);
bool isConnectedToInternet(nsm_ipversion ipversion);
nsm_internetState getInternetConnectionState(nsm_ipversion ipversion);
std::string getCaptivePortalURI();
Expand All @@ -126,16 +115,17 @@ namespace WPEFramework {
void signalConnectivityMonitor();
void resetConnectivityCache() { g_internetState = nsm_internetState::UNKNOWN;}

private:
ConnectivityMonitor() : stopFlag(false), threadRunning(false), isContinuesMonitoringNeeded(false)
{
setConnectivityMonitorEndpoints(getConnectivityDefaultEndpoints());
}

~ConnectivityMonitor() {
NMLOG_INFO("~ConnectivityMonitor");
stopContinuousConnectivityMonitoring();
}

private:
ConnectivityMonitor(const ConnectivityMonitor&) = delete;
ConnectivityMonitor& operator=(const ConnectivityMonitor&) = delete;
void connectivityMonitorFunction();
Expand All @@ -153,9 +143,6 @@ namespace WPEFramework {
std::mutex mutex_;
std::mutex endpointMutex;
std::atomic<nsm_internetState> g_internetState = {nsm_internetState::UNKNOWN};
public:
static ConnectivityMonitor *connectivityMonitor;
NetworkManagerImplementation *networkManagerImpl = nullptr;
};
} // namespace Plugin
} // namespace WPEFramework
1 change: 1 addition & 0 deletions NetworkManager/service/NetworkManagerGnomeProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace WPEFramework

void NetworkManagerImplementation::platform_init()
{
::_instance = this;
GError *error = NULL;
GMainContext *context = g_main_context_new();
// initialize the NMClient object
Expand Down
18 changes: 8 additions & 10 deletions NetworkManager/service/NetworkManagerImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ namespace WPEFramework
/* Name says it all */
platform_init();

/* set the callback function of connectivity monitor*/
ConnectivityMonitor::getInstance()->registerConnectivityMonitorCallback(this);
WifiSignalStrengthMonitor::getInstance()->registerWifiSignalStrengthNotify(this);
/* Initialize STUN Endpoints */
m_stunEndPoint = "stun.l.google.com";
m_stunPort = 19302;
Expand All @@ -57,6 +54,7 @@ namespace WPEFramework

NetworkManagerImplementation::~NetworkManagerImplementation()
{
connectivityMonitor.stopContinuousConnectivityMonitoring();
LOG_ENTRY_FUNCTION();
}

Expand Down Expand Up @@ -141,7 +139,7 @@ namespace WPEFramework
endpoints.push_back(config.connectivity.endpoint_5.Value().c_str());

//set connectivity endpoint
ConnectivityMonitor::getInstance()->setConnectivityMonitorEndpoints(endpoints);
connectivityMonitor.setConnectivityMonitorEndpoints(endpoints);
}
else
NMLOG_ERROR("Plugin configuration read error !");
Expand Down Expand Up @@ -178,7 +176,7 @@ namespace WPEFramework
uint32_t NetworkManagerImplementation::GetConnectivityTestEndpoints(IStringIterator*& endPoints/* @out */) const
{
LOG_ENTRY_FUNCTION();
std::vector<std::string> tmpEndPoints = ConnectivityMonitor::getInstance()->getConnectivityMonitorEndpoints();
std::vector<std::string> tmpEndPoints = connectivityMonitor.getConnectivityMonitorEndpoints();
endPoints = (Core::Service<RPC::StringIterator>::Create<RPC::IStringIterator>(tmpEndPoints));

return Core::ERROR_NONE;
Expand All @@ -196,7 +194,7 @@ namespace WPEFramework
{
tmpEndPoints.push_back(endPoint);
}
ConnectivityMonitor::getInstance()->setConnectivityMonitorEndpoints(tmpEndPoints);
connectivityMonitor.setConnectivityMonitorEndpoints(tmpEndPoints);
}
return Core::ERROR_NONE;
}
Expand All @@ -212,7 +210,7 @@ namespace WPEFramework
else if(0 == strcasecmp("IPv6", ipversion.c_str()))
tmpVersion = NSM_IPRESOLVE_V6;

isconnected = ConnectivityMonitor::getInstance()->getInternetConnectionState(tmpVersion);
isconnected = connectivityMonitor.getInternetConnectionState(tmpVersion);
if (FULLY_CONNECTED == isconnected)
result = INTERNET_FULLY_CONNECTED;
else if (CAPTIVE_PORTAL == isconnected)
Expand All @@ -229,15 +227,15 @@ namespace WPEFramework
uint32_t NetworkManagerImplementation::GetCaptivePortalURI(string &endPoints/* @out */) const
{
LOG_ENTRY_FUNCTION();
endPoints = ConnectivityMonitor::getInstance()->getCaptivePortalURI();
endPoints = connectivityMonitor.getCaptivePortalURI();
return Core::ERROR_NONE;
}

/* @brief Start The Internet Connectivity Monitoring */
uint32_t NetworkManagerImplementation::StartConnectivityMonitoring(const uint32_t interval/* @in */)
{
LOG_ENTRY_FUNCTION();
if (ConnectivityMonitor::getInstance()->doContinuousConnectivityMonitoring(interval))
if (connectivityMonitor.doContinuousConnectivityMonitoring(interval))
return Core::ERROR_NONE;
else
return Core::ERROR_GENERAL;
Expand All @@ -247,7 +245,7 @@ namespace WPEFramework
uint32_t NetworkManagerImplementation::StopConnectivityMonitoring(void) const
{
LOG_ENTRY_FUNCTION();
if (ConnectivityMonitor::getInstance()->stopContinuousConnectivityMonitoring())
if (connectivityMonitor.stopContinuousConnectivityMonitoring())
return Core::ERROR_NONE;
else
return Core::ERROR_GENERAL;
Expand Down
5 changes: 5 additions & 0 deletions NetworkManager/service/NetworkManagerImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ using namespace std;
//#include <interfaces/INetworkManager.h>
#include "INetworkManager.h"
#include "NetworkManagerLogger.h"
#include "WifiSignalStrengthMonitor.h"
#include "NetworkConnectivity.h"
#include "StunClient.h"

#define LOG_ENTRY_FUNCTION() { NMLOG_TRACE("Entering=%s", __FUNCTION__ ); }
Expand Down Expand Up @@ -231,6 +233,9 @@ namespace WPEFramework
uint16_t m_stunPort;
uint16_t m_stunBindTimeout;
uint16_t m_stunCacheTimeout;
public:
WifiSignalStrengthMonitor wifiSignalStrengthMonitor;
mutable ConnectivityMonitor connectivityMonitor;
};
}
}
2 changes: 1 addition & 1 deletion NetworkManager/service/NetworkManagerRDKProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ namespace WPEFramework

state = to_wifi_state(e->data.wifiStateChange.state);
if(e->data.wifiStateChange.state == WIFI_CONNECTED)
WifiSignalStrengthMonitor::getInstance()->startWifiSignalStrengthMonitor(DEFAULT_WIFI_SIGNAL_TEST_INTERVAL_SEC);
::_instance->wifiSignalStrengthMonitor.startWifiSignalStrengthMonitor(DEFAULT_WIFI_SIGNAL_TEST_INTERVAL_SEC);
::_instance->ReportWiFiStateChangedEvent(state);
break;
}
Expand Down
14 changes: 3 additions & 11 deletions NetworkManager/service/WifiSignalStrengthMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ namespace WPEFramework
{
namespace Plugin
{

WifiSignalStrengthMonitor* WifiSignalStrengthMonitor::wifiSignalStrengthMonitor = nullptr;

static const float signalStrengthThresholdExcellent = -50.0f;
static const float signalStrengthThresholdGood = -60.0f;
static const float signalStrengthThresholdFair = -67.0f;
extern NetworkManagerImplementation* _instance;

std::string WifiSignalStrengthMonitor::retrieveValues(const char *command, const char* keyword, char *output_buffer, size_t output_buffer_size)
{
Expand Down Expand Up @@ -117,15 +115,15 @@ namespace WPEFramework
string ssid = "";
string signalStrength;
Exchange::INetworkManager::WiFiSignalQuality newSignalQuality;
if (networkManagerImpl != nullptr)
if (_instance != nullptr)
{
NMLOG_TRACE("checking WiFi signal strength");
getSignalData(ssid, newSignalQuality, signalStrength);
if(oldSignalQuality != newSignalQuality)
{
NMLOG_INFO("Notifying WiFiSignalStrengthChangedEvent ...%s", signalStrength.c_str());
oldSignalQuality = newSignalQuality;
networkManagerImpl->ReportWiFiSignalStrengthChangedEvent(ssid, signalStrength, newSignalQuality);
_instance->ReportWiFiSignalStrengthChangedEvent(ssid, signalStrength, newSignalQuality);
}

if(newSignalQuality == Exchange::INetworkManager::WIFI_SIGNAL_DISCONNECTED)
Expand All @@ -142,11 +140,5 @@ namespace WPEFramework
}
isRunning = false;
}

void WifiSignalStrengthMonitor::registerWifiSignalStrengthNotify(NetworkManagerImplementation* nmImpl)
{
NMLOG_INFO("Registered WifiSignalStrength Notification !");
networkManagerImpl = nmImpl;
}
}
}
16 changes: 2 additions & 14 deletions NetworkManager/service/WifiSignalStrengthMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <atomic>
#include "Module.h"
#include "NetworkManagerLogger.h"
#include "NetworkManagerImplementation.h"

#define DEFAULT_WIFI_SIGNAL_TEST_INTERVAL_SEC 60
namespace WPEFramework
Expand All @@ -36,26 +35,15 @@ namespace WPEFramework
class WifiSignalStrengthMonitor
{
public:
static WifiSignalStrengthMonitor *wifiSignalStrengthMonitor;
WifiSignalStrengthMonitor(): networkManagerImpl(nullptr), isRunning(false) {}
WifiSignalStrengthMonitor():isRunning(false) {}
~WifiSignalStrengthMonitor(){ NMLOG_INFO("~WifiSignalStrengthMonitor"); }
void startWifiSignalStrengthMonitor(int interval);
void getSignalData(std::string &ssid, Exchange::INetworkManager::WiFiSignalQuality &quality, std::string &strengthOut);
void registerWifiSignalStrengthNotify(NetworkManagerImplementation* nmImpl);
static WifiSignalStrengthMonitor* getInstance()
{
if (wifiSignalStrengthMonitor == nullptr) {
static WifiSignalStrengthMonitor instance;
wifiSignalStrengthMonitor = &instance;
}
return wifiSignalStrengthMonitor;
}
private:
std::string retrieveValues(const char *command, const char* keyword, char *output_buffer, size_t output_buffer_size);
NetworkManagerImplementation* networkManagerImpl;
std::thread monitorThread;
std::atomic<bool> stopThread;
std::atomic<bool> isRunning;

void monitorThreadFunction(int interval);
};
}
Expand Down

0 comments on commit 9ecef91

Please sign in to comment.