Skip to content

Commit

Permalink
event memory fix added
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuhammedrafi committed Dec 9, 2024
1 parent a5d5c01 commit e8bdf1f
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 67 deletions.
2 changes: 1 addition & 1 deletion NetworkManagerLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#endif

namespace NetworkManagerLogger {
static LogLevel gDefaultLogLevel = INFO_LEVEL;
static LogLevel gDefaultLogLevel = DEBUG_LEVEL;


#ifdef USE_RDK_LOGGER
Expand Down
4 changes: 2 additions & 2 deletions Tests/raspberrypi/NetworkManagerGdbusTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ int main() {
std::cout << "Enter SSID to scan (leave blank for all): ";
std::cin.ignore();
std::getline(std::cin, ssid);
nmEvents->setwifiScanOptions(true);
// nmEvents->setwifiScanOptions(true);
if (nmClient->startWifiScan(ssid)) {
NMLOG_INFO("WiFi scan started successfully");
} else {
Expand Down Expand Up @@ -227,6 +227,6 @@ int main() {
}

NMLOG_INFO("Program completed successfully");
nmEvents->stopNetworkMangerEventMonitor();
// nmEvents->stopNetworkMangerEventMonitor();
return 0;
}
22 changes: 6 additions & 16 deletions gdbus/NetworkManagerGdbusClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@ namespace WPEFramework
if(ConnProxy == NULL)
return false;

settingsProxy = g_dbus_proxy_call_sync(ConnProxy,
"GetSettings",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
settingsProxy = g_dbus_proxy_call_sync(ConnProxy, "GetSettings", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (!settingsProxy) {
g_dbus_error_strip_remote_error(error);
NMLOG_ERROR("Failed to get connection settings: %s", error->message);
Expand Down Expand Up @@ -156,13 +150,7 @@ namespace WPEFramework
if(ConnProxy == NULL)
return false;

deleteVar = g_dbus_proxy_call_sync(ConnProxy,
"Delete",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
deleteVar = g_dbus_proxy_call_sync(ConnProxy, "Delete", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (!deleteVar) {
g_dbus_error_strip_remote_error(error);
NMLOG_ERROR("Failed to get connection settings: %s", error->message);
Expand Down Expand Up @@ -886,17 +874,19 @@ namespace WPEFramework
wProxy = m_dbus.getNetworkManagerDeviceProxy(devInfo.path.c_str());
if(wProxy == NULL)
return false;

else
g_dbus_proxy_call_sync(wProxy, "Disconnect", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
return true;
if (error) {
NMLOG_ERROR("Error calling Disconnect method: %s", error->message);
g_error_free(error);
g_object_unref(wProxy);
return false;
}
else
NMLOG_INFO("wifi disconnected success");
NMLOG_INFO("wifi disconnected success");

g_object_unref(wProxy);
return true;
}

Expand Down
115 changes: 71 additions & 44 deletions gdbus/NetworkManagerGdbusEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,74 +359,76 @@ namespace WPEFramework
}

static void onConnectionSignalReceivedCB (GDBusProxy *proxy,
gchar *sender_name,
gchar *signal_name,
gchar *senderName,
gchar *signalName,
GVariant *parameters,
gpointer user_data) {
gpointer userData) {

if (g_strcmp0(signal_name, "NewConnection") == 0) {
NMLOG_INFO("new Connection added success");
if (g_strcmp0(senderName, "NewConnection") == 0) {
NMLOG_INFO("new connection added success");
NMLOG_DEBUG("Parameters: %s", g_variant_print(parameters, TRUE));
} else if (g_strcmp0(signal_name, "ConnectionRemoved") == 0) {
} else if (g_strcmp0(signalName, "ConnectionRemoved") == 0) {
NMLOG_INFO("connection remove success");
NMLOG_DEBUG("Parameters: %s", g_variant_print(parameters, TRUE));
}
}

static void ipV4addressChangeCb(GDBusProxy *proxy,
GVariant *changed_properties,
GStrv invalidated_properties,
gpointer user_data) {
if (changed_properties == NULL || proxy == NULL) {
NMLOG_FATAL("cb doesn't have changed_properties ");
static void ipV4addressChangeCb(GDBusProxy *proxy, GVariant *changedProps, GStrv invalidProps, gpointer userData)
{
if (changedProps == NULL || proxy == NULL) {
NMLOG_FATAL("cb doesn't have changed properties ");
return;
}

GVariant *addressDataVariant = g_variant_lookup_value(changed_properties, "Addresses", NULL);
if (addressDataVariant != NULL)
GVariant *addressVariant = g_variant_lookup_value(changedProps, "Addresses", NULL);
if (addressVariant != NULL)
{
const char* iface = static_cast<char*>(user_data);
const char* iface = static_cast<char*>(userData);
if(iface != NULL )
{
std::string ipAddr; uint32_t prifix;
if(GnomeUtils::getIpv4AddrFromIP4ConfigProxy(proxy, ipAddr, prifix))
NetworkManagerEvents::onAddressChangeCb(std::string(iface), true, false, ipAddr);
}
g_variant_unref(addressVariant);
}
}

static void ipV6addressChangeCb(GDBusProxy *proxy,
GVariant *changed_properties,
GStrv invalidated_properties,
gpointer user_data) {
if (changed_properties == NULL || proxy == NULL) {
NMLOG_FATAL("cb doesn't have changed_properties ");
static void ipV6addressChangeCb(GDBusProxy *proxy, GVariant *changedProps, GStrv invalidProps, gpointer userData)
{
if (changedProps == NULL || proxy == NULL) {
NMLOG_FATAL("cb doesn't have changed properties ");
return;
}

GVariant *addressDataVariant = g_variant_lookup_value(changed_properties, "Addresses", NULL);
if (addressDataVariant != NULL)
GVariant *addressVariant = g_variant_lookup_value(changedProps, "Addresses", NULL);
if (addressVariant != NULL)
{
const char* iface = static_cast<char*>(user_data);
if(iface != NULL )
const char* iface = static_cast<char*>(userData);
if(iface != NULL)
{
std::string ipAddr; uint32_t prifix;
if(GnomeUtils::getIpv6AddrFromIP6ConfigProxy(proxy, ipAddr, prifix))
NetworkManagerEvents::onAddressChangeCb(std::string(iface), true, true, ipAddr);
}

g_variant_unref(addressVariant);
}
else
{
GVariantIter *props_iter;
const gchar *property_name;
GVariant *property_value;
// TODO remove
GVariantIter *propsIter= NULL;
const gchar *propertyName= NULL;
GVariant *propertyValue= NULL;

// Iterate over all changed properties
g_variant_get(changed_properties, "a{sv}", &props_iter);
while (g_variant_iter_loop(props_iter, "{&sv}", &property_name, &property_value)) {
NMLOG_DEBUG("Other Property: %s", property_name);
g_variant_get(changedProps, "a{sv}", &propsIter);
while (g_variant_iter_loop(propsIter, "{&sv}", &propertyName, &propertyValue)) {
NMLOG_DEBUG("Other Property: %s", propertyName);
// if(propertyValue)
// g_variant_unref(changedProps);
}
g_variant_iter_free(props_iter);
g_variant_iter_free(propsIter);
}
}

Expand All @@ -452,44 +454,60 @@ namespace WPEFramework

g_signal_connect(deviceProxy, "g-signal", G_CALLBACK(deviceStateChangedCB), NULL);
NMLOG_DEBUG("Monitoring device: %s", devicePath);
if(ifname == _NetworkManagerEvents->wlanIfname)
if(ifname == GnomeUtils::getWifiIfname())
{
_NetworkManagerEvents->nmEvents.wirelessDeviceProxy = deviceProxy;
_NetworkManagerEvents->nmEvents.wifiDevicePath = devicePath;
userdata = _NetworkManagerEvents->wlanIfname; // TODO change to GnomeUtils::getWifiIfname()
subscribeForlastScanPropertyEvent(devicePath);
userdata = _NetworkManagerEvents->wlanIfname;
}
else{
else if(ifname == GnomeUtils::getEthIfname())
{
_NetworkManagerEvents->nmEvents.wiredDeviceProxy = deviceProxy;
_NetworkManagerEvents->nmEvents.ethDevicePath = devicePath;
userdata = _NetworkManagerEvents->ethIfname;
}

const gchar *ipv4ConfigPath = NULL;
const gchar *ipv6ConfigPath = NULL;
GVariant *ip4_config = g_dbus_proxy_get_cached_property(deviceProxy, "Ip4Config");
if (ip4_config) {
ipv4ConfigPath = g_variant_get_string(ip4_config, NULL);
GVariant *ip4Config = g_dbus_proxy_get_cached_property(deviceProxy, "Ip4Config");
if (ip4Config)
{
ipv4ConfigPath = g_variant_get_string(ip4Config, NULL);
NMLOG_DEBUG("Monitoring ip4_config_path: %s", ipv4ConfigPath);
}

GVariant *ip6_config = g_dbus_proxy_get_cached_property(deviceProxy, "Ip6Config");
if (ip6_config) {
ipv6ConfigPath = g_variant_get_string(ip6_config, NULL);
GVariant *ip6Config = g_dbus_proxy_get_cached_property(deviceProxy, "Ip6Config");
if(ip6Config)
{
ipv6ConfigPath = g_variant_get_string(ip6Config, NULL);
NMLOG_DEBUG("Monitoring ip6_config_path: %s", ipv6ConfigPath);
}

if(ipv4ConfigPath)
{
GDBusProxy *ipV4Proxy = _NetworkManagerEvents->eventDbus.getNetworkManagerIpv4Proxy(ipv4ConfigPath);
g_signal_connect(ipV4Proxy, "g-properties-changed", G_CALLBACK(ipV4addressChangeCb), userdata);
if(ifname == GnomeUtils::getEthIfname())
_NetworkManagerEvents->nmEvents.ethIPv4Proxy = ipV4Proxy;
else if(ifname == GnomeUtils::getWifiIfname())
_NetworkManagerEvents->nmEvents.wlanIPv4Proxy = ipV4Proxy;
}

if(ipv6ConfigPath)
{
GDBusProxy *ipV6Proxy = _NetworkManagerEvents->eventDbus.getNetworkManagerIpv6Proxy(ipv6ConfigPath);
g_signal_connect(ipV6Proxy, "g-properties-changed", G_CALLBACK(ipV6addressChangeCb), userdata);
if(ifname == GnomeUtils::getEthIfname())
_NetworkManagerEvents->nmEvents.ethIPv6Proxy = ipV6Proxy;
else if(ifname == GnomeUtils::getWifiIfname())
_NetworkManagerEvents->nmEvents.wlanIPv6Proxy = ipV6Proxy;
}

if(ip4Config)
g_variant_unref(ip4Config);
if(ip6Config)
g_variant_unref(ip6Config);
}

void* NetworkManagerEvents::networkMangerEventMonitor(void *arg)
Expand All @@ -512,12 +530,13 @@ namespace WPEFramework
GVariant *devices = g_dbus_proxy_get_cached_property(nmEvents->networkManagerProxy, "Devices");
if (devices != NULL) {
GVariantIter iter;
const gchar *devicePath;
gchar *devicePath = NULL;

g_variant_iter_init(&iter, devices);
while (g_variant_iter_loop(&iter, "&o", &devicePath)) {
monitorDevice(devicePath);
}

g_variant_unref(devices);
}

Expand All @@ -540,8 +559,16 @@ namespace WPEFramework
g_object_unref(nmEvents->networkManagerProxy);
if(nmEvents->settingsProxy)
g_object_unref(nmEvents->settingsProxy);

NMLOG_WARNING("stoping all event monitor");
if(nmEvents->ethIPv4Proxy)
g_object_unref(nmEvents->ethIPv4Proxy);
if(nmEvents->ethIPv6Proxy)
g_object_unref(nmEvents->ethIPv6Proxy);
if(nmEvents->wlanIPv4Proxy)
g_object_unref(nmEvents->wlanIPv4Proxy);
if(nmEvents->wlanIPv6Proxy)
g_object_unref(nmEvents->wlanIPv6Proxy);

NMLOG_WARNING("unregistered all event monitor");
return nullptr;
}

Expand Down
7 changes: 6 additions & 1 deletion gdbus/NetworkManagerGdbusEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ namespace WPEFramework
GDBusProxy *networkManagerProxy; // networkmanager main bus
GDBusProxy *settingsProxy; // settings

GDBusProxy *ethIPv4Proxy;
GDBusProxy *ethIPv6Proxy;
GDBusProxy *wlanIPv4Proxy;
GDBusProxy *wlanIPv6Proxy;

std::string wifiDevicePath;
std::string ethDevicePath;

Expand Down Expand Up @@ -69,7 +74,7 @@ namespace WPEFramework
std::atomic<bool>doScanNotify = {true};
GThread *eventThrdID;
public:
NMEvents nmEvents;
NMEvents nmEvents{};
DbusMgr eventDbus;
char wlanIfname[16];
char ethIfname[16];
Expand Down
5 changes: 2 additions & 3 deletions gdbus/NetworkManagerGdbusUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ namespace WPEFramework
if(iface != NULL)
{
properties.interface = iface;
//g_free(iface);
}
//NMLOG_DEBUG("Interface: %s", iface);
g_variant_unref(devicesVar);
Expand Down Expand Up @@ -272,10 +271,10 @@ namespace WPEFramework
return false;
}

GVariantIter* iter;
GVariantIter* iter = NULL;
gchar* devicePath = NULL;
g_variant_get(devicesVar, "(ao)", &iter);
while (g_variant_iter_loop(iter, "o", &devicePath))
while (iter != NULL && g_variant_iter_loop(iter, "o", &devicePath))
{
if(devicePath == NULL )
continue;
Expand Down

0 comments on commit e8bdf1f

Please sign in to comment.