Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rename ConnectionAgentPlugin as DeclarativeConnectionAgent
Qml type is not a plugin really.
  • Loading branch information
pvuorela committed Jul 7, 2015
1 parent 4f608a3 commit c7a2512
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 70 deletions.
4 changes: 2 additions & 2 deletions connectionagentplugin/connectionagentplugin.pro
Expand Up @@ -7,11 +7,11 @@ uri = com.jolla.connection

SOURCES += \
connectionagentplugin_plugin.cpp \
connectionagentplugin.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
39 changes: 2 additions & 37 deletions connectionagentplugin/connectionagentplugin_plugin.cpp
Expand Up @@ -15,45 +15,10 @@
****************************************************************************/

#include "connectionagentplugin_plugin.h"
#include "connectionagentplugin.h"

/*
*This class is for accessing connman's UserAgent from multiple sources.
*This is because currently, there can only be one UserAgent per system.
*
*It also makes use of a patch to connman, that allows the UserAgent
*to get signaled when a connection is needed. This is the real reason
*this daemon is needed. An InputRequest is short lived, and thus, may
*not clash with other apps that need to use UserAgent.
*
*When you are trying to intercept a connection request, you need a long
*living process to wait until such time. This will immediately clash if
*a wlan needs user Input signal from connman, and the configure will never
*get the proper signal.
*
*This qml type can be used as such:
*
*import com.jolla.connection 1.0
*
* ConnectionAgent {
* id: userAgent
* onUserInputRequested: {
* console.log(" onUserInputRequested:")
* }
*
* onConnectionRequest: {
* console.log("onConnectionRequest ")
* sendSuppress()
* }
* onErrorReported: {
* console.log("Got error from connman: " + error);
* }
* }
*
**/
#include "declarativeconnectionagent.h"

void ConnectionagentpluginPlugin::registerTypes(const char *uri)
{
// @uri com.jolla.connection
qmlRegisterType<ConnectionAgentPlugin>(uri, 1, 0, "ConnectionAgent");
qmlRegisterType<DeclarativeConnectionAgent>(uri, 1, 0, "ConnectionAgent");
}
Expand Up @@ -14,7 +14,7 @@
**
****************************************************************************/

#include "connectionagentplugin.h"
#include "declarativeconnectionagent.h"
#include "connectiond_interface.h"

#include <connman-qt5/networkmanager.h>
Expand All @@ -26,7 +26,7 @@
#define CONND_SERVICE "com.jolla.Connectiond"
#define CONND_PATH "/Connectiond"

ConnectionAgentPlugin::ConnectionAgentPlugin(QObject *parent):
DeclarativeConnectionAgent::DeclarativeConnectionAgent(QObject *parent):
QObject(parent),
connManagerInterface(0)
{
Expand All @@ -42,11 +42,11 @@ ConnectionAgentPlugin::ConnectionAgentPlugin(QObject *parent):
connectToConnectiond();
}

ConnectionAgentPlugin::~ConnectionAgentPlugin()
DeclarativeConnectionAgent::~DeclarativeConnectionAgent()
{
}

void ConnectionAgentPlugin::connectToConnectiond(QString)
void DeclarativeConnectionAgent::connectToConnectiond(QString)
{
if (connManagerInterface) {
delete connManagerInterface;
Expand Down Expand Up @@ -92,7 +92,7 @@ void ConnectionAgentPlugin::connectToConnectiond(QString)
this,SLOT(onTetheringFinished(bool)));
}

void ConnectionAgentPlugin::sendUserReply(const QVariantMap &input)
void DeclarativeConnectionAgent::sendUserReply(const QVariantMap &input)
{
if (!connManagerInterface || !connManagerInterface->isValid()) {
Q_EMIT errorReported("","ConnectionAgent not available");
Expand All @@ -106,7 +106,7 @@ void ConnectionAgentPlugin::sendUserReply(const QVariantMap &input)
}
}

