summaryrefslogtreecommitdiff
path: root/distfoldd
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2016-05-23 00:20:25 +0200
committerJavier <dev.git@javispedro.com>2016-05-23 00:20:25 +0200
commitf60d4bf53339876cf5dbf4382eafb8aad33a27c1 (patch)
treeee4b2b897438cdd0a6f037776f0e6e03803fa424 /distfoldd
parent2e45a5a7776b79732cd500c7462574f8fbe7ca23 (diff)
downloaddistfold-qt5.tar.gz
distfold-qt5.zip
initial qt5 portqt5
Diffstat (limited to 'distfoldd')
-rw-r--r--distfoldd/discoverer.cc56
-rw-r--r--distfoldd/discoverer.h9
-rw-r--r--distfoldd/distfoldd.pro11
-rw-r--r--distfoldd/watcher.cc2
4 files changed, 15 insertions, 63 deletions
diff --git a/distfoldd/discoverer.cc b/distfoldd/discoverer.cc
index 629a955..011f938 100644
--- a/distfoldd/discoverer.cc
+++ b/distfoldd/discoverer.cc
@@ -8,8 +8,7 @@ Discoverer::Discoverer(const QUuid &uuid, uint port, const QString &serviceName,
_mtime(), _mtimeChanged(false),
_receiver(new QUdpSocket(this)), _sender(new QUdpSocket(this)),
_netConfig(new QNetworkConfigurationManager(this)),
- _netInfo(new QSystemNetworkInfo(this)),
- _timer(new QSystemAlignedTimer(this)), _fallbackTimer(new QTimer(this))
+ _timer(new QTimer(this))
{
connect(_receiver, SIGNAL(readyRead()), SLOT(handleDataAvailable()));
if (!_receiver->bind(servicePort, QUdpSocket::ShareAddress)) {
@@ -17,21 +16,13 @@ Discoverer::Discoverer(const QUuid &uuid, uint port, const QString &serviceName,
}
connect(_netConfig, SIGNAL(onlineStateChanged(bool)), SLOT(handleOnlineStateChanged(bool)));
connect(_timer, SIGNAL(timeout()), SLOT(handleTimerTimeout()));
- connect(_fallbackTimer, SIGNAL(timeout()), SLOT(handleTimerTimeout()));
- connect(_timer, SIGNAL(error(QSystemAlignedTimer::AlignedTimerError)), SLOT(handleTimerError()));
_timer->setSingleShot(true);
- _fallbackTimer->setSingleShot(true);
+ _timer->setTimerType(Qt::VeryCoarseTimer);
if (_netConfig->isOnline() ||
_netConfig->allConfigurations(QNetworkConfiguration::Defined).empty()) {
// Either only, or _netConfig has no configs so it is useless.
qDebug() << "Start timer";
- _timer->start(0, activeBroadcastInterval);
- if (_timer && _timer->lastError() != QSystemAlignedTimer::NoError) {
- qDebug() << "QSystemAlignedTimer broken at start";
- delete _timer;
- _timer = 0;
- _fallbackTimer->start(activeBroadcastInterval * 1000);
- }
+ _timer->start(activeBroadcastInterval * 1000);
} else {
qDebug() << "I am NOT online";
}
@@ -52,8 +43,8 @@ void Discoverer::setLastModifiedTime(const QDateTime& dateTime)
QByteArray Discoverer::encodeMessage() const
{
QByteArray ba;
- QByteArray hostUuid = _hostUuid.toString().toAscii();
- QByteArray folderUuid = _folderUuid.toString().toAscii();
+ QByteArray hostUuid = _hostUuid.toString().toLatin1();
+ QByteArray folderUuid = _folderUuid.toString().toLatin1();
QByteArray serviceNameUtf8 = _serviceName.toUtf8();
Message msg;
@@ -74,13 +65,8 @@ QByteArray Discoverer::encodeMessage() const
void Discoverer::switchToActiveMode()
{
- if (_timer) {
- if (!_timer->isActive() || _timer->maximumInterval() > activeBroadcastInterval) {
- if (_timer->isActive()) _timer->wokeUp();
- _timer->start(0, activeBroadcastInterval);
- }
- } else if (!_fallbackTimer->isActive() || _fallbackTimer->interval() > activeBroadcastInterval * 1000) {
- _fallbackTimer->start(activeBroadcastInterval * 1000);
+ if (!_timer->isActive() || _timer->interval() > activeBroadcastInterval * 1000) {
+ _timer->start(activeBroadcastInterval * 1000);
}
}
@@ -112,9 +98,9 @@ void Discoverer::handleBroadcastMessage(const QHostAddress& sender, const QByteA
char uuidData[sizeof(msg->hostUuid)];
strncpy(uuidData, msg->hostUuid, sizeof(uuidData));
- QUuid hostUuid(QString::fromAscii(uuidData, sizeof(uuidData)));
+ QUuid hostUuid(QString::fromLatin1(uuidData, sizeof(uuidData)));
strncpy(uuidData, msg->folderUuid, sizeof(uuidData));
- QUuid folderUuid(QString::fromAscii(uuidData, sizeof(uuidData)));
+ QUuid folderUuid(QString::fromLatin1(uuidData, sizeof(uuidData)));
if (hostUuid.isNull() || folderUuid.isNull()) {
qWarning() << "Null uuid";
@@ -151,7 +137,7 @@ void Discoverer::handleHostSeen(const QUuid &hostUuid)
void Discoverer::handleTimerTimeout()
{
- qDebug() << "Timer";
+ qDebug() << "Timer tick";
broadcastMessage();
QDateTime now = QDateTime::currentDateTime();
QHash<QUuid, HostInfo>::iterator i = _knownHosts.begin();
@@ -163,33 +149,17 @@ void Discoverer::handleTimerTimeout()
}
}
qDebug() << "Known hosts" << _knownHosts.size();
- if (_timer) {
- _timer->start(idleBroadcastInterval * 0.7f, idleBroadcastInterval * 1.3f);
- } else {
- _fallbackTimer->start(idleBroadcastInterval * 1000);
- }
-}
-
-void Discoverer::handleTimerError()
-{
- qDebug() << "SystemAlignedTimer broken";
- _timer->deleteLater();
- _timer = 0;
- _fallbackTimer->start(activeBroadcastInterval * 1000);
+ _timer->start(idleBroadcastInterval * 1000);
}
void Discoverer::handleOnlineStateChanged(bool online)
{
if (online) {
qDebug() << "Online";
- if (_netInfo->currentMode() == QSystemNetworkInfo::UnknownMode ||
- _netInfo->currentMode() == QSystemNetworkInfo::WlanMode) {
- switchToActiveMode();
- }
+ switchToActiveMode();
} else {
qDebug() << "Offline";
_knownHosts.clear();
- _fallbackTimer->stop();
- if (_timer) _timer->stop();
+ _timer->stop();
}
}
diff --git a/distfoldd/discoverer.h b/distfoldd/discoverer.h
index ae106de..3a2bffc 100644
--- a/distfoldd/discoverer.h
+++ b/distfoldd/discoverer.h
@@ -7,10 +7,6 @@
#include <QtNetwork/QNetworkConfigurationManager>
#include <QtNetwork/QHostAddress>
#include <QtNetwork/QUdpSocket>
-#include <QtSystemInfo/QSystemNetworkInfo>
-#include <QtSystemInfo/QSystemAlignedTimer>
-
-QTM_USE_NAMESPACE
class Discoverer : public QObject
{
@@ -58,7 +54,6 @@ private slots:
void handleBroadcastMessage(const QHostAddress& sender, const QByteArray &data);
void handleHostSeen(const QUuid& hostUuid);
void handleTimerTimeout();
- void handleTimerError();
void handleOnlineStateChanged(bool online);
private:
@@ -72,10 +67,8 @@ private:
QUdpSocket *_sender;
quint32 _myId;
QNetworkConfigurationManager *_netConfig;
- QSystemNetworkInfo *_netInfo;
QDateTime _lastBroadcast;
- QSystemAlignedTimer *_timer;
- QTimer *_fallbackTimer;
+ QTimer *_timer;
QHash<QUuid, HostInfo> _knownHosts;
};
diff --git a/distfoldd/distfoldd.pro b/distfoldd/distfoldd.pro
index f2315d4..4631ab2 100644
--- a/distfoldd/distfoldd.pro
+++ b/distfoldd/distfoldd.pro
@@ -6,9 +6,6 @@ CONFIG -= app_bundle
QT += core network
QT -= gui
-CONFIG += mobility
-MOBILITY += systeminfo
-
CONFIG += crypto
SOURCES += main.cc \
@@ -33,11 +30,3 @@ HEADERS += \
compressor.h \
localkey.h
-contains(MEEGO_EDITION,harmattan) {
- target.path = /opt/distfold/bin
- INSTALLS += target
-
- service.files = distfoldd.conf
- service.path = /etc/init/apps
- INSTALLS += service
-}
diff --git a/distfoldd/watcher.cc b/distfoldd/watcher.cc
index 39b68f3..5848f4e 100644
--- a/distfoldd/watcher.cc
+++ b/distfoldd/watcher.cc
@@ -1,12 +1,12 @@
#include <QtCore/QDebug>
+#include <unistd.h>
#include <sys/errno.h>
#include <sys/fcntl.h>
#include <sys/inotify.h>
#include "watcher.h"
-
Watcher::Watcher(const QString& path, QObject *parent) :
QObject(parent)
{