Skip to content

Commit

Permalink
Merge pull request rdkcentral#7 from karuna2git/develop
Browse files Browse the repository at this point in the history
DELIA-66318 : Update NetworkManager Plugin
  • Loading branch information
karuna2git authored Sep 18, 2024
2 parents 4392c33 + 3ae380d commit 0465aea
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 117 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ set(PLUGIN_LEGACY_DEPRECATED_WIFI ${NAMESPACE}WiFiManager)
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")

if(ENABLE_GNOME_NETWORKMANAGER)
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(LIBNM REQUIRED libnm)
Expand Down
1 change: 1 addition & 0 deletions LegacyPlugin_NetworkAPIs.conf.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
precondition = ["Platform"]
callsign = "org.rdk.Network"
autostart = "true"
startuporder = "@PLUGIN_LEGACY_NW_STARTUPORDER@"
1 change: 1 addition & 0 deletions LegacyPlugin_NetworkAPIs.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set (autostart true)
set (preconditions Platform)
set (callsign "org.rdk.Network")
set (startuporder ${PLUGIN_LEGACY_NW_STARTUPORDER})
19 changes: 2 additions & 17 deletions LegacyPlugin_NetworkAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ namespace WPEFramework
}

Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), (_T("127.0.0.1:9998")));
m_networkmanager = make_shared<WPEFramework::JSONRPC::LinkType<WPEFramework::Core::JSON::IElement> >(_T(NETWORK_MANAGER_CALLSIGN), _T(NETWORK_MANAGER_CALLSIGN), false, query);
m_networkmanager = make_shared<WPEFramework::JSONRPC::SmartLinkType<WPEFramework::Core::JSON::IElement> >(_T(NETWORK_MANAGER_CALLSIGN), _T("org.rdk.Network"), query);

doTheSubscriptions();
subscribeToEvents();
return string();
}

Expand Down Expand Up @@ -787,21 +787,6 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = {
}

/** Private */
void Network::doTheSubscriptions(void)
{
uint32_t result = Core::ERROR_ASYNC_FAILED;
Core::Event event(false, true);
Core::IWorkerPool::Instance().Submit(Core::ProxyType<Core::IDispatch>(Core::ProxyType<Job>::Create([&]() {
NMLOG_INFO ("Start Subscription %s", __FUNCTION__);
subscribeToEvents();
m_timer.start(SUBSCRIPTION_TIMEOUT_IN_MILLISECONDS);
event.SetEvent();
})));
event.Lock();

return;
}

void Network::subscribeToEvents(void)
{
uint32_t errCode = Core::ERROR_GENERAL;
Expand Down
3 changes: 1 addition & 2 deletions LegacyPlugin_NetworkAPIs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace WPEFramework {
void registerLegacyMethods(void);
void unregisterLegacyMethods(void);
void subscribeToEvents(void);
void doTheSubscriptions(void);
static std::string getInterfaceMapping(const std::string &interface);
void activatePrimaryPlugin();

Expand Down Expand Up @@ -83,7 +82,7 @@ namespace WPEFramework {

private:
PluginHost::IShell* m_service;
std::shared_ptr<WPEFramework::JSONRPC::LinkType<WPEFramework::Core::JSON::IElement>> m_networkmanager;
std::shared_ptr<WPEFramework::JSONRPC::SmartLinkType<WPEFramework::Core::JSON::IElement>> m_networkmanager;
string m_defaultInterface;
NetworkManagerTimer m_timer;

Expand Down
1 change: 1 addition & 0 deletions LegacyPlugin_WiFiManagerAPIs.conf.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
precondition = ["Platform"]
callsign = "org.rdk.Wifi"
autostart = "true"
startuporder = "@PLUGIN_LEGACY_WIFI_STARTUPORDER@"
1 change: 1 addition & 0 deletions LegacyPlugin_WiFiManagerAPIs.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set (autostart true)
set (preconditions Platform)
set (callsign "org.rdk.Wifi")
set (startuporder ${PLUGIN_LEGACY_WIFI_STARTUPORDER})
19 changes: 2 additions & 17 deletions LegacyPlugin_WiFiManagerAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ namespace WPEFramework
}

Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), (_T("127.0.0.1:9998")));
m_networkmanager = make_shared<WPEFramework::JSONRPC::LinkType<WPEFramework::Core::JSON::IElement> >(_T(NETWORK_MANAGER_CALLSIGN), _T(NETWORK_MANAGER_CALLSIGN), false, query);
m_networkmanager = make_shared<WPEFramework::JSONRPC::SmartLinkType<WPEFramework::Core::JSON::IElement> >(_T(NETWORK_MANAGER_CALLSIGN), _T("org.rdk.Wifi"), query);

