forked from openkylin/quarkai
Add QDbus module(system dbus and session dbus)
This commit is contained in:
parent
7256d8aa2b
commit
0c31512548
|
@ -16,5 +16,6 @@ kylin-assistant (1.0.0-0ubuntu1) bionic; urgency=low
|
|||
* Add auto startup manager.
|
||||
* Add monitor for auto startup manager.
|
||||
* Add monitor for file system.
|
||||
* Add QDbus module(system dbus and session dbus).
|
||||
|
||||
-- lixiang <lixiang@kylinos.cn> Mon, 29 Jan 2018 17:54:44 +0800
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
TEMPLATE = subdirs
|
||||
SUBDIRS = \
|
||||
systemdbus \
|
||||
sessiondbus
|
|
@ -0,0 +1,3 @@
|
|||
[D-BUS Service]
|
||||
Name=com.kylin.assistant.qsessiondbus
|
||||
Exec=/usr/lib/kylin-assistant/daemon/kylin-assistant-qsessiondbus-service
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="com.kylin.assistant.qsessiondbus">
|
||||
<method name="demoInfo">
|
||||
<arg type="s" direction="out"/>
|
||||
</method>
|
||||
<method name="exitService">
|
||||
</method>
|
||||
</interface>
|
||||
</node>
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.8
|
||||
* Command line was: qdbusxml2cpp com.kylin.assistant.qsessiondbus.xml -a sessionadaptor -c SessionAdaptor
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* Do not edit! All changes made to it will be lost.
|
||||
*/
|
||||
|
||||
#include "sessionadaptor.h"
|
||||
#include <QtCore/QMetaObject>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
/*
|
||||
* Implementation of adaptor class SessionAdaptor
|
||||
*/
|
||||
|
||||
SessionAdaptor::SessionAdaptor(QObject *parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
{
|
||||
// constructor
|
||||
setAutoRelaySignals(true);
|
||||
}
|
||||
|
||||
SessionAdaptor::~SessionAdaptor()
|
||||
{
|
||||
// destructor
|
||||
}
|
||||
|
||||
QString SessionAdaptor::demoInfo()
|
||||
{
|
||||
// handle method call com.kylin.assistant.qsessiondbus.demoInfo
|
||||
QString out0;
|
||||
QMetaObject::invokeMethod(parent(), "demoInfo", Q_RETURN_ARG(QString, out0));
|
||||
return out0;
|
||||
}
|
||||
|
||||
void SessionAdaptor::exitService()
|
||||
{
|
||||
// handle method call com.kylin.assistant.qsessiondbus.exitService
|
||||
QMetaObject::invokeMethod(parent(), "exitService");
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.8
|
||||
* Command line was: qdbusxml2cpp com.kylin.assistant.qsessiondbus.xml -a sessionadaptor -c SessionAdaptor
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* This file may have been hand-edited. Look for HAND-EDIT comments
|
||||
* before re-generating it.
|
||||
*/
|
||||
|
||||
#ifndef SESSIONADAPTOR_H
|
||||
#define SESSIONADAPTOR_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtDBus/QtDBus>
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QByteArray;
|
||||
template<class T> class QList;
|
||||
template<class Key, class Value> class QMap;
|
||||
class QString;
|
||||
class QStringList;
|
||||
class QVariant;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
/*
|
||||
* Adaptor class for interface com.kylin.assistant.qsessiondbus
|
||||
*/
|
||||
class SessionAdaptor: public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "com.kylin.assistant.qsessiondbus")
|
||||
Q_CLASSINFO("D-Bus Introspection", ""
|
||||
" <interface name=\"com.kylin.assistant.qsessiondbus\">\n"
|
||||
" <method name=\"demoInfo\">\n"
|
||||
" <arg direction=\"out\" type=\"s\"/>\n"
|
||||
" </method>\n"
|
||||
" <method name=\"exitService\"/>\n"
|
||||
" </interface>\n"
|
||||
"")
|
||||
public:
|
||||
SessionAdaptor(QObject *parent);
|
||||
virtual ~SessionAdaptor();
|
||||
|
||||
public: // PROPERTIES
|
||||
public Q_SLOTS: // METHODS
|
||||
QString demoInfo();
|
||||
void exitService();
|
||||
Q_SIGNALS: // SIGNALS
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd.
|
||||
*
|
||||
* Authors:
|
||||
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
|
||||
*
|
||||
* This program 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; version 3.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//qdbusxml2cpp -a sessionadaptor -c SessionAdaptor -l SessionAdaptor com.kylin.assistant.qsessiondbus.xml
|
||||
//qdbusxml2cpp com.kylin.assistant.qsessiondbus.xml -a sessionadaptor -c SessionAdaptor
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusError>
|
||||
#include <QDebug>
|
||||
|
||||
#include "sessionservice.h"
|
||||
#include "./data/sessionadaptor.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
app.setOrganizationName("kylin");
|
||||
app.setApplicationName("kylin-assistant-qsessiondbus-service");
|
||||
|
||||
SessionService service;
|
||||
// SessionService *service = new SessionService();
|
||||
new SessionAdaptor(&service);
|
||||
auto connection = QDBusConnection::sessionBus();
|
||||
if (!connection.registerService("com.kylin.assistant.qsessiondbus")) {
|
||||
qCritical() << "QDbus register service failed reason:" << connection.lastError();
|
||||
exit(1);
|
||||
}//QDBusConnection::sessionBus().unregisterService("com.kylin.assistant.qsessiondbus");
|
||||
|
||||
if (!connection.registerObject("/com/kylin/assistant/qsessiondbus",
|
||||
&service,
|
||||
QDBusConnection::ExportAllSlots |
|
||||
QDBusConnection::ExportAllSignals)) {
|
||||
qCritical() << "QDbus register object failed reason:" << connection.lastError();
|
||||
exit(2);
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
QT += core dbus
|
||||
QT -= gui
|
||||
|
||||
TARGET = kylin-assistant-qsessiondbus-service
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
CONFIG += console c++11 link_pkgconfig
|
||||
CONFIG -= app_bundle
|
||||
|
||||
SOURCES += main.cpp \
|
||||
sessionservice.cpp \
|
||||
./data/sessionadaptor.cpp
|
||||
|
||||
HEADERS += \
|
||||
sessionservice.h \
|
||||
./data/sessionadaptor.h
|
||||
|
||||
unix {
|
||||
isEmpty(PREFIX) {
|
||||
PREFIX = /usr
|
||||
}
|
||||
}
|
||||
|
||||
unix {
|
||||
UI_DIR = .ui
|
||||
MOC_DIR = .moc
|
||||
OBJECTS_DIR = .obj
|
||||
}
|
||||
|
||||
unix {
|
||||
service.files = $$PWD/data/com.kylin.assistant.qsessiondbus.service
|
||||
service.path = $${PREFIX}/share/dbus-1/services/
|
||||
|
||||
binary.files = $$TARGET
|
||||
binary.path = $${PREFIX}/lib/kylin-assistant/daemon/
|
||||
|
||||
INSTALLS += service binary
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd.
|
||||
*
|
||||
* Authors:
|
||||
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
|
||||
*
|
||||
* This program 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; version 3.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "sessionservice.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusContext>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusConnectionInterface>
|
||||
#include <QDebug>
|
||||
|
||||
SessionService::SessionService(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SessionService::~SessionService()
|
||||
{
|
||||
this->exitService();
|
||||
}
|
||||
|
||||
|
||||
QString SessionService::demoInfo()
|
||||
{
|
||||
return "QtSessionDbus";
|
||||
}
|
||||
|
||||
void SessionService::exitService()
|
||||
{
|
||||
qApp->exit(0);
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd.
|
||||
*
|
||||
* Authors:
|
||||
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
|
||||
*
|
||||
* This program 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; version 3.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SESSIONSERVICE_H
|
||||
#define SESSIONSERVICE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusContext>
|
||||
#include <QScopedPointer>
|
||||
|
||||
class SessionService : public QObject, protected QDBusContext
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "com.kylin.assistant.qsessiondbus")
|
||||
|
||||
public:
|
||||
explicit SessionService(QObject *parent = 0);
|
||||
virtual ~SessionService();
|
||||
|
||||
public slots:
|
||||
Q_SCRIPTABLE QString demoInfo();
|
||||
Q_SCRIPTABLE void exitService();
|
||||
|
||||
};
|
||||
|
||||
#endif // SESSIONSERVICE_H
|
|
@ -0,0 +1,29 @@
|
|||
#include <QDBusMetaType>
|
||||
|
||||
#include "customdata.h"
|
||||
|
||||
/*QDBusArgument &operator<<(QDBusArgument &argument, const CustomData &data) {
|
||||
argument.beginStructure();
|
||||
argument << data.hash << data.name << data.description << data.index << data.valid;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
const QDBusArgument &operator>>(const QDBusArgument &argument, CustomData &data) {
|
||||
argument.beginStructure();
|
||||
argument >> data.hash >> data.name >> data.description >> data.index >> data.valid;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
void CustomData::registerCustomDataMetaType()
|
||||
{
|
||||
qRegisterMetaType<CustomData>("CustomData");
|
||||
qDBusRegisterMetaType<CustomData>();
|
||||
}*/
|
||||
|
||||
void registerCustomDataMetaType()
|
||||
{
|
||||
qRegisterMetaType<CustomData>("CustomData");
|
||||
qDBusRegisterMetaType<CustomData>();
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
#ifndef CUSTOMDATA_H
|
||||
#define CUSTOMDATA_H
|
||||
|
||||
#include <QDBusMetaType>
|
||||
#include <QDBusArgument>
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
|
||||
class CustomData
|
||||
{
|
||||
public:
|
||||
QString hash;
|
||||
QString name;
|
||||
QString description;
|
||||
int index;
|
||||
bool valid;
|
||||
|
||||
// friend QDebug operator<<(QDebug argument, const CustomData &data);
|
||||
friend QDebug operator<<(QDebug argument, const CustomData &data) {
|
||||
argument << data.name;
|
||||
return argument;
|
||||
}
|
||||
|
||||
// friend QDBusArgument &operator<<(QDBusArgument &argument, const CustomData &data);
|
||||
friend QDBusArgument &operator<<(QDBusArgument &argument, const CustomData &data) {
|
||||
argument.beginStructure();
|
||||
argument << data.hash << data.name << data.description << data.index << data.valid;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
friend const QDBusArgument &operator>>(const QDBusArgument &argument, CustomData &data) {
|
||||
argument.beginStructure();
|
||||
argument >> data.hash >> data.name >> data.description >> data.index >> data.valid;
|
||||
argument.endStructure();
|
||||
return argument;
|
||||
}
|
||||
|
||||
bool operator==(const CustomData data) const {
|
||||
return data.hash == hash;
|
||||
}
|
||||
|
||||
bool operator!=(const CustomData data) const {
|
||||
return data.hash != hash;
|
||||
}
|
||||
|
||||
// static void registerCustomDataMetaType();
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(CustomData)
|
||||
|
||||
void registerCustomDataMetaType();
|
||||
|
||||
#endif // CUSTOMDATA_H
|
|
@ -0,0 +1,7 @@
|
|||
#include "customdatalist.h"
|
||||
|
||||
void registerCustomDataListMetaType()
|
||||
{
|
||||
qRegisterMetaType<CustomDataList>("CustomDataList");
|
||||
qDBusRegisterMetaType<CustomDataList>();
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef CUSTOMDATALIST_H
|
||||
#define CUSTOMDATALIST_H
|
||||
|
||||
#include <QDBusMetaType>
|
||||
#include <QList>
|
||||
|
||||
#include "customdata.h"
|
||||
|
||||
typedef QList<CustomData> CustomDataList;
|
||||
|
||||
Q_DECLARE_METATYPE(CustomDataList)
|
||||
|
||||
void registerCustomDataListMetaType();
|
||||
|
||||
#endif // CUSTOMDATALIST_H
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->
|
||||
|
||||
<!DOCTYPE busconfig PUBLIC
|
||||
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<busconfig>
|
||||
<!-- Only root can own the service -->
|
||||
<policy user="root">
|
||||
<allow own="com.kylin.assistant.qsystemdbus"/>
|
||||
<allow send_interface="com.kylin.assistant.qsystemdbus"/>
|
||||
</policy>
|
||||
|
||||
<!-- Allow anyone to invoke methods on the interfaces -->
|
||||
<policy context="default">
|
||||
<allow own="com.kylin.assistant.qsystemdbus"/>
|
||||
<allow send_destination="com.kylin.assistant.qsystemdbus"/>
|
||||
<allow send_destination="com.kylin.assistant.qsystemdbus"
|
||||
send_interface="com.kylin.assistant.qsystemdbus"/>
|
||||
<allow send_destination="com.kylin.assistant.qsystemdbus"
|
||||
send_interface="org.freedesktop.DBus.Properties"/>
|
||||
<allow send_destination="com.kylin.assistant.qsystemdbus"
|
||||
send_interface="org.freedesktop.DBus.Introspectable"/>
|
||||
</policy>
|
||||
</busconfig>
|
|
@ -0,0 +1,4 @@
|
|||
[D-BUS Service]
|
||||
Name=com.kylin.assistant.qsystemdbus
|
||||
Exec=/usr/lib/kylin-assistant/daemon/kylin-assistant-qsystemdbus-service
|
||||
User=root
|
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="com.kylin.assistant.qsystemdbus">
|
||||
<!--
|
||||
kobe test custom data(lixiang@kylinos.cn)
|
||||
-->
|
||||
<method name="demoInfo">
|
||||
<arg type="s" direction="out"/>
|
||||
</method>
|
||||
<method name="userIsActive">
|
||||
<arg name="user" type="s" direction="in"/>
|
||||
<arg name="active" type="b" direction="in"/>
|
||||
<arg type="b" direction="out"/>
|
||||
</method>
|
||||
<method name="getCustomData">
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="CustomData"/>
|
||||
<arg name="message" type="(sssib)" direction="out"/>
|
||||
</method>
|
||||
<method name="sendCustomData">
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="CustomData"/>
|
||||
<arg name="message" type="(sssib)" direction="in"/>
|
||||
</method>
|
||||
<method name="exitService">
|
||||
</method>
|
||||
<signal name="reportAlert">
|
||||
<arg name="ret" type="i" direction="out"/>
|
||||
<arg name="description" type="s" direction="out"/>
|
||||
</signal>
|
||||
<signal name="alertCustomData">
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="CustomData"/>
|
||||
<arg name="message" type="(sssib)" direction="out"/>
|
||||
</signal>
|
||||
<property name="Customs" type="a(sssib)" access="read">
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName" value="CustomDataList"/>
|
||||
</property>
|
||||
</interface>
|
||||
</node>
|
|
@ -0,0 +1,56 @@
|
|||
#pragma once
|
||||
|
||||
#include "systemdbusproxy.h"
|
||||
#include "systeminterface.h"
|
||||
#include "../customdata.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include <QDBusConnection>
|
||||
|
||||
class SystemDbusHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SystemDbusHandler(QObject *parent = 0)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_sysDbus = new SystemInterface("com.kylin.assistant.qsystemdbus",
|
||||
"/com/kylin/assistant/qsystemdbus",
|
||||
QDBusConnection::systemBus(),
|
||||
this);
|
||||
connect(m_sysDbus, &SystemInterface::reportAlert, this, &SystemDbusHandler::reportAlert);
|
||||
}
|
||||
|
||||
QString demoInfo()
|
||||
{
|
||||
return m_sysDbus->demoInfo();
|
||||
}
|
||||
|
||||
bool userIsActive(const QString &user, bool active)
|
||||
{
|
||||
return m_sysDbus->userIsActive(user, active);
|
||||
}
|
||||
|
||||
CustomData getCustomData()
|
||||
{
|
||||
return m_sysDbus->getCustomData();
|
||||
}
|
||||
|
||||
void sendCustomData(const CustomData &message)
|
||||
{
|
||||
m_sysDbus->sendCustomData(message);
|
||||
}
|
||||
|
||||
void exitService()
|
||||
{
|
||||
m_sysDbus->exitService();
|
||||
}
|
||||
|
||||
signals:
|
||||
void reportAlert(int ret, const QString &description);
|
||||
|
||||
private:
|
||||
SystemInterface *m_sysDbus = nullptr;
|
||||
};
|
|
@ -0,0 +1,47 @@
|
|||
#include "systemdbusproxy.h"
|
||||
#include "systemdbushandler.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QThread>
|
||||
|
||||
SystemDbusProxy::SystemDbusProxy(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
m_handler = new SystemDbusHandler;
|
||||
|
||||
QThread *handlerwork = new QThread;
|
||||
m_handler->moveToThread(handlerwork);
|
||||
handlerwork->start();
|
||||
|
||||
connect(m_handler, &SystemDbusHandler::reportAlert, this, &SystemDbusProxy::reportAlert);
|
||||
}
|
||||
|
||||
SystemDbusProxy::~SystemDbusProxy()
|
||||
{
|
||||
m_handler->deleteLater();
|
||||
}
|
||||
|
||||
QString SystemDbusProxy::demoInfo()
|
||||
{
|
||||
return m_handler->demoInfo();
|
||||
}
|
||||
|
||||
bool SystemDbusProxy::userIsActive(const QString &user, bool active)
|
||||
{
|
||||
return m_handler->userIsActive(user, active);
|
||||
}
|
||||
|
||||
CustomData SystemDbusProxy::getCustomData()
|
||||
{
|
||||
return m_handler->getCustomData();
|
||||
}
|
||||
|
||||
void SystemDbusProxy::sendCustomData(const CustomData &message)
|
||||
{
|
||||
m_handler->sendCustomData(message);
|
||||
}
|
||||
|
||||
void SystemDbusProxy::exitService()
|
||||
{
|
||||
m_handler->exitService();
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include "../customdata.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QScopedPointer>
|
||||
|
||||
class SystemDbusHandler;
|
||||
|
||||
class SystemDbusProxy : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SystemDbusProxy(QObject *parent = 0);
|
||||
~SystemDbusProxy();
|
||||
|
||||
QString demoInfo();
|
||||
bool userIsActive(const QString &user, bool active);
|
||||
CustomData getCustomData();
|
||||
void sendCustomData(const CustomData &message);
|
||||
void exitService();
|
||||
|
||||
signals:
|
||||
void reportAlert(int ret, const QString &description);
|
||||
|
||||
private:
|
||||
SystemDbusHandler *m_handler = nullptr;
|
||||
};
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.8
|
||||
* Command line was: qdbusxml2cpp -v -c SystemInterface -p systeminterface.h:systeminterface.cpp com.kylin.assistant.qsystemdbus.xml
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* This file may have been hand-edited. Look for HAND-EDIT comments
|
||||
* before re-generating it.
|
||||
*/
|
||||
|
||||
#include "systeminterface.h"
|
||||
|
||||
/*
|
||||
* Implementation of interface class SystemInterface
|
||||
*/
|
||||
|
||||
SystemInterface::SystemInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
|
||||
: QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
|
||||
{
|
||||
}
|
||||
|
||||
SystemInterface::~SystemInterface()
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.8
|
||||
* Command line was: qdbusxml2cpp -v -c SystemInterface -p systeminterface.h:systeminterface.cpp com.kylin.assistant.qsystemdbus.xml
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* Do not edit! All changes made to it will be lost.
|
||||
*/
|
||||
|
||||
#ifndef SYSTEMINTERFACE_H
|
||||
#define SYSTEMINTERFACE_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtDBus/QtDBus>
|
||||
|
||||
//NOTICE:add by manual
|
||||
#include "../customdata.h"
|
||||
#include "../customdatalist.h"
|
||||
|
||||
/*
|
||||
* Proxy class for interface com.kylin.assistant.qsystemdbus
|
||||
*/
|
||||
class SystemInterface: public QDBusAbstractInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static inline const char *staticInterfaceName()
|
||||
{ return "com.kylin.assistant.qsystemdbus"; }
|
||||
|
||||
public:
|
||||
SystemInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
|
||||
|
||||
~SystemInterface();
|
||||
|
||||
Q_PROPERTY(CustomDataList Customs READ customs)
|
||||
inline CustomDataList customs() const
|
||||
{ return qvariant_cast< CustomDataList >(property("Customs")); }
|
||||
|
||||
public Q_SLOTS: // METHODS
|
||||
inline QDBusPendingReply<QString> demoInfo()
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
return asyncCallWithArgumentList(QStringLiteral("demoInfo"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<> exitService()
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
return asyncCallWithArgumentList(QStringLiteral("exitService"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<CustomData> getCustomData()
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
return asyncCallWithArgumentList(QStringLiteral("getCustomData"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<> sendCustomData(CustomData message)
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << QVariant::fromValue(message);
|
||||
return asyncCallWithArgumentList(QStringLiteral("sendCustomData"), argumentList);
|
||||
}
|
||||
|
||||
inline QDBusPendingReply<bool> userIsActive(const QString &user, bool active)
|
||||
{
|
||||
QList<QVariant> argumentList;
|
||||
argumentList << QVariant::fromValue(user) << QVariant::fromValue(active);
|
||||
return asyncCallWithArgumentList(QStringLiteral("userIsActive"), argumentList);
|
||||
}
|
||||
|
||||
Q_SIGNALS: // SIGNALS
|
||||
void alertCustomData(CustomData message);
|
||||
void reportAlert(int ret, const QString &description);
|
||||
};
|
||||
|
||||
namespace com {
|
||||
namespace kylin {
|
||||
namespace assistant {
|
||||
typedef ::SystemInterface qsystemdbus;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd.
|
||||
*
|
||||
* Authors:
|
||||
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
|
||||
*
|
||||
* This program 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; version 3.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//qdbusxml2cpp -v -c SystemInterface -p systeminterface.h:systeminterface.cpp com.kylin.assistant.qsystemdbus.xml
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusError>
|
||||
#include <QDebug>
|
||||
|
||||
#include "systemservice.h"
|
||||
#include "customdata.h"
|
||||
#include "customdatalist.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
app.setOrganizationName("kylin");
|
||||
app.setApplicationName("kylin-assistant-qsystemdbus-service");
|
||||
|
||||
registerCustomDataMetaType();
|
||||
registerCustomDataListMetaType();
|
||||
|
||||
SystemService service;
|
||||
auto connection = QDBusConnection::systemBus();
|
||||
if (!connection.registerService("com.kylin.assistant.qsystemdbus")) {
|
||||
qCritical() << "QDbus register service failed reason:" << connection.lastError();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!connection.registerObject("/com/kylin/assistant/qsystemdbus",
|
||||
&service,
|
||||
QDBusConnection::ExportAllSlots |
|
||||
QDBusConnection::ExportAllSignals)) {
|
||||
qCritical() << "QDbus register object failed reason:" << connection.lastError();
|
||||
exit(2);
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
QT += core dbus
|
||||
QT -= gui
|
||||
|
||||
TARGET = kylin-assistant-qsystemdbus-service
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
CONFIG += console c++11 link_pkgconfig
|
||||
CONFIG -= app_bundle
|
||||
|
||||
SOURCES += main.cpp \
|
||||
systemservice.cpp \
|
||||
customdata.cpp \
|
||||
customdatalist.cpp
|
||||
|
||||
HEADERS += \
|
||||
systemservice.h \
|
||||
customdata.h \
|
||||
customdatalist.h
|
||||
|
||||
unix {
|
||||
isEmpty(PREFIX) {
|
||||
PREFIX = /usr
|
||||
}
|
||||
}
|
||||
|
||||
unix {
|
||||
UI_DIR = .ui
|
||||
MOC_DIR = .moc
|
||||
OBJECTS_DIR = .obj
|
||||
}
|
||||
|
||||
unix {
|
||||
service.files = $$PWD/data/com.kylin.assistant.qsystemdbus.service
|
||||
service.path = $${PREFIX}/share/dbus-1/system-services/
|
||||
|
||||
dbus.files = $$PWD/data/com.kylin.assistant.qsystemdbus.conf
|
||||
dbus.path = /etc/dbus-1/system.d/
|
||||
|
||||
binary.files = $$TARGET
|
||||
binary.path = $${PREFIX}/lib/kylin-assistant/daemon/
|
||||
|
||||
INSTALLS += service dbus binary
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd.
|
||||
*
|
||||
* Authors:
|
||||
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
|
||||
*
|
||||
* This program 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; version 3.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "systemservice.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusContext>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusConnectionInterface>
|
||||
#include <QDebug>
|
||||
|
||||
SystemService::SystemService(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SystemService::~SystemService()
|
||||
{
|
||||
this->exitService();
|
||||
}
|
||||
|
||||
bool SystemService::userIsActive(const QString &user, bool active)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QString SystemService::demoInfo()
|
||||
{
|
||||
emit this->reportAlert(0, "demo");
|
||||
|
||||
auto callerPid = static_cast<int>(this->connection().interface()->servicePid(this->message().service()).value());
|
||||
qDebug() << "callerPid="<<callerPid;
|
||||
return QString::number(callerPid);
|
||||
}
|
||||
|
||||
CustomData SystemService::getCustomData()
|
||||
{
|
||||
CustomData message;
|
||||
message.hash = "01234567890";
|
||||
message.name = "lixiang";
|
||||
message.description = "Engineer";
|
||||
message.index = 8;
|
||||
message.valid = true;
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
void SystemService::sendCustomData(const CustomData &message)
|
||||
{
|
||||
qDebug() << message.hash;
|
||||
}
|
||||
|
||||
void SystemService::exitService()
|
||||
{
|
||||
qApp->exit(0);
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd.
|
||||
*
|
||||
* Authors:
|
||||
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
|
||||
*
|
||||
* This program 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; version 3.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SYSTEMSERVICE_H
|
||||
#define SYSTEMSERVICE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusContext>
|
||||
#include <QScopedPointer>
|
||||
#include "customdata.h"
|
||||
|
||||
class SystemService : public QObject, protected QDBusContext
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "com.kylin.assistant.qsystemdbus")
|
||||
|
||||
public:
|
||||
explicit SystemService(QObject *parent = 0);
|
||||
virtual ~SystemService();
|
||||
|
||||
public slots:
|
||||
Q_SCRIPTABLE bool userIsActive(const QString &user, bool active);
|
||||
Q_SCRIPTABLE QString demoInfo();
|
||||
Q_SCRIPTABLE CustomData getCustomData();
|
||||
Q_SCRIPTABLE void sendCustomData(const CustomData &message);
|
||||
Q_SCRIPTABLE void exitService();
|
||||
|
||||
signals:
|
||||
Q_SCRIPTABLE void reportAlert(int ret, const QString &description);
|
||||
Q_SCRIPTABLE void alertCustomData(const CustomData &message);
|
||||
};
|
||||
|
||||
#endif // SYSTEMSERVICE_H
|
Loading…
Reference in New Issue