Commit a871c7fe authored by lpotter's avatar lpotter Committed by Lorn Potter

Initial commit

parents
This diff is collapsed.
connectionagent
===============
Connectionagent is a daemon and declarative plugin for accessing connman's UserAgent. It allows multiple access to UserAgent
\ 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">
<node>
<interface name="com.jolla.Connectiond">
<method name="sendUserReply">
<annotation value="QVariantMap" name="org.qtproject.QtDBus.QtTypeName.In0"/>
<arg type="a{sv}" name="input"/>
</method>
<method name="sendConnectReply">
<arg direction="in" type="s"/>
<arg direction="in" type="i"/>
</method>
<signal name="userInputRequested">
<annotation value="QVariantMap" name="org.qtproject.QtDBus.QtTypeName.In1"/>
<arg type="s" name="service"/>
<arg type="a{sv}" name="fields"/>
</signal>
<signal name="userInputCanceled"/>
<signal name="errorReported">
<arg type="s" name="error"/>
</signal>
<signal name="requestBrowser">
<arg type="s" name="url"/>
</signal>
<signal name="connectionRequest"/>
</interface>
</node>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="com.jolla.Connectiond">
<method name="sendUserReply">
<annotation value="QVariantMap" name="org.qtproject.QtDBus.QtTypeName.In0"/>
<arg type="a{sv}" name="input"/>
</method>
<method name="sendConnectReply">
<arg direction="in" type="s"/>
<arg direction="in" type="i"/>
</method>
<signal name="userInputRequested">
<annotation value="QVariantMap" name="org.qtproject.QtDBus.QtTypeName.In1"/>
<arg type="s" name="service"/>
<arg type="a{sv}" name="fields "/>
</signal>
<signal name="userInputCanceled"/>
<signal name="errorReported">
<arg type="s" name="service"/>
<arg type="s" name="error"/>
</signal>
<signal name="requestBrowser">
<arg type="s" name="service"/>
<arg type="s" name="url"/>
</signal>
<signal name="connectionRequest"/>
</interface>
</node>
/*
* This file was generated by qdbusxml2cpp version 0.7
* Command line was: qdbusxml2cpp -c ConnAdaptor -a connadaptor.h:connadaptor.cpp com.jolla.Connectiond.xml
*
* qdbusxml2cpp is Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
*
* This is an auto-generated file.
* Do not edit! All changes made to it will be lost.
*/
#include "connadaptor.h"
#include <QtCore/QMetaObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariant>
/*
* Implementation of adaptor class ConnAdaptor
*/
ConnAdaptor::ConnAdaptor(QObject *parent)
: QDBusAbstractAdaptor(parent)
{
// constructor
setAutoRelaySignals(true);
}
ConnAdaptor::~ConnAdaptor()
{
// destructor
}
void ConnAdaptor::sendConnectReply(const QString &in0, int in1)
{
qDebug() << Q_FUNC_INFO << in0 << in1;
// handle method call com.jolla.Connectiond.sendConnectReply
QMetaObject::invokeMethod(parent(), "sendConnectReply", Q_ARG(QString, in0), Q_ARG(int, in1));
}
void ConnAdaptor::sendUserReply(const QVariantMap &input)
{
qDebug() << Q_FUNC_INFO << input;
// handle method call com.jolla.Connectiond.sendUserReply
QMetaObject::invokeMethod(parent(), "sendUserReply", Q_ARG(QVariantMap, input));
}
/*
* This file was generated by qdbusxml2cpp version 0.7
* Command line was: qdbusxml2cpp -c ConnAdaptor -a connadaptor.h:connadaptor.cpp com.jolla.Connectiond.xml
*
* qdbusxml2cpp is Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
*
* This is an auto-generated file.
* This file may have been hand-edited. Look for HAND-EDIT comments
* before re-generating it.
*/
#ifndef CONNADAPTOR_H_1363412350
#define CONNADAPTOR_H_1363412350
#include <QtCore/QObject>
#include <QtDBus/QtDBus>
class QByteArray;
template<class T> class QList;
template<class Key, class Value> class QMap;
class QString;
class QStringList;
class QVariant;
/*
* Adaptor class for interface com.jolla.Connectiond
*/
class ConnAdaptor: public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "com.jolla.Connectiond")
Q_CLASSINFO("D-Bus Introspection", ""
" <interface name=\"com.jolla.Connectiond\">\n"
" <method name=\"sendUserReply\">\n"
" <annotation value=\"QVariantMap\" name=\"org.qtproject.QtDBus.QtTypeName.In0\"/>\n"
" <arg type=\"a{sv}\" name=\"input\"/>\n"
" </method>\n"
" <method name=\"sendConnectReply\">\n"
" <arg direction=\"in\" type=\"s\"/>\n"
" <arg direction=\"in\" type=\"i\"/>\n"
" </method>\n"
" <signal name=\"userInputRequested\">\n"
" <annotation value=\"QVariantMap\" name=\"org.qtproject.QtDBus.QtTypeName.In1\"/>\n"
" <arg type=\"s\" name=\"service\"/>\n"
" <arg type=\"a{sv}\" name=\"fields \"/>\n"
" </signal>\n"
" <signal name=\"userInputCanceled\"/>\n"
" <signal name=\"errorReported\">\n"
" <arg type=\"s\" name=\"error\"/>\n"
" </signal>\n"
" <signal name=\"requestBrowser\">\n"
" <arg type=\"s\" name=\"url\"/>\n"
" </signal>\n"
" <signal name=\"connectionRequest\"/>\n"
" </interface>\n"
"")
public:
ConnAdaptor(QObject *parent);
virtual ~ConnAdaptor();
public: // PROPERTIES
public Q_SLOTS: // METHODS
void sendConnectReply(const QString &in0, int in1);
void sendUserReply(const QVariantMap &input);
Q_SIGNALS: // SIGNALS
void connectionRequest();
void errorReported(const QString &error);
void requestBrowser(const QString &url);
void userInputCanceled();
void userInputRequested(const QString &service, const QVariantMap &fields);
};
#endif
QT += core network dbus gui
QT -= gui
TARGET = connectionagent
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
QT += core network dbus
QT -= gui
INCLUDEPATH += libconnman-qt
OTHER_FILES += com.jolla.Connectiond.xml
# create adaptor
system(qdbusxml2cpp -c ConnAdaptor -a connadaptor.h:connadaptor.cpp com.jolla.Connectiond.xml)
SOURCES += main.cpp \
qconnectionmanager.cpp \
connadaptor.cpp
HEADERS+= \
qconnectionmanager.h \
connadaptor.h
LIBS += -lconnman-qt4
# LIBS += -llipstick
target.path = /usr/sbin
INSTALLS += target
MOC_DIR=.moc
OBJECTS_DIR=.obj
#include <QtCore/QCoreApplication>
#include <QTimer>
#include <QDebug>
#include <QDBusConnection>
#include <signal.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "qconnectionmanager.h"
#include "connadaptor.h"
static void signal_handler(int signum)
{
switch(signum) {
case SIGHUP: exit(EXIT_FAILURE); break;
case SIGTERM: exit(EXIT_SUCCESS); exit(0); break;
}
}
static void daemonize(void)
{
pid_t pid, sid;
int fd;
if ( getppid() == 1 ) return;
signal(SIGHUP,signal_handler);
signal(SIGTERM,signal_handler);
pid = fork();
if (pid < 0) {
exit(EXIT_FAILURE);
}
if (pid > 0) {
exit(EXIT_SUCCESS);
}
sid = setsid();
if (sid < 0) {
exit(EXIT_FAILURE);
}
if ((chdir("/")) < 0) {
exit(EXIT_FAILURE);
}
fd = open("/dev/null",O_RDWR, 0);
if (fd != -1) {
dup2 (fd, STDIN_FILENO);
dup2 (fd, STDOUT_FILENO);
dup2 (fd, STDERR_FILENO);
if (fd > 2) {
close (fd);
}
}
umask(027);
}
int main(int argc, char *argv[])
{
if (argc > 1)
if (strcmp(argv[1],"-d") == 0) {
daemonize();
}
QCoreApplication::setOrganizationName("Jolla Ltd");
QCoreApplication::setOrganizationDomain("com.jollamobile");
QCoreApplication::setApplicationName("connectionagent");
QCoreApplication::setApplicationVersion("1.0");
QCoreApplication a(argc, argv);
QConnectionManager::instance();
return a.exec();
}
/****************************************************************************
**
** Copyright (C) 2012 Jolla Ltd.
** Contact: lorn.potter@gmail.com
**
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qconnectionmanager.h"
#include "connadaptor.h"
#include <connman-qt/useragent.h>
#include <connman-qt/service.h>
//#include <connman-qt/counter.h>
//#include <connman-qt/session.h>
//#include <connman-qt/networksession.h>
//#include <connman-qt/sessionagent.h>
#include <connman-qt/networkmanager.h>
#include <connman-qt/networktechnology.h>
#include <connman-qt/networkservice.h>
//#include <lipstick/notificationmanager.h>
QConnectionManager* QConnectionManager::self = NULL;
QConnectionManager::QConnectionManager(QObject *parent) :
QObject(parent),
netman(NetworkManagerFactory::createInstance())
{
connectionAdaptor = new ConnAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
if (!dbus.registerObject("/Connectiond", this)) {
qDebug() << "XXXXXXXXXXX could not register object XXXXXXXXXXXXXXXXXX";
}
if (!dbus.registerService("com.jolla.Connectiond")) {
qDebug() << "XXXXXXXXXXX could not register service XXXXXXXXXXXXXXXXXX";
}
qDebug() << "XXXXXXXXXXX everything hunky dory XXXXXXXXXXXXXXXXXX";
ua = new UserAgent(this);
connect(ua,SIGNAL(userInputRequested(QString,QVariantMap)),
this,SLOT(onUserInputRequested(QString,QVariantMap)));
connect(ua,SIGNAL(connectionRequest()),this,SLOT(onConnectionRequest()));
connect(ua,SIGNAL(errorReported(QString)),this,SLOT(onErrorReported(QString)));
connect(ua,SIGNAL(userInputCanceled()),this,SLOT(onUserInputCanceled()));
connect(ua,SIGNAL(userInputRequested(QString,QVariantMap)),
this,SLOT(onUserInputRequested(QString,QVariantMap)), Qt::UniqueConnection);
ua->sendConnectReply("Clear");
connect(netman,SIGNAL(serviceAdded(QString)),this,SLOT(onServiceAdded(QString)));
connect(netman,SIGNAL(stateChanged(QString)),this,SLOT(networkStateChanged(QString)));
currentNetworkState = netman->state();
}
QConnectionManager::~QConnectionManager()
{
delete self;
}
QConnectionManager & QConnectionManager::instance()
{
if (!self) {
self = new QConnectionManager;
}
return *self;
}
// from useragent
void QConnectionManager::onUserInputRequested(const QString &servicePath, const QVariantMap &fields)
{
// gets called when a connman service gets called to connect and needs more configurations.
qDebug() << Q_FUNC_INFO;// << servicePath << fields;
Q_EMIT userInputRequested(servicePath, fields);
}
// from useragent
void QConnectionManager::onUserInputCanceled()
{
qDebug() << Q_FUNC_INFO;
Q_EMIT userInputCanceled();
}
// from useragent
void QConnectionManager::onErrorReported(const QString &error)
{
qDebug() << Q_FUNC_INFO << error;
Q_EMIT errorReported(error);
}
// from useragent
void QConnectionManager::onConnectionRequest()
{
qDebug() << Q_FUNC_INFO;
// if (!autoConnect()) {
Q_EMIT connectionRequest();
// }
}
void QConnectionManager::sendMessage()
{
// ua->sendConnectReply(QLatin1String("Suppress"));
}
void QConnectionManager::sendConnectReply(const QString &in0, int in1)
{
qDebug() << Q_FUNC_INFO << in0 << in1;
ua->sendConnectReply(in0, in1);
}
void QConnectionManager::sendUserReply(const QVariantMap &input)
{
qDebug() << Q_FUNC_INFO;
ua->sendUserReply(input);
}
void QConnectionManager::networkStateChanged(const QString &state)
{
QString msg;
if (currentNetworkState == "idle" && state == "association") {
msg = "Connecting...";
} else if (currentNetworkState == "ready" && state == "online") {
msg = "Connected";
} else if (state == "offline") {
msg = "Offline";
}
qDebug() << Q_FUNC_INFO << currentNetworkState << state << msg;
// NotificationManager *manager = NotificationManager::instance();
// QVariantHash hints;
// hints.insert(NotificationManager::HINT_URGENCY, 2);
// hints.insert(NotificationManager::HINT_CATEGORY, "device.error");
// hints.insert(NotificationManager::HINT_PREVIEW_BODY, msg);
// manager->Notify(qApp->applicationName(), 0, QString(), QString(), QString(), QStringList(), hints, -1);
// if (!msg.isEmpty()) {
// emit serviceStateChanged(msg);
// }
currentNetworkState = state;
}
void QConnectionManager::onServiceAdded(const QString &servicePath)
{
// qDebug() << Q_FUNC_INFO << servicePath;
}
void QConnectionManager::serviceErrorChanged(const QString &error)
{
qDebug() << Q_FUNC_INFO << error;
// NotificationManager *manager = NotificationManager::instance();
// QVariantHash hints;
// hints.insert(NotificationManager::HINT_URGENCY, 1);
// hints.insert(NotificationManager::HINT_CATEGORY, "device.error");
// hints.insert(NotificationManager::HINT_PREVIEW_BODY, error);
// manager->Notify(qApp->applicationName(), 0, QString(), QString(), QString(), QStringList(), hints, -1);
}
void QConnectionManager::stateChanged(const QString &state)
{
qDebug() << Q_FUNC_INFO << state;
}
bool QConnectionManager::autoConnect()
{
qDebug() << Q_FUNC_INFO;
QStringList techList = netman->technologiesList();
Q_FOREACH (const QString &tech, techList) {
QVector<NetworkService*> serviceList = netman->getServices(tech);
Q_FOREACH (NetworkService *service, serviceList) {
if(service->autoConnect() && service->favorite()) {
QObject::connect(service, SIGNAL(stateChanged(QString)),
this,SLOT(stateChanged(QString)));
QObject::connect(service, SIGNAL(connectRequestFailed(QString)),
this,SLOT(serviceErrorChanged(QString)));
service->requestConnect();
return true;
}
}
}
return false;
}
/****************************************************************************
**
** Copyright (C) 2012 Jolla Ltd.
** Contact: lorn.potter@gmail.com
**
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QCONNECTIONMANAGER_H
#define QCONNECTIONMANAGER_H
#include <QObject>
#include <QMap>
#include <QStringList>
#include <QVariant>
#include <QDBusMessage>
#include <QDBusObjectPath>
class UserAgent;
class SessionAgent;
class ConnAdaptor;
class NetworkManager;
class QConnectionManager : public QObject
{
Q_OBJECT
public:
~QConnectionManager();
static QConnectionManager &instance();
Q_SIGNALS:
void connectionChanged(const QString &, bool); // ?
void connected(); // ?
void userInputRequested(const QString &servicePath, const QVariantMap &fields);
void userInputCanceled();
void errorReported(const QString &error);
void connectionRequest();
public Q_SLOTS:
void onUserInputRequested(const QString &servicePath, const QVariantMap &fields);
void onUserInputCanceled();
void onErrorReported(const QString &error);
void onConnectionRequest();
void sendMessage();// ?
void sendConnectReply(const QString &in0, int in1);
void sendUserReply(const QVariantMap &input);
void networkStateChanged(const QString &state);
void onServiceAdded(const QString &servicePath);
void serviceErrorChanged(const QString &error);
void stateChanged(const QString &state);
private:
explicit QConnectionManager(QObject *parent = 0);
static QConnectionManager *self;
ConnAdaptor *connectionAdaptor;
UserAgent *ua;
NetworkManager *netman;
bool autoConnect();
QString currentNetworkState;
};
#endif // QCONNECTIONMANAGER_H
#-------------------------------------------------
#
# Project created by QtCreator 2011-05-11T09:46:44
#
#-------------------------------------------------
TEMPLATE = subdirs
#INCLUDEPATH += libconnman-qt
#DEPENDPATH += /home/lpotter/mer/builds/libconnman-qt-build/libconnman-qt
TEMPLATE += ordered
#SUBDIRS = lib
SUBDIRS += connd
SUBDIRS += connectionagentplugin
SUBDIRS += test/testqml
This diff is collapsed.
#include "connectionagentplugin.h"
#include "connectionamanagerinterface.h"
#include <qobject.h>
#define CONND_SERVICE "com.jolla.Connectiond"
#define CONND_PATH "/Connectiond"
ConnectionAgentPlugin::ConnectionAgentPlugin(QObject *parent):
QObject(parent)
{
qDebug() << Q_FUNC_INFO << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << this;
connectiondWatcher = new QDBusServiceWatcher(CONND_SERVICE,QDBusConnection::sessionBus(),
QDBusServiceWatcher::WatchForRegistration |
QDBusServiceWatcher::WatchForUnregistration, this);
connect(connectiondWatcher, SIGNAL(serviceRegistered(QString)),
this, SLOT(connectToConnectiond(QString)));
connect(connectiondWatcher, SIGNAL(serviceUnregistered(QString)),
this, SLOT(connectiondUnregistered(QString)));
bool available = QDBusConnection::sessionBus().interface()->isServiceRegistered(CONND_SERVICE);
if(available) {
connectToConnectiond();
qDebug() << Q_FUNC_INFO << CONND_SERVICE << "success!!";
} else {
qDebug() << Q_FUNC_INFO << CONND_SERVICE << "not available";
}
}
ConnectionAgentPlugin::~ConnectionAgentPlugin()
{
}
void ConnectionAgentPlugin::sendUserReply(const QVariantMap &input)
{
qDebug() << Q_FUNC_INFO << this << sender();
QDBusPendingReply<> reply = connManagerInterface->sendUserReply(input);
if (reply.isError()) {
qDebug() << Q_FUNC_INFO << reply.error().message();
}
}
void ConnectionAgentPlugin::sendConnectReply(const QString &replyMessage, int timeout)
{
qDebug() << Q_FUNC_INFO << replyMessage << timeout;
connManagerInterface->sendConnectReply(replyMessage,timeout);
}
void ConnectionAgentPlugin::onErrorReported(const QString &error)
{
qDebug() << Q_FUNC_INFO << error;
Q_EMIT errorReported(error);
}
void ConnectionAgentPlugin::onRequestBrowser(const QString &url)
{
qDebug() << Q_FUNC_INFO <<url;
}
void ConnectionAgentPlugin::onUserInputRequested(const QString &service, const QVariantMap &fields)
{
// we do this as qtdbus does not understand QVariantMap very well.
// we need to manually demarshall