Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
update readme. reset the connection after a failure.
change signal to handle other types
  • Loading branch information
Lorn Potter committed Apr 10, 2013
1 parent d00488a commit 839c63d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 22 deletions.
8 changes: 6 additions & 2 deletions README.md
Expand Up @@ -9,7 +9,11 @@ The daemon and QtDeclarative plugin are licensed un ther LGPL.
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
It also handles autoconnect features. In the future it might handle
sessions and connection 'migration' or re-connection when a better known
service becomes available.

It 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.
Expand Down Expand Up @@ -37,4 +41,4 @@ import com.jolla.connection 1.0
console.log("Got error from connman: " + error);
}
}


6 changes: 4 additions & 2 deletions connd/connadaptor.h
Expand Up @@ -31,7 +31,9 @@ class ConnAdaptor: public QDBusAbstractAdaptor
Q_CLASSINFO("D-Bus Introspection", ""
" <interface name=\"com.jolla.Connectiond\">\n"
" <signal name=\"connectionRequest\"/>\n"
" <signal name=\"wlanConfigurationNeeded\"/>\n"
" <signal name=\"configurationNeeded\">\n"
" <arg direction=\"out\" type=\"s\" name=\"url\"/>\n"
" </signal>\n"
" <signal name=\"errorReported\">\n"
" <arg direction=\"out\" type=\"s\" name=\"error\"/>\n"
" </signal>\n"
Expand Down Expand Up @@ -77,7 +79,7 @@ public Q_SLOTS: // METHODS
void requestBrowser(const QString &url);
void userInputCanceled();
void userInputRequested(const QString &service, const QVariantMap &fields);
void wlanConfigurationNeeded();
void configurationNeeded( const QString &type);
};

#endif
56 changes: 44 additions & 12 deletions connd/qconnectionmanager.cpp
Expand Up @@ -43,9 +43,6 @@ QConnectionManager::QConnectionManager(QObject *parent) :
serviceConnect(0),
currentNotification(0)
{
bool available = QDBusConnection::sessionBus().interface()->isServiceRegistered(CONND_SERVICE);

qDebug() << Q_FUNC_INFO << available;
connectionAdaptor = new ConnAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();

Expand All @@ -56,7 +53,6 @@ QConnectionManager::QConnectionManager(QObject *parent) :
if (!dbus.registerObject(CONND_PATH, this)) {
qDebug() << "XXXXXXXXXXX could not register object XXXXXXXXXXXXXXXXXX";
}
qDebug() << "XXXXXXXXXXX everything hunky dory XXXXXXXXXXXXXXXXXX";

ua = new UserAgent(this);

Expand Down Expand Up @@ -116,9 +112,9 @@ void QConnectionManager::onUserInputCanceled()
// from useragent
void QConnectionManager::onErrorReported(const QString &error)
{
qDebug() << Q_FUNC_INFO << error;;

qDebug() << Q_FUNC_INFO << error;
Q_EMIT errorReported(error);

}

// from useragent
Expand Down Expand Up @@ -155,10 +151,30 @@ void QConnectionManager::onServiceAdded(const QString &servicePath)
&& servicesMap.value(servicePath)->favorite()) {
connectToNetworkService(servicePath);
} else {
Q_EMIT wlanConfigurationNeeded();
Q_EMIT configurationNeeded(servicesMap.value(servicePath)->type());
serviceConnect = false;
}
}
//automigrate
for (int i = 0; i < servicesMap.keys().count(); i++) {
QString path = servicesMap.keys().at(i);

if (!connectedServices.isEmpty()
&& !connectedServices.contains(path)
&& (servicesMap.value(path)->strength() > servicesMap.value(connectedServices.at(0))->strength())
&& (servicesMap.value(path)->state() != "online")
&& servicesMap.value(path)->favorite()
&& servicesMap.value(path)->autoConnect()) {

qDebug() << " a better service becomes available";

connectionHandover(connectedServices.at(0),path);
}
qDebug() << Q_FUNC_INFO
<< servicesMap.value(path)->name()
<< servicesMap.value(path)->state()
<< servicesMap.value(path)->favorite();
}
}

void QConnectionManager::onServiceRemoved(const QString &servicePath)
Expand All @@ -179,7 +195,13 @@ void QConnectionManager::stateChanged(const QString &state)
NetworkService *service = qobject_cast<NetworkService *>(sender());

qDebug() << Q_FUNC_INFO << state << service->name();

if (currentNetworkState == "disconnect") {
ua->sendConnectReply("Clear");
}
if (state == "failure") {
service->requestDisconnect();
service->remove(); //reset this service
}
if (!(currentNetworkState == "online" && state == "association"))
Q_EMIT connectionState(state, service->type());

