Skip to content

Commit

Permalink
[ssud] Initial version of ssu dbus service
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernd Wachter committed Sep 3, 2013
1 parent fd7618a commit 6ed1598
Show file tree
Hide file tree
Showing 14 changed files with 322 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -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
17 changes: 17 additions & 0 deletions dbus/org.nemo.ssu.conf
@@ -0,0 +1,17 @@
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">

<busconfig>
<policy user="root">
<allow own="org.nemo.ssu"/>
<allow send_destination="org.nemo.ssu" send_interface="org.nemo.ssu"/>
</policy>

<policy group="system">
<allow send_destination="org.nemo.ssu" send_interface="org.nemo.ssu"/>
<allow send_destination="org.nemo.ssu" send_interface="org.freedesktop.DBus.Introspectable"/>
<allow send_destination="org.nemo.ssu" send_interface="org.freedesktop.DBus.Peer"/>
<allow send_destination="org.nemo.ssu" send_interface="org.freedesktop.DBus.Properties"/>
</policy>
</busconfig>
5 changes: 5 additions & 0 deletions 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
59 changes: 59 additions & 0 deletions dbus/org.nemo.ssu.xml
@@ -0,0 +1,59 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">

<!--
/**
* DBus service for interfacing with ssu management
* Copyright (C) 2013 Jolla Ltd.
* Contact: Bernd Wachter <bernd.wachter@jollamobile.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; either version 2
* of the License, or (at your option) any later version.
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-->

<node name="/org/nemo/ssu">
<interface name="org.nemo.ssu">
<method name="registerDevice">
<arg direction="in" type="s" name="username"/>
<arg direction="in" type="s" name="password"/>
</method>
<method name="unregisterDevice">
</method>
<method name="isRegistered">
<arg direction="out" type="b" name="status"/>
</method>
<method name="deviceModel">
<arg direction="out" type="s" name="model"/>
</method>
<method name="deviceUid">
<arg direction="out" type="s" name="model"/>
</method>
<method name="error">
<arg direction="out" type="b" name="status"/>
</method>
<method name="lastError">
<arg direction="out" type="s" name="status"/>
</method>
<method name="quit">
</method>

<signal name="credentialsChanged">
</signal>
<signal name="done">
</signal>
<signal name="registrationStatusChanged">
</signal>
</interface>
</node>
44 changes: 42 additions & 2 deletions rndssucli/rndssucli.cpp
Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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"){
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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<QString> 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
Expand Down
3 changes: 3 additions & 0 deletions rndssucli/rndssucli.h
Expand Up @@ -14,6 +14,7 @@
#include <QDebug>

#include "libssu/ssu.h"
#include "ssuproxy.h"

class RndSsuCli: public QObject {
Q_OBJECT
Expand All @@ -26,6 +27,7 @@ class RndSsuCli: public QObject {

private:
Ssu ssu;
SsuProxy *ssuProxy;
QSettings settings;
int state;
void usage();
Expand Down Expand Up @@ -57,6 +59,7 @@ class RndSsuCli: public QObject {

private slots:
void handleResponse();
void handleDBusResponse();

signals:
void done();
Expand Down
9 changes: 5 additions & 4 deletions rndssucli/rndssucli.pro
Expand Up @@ -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
4 changes: 3 additions & 1 deletion rpm/ssu.spec
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion ssu.pro
Expand Up @@ -3,7 +3,7 @@ contains(QT_VERSION, ^4\\.[0-7]\\..*) {
}

TEMPLATE = subdirs
SUBDIRS = libssu
SUBDIRS = libssu ssud
SUBDIRS += rndssucli ssuurlresolver ssuks

ssuconfhack {
Expand All @@ -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
Expand All @@ -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)
31 changes: 31 additions & 0 deletions ssud/main.cpp
@@ -0,0 +1,31 @@
/**
* @file main.cpp
* @copyright 2013 Jolla Ltd.
* @author Bernd Wachter <bwachter@lart.info>
* @date 2013
*/

#include <QCoreApplication>
#include <QTranslator>
#include <QLocale>
#include <QLibraryInfo>
#include <QNetworkProxyFactory>
#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();
}
75 changes: 75 additions & 0 deletions ssud/ssud.cpp
@@ -0,0 +1,75 @@
/**
* @file ssud.cpp
* @copyright 2013 Jolla Ltd.
* @author Bernd Wachter <bwachter@lart.info>
* @date 2013
*/

#include "ssud.h"
#include "ssuadaptor.h"

#include "libssu/ssudeviceinfo.h"

#include <QDBusConnection>

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();
};

0 comments on commit 6ed1598

Please sign in to comment.