add dbus session prototype

This commit is contained in:
Evgenii Alekseev 2016-10-21 08:10:29 +03:00
parent 7568ae2a3b
commit c103986f37
9 changed files with 124 additions and 2 deletions

View File

@ -21,6 +21,7 @@
Q_LOGGING_CATEGORY(LOG_AW, "org.kde.plasma.awesomewidget",
QtMsgType::QtWarningMsg)
Q_LOGGING_CATEGORY(LOG_DBUS, "org.kde.plasma.awdbus", QtMsgType::QtWarningMsg)
Q_LOGGING_CATEGORY(LOG_DP, "org.kde.plasma.desktoppanel",
QtMsgType::QtWarningMsg)
Q_LOGGING_CATEGORY(LOG_ESM, "org.kde.plasma.extsysmon", QtMsgType::QtWarningMsg)

View File

@ -31,6 +31,7 @@ const char LOG_FORMAT[] = "[%{time "
Q_DECLARE_LOGGING_CATEGORY(LOG_AW)
Q_DECLARE_LOGGING_CATEGORY(LOG_DBUS)
Q_DECLARE_LOGGING_CATEGORY(LOG_DP)
Q_DECLARE_LOGGING_CATEGORY(LOG_ESM)
Q_DECLARE_LOGGING_CATEGORY(LOG_ESS)

View File

@ -0,0 +1,41 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awdbusadaptor.h"
#include "awdebug.h"
#include "awkeys.h"
AWDBusAdaptor::AWDBusAdaptor(AWKeys *parent)
: QDBusAbstractAdaptor(parent)
, m_plugin(parent)
{
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
}
AWDBusAdaptor::~AWDBusAdaptor()
{
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
}
qlonglong AWDBusAdaptor::whoAmI() const
{
return reinterpret_cast<qlonglong>(m_plugin);
}

View File

@ -0,0 +1,46 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef AWDBUSADAPTOR_H
#define AWDBUSADAPTOR_H
#include <QDBusAbstractAdaptor>
#include "version.h"
class AWKeys;
class AWDBusAdaptor : public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", AWDBUS_SERVICE_NAME)
public:
explicit AWDBusAdaptor(AWKeys *parent = nullptr);
~AWDBusAdaptor();
public slots:
qlonglong whoAmI() const;
private:
AWKeys *m_plugin = nullptr;
};
#endif /* AWDBUSADAPTOR_H */

View File

@ -17,7 +17,8 @@
#include "awkeys.h"
#include <QJSEngine>
#include <QDBusConnection>
#include <QDBusError>
#include <QRegExp>
#include <QThread>
#include <QTimer>
@ -25,6 +26,7 @@
#include "awdataaggregator.h"
#include "awdataengineaggregator.h"
#include "awdbusadaptor.h"
#include "awdebug.h"
#include "awkeycache.h"
#include "awkeyoperations.h"
@ -52,6 +54,8 @@ AWKeys::AWKeys(QObject *parent)
m_timer = new QTimer(this);
m_timer->setSingleShot(false);
createDBusInterface();
// update key data if required
connect(m_keyOperator, SIGNAL(updateKeys(QStringList)), this,
SLOT(reinitKeys(QStringList)));
@ -74,6 +78,11 @@ AWKeys::~AWKeys()
m_timer->stop();
delete m_timer;
// delete dbus session
long id = reinterpret_cast<long>(this);
QDBusConnection::sessionBus().unregisterObject(QString("/%1").arg(id));
QDBusConnection::sessionBus().unregisterService(AWDBUS_SERVICE);
// core
delete m_dataEngineAggregator;
delete m_threadPool;
@ -319,6 +328,23 @@ void AWKeys::calculateValues()
}
void AWKeys::createDBusInterface()
{
// get this object id
long id = reinterpret_cast<long>(this);
// create session
QDBusConnection bus = QDBusConnection::sessionBus();
if (!bus.registerService(AWDBUS_SERVICE))
qCWarning(LOG_AW) << "Could not register DBus service, last error"
<< bus.lastError().message();
if (!bus.registerObject(QString("/%1").arg(id), new AWDBusAdaptor(this),
QDBusConnection::ExportAllContents))
qCWarning(LOG_AW) << "Could not register DBus object, last error"
<< bus.lastError().message();
}
QString AWKeys::parsePattern(QString pattern) const
{
// screen sign

View File

@ -76,6 +76,7 @@ private slots:
private:
// methods
void calculateValues();
void createDBusInterface();
QString parsePattern(QString pattern) const;
void setDataBySource(const QString &sourceName, const QVariantMap &data);
// objects

View File

@ -45,7 +45,8 @@ public:
virtual ~DPAdds();
Q_INVOKABLE bool isDebugEnabled() const;
Q_INVOKABLE int currentDesktop() const;
Q_INVOKABLE QStringList dictKeys(const bool = true, const QString = QString()) const;
Q_INVOKABLE QStringList dictKeys(const bool = true,
const QString = QString()) const;
Q_INVOKABLE int numberOfDesktops() const;
Q_INVOKABLE QString toolTipImage(const int desktop) const;
Q_INVOKABLE QString parsePattern(const QString pattern,

View File

@ -45,6 +45,7 @@ foreach (TEST_MODULE ${TEST_MODULES})
set(${TEST_MODULE}_SOURCES ${${TEST_MODULE}_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awactions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awdataaggregator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awdataengineaggregator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awdbusadaptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awformatterhelper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awkeycache.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awkeyoperations.cpp

View File

@ -38,6 +38,10 @@ const int AWEWAPI = 3;
const int AWEFAPI = 2;
// telemetry api version
const int AWTEAPI = 1;
// dbus adaptor properties
// use define here instead of normal const definition for moc
#define AWDBUS_SERVICE_NAME "org.kde.plasma.awesomewidget"
const char AWDBUS_SERVICE[] = AWDBUS_SERVICE_NAME;
// network requests timeout, ms
const int REQUEST_TIMEOUT = 3000;
// available time keys