Commit 6ed15989 authored by Aard's avatar Aard

[ssud] Initial version of ssu dbus service

parent fd7618aa
......@@ -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
<!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>
[D-BUS Service]
Interface=org.nemo.ssu
Name=org.nemo.ssu
Exec=/usr/bin/ssud
User=root
\ No newline at end of file
<!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>
......@@ -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<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
......
......@@ -14,6 +14,7 @@
#include <QDebug>
#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();
......
......@@ -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
......@@ -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
......
......@@ -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
/**
* @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();
}
/**
* @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();
};
/**
* @file ssud.h
* @copyright 2013 Jolla Ltd.
* @author Bernd Wachter <bwachter@lart.info>
* @date 2013
*/
#ifndef _SSUD_H
#define _SSUD_H
#include <QObject>
#include <QString>
#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
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
include(../libssu/libssu.pri)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment