From 4f713dfa2728b5727481604ad7249e9c71a6487d Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 29 Aug 2011 15:08:23 +0200 Subject: added makefiles --- workspace/LogReceiver/logreceiver.cpp | 88 +++++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 25 deletions(-) (limited to 'workspace/LogReceiver/logreceiver.cpp') diff --git a/workspace/LogReceiver/logreceiver.cpp b/workspace/LogReceiver/logreceiver.cpp index 93e8373..e0ae336 100644 --- a/workspace/LogReceiver/logreceiver.cpp +++ b/workspace/LogReceiver/logreceiver.cpp @@ -209,26 +209,42 @@ void LogReceiver::checkInternetConnection(QList &interfaces) { } void LogReceiver::checkInternetConnectionViaTCP(QString ifName) { - const bool canStartIAP = (configurationManager.capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces); - QList configs = configurationManager.allConfigurations(); - QNetworkConfiguration cfg; - foreach(QNetworkConfiguration nC, configs) { - if(nC.name() == ifName) { - cfg = nC; - } - } - - if(!cfg.isValid() || (!canStartIAP && cfg.state() != QNetworkConfiguration::Active)) { - - return; - } - session = new QNetworkSession(cfg, this); - session->open(); - session->waitForOpened(-1); - - - QTcpSocket *tcpSocket = new QTcpSocket(this); - tcpSocket->connectToHost(); + const bool canStartIAP = (configurationManager.capabilities() + & QNetworkConfigurationManager::CanStartAndStopInterfaces); + QList configs = + configurationManager.allConfigurations(); + QNetworkConfiguration cfg; + foreach(QNetworkConfiguration nC, configs) + { + if (nC.name() == ifName) { + qDebug() << "found config" << nC.name(); + cfg = nC; + break; + } + } + if (!cfg.isValid() || (!canStartIAP && cfg.state() + != QNetworkConfiguration::Active)) { + qDebug() << "config is not valid" << cfg.name(); + return; + } + QNetworkSession *session = new QNetworkSession(cfg, this); + session->open(); + if (session->waitForOpened(-1)) { + + QTcpSocket *tcpSocket = new QTcpSocket(this); + tcpSocket->connectToHost(QString("209.85.148.105"), 80); + if (!tcpSocket->waitForConnected()) { + qDebug() << tcpSocket->errorString(); + emit updateStatusLabel(ifName, "connection not possible"); + } else { + emit updateStatusLabel(ifName, "connection possible"); + emit connectionEstablished(ifName); + } + } + else { + qDebug() << "couldn't open session"; + } + session->close(); } void LogReceiver::handleNewConnection() { @@ -258,6 +274,21 @@ void LogReceiver::handleNewInput() { } } + +void LogReceiver::handleNewInput_(QLocalSocket *client) { + + QString data(client->readAll()); + + data = data.trimmed(); + + QStringList lines = data.split("\n"); + + for (int i=0; i < lines.length(); i++) { + handleNewInputLine(lines.at(i)); + } +} + + void LogReceiver::handleNewInputLine(QString data) { QString logMsg(data); @@ -323,9 +354,6 @@ void LogReceiver::handleNewInputLine(QString data) { void LogReceiver::handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) { QProcess* p = qobject_cast(QObject::sender()); - - - QString ifName = clientProcessToIfNameMap.value(p,"ifName"); if(ifName.compare("ifName") == 0) { @@ -341,9 +369,19 @@ void LogReceiver::handleProcessFinished(int exitCode, qDebug() << "process normal exit"; qDebug() << "check internet connction"; emit updateStatusLabel(ifName, "check connectivity"); - checkInternetConnection(ifName); + //checkInternetConnection(ifName); + checkInternetConnectionViaTCP(ifName); } - + } + if (numberOfProcesses == 1) { + QLocalSocket *s; + qDebug() << "try to read socket buffer.."; + foreach(s, clients.keys()) { + if (s->bytesAvailable() > 0) { + qDebug() << "read socket buffer.."; + handleNewInput_(s); + } + } } numberOfProcesses = numberOfProcesses -1; if (numberOfProcesses <= 0) { -- cgit v1.2.3-55-g7522