Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #97 from pvuorela/master
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 131 additions and 241 deletions.
2 changes: 1 addition & 1 deletion 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
11 changes: 5 additions & 6 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,7 +78,7 @@ static void daemonize(void)
}

static QtMessageHandler previousMessageHandler;
bool toggleDebug;
static bool toggleDebug;

void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &str)
{
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
Whitespace-only changes.
54 changes: 9 additions & 45 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;

ua = new UserAgent(this);

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

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

Expand Down
25 changes: 10 additions & 15 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 @@ -114,9 +113,13 @@ public Q_SLOTS:
}
};

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
13 changes: 1 addition & 12 deletions connd/wakeupwatcher.h
Expand Up @@ -20,17 +20,6 @@
#include <QObject>
#include <QDBusInterface>

#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"

class WakeupWatcher : public QObject
{
Q_OBJECT
Expand All @@ -40,11 +29,11 @@ class WakeupWatcher : public QObject
signals:
void displayStateChanged(const QString&);
void sleepStateChanged(bool);
public slots:

private slots:
void mceDisplayStateChanged(const QString &state);
void mceSleepStateChanged(bool mode);

private:
QDBusInterface *mceInterface;
QString currentDisplayState;
Expand Down
5 changes: 1 addition & 4 deletions connectionagent.pro
Expand Up @@ -8,7 +8,4 @@ SUBDIRS = \

test.depends = connd # xml interface

OTHER_FILES += rpm/connectionagent-qt5.spec \
rpm/connectionagent-qt5.yaml \
rpm/connectionagent.tracing

OTHER_FILES += rpm/connectionagent-qt5.spec
7 changes: 3 additions & 4 deletions connectionagentplugin/connectionagentplugin.pro
Expand Up @@ -6,12 +6,11 @@ CONFIG += qt plugin
uri = com.jolla.connection

SOURCES += \
connectionagentplugin_plugin.cpp \
connectionagentplugin.cpp
plugin.cpp \
declarativeconnectionagent.cpp

HEADERS += \
connectionagentplugin_plugin.h \
connectionagentplugin.h
declarativeconnectionagent.h

DBUS_INTERFACES = connectiond_interface
connectiond_interface.files = ../connd/com.jollamobile.Connectiond.xml
Expand Down
59 changes: 0 additions & 59 deletions connectionagentplugin/connectionagentplugin_plugin.cpp

This file was deleted.

0 comments on commit 2be9875

Please sign in to comment.