diff --git a/debian/changelog b/debian/changelog index e7ffbc1..1d72239 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Mon, 29 Jan 2018 17:54:44 +0800 diff --git a/qdbusservice/qdbusservice.pro b/qdbusservice/qdbusservice.pro new file mode 100644 index 0000000..5581c9c --- /dev/null +++ b/qdbusservice/qdbusservice.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS = \ + systemdbus \ + sessiondbus diff --git a/qdbusservice/sessiondbus/data/com.kylin.assistant.qsessiondbus.service b/qdbusservice/sessiondbus/data/com.kylin.assistant.qsessiondbus.service new file mode 100644 index 0000000..148f3b9 --- /dev/null +++ b/qdbusservice/sessiondbus/data/com.kylin.assistant.qsessiondbus.service @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=com.kylin.assistant.qsessiondbus +Exec=/usr/lib/kylin-assistant/daemon/kylin-assistant-qsessiondbus-service diff --git a/qdbusservice/sessiondbus/data/com.kylin.assistant.qsessiondbus.xml b/qdbusservice/sessiondbus/data/com.kylin.assistant.qsessiondbus.xml new file mode 100644 index 0000000..6682126 --- /dev/null +++ b/qdbusservice/sessiondbus/data/com.kylin.assistant.qsessiondbus.xml @@ -0,0 +1,11 @@ + + + + + + + + + + diff --git a/qdbusservice/sessiondbus/data/sessionadaptor.cpp b/qdbusservice/sessiondbus/data/sessionadaptor.cpp new file mode 100644 index 0000000..3aaf873 --- /dev/null +++ b/qdbusservice/sessiondbus/data/sessionadaptor.cpp @@ -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 +#include +#include +#include +#include +#include +#include + +/* + * 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"); +} + diff --git a/qdbusservice/sessiondbus/data/sessionadaptor.h b/qdbusservice/sessiondbus/data/sessionadaptor.h new file mode 100644 index 0000000..8225564 --- /dev/null +++ b/qdbusservice/sessiondbus/data/sessionadaptor.h @@ -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 +#include +QT_BEGIN_NAMESPACE +class QByteArray; +template class QList; +template 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", "" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" + "") +public: + SessionAdaptor(QObject *parent); + virtual ~SessionAdaptor(); + +public: // PROPERTIES +public Q_SLOTS: // METHODS + QString demoInfo(); + void exitService(); +Q_SIGNALS: // SIGNALS +}; + +#endif diff --git a/qdbusservice/sessiondbus/main.cpp b/qdbusservice/sessiondbus/main.cpp new file mode 100644 index 0000000..7d99d05 --- /dev/null +++ b/qdbusservice/sessiondbus/main.cpp @@ -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 . + */ + +//qdbusxml2cpp -a sessionadaptor -c SessionAdaptor -l SessionAdaptor com.kylin.assistant.qsessiondbus.xml +//qdbusxml2cpp com.kylin.assistant.qsessiondbus.xml -a sessionadaptor -c SessionAdaptor + +#include +#include +#include +#include + +#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(); +} diff --git a/qdbusservice/sessiondbus/sessiondbus.pro b/qdbusservice/sessiondbus/sessiondbus.pro new file mode 100644 index 0000000..3e69d7b --- /dev/null +++ b/qdbusservice/sessiondbus/sessiondbus.pro @@ -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 +} diff --git a/qdbusservice/sessiondbus/sessionservice.cpp b/qdbusservice/sessiondbus/sessionservice.cpp new file mode 100644 index 0000000..43dffa1 --- /dev/null +++ b/qdbusservice/sessiondbus/sessionservice.cpp @@ -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 . + */ + +#include "sessionservice.h" + +#include +#include +#include +#include +#include + +SessionService::SessionService(QObject *parent) : + QObject(parent) +{ + +} + +SessionService::~SessionService() +{ + this->exitService(); +} + + +QString SessionService::demoInfo() +{ + return "QtSessionDbus"; +} + +void SessionService::exitService() +{ + qApp->exit(0); +} diff --git a/qdbusservice/sessiondbus/sessionservice.h b/qdbusservice/sessiondbus/sessionservice.h new file mode 100644 index 0000000..55daa1d --- /dev/null +++ b/qdbusservice/sessiondbus/sessionservice.h @@ -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 . + */ + +#ifndef SESSIONSERVICE_H +#define SESSIONSERVICE_H + +#include +#include +#include + +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 diff --git a/qdbusservice/systemdbus/customdata.cpp b/qdbusservice/systemdbus/customdata.cpp new file mode 100644 index 0000000..431a649 --- /dev/null +++ b/qdbusservice/systemdbus/customdata.cpp @@ -0,0 +1,29 @@ +#include + +#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"); + qDBusRegisterMetaType(); +}*/ + +void registerCustomDataMetaType() +{ + qRegisterMetaType("CustomData"); + qDBusRegisterMetaType(); +} diff --git a/qdbusservice/systemdbus/customdata.h b/qdbusservice/systemdbus/customdata.h new file mode 100644 index 0000000..e34e2fc --- /dev/null +++ b/qdbusservice/systemdbus/customdata.h @@ -0,0 +1,54 @@ +#ifndef CUSTOMDATA_H +#define CUSTOMDATA_H + +#include +#include +#include +#include + +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 diff --git a/qdbusservice/systemdbus/customdatalist.cpp b/qdbusservice/systemdbus/customdatalist.cpp new file mode 100644 index 0000000..7d0c5b1 --- /dev/null +++ b/qdbusservice/systemdbus/customdatalist.cpp @@ -0,0 +1,7 @@ +#include "customdatalist.h" + +void registerCustomDataListMetaType() +{ + qRegisterMetaType("CustomDataList"); + qDBusRegisterMetaType(); +} diff --git a/qdbusservice/systemdbus/customdatalist.h b/qdbusservice/systemdbus/customdatalist.h new file mode 100644 index 0000000..d5e5299 --- /dev/null +++ b/qdbusservice/systemdbus/customdatalist.h @@ -0,0 +1,15 @@ +#ifndef CUSTOMDATALIST_H +#define CUSTOMDATALIST_H + +#include +#include + +#include "customdata.h" + +typedef QList CustomDataList; + +Q_DECLARE_METATYPE(CustomDataList) + +void registerCustomDataListMetaType(); + +#endif // CUSTOMDATALIST_H diff --git a/qdbusservice/systemdbus/data/com.kylin.assistant.qsystemdbus.conf b/qdbusservice/systemdbus/data/com.kylin.assistant.qsystemdbus.conf new file mode 100644 index 0000000..cfd765f --- /dev/null +++ b/qdbusservice/systemdbus/data/com.kylin.assistant.qsystemdbus.conf @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + diff --git a/qdbusservice/systemdbus/data/com.kylin.assistant.qsystemdbus.service b/qdbusservice/systemdbus/data/com.kylin.assistant.qsystemdbus.service new file mode 100644 index 0000000..d925f41 --- /dev/null +++ b/qdbusservice/systemdbus/data/com.kylin.assistant.qsystemdbus.service @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=com.kylin.assistant.qsystemdbus +Exec=/usr/lib/kylin-assistant/daemon/kylin-assistant-qsystemdbus-service +User=root diff --git a/qdbusservice/systemdbus/data/com.kylin.assistant.qsystemdbus.xml b/qdbusservice/systemdbus/data/com.kylin.assistant.qsystemdbus.xml new file mode 100644 index 0000000..2641559 --- /dev/null +++ b/qdbusservice/systemdbus/data/com.kylin.assistant.qsystemdbus.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/qdbusservice/systemdbus/data/systemdbushandler.h b/qdbusservice/systemdbus/data/systemdbushandler.h new file mode 100644 index 0000000..5826d5f --- /dev/null +++ b/qdbusservice/systemdbus/data/systemdbushandler.h @@ -0,0 +1,56 @@ +#pragma once + +#include "systemdbusproxy.h" +#include "systeminterface.h" +#include "../customdata.h" + +#include +#include +#include + +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; +}; diff --git a/qdbusservice/systemdbus/data/systemdbusproxy.cpp b/qdbusservice/systemdbus/data/systemdbusproxy.cpp new file mode 100644 index 0000000..c9b159d --- /dev/null +++ b/qdbusservice/systemdbus/data/systemdbusproxy.cpp @@ -0,0 +1,47 @@ +#include "systemdbusproxy.h" +#include "systemdbushandler.h" + +#include +#include + +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(); +} diff --git a/qdbusservice/systemdbus/data/systemdbusproxy.h b/qdbusservice/systemdbus/data/systemdbusproxy.h new file mode 100644 index 0000000..de7825c --- /dev/null +++ b/qdbusservice/systemdbus/data/systemdbusproxy.h @@ -0,0 +1,28 @@ +#pragma once + +#include "../customdata.h" + +#include +#include + +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; +}; diff --git a/qdbusservice/systemdbus/data/systeminterface.cpp b/qdbusservice/systemdbus/data/systeminterface.cpp new file mode 100644 index 0000000..8d57f71 --- /dev/null +++ b/qdbusservice/systemdbus/data/systeminterface.cpp @@ -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() +{ +} + diff --git a/qdbusservice/systemdbus/data/systeminterface.h b/qdbusservice/systemdbus/data/systeminterface.h new file mode 100644 index 0000000..85a28d5 --- /dev/null +++ b/qdbusservice/systemdbus/data/systeminterface.h @@ -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 +#include +#include +#include +#include +#include +#include +#include + +//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 demoInfo() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("demoInfo"), argumentList); + } + + inline QDBusPendingReply<> exitService() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("exitService"), argumentList); + } + + inline QDBusPendingReply getCustomData() + { + QList argumentList; + return asyncCallWithArgumentList(QStringLiteral("getCustomData"), argumentList); + } + + inline QDBusPendingReply<> sendCustomData(CustomData message) + { + QList argumentList; + argumentList << QVariant::fromValue(message); + return asyncCallWithArgumentList(QStringLiteral("sendCustomData"), argumentList); + } + + inline QDBusPendingReply userIsActive(const QString &user, bool active) + { + QList 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 diff --git a/qdbusservice/systemdbus/main.cpp b/qdbusservice/systemdbus/main.cpp new file mode 100644 index 0000000..82d7728 --- /dev/null +++ b/qdbusservice/systemdbus/main.cpp @@ -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 . + */ + +//qdbusxml2cpp -v -c SystemInterface -p systeminterface.h:systeminterface.cpp com.kylin.assistant.qsystemdbus.xml + +#include +#include +#include +#include + +#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(); +} diff --git a/qdbusservice/systemdbus/systemdbus.pro b/qdbusservice/systemdbus/systemdbus.pro new file mode 100644 index 0000000..eeabc04 --- /dev/null +++ b/qdbusservice/systemdbus/systemdbus.pro @@ -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 +} diff --git a/qdbusservice/systemdbus/systemservice.cpp b/qdbusservice/systemdbus/systemservice.cpp new file mode 100644 index 0000000..202a2fc --- /dev/null +++ b/qdbusservice/systemdbus/systemservice.cpp @@ -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 . + */ + +#include "systemservice.h" + +#include +#include +#include +#include +#include + +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(this->connection().interface()->servicePid(this->message().service()).value()); + qDebug() << "callerPid="<exit(0); +} diff --git a/qdbusservice/systemdbus/systemservice.h b/qdbusservice/systemdbus/systemservice.h new file mode 100644 index 0000000..0fc280a --- /dev/null +++ b/qdbusservice/systemdbus/systemservice.h @@ -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 . + */ + +#ifndef SYSTEMSERVICE_H +#define SYSTEMSERVICE_H + +#include +#include +#include +#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