Skip to content

Commit

Permalink
Merge pull request #97 from pvuorela/master
Browse files Browse the repository at this point in the history
refactor, cleanup, polish
  • Loading branch information
pvuorela committed Jul 13, 2015
2 parents ba458ea + 949b18c commit 2be9875
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 274 deletions.
8 changes: 4 additions & 4 deletions connd/connd.pro
Expand Up @@ -2,7 +2,7 @@
QT = core network dbus

TARGET = connectionagent
PKGCONFIG += connman-qt5 qofono-qt5
PKGCONFIG += connman-qt5

packagesExist(qt5-boostable) {
DEFINES += HAS_BOOSTER
Expand Down Expand Up @@ -30,15 +30,15 @@ SOURCES += main.cpp \
qconnectionagent.cpp \
wakeupwatcher.cpp

HEADERS+= \
HEADERS += \
qconnectionagent.h \
wakeupwatcher.h

target.path = /usr/bin
INSTALLS += target

MOC_DIR=.moc
OBJECTS_DIR=.obj
MOC_DIR = .moc
OBJECTS_DIR = .obj



15 changes: 7 additions & 8 deletions connd/main.cpp
Expand Up @@ -18,7 +18,6 @@
#include <QTimer>
#include <QtGlobal>
#include <QDebug>
#include <QDBusConnection>
#include <signal.h>
#include <fcntl.h>
#include <sys/types.h>
Expand Down Expand Up @@ -79,13 +78,13 @@ static void daemonize(void)
}

static QtMessageHandler previousMessageHandler;
bool toggleDebug;
static bool toggleDebug;

void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &str)
{
{
if (toggleDebug)
previousMessageHandler(type,context,str);
}
}

Q_DECL_EXPORT int main(int argc, char *argv[])
{
Expand All @@ -104,13 +103,13 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
QCoreApplication::setApplicationVersion("1.0");

QCoreApplication a(argc, argv);
if (QDBusConnection::sessionBus().interface()->isServiceRegistered("com.jolla.Connectiond")) {
qDebug() << "Connectionagent service is already running. Exiting now";

QConnectionAgent agent;
if (!agent.isValid()) {
qDebug() << "Connectionagent service failed to register. Exiting now";
return 1;
}

QConnectionAgent::instance();

return a.exec();
}

Empty file removed connd/notes.txt
Empty file.
60 changes: 12 additions & 48 deletions connd/qconnectionagent.cpp
Expand Up @@ -23,20 +23,12 @@
#include <connman-qt5/networktechnology.h>
#include <connman-qt5/networkservice.h>
#include <connman-qt5/sessionagent.h>
#include <qofono-qt5/qofonoconnectioncontext.h>
#include <qofono-qt5/qofonoconnectionmanager.h>
#include <qofono-qt5/qofononetworkregistration.h>
#include <qofono-qt5/qofonomanager.h>

#include <QtDBus/QDBusConnection>

#include <QObject>
#include <QSettings>

#define CONNMAN_1_21

QConnectionAgent* QConnectionAgent::self = NULL;

#define CONND_SERVICE "com.jolla.Connectiond"
#define CONND_PATH "/Connectiond"
#define CONND_SESSION_PATH = "/ConnectionSession"
Expand All @@ -48,30 +40,31 @@ QConnectionAgent::QConnectionAgent(QObject *parent) :
currentNetworkState(QString()),
isEthernet(false),
connmanAvailable(false),
oContext(0),
tetheringWifiTech(0),
tetheringEnabled(false),
flightModeSuppression(false),
scanTimeoutInterval(1),
delayedTethering(false)
delayedTethering(false),
valid(true)
{
qDebug() << Q_FUNC_INFO;

connect(netman,SIGNAL(availabilityChanged(bool)),this,SLOT(connmanAvailabilityChanged(bool)));

connectionAdaptor = new ConnAdaptor(this);
new ConnAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();

if (!dbus.registerService(CONND_SERVICE)) {
qDebug() << "XXXXXXXXXXX could not register service XXXXXXXXXXXXXXXXXX";
valid = false;
}

if (!dbus.registerObject(CONND_PATH, this)) {
qDebug() << "XXXXXXXXXXX could not register object XXXXXXXXXXXXXXXXXX";
valid = false;
}

connect(this,SIGNAL(configurationNeeded(QString)),this,SLOT(openConnectionDialog(QString)));

connect(netman,SIGNAL(availabilityChanged(bool)),this,SLOT(connmanAvailabilityChanged(bool)));
connect(netman,SIGNAL(servicesListChanged(QStringList)),this,SLOT(servicesListChanged(QStringList)));
connect(netman,SIGNAL(stateChanged(QString)),this,SLOT(networkStateChanged(QString)));
connect(netman,SIGNAL(offlineModeChanged(bool)),this,SLOT(offlineModeChanged(bool)));
Expand Down Expand Up @@ -102,23 +95,17 @@ QConnectionAgent::QConnectionAgent(QObject *parent) :
scanTimer = new QTimer(this);
connect(scanTimer,SIGNAL(timeout()),this,SLOT(scanTimeout()));
scanTimer->setSingleShot(true);
if (connmanAvailable)
if (connmanAvailable && valid)
setup();
}

QConnectionAgent::~QConnectionAgent()
{
delete self;
}

QConnectionAgent & QConnectionAgent::instance()
bool QConnectionAgent::isValid() const
{
qDebug() << Q_FUNC_INFO;
if (!self) {
self = new QConnectionAgent;
}

return *self;
return valid;
}

// from useragent
Expand Down Expand Up @@ -387,20 +374,6 @@ void QConnectionAgent::servicesError(const QString &errorMessage)
Q_EMIT onErrorReported(serv->path(), errorMessage);
}