Expand Down Expand Up @@ -220,7 +242,7 @@ bool QConnectionManager::autoConnect()
if (!selectedService.isEmpty()) {
qDebug() << Q_FUNC_INFO << servicesMap.value(selectedService)->name();
serviceConnect = true;
servicesMap.value(selectedService)->requestConnect();
connectToNetworkService(selectedService); //->requestConnect();
return true;
}

Expand Down Expand Up @@ -268,7 +290,7 @@ void QConnectionManager::connectToType(const QString &type)

if (needConfig) {
qDebug() << Q_FUNC_INFO << "no favorite service found. Configuration needed";
Q_EMIT wlanConfigurationNeeded();
Q_EMIT configurationNeeded(type);
serviceConnect = false;
okToConnect = false;
}
Expand All @@ -279,8 +301,6 @@ void QConnectionManager::connectToNetworkService(const QString &servicePath)
{
serviceConnect = true;

QObject::connect(servicesMap.value(servicePath), SIGNAL(connectRequestFailed(QString)),
this,SLOT(serviceErrorChanged(QString)), Qt::UniqueConnection);

qDebug() << Q_FUNC_INFO << "just connect to this thing"
<< servicesMap.value(servicePath)->type();
Expand All @@ -302,6 +322,7 @@ void QConnectionManager::onScanFinished()

void QConnectionManager::defaultRouteChanged(NetworkService* defaultRoute)
{
//not really default route, more of default/first service in list
qDebug() << Q_FUNC_INFO << defaultRoute;

if (defaultRoute) //this apparently can be null
Expand All @@ -326,6 +347,17 @@ void QConnectionManager::updateServicesMap()
qDebug() << Q_FUNC_INFO <<"::::::::::::::::::::: "<< serv->path();
QObject::connect(serv, SIGNAL(stateChanged(QString)),
this,SLOT(stateChanged(QString)), Qt::UniqueConnection);
QObject::connect(serv, SIGNAL(connectRequestFailed(QString)),
this,SLOT(serviceErrorChanged(QString)), Qt::UniqueConnection);
}
}
}

void QConnectionManager::connectionHandover(const QString &oldService, const QString &newService)
{
qDebug() << Q_FUNC_INFO <<"XXXXXXXXXXXXXXXXXXXXXXXXXXX" << oldService << newService;

servicesMap.value(oldService)->requestDisconnect();
connectToNetworkService(newService);
}

4 changes: 3 additions & 1 deletion connd/qconnectionmanager.h
Expand Up @@ -48,7 +48,7 @@ class QConnectionManager : public QObject
void userInputCanceled();
void errorReported(const QString &error);
void connectionRequest();
void wlanConfigurationNeeded();
void configurationNeeded(const QString &type);
void connectionState(const QString &state, const QString &type);

public Q_SLOTS:
Expand Down Expand Up @@ -88,6 +88,8 @@ public Q_SLOTS:
uint currentNotification;

QHash<QString,NetworkService *> servicesMap;
void connectionHandover(const QString &oldService, const QString &newService);
QList <QString> connectedServices;

private slots:
void onScanFinished();
Expand Down
5 changes: 2 additions & 3 deletions connectionagentplugin/connectionagentplugin.cpp
Expand Up @@ -139,7 +139,6 @@ void ConnectionAgentPlugin::onConnectionRequested()
Q_EMIT connectionRequest();
}


void ConnectionAgentPlugin::connectiondUnregistered(QString)
{
if (connManagerInterface) {
Expand All @@ -148,10 +147,10 @@ void ConnectionAgentPlugin::connectiondUnregistered(QString)
}
}

void ConnectionAgentPlugin::onWlanConfigurationNeeded()
void ConnectionAgentPlugin::onConfigurationNeeded(const QString &type)
{
qDebug() << Q_FUNC_INFO;
Q_EMIT wlanConfigurationNeeded();
Q_EMIT configurationNeeded(type);
}

void ConnectionAgentPlugin::onConnectionState(const QString &state, const QString &type)
Expand Down
4 changes: 2 additions & 2 deletions connectionagentplugin/connectionagentplugin.h
Expand Up @@ -41,7 +41,7 @@ public slots:
void userInputCanceled();
void errorReported(const QString &error);
void connectionRequest();
void wlanConfigurationNeeded();
void configurationNeeded(const QString &type);
void connectionState(const QString &state, const QString &type);

private:
Expand All @@ -53,7 +53,7 @@ private slots:
void onRequestBrowser(const QString &url);
void onUserInputRequested(const QString &service, const QVariantMap &fields);
void onConnectionRequested();
void onWlanConfigurationNeeded();
void onConfigurationNeeded(const QString &type);
void onConnectionState(const QString &state, const QString &type);

void connectToConnectiond(const QString = QString());
Expand Down

0 comments on commit 839c63d

Please sign in to comment.