Skip to content

Commit

Permalink
event test added
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuhammedrafi committed Oct 18, 2024
1 parent 0f2d8db commit 53f37ca
Show file tree
Hide file tree
Showing 10 changed files with 935 additions and 48 deletions.
78 changes: 78 additions & 0 deletions GnomeProxy/NetworkManagerDbusMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,84 @@ namespace WPEFramework
return connection;
}

DbusMgr::DbusMgr() : connection(nullptr), error(nullptr)
{
NMLOG_INFO("DbusMgr");
connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (!connection) {
NMLOG_FATAL("Error connecting to system bus: %s ", error->message);
g_error_free(error);
}
}

DbusMgr::~DbusMgr() {
NMLOG_INFO("~DbusMgr");
if (connection) {
g_object_unref(connection);
connection = nullptr;
}
}

GDBusConnection* DbusMgr::getConnection()
{
if (connection) {
return connection;
}

connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (!connection && error) {
NMLOG_FATAL("Error reconnecting to system bus: %s ", error->message);
g_error_free(error);
return nullptr;
}

flags = static_cast<GDBusProxyFlags>(G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START);
return connection;
}

GDBusProxy* DbusMgr::getNetworkManagerProxy()
{
nmProxy = NULL;
nmProxy = g_dbus_proxy_new_sync(
getConnection(), G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
"org.freedesktop.NetworkManager",
NULL,
&error
);

if (nmProxy == NULL|| error != NULL) {
g_dbus_error_strip_remote_error(error);
NMLOG_FATAL("Error creating D-Bus proxy: %s", error->message);
g_error_free(error);
return nullptr;
}

return nmProxy;
}

GDBusProxy* DbusMgr::getNetworkManagerSettingsProxy()
{
return g_dbus_proxy_new_sync(
getConnection(), flags, NULL, "org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager/Settings",
"org.freedesktop.NetworkManager.Settings",
NULL,
&error
);
}

GDBusProxy* DbusMgr::getNetworkManagerDeviceProxy(const char* devicePath)
{
return g_dbus_proxy_new_sync(
getConnection(), flags, NULL, "org.freedesktop.NetworkManager",
devicePath,
"org.freedesktop.NetworkManager.Device",
NULL,
&error
);
}

} // Plugin
} // WPEFramework

20 changes: 19 additions & 1 deletion GnomeProxy/NetworkManagerDbusMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <list>

/* include NetworkManager.h for the defines, but we don't link against libnm. */
#include <nm-dbus-interface.h>
#include <libnm/nm-dbus-interface.h>

namespace WPEFramework
{
Expand All @@ -43,5 +43,23 @@ namespace WPEFramework
GDBusConnection* connection;
};

class DbusMgr {
public:
DbusMgr();
~DbusMgr();

GDBusProxy* getNetworkManagerProxy();
GDBusProxy* getNetworkManagerSettingsProxy();
GDBusProxy* getNetworkManagerDeviceProxy(const char* devicePath);
GDBusConnection* getConnection();

private:

GDBusConnection* connection;
GError* error;
GDBusProxyFlags flags;
GDBusProxy *nmProxy = NULL;
};

}
}
18 changes: 8 additions & 10 deletions GnomeProxy/NetworkManagerGnomeClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ namespace WPEFramework
{

NetworkManagerClient::NetworkManagerClient() {
NMLOG_INFO("NetworkManagerClient created");
if (!dbusConnection.InitializeBusConnection("org.freedesktop.NetworkManager")) {
NMLOG_ERROR("Failed to initialize D-Bus connection for NetworkManager");
}
NMLOG_INFO("NetworkManagerClient");
}

NetworkManagerClient::~NetworkManagerClient() {
NMLOG_INFO("NetworkManagerClient destroyed");
NMLOG_INFO("~NetworkManagerClient");
}

static bool getSSIDFromConnection(GDBusConnection *dbusConn, const std::string connPath, std::string& ssid)
Expand Down Expand Up @@ -97,7 +94,7 @@ namespace WPEFramework
G_VARIANT_LOOKUP(gVarConn, "type", "&s", &connTyp);
if(strcmp(connTyp, "802-11-wireless") != 0)
{
NMLOG_ERROR("connection is not 802-11-wireless type");
//NMLOG_DEBUG("ERROR: connection is not 802-11-wireless type");
ret = false;
}
else
Expand All @@ -124,13 +121,14 @@ namespace WPEFramework
ssid.empty();
}
}
if(value) {
g_variant_unref(value);
value = NULL;
}
}
if(value)
g_variant_unref(value);
g_variant_unref(setting);
setting = NULL;
}

if(!ssid.empty())
{
// 802-11-wireless-security.key-mgmt: wpa-psk
Expand Down Expand Up @@ -931,7 +929,7 @@ namespace WPEFramework
default:
state = Exchange::INetworkManager::WiFiState::WIFI_STATE_DISABLED;
}
NMLOG_DEBUG("nm Wifi sate %d mapped state %d ", (int)deviceProp.state, (int)state);
NMLOG_DEBUG("networkmanager wifi state (%d) mapped state (%d) ", (int)deviceProp.state, (int)state);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion GnomeProxy/NetworkManagerGnomeClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace WPEFramework
NetworkManagerClient();
~NetworkManagerClient();

DbusConnectionManager dbusConnection;
DbusMgr dbusConnection;
};
} // Plugin
} // WPEFramework
Loading

0 comments on commit 53f37ca

Please sign in to comment.