diff options
author | Emanoil Kotsev <deloptes@gmail.com> | 2024-06-26 20:21:35 +0000 |
---|---|---|
committer | Emanoil Kotsev <deloptes@gmail.com> | 2024-11-09 18:49:26 +0000 |
commit | 7ea09f3f10350e44b8b41566f50449219cf6a4bf (patch) | |
tree | 13f43bb3f49078d63cdc992a5f50301bcba6e10d /src/daemon/NotificationDaemon.cpp | |
parent | fddb92945609b0b1f69967a9729f030b712ebdca (diff) | |
download | kdbusnotification-7ea09f3f10350e44b8b41566f50449219cf6a4bf.tar.gz kdbusnotification-7ea09f3f10350e44b8b41566f50449219cf6a4bf.zip |
Update and clean up
Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
Diffstat (limited to 'src/daemon/NotificationDaemon.cpp')
-rw-r--r-- | src/daemon/NotificationDaemon.cpp | 81 |
1 files changed, 43 insertions, 38 deletions
diff --git a/src/daemon/NotificationDaemon.cpp b/src/daemon/NotificationDaemon.cpp index 2b3979d..c982883 100644 --- a/src/daemon/NotificationDaemon.cpp +++ b/src/daemon/NotificationDaemon.cpp @@ -26,16 +26,16 @@ #include "NotificationDaemon.h" -#define NOTIFICATIONS_DBUS_PATH "/org/freedesktop/Notifications" +// path /org/freedesktop/Notifications #define NOTIFICATIONS_DBUS_SRVC "org.freedesktop.Notifications" #define DBUS_CONNECTION_TIMEOUT 4000 #define DBUS_CONNECTION_RETRY 3 -NotificationDaemon::NotificationDaemon() : KUniqueApplication() +NotificationDaemon::NotificationDaemon() + : KUniqueApplication(), + retryCount(0) { - // TODO Auto-generated constructor stub - retryCount=0; // init session connection to dbus if (!initDBUS()) { tqDebug("Failed to initialize the connection to DBus"); @@ -47,16 +47,7 @@ NotificationDaemon::NotificationDaemon() : KUniqueApplication() NotificationDaemon::~NotificationDaemon() { // close D-Bus connection - close(); - - delete notificationNodeService; - delete freedesktopService; - delete orgService; - delete rootService; -} - -bool NotificationDaemon::isConnectedToDBUS(){ - return mConnection.isConnected(); + dbusConnectionClose(); } bool NotificationDaemon::initDBUS(){ @@ -67,29 +58,51 @@ bool NotificationDaemon::initDBUS(){ + mConnection.lastError().message()); return false; } + mConnection.connect(this, TQ_SLOT(slotDbusSignal(const TQT_DBusMessage&))); // try to get a specific service name if (!mConnection.requestName(NOTIFICATIONS_DBUS_SRVC, TQT_DBusConnection::NoReplace)) return false; + // make sure we get a reply mConnection.scheduleDispatch(); - mConnection.connect(this, TQ_SLOT(slotDbusSignal(const TQT_DBusMessage&))); - - TQTimer::singleShot(10, this, TQ_SLOT(slotConnectionCheck())); return true; } -void NotificationDaemon::close() { +void NotificationDaemon::dbusConnectionClose() { + + if(rootService) + { + delete rootService; + rootService=0; + } + if(orgService) + { + delete orgService; + orgService=0; + } + if(freedesktopService) + { + delete freedesktopService; + freedesktopService=0; + } + if(notificationNodeService) + { + delete notificationNodeService; + notificationNodeService=0; + } + if(mConnection.isConnected()) { mConnection.disconnect(this, TQ_SLOT(slotDbusSignal(const TQT_DBusMessage&))); mConnection.closeConnection(NOTIFICATIONS_DBUS_SRVC); } + retryCount=0; } void NotificationDaemon::slotReconnect() { - close(); + dbusConnectionClose(); if (!initDBUS()) { if (DBUS_CONNECTION_RETRY > retryCount) { @@ -101,26 +114,18 @@ void NotificationDaemon::slotReconnect() { } void NotificationDaemon::slotDbusSignal(const TQT_DBusMessage& message) { - if (message.interface() != TQString("org.freedesktop.DBus")) - return; - if (message.member() != TQString("NameAcquired")) - return; - tqDebug("Name acquired: " + message[0].toString()); - serviceName = message[0].toString(); -} - -void NotificationDaemon::slotConnectionCheck() { - - if (serviceName != NOTIFICATIONS_DBUS_SRVC) { - tqFatal("TDE Notification service already running or no unique name possible."); + TQString serviceName = message[0].toString(); + if ( message.interface() == TQString("org.freedesktop.DBus") && + message.member() == TQString("NameAcquired") && + serviceName == NOTIFICATIONS_DBUS_SRVC ) + { + tqDebug("TDENotification unique DBus name acquired: " + serviceName); + rootService = new RootNodeService(mConnection); + orgService = new OrgNodeService(mConnection); + freedesktopService = new FreeDesktopNodeService(mConnection); + notificationNodeService = new NotificationsNodeService(mConnection); + tqDebug("TDENotification service setup done."); } - - rootService = new RootNodeService(mConnection); - orgService = new OrgNodeService(mConnection); - freedesktopService = new FreeDesktopNodeService(mConnection); - notificationNodeService = new NotificationsNodeService(mConnection); - - tqDebug("TDE Notification service setup done."); } #include "NotificationDaemon.moc" |