Don't initialize MCE QDBusInterface on every D-Bus call

It's enough to initialize it once at startup.

Also avoided a few per-call ASCII => QString conversions and dropped
unnecessary mutex.
This commit is contained in:
Slava Monich 2020-10-10 16:55:46 +03:00
parent 65738a4ddf
commit 6e1e100a87
2 changed files with 17 additions and 20 deletions

View file

@ -26,11 +26,11 @@
#include <QUrl>
#include <QDateTime>
#include <QDBusConnection>
#include <QDBusInterface>
#define LOG(x) qDebug() << "[NotificationManager]" << x
NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, QObject *parent) : QObject(parent)
NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper) :
mceInterface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", QDBusConnection::systemBus())
{
LOG("Initializing...");
this->tdLibWrapper = tdLibWrapper;
@ -131,10 +131,8 @@ void NotificationManager::handleUpdateNotification(const QVariantMap updatedNoti
void NotificationManager::handleChatDiscovered(const QString &chatId, const QVariantMap &chatInformation)
{
this->chatListMutex.lock();
LOG("Adding chat to internal map" << chatId);
this->chatMap.insert(chatId, chatInformation);
this->chatListMutex.unlock();
}
void NotificationManager::handleNgfConnectionStatus(const bool &connected)
@ -226,13 +224,10 @@ QString NotificationManager::getNotificationText(const QVariantMap &notification
void NotificationManager::controlLedNotification(const bool &enabled)
{
LOG("Controlling notification LED" << enabled;
QDBusConnection dbusConnection = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "system");
QDBusInterface dbusInterface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", dbusConnection);
static const QString PATTERN("PatternCommunicationIM");
static const QString ACTIVATE("req_led_pattern_activate");
static const QString DEACTIVATE("req_led_pattern_deactivate");
if (enabled) {
dbusInterface.call("req_led_pattern_activate", "PatternCommunicationIM");
} else {
dbusInterface.call("req_led_pattern_deactivate", "PatternCommunicationIM");
}
LOG("Controlling notification LED" << enabled);
mceInterface.call(enabled ? ACTIVATE : DEACTIVATE, PATTERN);
}

View file

@ -21,7 +21,7 @@
#define NOTIFICATIONMANAGER_H
#include <QObject>
#include <QMutex>
#include <QDBusInterface>
#include <ngf-qt5/NgfClient>
#include "tdlibwrapper.h"
@ -29,7 +29,7 @@ class NotificationManager : public QObject
{
Q_OBJECT
public:
explicit NotificationManager(TDLibWrapper *tdLibWrapper, QObject *parent = nullptr);
NotificationManager(TDLibWrapper *tdLibWrapper);
~NotificationManager() override;
signals:
@ -48,17 +48,19 @@ public slots:
private:
TDLibWrapper *tdLibWrapper;
Ngf::Client *ngfClient;
QVariantMap chatMap;
QVariantMap notificationGroups;
QMutex chatListMutex;
QVariantMap sendNotification(const QString &chatId, const QVariantMap &notificationInformation, const QVariantMap &activeNotifications);
void removeNotification(const QVariantMap &notificationInformation);
QString getNotificationText(const QVariantMap &notificationContent);
void controlLedNotification(const bool &enabled);
private:
TDLibWrapper *tdLibWrapper;
Ngf::Client *ngfClient;
QVariantMap chatMap;
QVariantMap notificationGroups;
QDBusInterface mceInterface;
};
#endif // NOTIFICATIONMANAGER_H