doTheSubscriptions();
subscribeToEvents();
return string();
}

Expand Down Expand Up @@ -504,21 +504,6 @@ namespace WPEFramework
}

/** Private */
void WiFiManager::doTheSubscriptions(void)
{
uint32_t result = Core::ERROR_ASYNC_FAILED;
Core::Event event(false, true);
Core::IWorkerPool::Instance().Submit(Core::ProxyType<Core::IDispatch>(Core::ProxyType<Job>::Create([&]() {
NMLOG_INFO ("Start Subscription %s", __FUNCTION__);
subscribeToEvents();
m_timer.start(SUBSCRIPTION_TIMEOUT_IN_MILLISECONDS);
event.SetEvent();
})));
event.Lock();

return;
}

void WiFiManager::subscribeToEvents(void)
{
uint32_t errCode = Core::ERROR_GENERAL;
Expand Down
3 changes: 1 addition & 2 deletions LegacyPlugin_WiFiManagerAPIs.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,13 @@ namespace WPEFramework {
void registerLegacyMethods(void);
void unregisterLegacyMethods(void);
void subscribeToEvents(void);
void doTheSubscriptions(void);
static std::string getInterfaceMapping(const std::string &interface);
static bool ErrorCodeMapping(const uint32_t ipvalue , uint32_t &opvalue);
void activatePrimaryPlugin();

private:
PluginHost::IShell* m_service;
std::shared_ptr<WPEFramework::JSONRPC::LinkType<WPEFramework::Core::JSON::IElement>> m_networkmanager;
std::shared_ptr<WPEFramework::JSONRPC::SmartLinkType<WPEFramework::Core::JSON::IElement>> m_networkmanager;
NetworkManagerTimer m_timer;
bool m_subsWiFiStateChange;
bool m_subsAvailableSSIDs;
Expand Down
2 changes: 1 addition & 1 deletion NetworkManager.conf.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
autostart = "true"
callsign= "org.rdk.NetworkManager"
startuporder = "@PLUGIN_NETWORKMANAGER_STARTUPORDER@"

process= JSON()
process.add("outofprocess", "true")
Expand Down
2 changes: 1 addition & 1 deletion NetworkManager.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set(autostart true)
set(callsign "org.rdk.NetworkManager")
set (startuporder ${PLUGIN_NETWORKMANAGER_STARTUPORDER})

map()
key(root)
Expand Down
44 changes: 33 additions & 11 deletions NetworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ namespace WPEFramework
NetworkManager::NetworkManager()
: _connectionId(0),
_service(nullptr),
_NetworkManager(nullptr),
_networkManagerImpl(nullptr),
_networkManager(nullptr),
_notification(this)
{
// Don't do any work in the constructor - all set up should be done in Initialize
Expand All @@ -63,7 +64,7 @@ namespace WPEFramework
{
// Make sure everything is null as we expect
ASSERT(_service == nullptr);
ASSERT(_NetworkManager == nullptr);
ASSERT(_networkManager == nullptr);

// Syslog Startup messages are always printed by default
SYSLOG(Logging::Startup, (_T("Initializing NetworkManager")));
Expand All @@ -81,20 +82,23 @@ namespace WPEFramework
//
// Ideally for large, complex plugins we would actually split the plugin into two libraries - a thin library that just calls
// _service->Root to launch WPEProcess, and a larger library that is only ever run inside WPEProcess only (we do this for Cobalt and WebKitBrowser)
_NetworkManager = service->Root<Exchange::INetworkManager>(_connectionId, 25000, _T("NetworkManagerImplementation"));
_networkManager = service->Root<Exchange::INetworkManager>(_connectionId, 25000, _T("NetworkManagerImplementation"));

// Still running inside the main WPEFramework process - the child process will have now been spawned and registered if necessary
if (_NetworkManager != nullptr)
if (_networkManager != nullptr)
{
// set the plugin configuration
Exchange::INetworkManager::NMLogging _loglevel;
_NetworkManager->Configure(_service->ConfigLine(), _loglevel);
_networkManager->Configure(_service->ConfigLine(), _loglevel);
// configure loglevel in libWPEFrameworkNetworkManager.so
NetworkManagerLogger::SetLevel(static_cast <NetworkManagerLogger::LogLevel>(_loglevel));
_NetworkManager->Register(&_notification);
_networkManager->Register(&_notification);

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

// Get IPlugin interface for this plugin
_networkManagerImpl = _networkManager->QueryInterface<PluginHost::IPlugin>();
}
else
{
Expand All @@ -119,26 +123,44 @@ namespace WPEFramework
void NetworkManager::Deinitialize(PluginHost::IShell *service)
{
ASSERT(_service == service);
ASSERT(_NetworkManager != nullptr);
ASSERT(_networkManager != nullptr);

TRACE(Trace::Information, (_T("Deinitializing NetworkManager")));
TRACE(Trace::Information, (_T("Deinitialize running in process %d"), Core::ProcessInfo().Id()));

if (_NetworkManager != nullptr)
if (_networkManager != nullptr)
{
// TODO:: Work out exactly what triggers the shutdown of the out-of-process host
_service->Unregister(&_notification);
_NetworkManager->Unregister(&_notification);
_networkManager->Unregister(&_notification);

// Unregister all our JSON-RPC methods
UnregisterAllMethods();
_NetworkManager->Release();

// Release the IPlugin
if(_networkManagerImpl)
{
_networkManagerImpl->Release();
_networkManagerImpl = nullptr;
}

RPC::IRemoteConnection* connection = service->RemoteConnection(_connectionId);
_networkManager->Release();
if (connection != nullptr) {
// Lets trigger the cleanup sequence for
// out-of-process code. Which will guard
// that unwilling processes, get shot if
// not stopped friendly :-)
connection->Terminate();
connection->Release();
}
}

// Set everything back to default
_connectionId = 0;
_service = nullptr;
_NetworkManager = nullptr;
_networkManagerImpl = nullptr;
_networkManager = nullptr;
}

string NetworkManager::Information() const
Expand Down
5 changes: 3 additions & 2 deletions NetworkManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ namespace WPEFramework
// find the real implementation
// This allows other components to call QueryInterface<INetworkManager>() and
// receive the actual implementation (which could be in-process or out-of-process)
INTERFACE_AGGREGATE(Exchange::INetworkManager, _NetworkManager)
INTERFACE_AGGREGATE(Exchange::INetworkManager, _networkManager)
END_INTERFACE_MAP

/*
Expand Down Expand Up @@ -311,7 +311,8 @@ namespace WPEFramework
private:
uint32_t _connectionId;
PluginHost::IShell *_service;
Exchange::INetworkManager *_NetworkManager;
PluginHost::IPlugin* _networkManagerImpl;
Exchange::INetworkManager *_networkManager;
Core::Sink<Notification> _notification;
string m_publicIPAddress;
string m_defaultInterface;
Expand Down
Loading

0 comments on commit 0465aea

Please sign in to comment.