From c42d5abff1f5f51facc169dd593725d819c4c868 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sun, 18 Sep 2011 04:26:20 +0200 Subject: separation into lib and plugins complete --- sowatchd/daemon.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ sowatchd/daemon.h | 30 +++++++++++++++++++ sowatchd/main.cpp | 20 +++++++++++++ sowatchd/sowatchd.pro | 38 +++++++++++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 sowatchd/daemon.cpp create mode 100644 sowatchd/daemon.h create mode 100644 sowatchd/main.cpp create mode 100644 sowatchd/sowatchd.pro (limited to 'sowatchd') diff --git a/sowatchd/daemon.cpp b/sowatchd/daemon.cpp new file mode 100644 index 0000000..a2d7b5a --- /dev/null +++ b/sowatchd/daemon.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include +#include "daemon.h" + +using namespace sowatch; + +Daemon::Daemon(QObject *parent) : + QObject(parent) +{ + loadDrivers(); + loadWatches(); + loadWatchlets(); +} + +void Daemon::loadDrivers() +{ + QDir dir(SOWATCH_DRIVERS_DIR); + foreach (QString file, dir.entryList(QDir::Files)) { + QPluginLoader loader(dir.absoluteFilePath(file)); + QObject *pluginObj = loader.instance(); + if (pluginObj) { + WatchPluginInterface *plugin = qobject_cast(pluginObj); + if (plugin) { + QStringList drivers = plugin->drivers(); + foreach (const QString& driver, drivers) { + _drivers[driver] = plugin; + } + } + } else { + qWarning() << "Invalid plugin" << file; + } + } + + qDebug() << "loaded drivers" << _drivers.keys(); +} + +void Daemon::loadWatches() +{ + QSettings settings; + int size = settings.beginReadArray("watches"); + + for (int i = 0; i < size; i++) { + settings.setArrayIndex(i); + QString driver = settings.value("driver").toString().toLower(); + WatchPluginInterface *plugin = _drivers[driver]; + if (plugin) { + Watch *watch = plugin->getWatch(driver, settings, this); + if (watch) { + _watches.append(watch); + } else { + qWarning() << "Driver" << driver << "refused to getWatch"; + } + } else { + qWarning() << "Invalid driver" << driver; + } + } + + settings.endArray(); + qDebug() << "handling" << _watches.size() << "watches"; +} + +void Daemon::loadWatchlets() +{ +#if 0 + QDir dir(SOWATCH_WATCHLETS_DIR); + foreach (QString file, dir.entryList(QDir::Files)) { + QPluginLoader loader(dir.absoluteFilePath(file)); + QObject *pluginObj = loader.instance(); + if (pluginObj) { + WatchPluginInterface *plugin = qobject_cast(pluginObj); + if (plugin) { + QStringList drivers = plugin->drivers(); + foreach (const QString& driver, drivers) { + _drivers[driver] = plugin; + } + } + } + } +#endif +} diff --git a/sowatchd/daemon.h b/sowatchd/daemon.h new file mode 100644 index 0000000..9346a41 --- /dev/null +++ b/sowatchd/daemon.h @@ -0,0 +1,30 @@ +#ifndef WATCHDAEMON_H +#define WATCHDAEMON_H + +#include +#include +#include + +#include + +namespace sowatch +{ + +class Daemon : public QObject +{ + Q_OBJECT +public: + explicit Daemon(QObject *parent = 0); + +protected: + QMap _drivers; + QList _watches; + + void loadDrivers(); + void loadWatches(); + void loadWatchlets(); +}; + +} + +#endif // WATCHDAEMON_H diff --git a/sowatchd/main.cpp b/sowatchd/main.cpp new file mode 100644 index 0000000..0d7abb9 --- /dev/null +++ b/sowatchd/main.cpp @@ -0,0 +1,20 @@ +#include + +#include +#include "daemon.h" + +using namespace sowatch; + +static Daemon* d; + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + QApplication::setOrganizationDomain("com.javispedro.sowatch"); + QApplication::setOrganizationName("sowatch"); + QApplication::setApplicationName("sowatchd"); + + d = new Daemon(); + + return a.exec(); +} diff --git a/sowatchd/sowatchd.pro b/sowatchd/sowatchd.pro new file mode 100644 index 0000000..1c09046 --- /dev/null +++ b/sowatchd/sowatchd.pro @@ -0,0 +1,38 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2011-09-17T04:55:26 +# +#------------------------------------------------- + +TEMPLATE = app + +TARGET = sowatchd + +QT += core gui +CONFIG += console +CONFIG -= app_bundle + +SOURCES += main.cpp \ + daemon.cpp + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../libsowatch/release/ -llibsowatch +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../libsowatch/debug/ -llibsowatch +else:symbian: LIBS += -llibsowatch +else:unix: LIBS += -L$$OUT_PWD/../libsowatch/ -llibsowatch + +INCLUDEPATH += $$PWD/../libsowatch +DEPENDPATH += $$PWD/../libsowatch + +unix { + maemo5 { + target.path = /opt/sowatch + } else { + target.path = /usr/bin + } + INSTALLS += target +} + +HEADERS += \ + daemon.h + + -- cgit v1.2.3