void QConnectionAgent::ofonoServicesError(const QString &errorMessage)
{
QOfonoConnectionContext *context = static_cast<QOfonoConnectionContext *>(sender());
QVector<NetworkService*> services = netman->getServices("cellular");
Q_FOREACH (NetworkService *serv, services) {
if (context->contextPath().contains(serv->path().section("_",2,2))) {
Q_EMIT onErrorReported(serv->path(), errorMessage);
qDebug() << serv->name() << errorMessage;
return;
}
}
qWarning() << "ofono error but could not discover connman service";
}

void QConnectionAgent::networkStateChanged(const QString &state)
{
qDebug() << state;
Expand Down Expand Up @@ -448,12 +421,6 @@ void QConnectionAgent::connmanAvailabilityChanged(bool b)
}
}

void QConnectionAgent::serviceAdded(const QString &srv)
{
qDebug() << Q_FUNC_INFO << "<<<<"<< srv;
updateServices();
}

void QConnectionAgent::setup()
{
qDebug() << Q_FUNC_INFO
Expand All @@ -462,9 +429,7 @@ void QConnectionAgent::setup()
if (connmanAvailable) {
qDebug() << Q_FUNC_INFO
<< netman->state();
if (ua)
delete ua;

delete ua;
ua = new UserAgent(this);

connect(ua,SIGNAL(userInputRequested(QString,QVariantMap)),
Expand Down Expand Up @@ -595,8 +560,7 @@ void QConnectionAgent::offlineModeChanged(bool b)

void QConnectionAgent::flightModeDialogSuppressionTimeout()
{
if (flightModeSuppression)
flightModeSuppression = false;
flightModeSuppression = false;
}

void QConnectionAgent::displayStateChanged(const QString &state)
Expand Down Expand Up @@ -641,7 +605,7 @@ bool QConnectionAgent::isBestService(NetworkService *service)
void QConnectionAgent::scanTimeout()
{
if (!tetheringWifiTech || tetheringWifiTech->tethering())
return;
return;

if (tetheringWifiTech->powered() && !tetheringWifiTech->connected() && netman->defaultRoute()->type() != "wifi" ) {
tetheringWifiTech->scan();
Expand Down
73 changes: 34 additions & 39 deletions connd/qconnectionagent.h
Expand Up @@ -31,10 +31,8 @@
class UserAgent;
class SessionAgent;

class ConnAdaptor;
class NetworkManager;
class NetworkService;
class QOfonoConnectionContext;
class NetworkTechnology;
class WakeupWatcher;
class QTimer;
Expand All @@ -44,9 +42,10 @@ class QConnectionAgent : public QObject
Q_OBJECT

public:
explicit QConnectionAgent(QObject *parent = 0);
~QConnectionAgent();

static QConnectionAgent &instance();
bool isValid() const;

Q_SIGNALS:

Expand Down Expand Up @@ -82,41 +81,45 @@ public Q_SLOTS:
class Service
{
public:
QString path;
NetworkService *service;
QString path;
NetworkService *service;

bool operator==(const Service &other) const {
return other.path == path;
}
bool operator==(const Service &other) const {
return other.path == path;
}
};

class ServiceList : public QVector<Service>
{
public:
int indexOf(const QString &path, int from = 0) const {
Service key;
key.path = path;
return QVector<Service>::indexOf(key, from);
}

bool contains(const QString &path) const {
Service key;
key.path = path;
return QVector<Service>::indexOf(key) >= 0;
}

void remove(const QString &path) {
Service key;
key.path = path;
int pos = QVector<Service>::indexOf(key);
if (pos >= 0)
QVector<Service>::remove(pos);
}
int indexOf(const QString &path, int from = 0) const {
Service key;
key.path = path;
return QVector<Service>::indexOf(key, from);
}

bool contains(const QString &path) const {
Service key;
key.path = path;
return QVector<Service>::indexOf(key) >= 0;
}

void remove(const QString &path) {
Service key;
key.path = path;
int pos = QVector<Service>::indexOf(key);
if (pos >= 0)
QVector<Service>::remove(pos);
}
};

explicit QConnectionAgent(QObject *parent = 0);
static QConnectionAgent *self;
ConnAdaptor *connectionAdaptor;
void setup();
void updateServices();
bool isStateOnline(const QString &state);
bool isBestService(NetworkService *service);
QString findBestConnectableService();
void removeAllTypes(const QString &type);

UserAgent *ua;

NetworkManager *netman;
Expand All @@ -130,8 +133,6 @@ public Q_SLOTS:
bool isEthernet;
bool connmanAvailable;

bool isStateOnline(const QString &state);
QOfonoConnectionContext *oContext;
NetworkTechnology *tetheringWifiTech;
bool tetheringEnabled;
bool flightModeSuppression;
Expand All @@ -140,29 +141,23 @@ public Q_SLOTS:

QTimer *scanTimer;
QStringList knownTechnologies;
bool isBestService(NetworkService *service);
QString findBestConnectableService();
void removeAllTypes(const QString &type);
bool tetheringStarted;
bool delayedTethering;
bool valid;

private slots:
void onScanFinished();
void updateServices();

void serviceErrorChanged(const QString &error);
void serviceStateChanged(const QString &state);
void networkStateChanged(const QString &state);

void connmanAvailabilityChanged(bool b);
void setup();
void servicesError(const QString &);
void ofonoServicesError(const QString &);
void technologyPowerChanged(bool);
void browserRequest(const QString &servicePath, const QString &url);
void techChanged();

void serviceAdded(const QString &);
void servicesListChanged(const QStringList &);
void offlineModeChanged(bool);
void flightModeDialogSuppressionTimeout();
Expand Down
12 changes: 12 additions & 0 deletions connd/wakeupwatcher.cpp
Expand Up @@ -19,6 +19,18 @@

#include "wakeupwatcher.h"

#define MCE_SERVICE "com.nokia.mce"
#define MCE_SIGNAL_PATH "/com/nokia/mce/signal"
#define MCE_SIGNAL_INTERFACE "com.nokia.mce.signal"
#define MCE_PSM_STATE_IND "psm_state_ind"
#define MCE_DISPLAY_IND "display_status_ind"

#define MCE_REQUEST_PATH "/com/nokia/mce/request"
#define MCE_REQUEST_INTERFACE "com.nokia.mce.request"
#define MCE_DISPLAY_STATUS_GET "get_display_status"
#define MCE_PSM_STATE_GET "get_psm_state"


WakeupWatcher::WakeupWatcher(QObject *parent) :
QObject(parent),
currentPowerSave(false)
Expand Down

0 comments on commit 2be9875

Please sign in to comment.