Skip to content

Commit

Permalink
[connectionagent] make manual connect work better
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorn Potter committed Oct 3, 2013
1 parent b4f97a1 commit 52f2341
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 40 deletions.
2 changes: 1 addition & 1 deletion connd/main.cpp
Expand Up @@ -107,7 +107,7 @@ int main(int argc, char *argv[])
if (strcmp(argv[1],"-n") == 0) { //nodaemon
daemonize();
} else if (strcmp(argv[1],"-d") == 0) { //debug
loggerStatic ->toggleDebug(true);
loggerStatic->toggleDebug(true);
}
}
QCoreApplication::setOrganizationName("Jolla");
Expand Down
95 changes: 59 additions & 36 deletions connd/qconnectionmanager.cpp
Expand Up @@ -98,9 +98,6 @@ QConnectionManager::QConnectionManager(QObject *parent) :
connect(netman,SIGNAL(stateChanged(QString)),this,SLOT(networkStateChanged(QString)));
connect(netman,SIGNAL(servicesChanged()),this,SLOT(setup()));

connect(netman, SIGNAL(serviceRemoved(QString)),
this,SLOT(serviceRemoved(QString)), Qt::UniqueConnection);

QFile connmanConf("/etc/connman/main.conf");
if (connmanConf.open(QIODevice::ReadOnly | QIODevice::Text)) {
while (!connmanConf.atEnd()) {
Expand Down Expand Up @@ -174,7 +171,6 @@ void QConnectionManager::onConnectionRequest()

void QConnectionManager::sendConnectReply(const QString &in0, int in1)
{
qDebug() << Q_FUNC_INFO;
ua->sendConnectReply(in0, in1);
}

Expand Down Expand Up @@ -207,12 +203,15 @@ void QConnectionManager::serviceStateChanged(const QString &state)

if (currentNetworkState == "disconnect") {
ua->sendConnectReply("Clear");
if (manuallyDisconnectedService.isEmpty() && !handoverInProgress) {
manuallyDisconnectedService = service->path();
}
}
if (state == "failure") {
// service->requestDisconnect();
handoverInProgress = false;

if (!manuallyConnectedService.isEmpty()) {
if (!manuallyConnectedService.isEmpty() && service->path() == manuallyDisconnectedService) {
manuallyConnectedService.clear();
}

Expand All @@ -224,22 +223,23 @@ void QConnectionManager::serviceStateChanged(const QString &state)
//auto migrate
if (service->path() == serviceInProgress
&& state == "online") {
/// if (!manuallyDisconnected)
serviceInProgress.clear();
// handoverInProgress = false;
}

if (isStateOnline(state)) {
lastConnectedService = service->path();


if(!connectedServices.contains(service->path()))
connectedServices.insert(0,service->path());
}
//auto migrate
if (state == "idle") {
// handoverInProgress = false;
if (!handoverInProgress) {
qDebug() << Q_FUNC_INFO << "<<<<<<<<<<<<<<<<<<" << "manual disconnect";
// manuallyDisconnected = true;

if (!manuallyConnectedService.isEmpty() && service->path() == manuallyDisconnectedService) {
manuallyConnectedService.clear();
}

connectedServices.removeOne(service->path());
Expand Down Expand Up @@ -385,8 +385,9 @@ void QConnectionManager::connectToNetworkService(const QString &servicePath)
if (type.isEmpty())
return;
technology.setPath(netman->technologyPathForType(type));
if (servicesMap.value(servicePath)->state() != "online")
requestDisconnect(servicePath);

if (manuallyDisconnectedService.isEmpty() && servicesMap.value(servicePath)->state() != "online")
requestDisconnect(netman->defaultRoute()->path());

if (manuallyConnectedService.isEmpty() && technology.powered() && !handoverInProgress) {
if (servicePath.contains("cellular")) {
Expand All @@ -399,7 +400,8 @@ void QConnectionManager::connectToNetworkService(const QString &servicePath)
if (contextPath.contains(servicePath.section("_",2,2))) {
qDebug() << Q_FUNC_INFO << "requesting cell connection";
serviceInProgress = servicePath;

autoConnectService = servicePath;
manualConnected = false;
handoverInProgress = true;
QOfonoConnectionContext oContext;
oContext.setContextPath(contextPath);
Expand All @@ -421,25 +423,36 @@ void QConnectionManager::onScanFinished()

void QConnectionManager::updateServicesMap()
{
qDebug() << Q_FUNC_INFO;
int numbServices = servicesMap.count();
qDebug() << Q_FUNC_INFO << numbServices << netman->getServices().count();
if (numbServices == netman->getServices().count())
return;
// qDebug() << Q_FUNC_INFO << numbServices << netman->getServices().count();
// if (numbServices == netman->getServices().count())
// return;
QStringList oldServices = orderedServicesList;
orderedServicesList.clear();

Q_FOREACH (const QString &tech,techPreferenceList) {
QVector<NetworkService*> services = netman->getServices(tech);
Q_FOREACH (NetworkService *serv, services) {
qDebug() << serv->name() << serv->strength();
// qDebug() << serv->name() << serv->strength();

// if (serv->strength() == 0)
// continue;

servicesMap.insert(serv->path(), serv);
orderedServicesList << serv->path();

if (isStateOnline(serv->state())) {

if (!oldServices.contains(serv->path())) {
//new!
qDebug() << Q_FUNC_INFO <<"new service"
<< serv->path()
<< (manuallyDisconnectedService == serv->path());

if (manuallyDisconnectedService == serv->path())
manuallyDisconnectedService.clear(); //if service comes in range again
}

if (isStateOnline(serv->state())) {
if(!connectedServices.contains(serv->path()))
connectedServices.insert(0,serv->path());

Expand Down Expand Up @@ -657,19 +670,22 @@ void QConnectionManager::onServiceConnectionStarted()
manuallyConnectedService = serv->path();
handoverInProgress = true;
serviceInProgress = serv->path();
manuallyDisconnectedService.clear();
}

void QConnectionManager::onServiceDisconnectionStarted()
{
NetworkService *serv = qobject_cast<NetworkService *>(sender());
qDebug() << Q_FUNC_INFO << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" ;
manuallyDisconnectedService = serv->path();
}

bool QConnectionManager::isBestService(const QString &servicePath)
{
qDebug() << Q_FUNC_INFO << servicePath
<< servicesMap.contains(servicePath)
<< servicesMap.value(servicePath)->strength() ;
if (servicePath == autoDisconnectService) return false;
qDebug() << Q_FUNC_INFO
<< servicePath
<< manuallyDisconnectedService;
if (!manuallyDisconnectedService.isEmpty() && manuallyDisconnectedService == servicePath) return false;
// if (servicesMap.contains(servicePath) && servicesMap.value(servicePath)->strength() == 0) return false;
// if (connectedServices.contains(servicePath)) return false;
if (netman->defaultRoute()->path().contains(servicePath)) return false;
Expand All @@ -686,30 +702,37 @@ bool QConnectionManager::isStateOnline(const QString &state)
return true;
return false;
}
void QConnectionManager::requestDisconnect(const QString &service)

void QConnectionManager::requestDisconnect(const QString &servicePath)
{
if (servicesMap.contains(service)) {
qDebug() << Q_FUNC_INFO << service << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";
servicesMap.value(service)->requestDisconnect();
autoDisconnectService = service;
if (servicesMap.contains(servicePath)) {
qDebug() << Q_FUNC_INFO << servicePath << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";

QDBusInterface service("net.connman", servicePath.toLocal8Bit(),
"net.connman.Service", QDBusConnection::systemBus());
QDBusMessage reply = service.call(QDBus::NoBlock, QStringLiteral("Disconnect"));
manuallyDisconnectedService.clear();
QTimer::singleShot(10 * 1000,this,SLOT(timeout()));
}
}

void QConnectionManager::requestConnect(const QString &service)
void QConnectionManager::requestConnect(const QString &servicePath)
{
if (servicesMap.contains(service)) {
qDebug() << Q_FUNC_INFO << service;
if (servicesMap.contains(servicePath)) {
qDebug() << Q_FUNC_INFO << servicePath;
handoverInProgress = true;
servicesMap.value(service)->requestConnect();
// servicesMap.value(servicePath)->requestConnect();

QDBusInterface service("net.connman", servicePath.toLocal8Bit(),
"net.connman.Service", QDBusConnection::systemBus());
QDBusMessage reply = service.call(QDBus::NoBlock, QStringLiteral("Connect"));
manualConnected = false;
autoConnectService = servicePath;
manuallyConnectedService.clear();
QTimer::singleShot(10 * 1000,this,SLOT(timeout()));
}
}

void QConnectionManager::serviceRemoved(const QString &servicePath)
{
qDebug() << Q_FUNC_INFO << servicePath;
}

void QConnectionManager::timeout()
{
qDebug() << Q_FUNC_INFO << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";
Expand Down
6 changes: 3 additions & 3 deletions connd/qconnectionmanager.h
Expand Up @@ -33,6 +33,7 @@ class ConnAdaptor;
class NetworkManager;
class NetworkService;


class QConnectionManager : public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -100,8 +101,8 @@ public Q_SLOTS:
bool manualConnected;
QString manuallyConnectedService;
QString serviceInProgress;
QString autoDisconnectService;
bool manuallyDisconnected;
QString autoConnectService;
QString manuallyDisconnectedService;

bool isBestService(const QString &servicePath);
bool isStateOnline(const QString &state);
Expand All @@ -128,7 +129,6 @@ private slots:
void onServiceConnectionStarted();

void onServiceDisconnectionStarted();
void serviceRemoved(const QString &servicePath);

void timeout();
};
Expand Down

0 comments on commit 52f2341

Please sign in to comment.