Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[ssud] Automatically exit ssud after a reasonable amount of time
  • Loading branch information
Bernd Wachter committed Oct 24, 2013
1 parent 076bf2d commit 98f1a03
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ssud/ssud.cpp
Expand Up @@ -26,6 +26,15 @@ Ssud::Ssud(QObject *parent): QObject(parent){
qFatal("Cannot register object at %s", OBJECT_PATH);
}

// prepare for controlled suicide on boredom
const int AUTOCLOSE_TIMEOUT_MS = 180 * 1000;

autoclose.setSingleShot(true);
autoclose.setInterval(AUTOCLOSE_TIMEOUT_MS);

connect(&autoclose, SIGNAL(timeout()),
this, SLOT(quit()));

new SsuAdaptor(this);

connect(&ssu, SIGNAL(done()),
Expand All @@ -34,6 +43,9 @@ Ssud::Ssud(QObject *parent): QObject(parent){
this, SIGNAL(credentialsChanged()));
connect(&ssu, SIGNAL(registrationStatusChanged()),
this, SIGNAL(registrationStatusChanged()));

// a cry for help everytime we do something to prevent suicide
autoclose.start();
}

Ssud::~Ssud(){
Expand All @@ -42,32 +54,38 @@ Ssud::~Ssud(){
QString Ssud::deviceModel(){
SsuDeviceInfo deviceInfo;

autoclose.start();
return deviceInfo.deviceModel();
}

QString Ssud::deviceFamily(){
SsuDeviceInfo deviceInfo;

autoclose.start();
return deviceInfo.deviceFamily();
}

QString Ssud::deviceUid(){
SsuDeviceInfo deviceInfo;

autoclose.start();
return deviceInfo.deviceUid();
}

QString Ssud::deviceVariant(){
SsuDeviceInfo deviceInfo;

autoclose.start();
return deviceInfo.deviceVariant();
}

bool Ssud::error(){
autoclose.start();
return ssu.error();
}

QString Ssud::lastError(){
autoclose.start();
return ssu.lastError();
}

Expand All @@ -76,19 +94,24 @@ void Ssud::quit(){
}

bool Ssud::isRegistered(){
autoclose.start();
return ssu.isRegistered();
}

void Ssud::registerDevice(const QString &username, const QString &password){
autoclose.stop();
ssu.sendRegistration(username, password);
autoclose.start();
}

void Ssud::unregisterDevice(){
autoclose.start();
ssu.unregister();
};


int Ssud::deviceMode(){
autoclose.start();
return ssu.deviceMode();
}

Expand All @@ -97,9 +120,11 @@ void Ssud::setDeviceMode(int mode){

SsuRepoManager repoManager;
repoManager.update();
autoclose.start();
}

QString Ssud::flavour(){
autoclose.start();
return ssu.flavour();
}

Expand All @@ -108,10 +133,12 @@ void Ssud::setFlavour(const QString &flavour){

SsuRepoManager repoManager;
repoManager.update();
autoclose.start();
}


QString Ssud::release(bool rnd){
autoclose.start();
return ssu.release(rnd);
}

Expand All @@ -120,11 +147,14 @@ void Ssud::setRelease(const QString &release, bool rnd){

SsuRepoManager repoManager;
repoManager.update();
autoclose.start();
}

void Ssud::modifyRepo(int action, const QString &repo){
SsuRepoManager repoManager;

autoclose.stop();

switch(action){
case Add:
repoManager.add(repo);
Expand All @@ -141,15 +171,19 @@ void Ssud::modifyRepo(int action, const QString &repo){
}

repoManager.update();
autoclose.start();
}

void Ssud::addRepo(const QString &repo, const QString &url){
SsuRepoManager repoManager;
repoManager.add(repo, url);
repoManager.update();
autoclose.start();
}

void Ssud::updateRepos(){
SsuRepoManager repoManager;
autoclose.stop();
repoManager.update();
autoclose.start();
}
2 changes: 2 additions & 0 deletions ssud/ssud.h
Expand Up @@ -10,6 +10,7 @@

#include <QObject>
#include <QString>
#include <QTimer>

#include "libssu/ssu.h"

Expand Down Expand Up @@ -56,6 +57,7 @@ class Ssud: public QObject {
Ssu ssu;
static const char *SERVICE_NAME;
static const char *OBJECT_PATH;
QTimer autoclose;

enum Actions {
Remove = 0,
Expand Down

0 comments on commit 98f1a03

Please sign in to comment.