From 6ed15989a731a5f9f3ab34f84cd3412c053cc2e3 Mon Sep 17 00:00:00 2001 From: Bernd Wachter Date: Wed, 4 Sep 2013 02:17:17 +0300 Subject: [PATCH] [ssud] Initial version of ssu dbus service --- .gitignore | 4 ++ dbus/org.nemo.ssu.conf | 17 +++++++++ dbus/org.nemo.ssu.service | 5 +++ dbus/org.nemo.ssu.xml | 59 ++++++++++++++++++++++++++++++ rndssucli/rndssucli.cpp | 44 +++++++++++++++++++++- rndssucli/rndssucli.h | 3 ++ rndssucli/rndssucli.pro | 9 +++-- rpm/ssu.spec | 4 +- ssu.pro | 13 ++++++- ssud/main.cpp | 31 ++++++++++++++++ ssud/ssud.cpp | 75 ++++++++++++++++++++++++++++++++++++++ ssud/ssud.h | 44 ++++++++++++++++++++++ ssud/ssud.pro | 21 +++++++++++ ssud/ssud_dependencies.pri | 1 + 14 files changed, 322 insertions(+), 8 deletions(-) create mode 100644 dbus/org.nemo.ssu.conf create mode 100644 dbus/org.nemo.ssu.service create mode 100644 dbus/org.nemo.ssu.xml create mode 100644 ssud/main.cpp create mode 100644 ssud/ssud.cpp create mode 100644 ssud/ssud.h create mode 100644 ssud/ssud.pro create mode 100644 ssud/ssud_dependencies.pri diff --git a/.gitignore b/.gitignore index 790a982..c5bf7a7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ doc/latex *.pro.user *.list /tests/testutils/Makefile.sandboxhook +/ssud/ssuadaptor.cpp +/ssud/ssuadaptor.h +/rndssucli/ssuproxy.cpp +/rndssucli/ssuproxy.h diff --git a/dbus/org.nemo.ssu.conf b/dbus/org.nemo.ssu.conf new file mode 100644 index 0000000..1941286 --- /dev/null +++ b/dbus/org.nemo.ssu.conf @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + diff --git a/dbus/org.nemo.ssu.service b/dbus/org.nemo.ssu.service new file mode 100644 index 0000000..6207810 --- /dev/null +++ b/dbus/org.nemo.ssu.service @@ -0,0 +1,5 @@ +[D-BUS Service] +Interface=org.nemo.ssu +Name=org.nemo.ssu +Exec=/usr/bin/ssud +User=root \ No newline at end of file diff --git a/dbus/org.nemo.ssu.xml b/dbus/org.nemo.ssu.xml new file mode 100644 index 0000000..ec19790 --- /dev/null +++ b/dbus/org.nemo.ssu.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rndssucli/rndssucli.cpp b/rndssucli/rndssucli.cpp index b372560..bad85b6 100644 --- a/rndssucli/rndssucli.cpp +++ b/rndssucli/rndssucli.cpp @@ -23,6 +23,12 @@ RndSsuCli::RndSsuCli(): QObject(){ QCoreApplication::instance(),SLOT(quit()), Qt::DirectConnection); connect(&ssu, SIGNAL(done()), this, SLOT(handleResponse())); + + ssuProxy = new SsuProxy("org.nemo.ssu", "/org/nemo/ssu", QDBusConnection::systemBus(), 0); + + connect(ssuProxy, SIGNAL(done()), + this, SLOT(handleDBusResponse())); + state = Idle; } @@ -32,6 +38,18 @@ void RndSsuCli::handleResponse(){ if (ssu.error()){ qout << "Last operation failed: \n" << ssu.lastError() << endl; QCoreApplication::exit(1); + } else { + qout << "Operation successful (direct)" << endl; + QCoreApplication::exit(0); + } +} + +void RndSsuCli::handleDBusResponse(){ + QTextStream qout(stdout); + + if (ssuProxy->error()){ + qout << "Last operation failed: \n" << ssuProxy->lastError() << endl; + QCoreApplication::exit(1); } else { qout << "Operation successful" << endl; QCoreApplication::exit(0); @@ -122,6 +140,7 @@ void RndSsuCli::optMode(QStringList opt){ void RndSsuCli::optModel(QStringList opt){ QTextStream qout(stdout); + QTextStream qerr(stderr); SsuDeviceInfo deviceInfo; if (opt.count() == 3 && opt.at(2) == "-s"){ @@ -189,6 +208,7 @@ void RndSsuCli::optRegister(QStringList opt){ QString username, password; QTextStream qin(stdin); QTextStream qout(stdout); + QTextStream qerr(stderr); SsuCoreConfig *ssuSettings = SsuCoreConfig::instance(); struct termios termNew, termOld; @@ -204,13 +224,21 @@ void RndSsuCli::optRegister(QStringList opt){ qout << "Password: " << flush; password = qin.readLine(); + qout << endl; tcsetattr(STDIN_FILENO, TCSANOW, &termOld); if (opt.count() == 3 && opt.at(2) == "-h") ssuSettings->setValue("repository-url-variables/user", username); - ssu.sendRegistration(username, password); + QDBusPendingReply<> reply = ssuProxy->registerDevice(username, password); + reply.waitForFinished(); + if (reply.isError()){ + qerr << "DBus call failed, falling back to libssu" << endl; + qerr << reply.error().message() << endl; + ssu.sendRegistration(username, password); + } + state = Busy; } @@ -400,17 +428,29 @@ void RndSsuCli::optRepos(QStringList opt){ void RndSsuCli::optStatus(){ QTextStream qout(stdout); + QTextStream qerr(stderr); SsuDeviceInfo deviceInfo; /* * print device information and registration status */ + + QString deviceUid; + + QDBusPendingReply reply = ssuProxy->deviceUid(); + reply.waitForFinished(); + if (reply.isError()){ + qerr << "DBus unavailable, UUID not necessarily connected to reality." << endl; + deviceUid = deviceInfo.deviceUid(); + } else + deviceUid = reply.value(); + qout << "Device registration status: " << (ssu.isRegistered() ? "registered" : "not registered") << endl; qout << "Device model: " << deviceInfo.deviceModel() << endl; if (deviceInfo.deviceVariant() != "") qout << "Device variant: " << deviceInfo.deviceVariant() << endl; - qout << "Device UID: " << deviceInfo.deviceUid() << endl; + qout << "Device UID: " << deviceUid << endl; if ((ssu.deviceMode() & Ssu::RndMode) == Ssu::RndMode) qout << "Release (rnd): " << ssu.release(true) << " (" << ssu.flavour() << ")" << endl; else diff --git a/rndssucli/rndssucli.h b/rndssucli/rndssucli.h index 90dfd30..a1519e8 100644 --- a/rndssucli/rndssucli.h +++ b/rndssucli/rndssucli.h @@ -14,6 +14,7 @@ #include #include "libssu/ssu.h" +#include "ssuproxy.h" class RndSsuCli: public QObject { Q_OBJECT @@ -26,6 +27,7 @@ class RndSsuCli: public QObject { private: Ssu ssu; + SsuProxy *ssuProxy; QSettings settings; int state; void usage(); @@ -57,6 +59,7 @@ class RndSsuCli: public QObject { private slots: void handleResponse(); + void handleDBusResponse(); signals: void done(); diff --git a/rndssucli/rndssucli.pro b/rndssucli/rndssucli.pro index 80790b1..232e624 100644 --- a/rndssucli/rndssucli.pro +++ b/rndssucli/rndssucli.pro @@ -2,9 +2,10 @@ TARGET = ssu include(../ssuapplication.pri) include(rndssucli_dependencies.pri) -QT += network +QT += network dbus -HEADERS = rndssucli.h +HEADERS = rndssucli.h \ + ssuproxy.h SOURCES = main.cpp \ - rndssucli.cpp -#RESOURCES = rndregister.qrc + rndssucli.cpp \ + ssuproxy.cpp diff --git a/rpm/ssu.spec b/rpm/ssu.spec index db43aaa..04dcaf1 100644 --- a/rpm/ssu.spec +++ b/rpm/ssu.spec @@ -35,7 +35,9 @@ Requires: ssu-vendor-data # ssu itself does not use the package-update triggers, but provides # them for the vendor data packages to use %attr(0755, -, -) %{_oneshotdir}/* - +%{_bindir}/ssud +%{_datadir}/dbus-1/system-services/*.service +%{_sysconfdir}/dbus-1/system.d/*.conf %package vendor-data-example Summary: Sample vendor configuration data diff --git a/ssu.pro b/ssu.pro index cb86336..7e672e3 100644 --- a/ssu.pro +++ b/ssu.pro @@ -3,7 +3,7 @@ contains(QT_VERSION, ^4\\.[0-7]\\..*) { } TEMPLATE = subdirs -SUBDIRS = libssu +SUBDIRS = libssu ssud SUBDIRS += rndssucli ssuurlresolver ssuks ssuconfhack { @@ -17,6 +17,7 @@ rndregisterui.depends = libssu ssuurlresolver.depends = libssu tests.depends = libssu ssuks.depends = libssu +ssud.depends = libssu config.files = ssu.ini config.path = /etc/ssu @@ -31,3 +32,13 @@ static_config.files = repos.ini ssu-defaults.ini board-mappings.ini static_config.path = /usr/share/ssu INSTALLS += config static_config oneshot macros + +system(qdbusxml2cpp \ + -c SsuAdaptor \ + -a ssud/ssuadaptor.h:ssud/ssuadaptor.cpp \ + dbus/org.nemo.ssu.xml) + +system(qdbusxml2cpp \ + -c SsuProxy \ + -p rndssucli/ssuproxy.h:rndssucli/ssuproxy.cpp \ + dbus/org.nemo.ssu.xml) \ No newline at end of file diff --git a/ssud/main.cpp b/ssud/main.cpp new file mode 100644 index 0000000..3447ad0 --- /dev/null +++ b/ssud/main.cpp @@ -0,0 +1,31 @@ +/** + * @file main.cpp + * @copyright 2013 Jolla Ltd. + * @author Bernd Wachter + * @date 2013 + */ + +#include +#include +#include +#include +#include +#include "ssud.h" + +int main(int argc, char** argv){ + QCoreApplication app(argc, argv); + QCoreApplication::setOrganizationName("Jolla"); + QCoreApplication::setOrganizationDomain("http://www.jollamobile.com"); + QCoreApplication::setApplicationName("ssud"); + + QTranslator qtTranslator; + qtTranslator.load("qt_" + QLocale::system().name(), + QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + app.installTranslator(&qtTranslator); + + QNetworkProxyFactory::setUseSystemConfiguration(true); + + Ssud ssud; + + app.exec(); +} diff --git a/ssud/ssud.cpp b/ssud/ssud.cpp new file mode 100644 index 0000000..b8189ce --- /dev/null +++ b/ssud/ssud.cpp @@ -0,0 +1,75 @@ +/** + * @file ssud.cpp + * @copyright 2013 Jolla Ltd. + * @author Bernd Wachter + * @date 2013 + */ + +#include "ssud.h" +#include "ssuadaptor.h" + +#include "libssu/ssudeviceinfo.h" + +#include + +const char *Ssud::SERVICE_NAME = "org.nemo.ssu"; +const char *Ssud::OBJECT_PATH = "/org/nemo/ssu"; + +Ssud::Ssud(QObject *parent): QObject(parent){ + QDBusConnection connection = QDBusConnection::systemBus(); + if (!connection.registerService(SERVICE_NAME)) { + qFatal("Cannot register D-Bus service at %s", SERVICE_NAME); + } + + if (!connection.registerObject(OBJECT_PATH, this)) { + qFatal("Cannot register object at %s", OBJECT_PATH); + } + + new SsuAdaptor(this); + + connect(&ssu, SIGNAL(done()), + this, SIGNAL(done())); + connect(&ssu, SIGNAL(credentialsChanged()), + this, SIGNAL(credentialsChanged())); + connect(&ssu, SIGNAL(registrationStatusChanged()), + this, SIGNAL(registrationStatusChanged())); +} + +Ssud::~Ssud(){ +} + +QString Ssud::deviceModel(){ + SsuDeviceInfo deviceInfo; + + return deviceInfo.deviceModel(); +}; + +QString Ssud::deviceUid(){ + SsuDeviceInfo deviceInfo; + + return deviceInfo.deviceUid(); +}; + +bool Ssud::error(){ + return ssu.error(); +} + +QString Ssud::lastError(){ + return ssu.lastError(); +} + +bool Ssud::isRegistered(){ + return ssu.isRegistered(); +} + +void Ssud::quit(){ + QCoreApplication::quit(); +} + +void Ssud::registerDevice(const QString &username, const QString &password){ + ssu.sendRegistration(username, password); +} + +void Ssud::unregisterDevice(){ + ssu.unregister(); +}; diff --git a/ssud/ssud.h b/ssud/ssud.h new file mode 100644 index 0000000..b442186 --- /dev/null +++ b/ssud/ssud.h @@ -0,0 +1,44 @@ +/** + * @file ssud.h + * @copyright 2013 Jolla Ltd. + * @author Bernd Wachter + * @date 2013 + */ + +#ifndef _SSUD_H +#define _SSUD_H + +#include +#include + +#include "libssu/ssu.h" + +class Ssud: public QObject { + Q_OBJECT + + public: + Ssud(QObject *parent=NULL); + virtual ~Ssud(); + + public slots: + QString deviceModel(); + QString deviceUid(); + bool error(); + QString lastError(); + bool isRegistered(); + void quit(); + void registerDevice(const QString &username, const QString &password); + void unregisterDevice(); + + signals: + void done(); + void credentialsChanged(); + void registrationStatusChanged(); + + private: + Ssu ssu; + static const char *SERVICE_NAME; + static const char *OBJECT_PATH; +}; + +#endif diff --git a/ssud/ssud.pro b/ssud/ssud.pro new file mode 100644 index 0000000..024dd67 --- /dev/null +++ b/ssud/ssud.pro @@ -0,0 +1,21 @@ +TARGET = ssud +include(../ssuapplication.pri) +include(ssud_dependencies.pri) + +QT += network dbus + +HEADERS = ssuadaptor.h \ + ssud.h +SOURCES = ssuadaptor.cpp \ + ssud.cpp \ + main.cpp + +DBUS_SERVICE_NAME=org.nemo.ssu + +service.files = ../dbus/$${DBUS_SERVICE_NAME}.service +service.path = /usr/share/dbus-1/system-services/ + +conf.files = ../dbus/$${DBUS_SERVICE_NAME}.conf +conf.path = /etc/dbus-1/system.d/ + +INSTALLS += service conf \ No newline at end of file diff --git a/ssud/ssud_dependencies.pri b/ssud/ssud_dependencies.pri new file mode 100644 index 0000000..48c7cf6 --- /dev/null +++ b/ssud/ssud_dependencies.pri @@ -0,0 +1 @@ +include(../libssu/libssu.pri)