void ConnectionAgentPlugin::sendConnectReply(const QString &replyMessage, int timeout)
void DeclarativeConnectionAgent::sendConnectReply(const QString &replyMessage, int timeout)
{
if (!connManagerInterface || !connManagerInterface->isValid()) {
Q_EMIT errorReported("","ConnectionAgent not available");
Expand All @@ -115,7 +115,7 @@ void ConnectionAgentPlugin::sendConnectReply(const QString &replyMessage, int ti
connManagerInterface->sendConnectReply(replyMessage,timeout);
}

void ConnectionAgentPlugin::connectToType(const QString &type)
void DeclarativeConnectionAgent::connectToType(const QString &type)
{
if (!connManagerInterface || !connManagerInterface->isValid()) {
Q_EMIT errorReported("","ConnectionAgent not available");
Expand All @@ -125,18 +125,18 @@ void ConnectionAgentPlugin::connectToType(const QString &type)
connManagerInterface->connectToType(type);
}

void ConnectionAgentPlugin::onErrorReported(const QString &servicePath, const QString &error)
void DeclarativeConnectionAgent::onErrorReported(const QString &servicePath, const QString &error)
{
Q_EMIT errorReported(servicePath, error);
}

void ConnectionAgentPlugin::onRequestBrowser(const QString &url)
void DeclarativeConnectionAgent::onRequestBrowser(const QString &url)
{
qDebug() << Q_FUNC_INFO <<url;
Q_EMIT browserRequested(url);
}

void ConnectionAgentPlugin::onUserInputRequested(const QString &service, const QVariantMap &fields)
void DeclarativeConnectionAgent::onUserInputRequested(const QString &service, const QVariantMap &fields)
{
// we do this as qtdbus does not understand QVariantMap very well.
// we need to manually demarshall
Expand All @@ -152,37 +152,37 @@ void ConnectionAgentPlugin::onUserInputRequested(const QString &service, const Q
Q_EMIT userInputRequested(service, map);
}

void ConnectionAgentPlugin::onConnectionRequested()
void DeclarativeConnectionAgent::onConnectionRequested()
{
qDebug() << Q_FUNC_INFO;
Q_EMIT connectionRequest();
}

void ConnectionAgentPlugin::connectiondUnregistered(QString)
void DeclarativeConnectionAgent::connectiondUnregistered(QString)
{
if (connManagerInterface) {
delete connManagerInterface;
connManagerInterface = 0;
}
}

void ConnectionAgentPlugin::onConnectionState(const QString &state, const QString &type)
void DeclarativeConnectionAgent::onConnectionState(const QString &state, const QString &type)
{
qDebug() << Q_FUNC_INFO << state;
Q_EMIT connectionState(state, type);
}

void ConnectionAgentPlugin::startTethering(const QString &type)
void DeclarativeConnectionAgent::startTethering(const QString &type)
{
connManagerInterface->startTethering(type);
}

void ConnectionAgentPlugin::onTetheringFinished(bool success)
void DeclarativeConnectionAgent::onTetheringFinished(bool success)
{
Q_EMIT tetheringFinished(success);
}

void ConnectionAgentPlugin::stopTethering(bool keepPowered)
void DeclarativeConnectionAgent::stopTethering(bool keepPowered)
{
connManagerInterface->stopTethering(keepPowered);
}
Expand Up @@ -14,22 +14,56 @@
**
****************************************************************************/

#ifndef CONNECTIONAGENTPLUGIN_H
#define CONNECTIONAGENTPLUGIN_H
#ifndef DECLARATIVECONNECTIONAGENT_H
#define DECLARATIVECONNECTIONAGENT_H

#include "connectionagentplugin.h"
#include "declarativeconnectionagent.h"
#include "connectiond_interface.h"

class NetworkManager;
class ConnectionAgentPlugin : public QObject
/*
*This class is for accessing connman's UserAgent from multiple sources.
*This is because currently, there can only be one UserAgent per system.
*
*It also makes use of a patch to connman, that allows the UserAgent
*to get signaled when a connection is needed. This is the real reason
*this daemon is needed. An InputRequest is short lived, and thus, may
*not clash with other apps that need to use UserAgent.
*
*When you are trying to intercept a connection request, you need a long
*living process to wait until such time. This will immediately clash if
*a wlan needs user Input signal from connman, and the configure will never
*get the proper signal.
*
*This qml type can be used as such:
*
*import com.jolla.connection 1.0
*
* ConnectionAgent {
* id: userAgent
* onUserInputRequested: {
* console.log(" onUserInputRequested:")
* }
*
* onConnectionRequest: {
* console.log("onConnectionRequest ")
* sendSuppress()
* }
* onErrorReported: {
* console.log("Got error from connman: " + error);
* }
* }
*
**/

class DeclarativeConnectionAgent : public QObject
{
Q_OBJECT

Q_DISABLE_COPY(ConnectionAgentPlugin)
Q_DISABLE_COPY(DeclarativeConnectionAgent)

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

public slots:
void sendUserReply(const QVariantMap &input);
Expand Down Expand Up @@ -64,5 +98,5 @@ private slots:
void connectiondUnregistered(const QString = QString());
};

#endif // CONNECTIONAGENTPLUGIN_H
#endif

Expand Up @@ -16,10 +16,10 @@ TEMPLATE = app


SOURCES += tst_connectionagent_plugintest.cpp \
../../../connectionagentplugin/connectionagentplugin.cpp
../../../connectionagentplugin/declarativeconnectionagent.cpp

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

DBUS_INTERFACES = connectiond_interface
connectiond_interface.files = ../../../connd/com.jollamobile.Connectiond.xml
Expand Down
Expand Up @@ -20,7 +20,7 @@

#include <QString>
#include <QtTest>
#include "../../../connectionagentplugin/connectionagentplugin.h"
#include "../../../connectionagentplugin/declarativeconnectionagent.h"

#include <networkmanager.h>
#include <networktechnology.h>
Expand Down Expand Up @@ -49,13 +49,13 @@ private Q_SLOTS:
void tst_tethering();

private:
ConnectionAgentPlugin *plugin;
NetworkManager *netman;
DeclarativeConnectionAgent *plugin;
NetworkManager *netman;
};

Tst_connectionagent_pluginTest::Tst_connectionagent_pluginTest()
{
plugin = new ConnectionAgentPlugin(this);
plugin = new DeclarativeConnectionAgent(this);
netman = NetworkManagerFactory::createInstance();
QTest::qWait(5000);
}
Expand Down

0 comments on commit c7a2512

Please sign in to comment.