diff options
Diffstat (limited to 'sowatchd')
-rw-r--r-- | sowatchd/com.javispedro.sowatch.service.sowatch-service.service | 3 | ||||
-rw-r--r-- | sowatchd/daemon.h | 2 | ||||
-rw-r--r-- | sowatchd/global.h | 11 | ||||
-rw-r--r-- | sowatchd/main.cpp | 69 | ||||
-rw-r--r-- | sowatchd/service.cpp | 15 | ||||
-rw-r--r-- | sowatchd/service.h | 26 | ||||
-rw-r--r-- | sowatchd/service.xml | 14 | ||||
-rw-r--r-- | sowatchd/sowatchd.pro | 23 |
8 files changed, 150 insertions, 13 deletions
diff --git a/sowatchd/com.javispedro.sowatch.service.sowatch-service.service b/sowatchd/com.javispedro.sowatch.service.sowatch-service.service new file mode 100644 index 0000000..714d1c4 --- /dev/null +++ b/sowatchd/com.javispedro.sowatch.service.sowatch-service.service @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=com.nokia.qtmobility.sfw.sowatch-service +Exec=/opt/sowatch/bin/sowatchd diff --git a/sowatchd/daemon.h b/sowatchd/daemon.h index 48125fb..249f525 100644 --- a/sowatchd/daemon.h +++ b/sowatchd/daemon.h @@ -13,7 +13,7 @@ namespace sowatch class Daemon : public QObject { - Q_OBJECT + Q_OBJECT public: explicit Daemon(QObject *parent = 0); diff --git a/sowatchd/global.h b/sowatchd/global.h new file mode 100644 index 0000000..45c2b13 --- /dev/null +++ b/sowatchd/global.h @@ -0,0 +1,11 @@ +#ifndef GLOBAL_H +#define GLOBAL_H + +#include "daemon.h" + +namespace sowatch +{ +extern sowatch::Daemon* daemon; +} + +#endif // GLOBAL_H diff --git a/sowatchd/main.cpp b/sowatchd/main.cpp index 0d7abb9..22e63a2 100644 --- a/sowatchd/main.cpp +++ b/sowatchd/main.cpp @@ -1,20 +1,79 @@ #include <QtGui/QApplication> +#include <QtServiceFramework/QServiceManager> +#include <QtServiceFramework/QRemoteServiceRegister> #include <sowatch.h> -#include "daemon.h" +#include "global.h" +#include "service.h" + +namespace sowatch +{ + Daemon* daemon; +} using namespace sowatch; +QTM_USE_NAMESPACE + + +static QString adjustPath(const QString &path) +{ +#ifdef Q_OS_UNIX +#ifdef Q_OS_MAC + if (!QDir::isAbsolutePath(path)) + return QCoreApplication::applicationDirPath() + + QLatin1String("/../Resources/") + path; +#else + QString pathInInstallDir; + const QString applicationDirPath = QCoreApplication::applicationDirPath(); + pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path); + + if (QFileInfo(pathInInstallDir).exists()) + return pathInInstallDir; +#endif +#endif + return path; +} + +static void unregisterService() +{ + QServiceManager m; + m.removeService("sowatch-service"); +} -static Daemon* d; +static void registerService() +{ + unregisterService(); + QServiceManager m; + QString path = adjustPath("xml/service.xml"); + if (!m.addService(path)) { + qWarning() << "Cannot register sowatch-service" << m.error() << "from" << path; + } +} int main(int argc, char *argv[]) { - QApplication a(argc, argv); + QApplication a(argc, argv); // Some plugins might require a UI. QApplication::setOrganizationDomain("com.javispedro.sowatch"); QApplication::setOrganizationName("sowatch"); QApplication::setApplicationName("sowatchd"); - d = new Daemon(); + sowatch::daemon = new Daemon(); + + registerService(); + + QRemoteServiceRegister *serviceRegister = new QRemoteServiceRegister(); + QRemoteServiceRegister::Entry entry = + serviceRegister->createEntry<Service>("sowatch-service", + "com.javispedro.sowatch.service", "1.0"); + entry.setInstantiationType(QRemoteServiceRegister::PrivateInstance); + + serviceRegister->setQuitOnLastInstanceClosed(false); + serviceRegister->publishEntries("sowatchd"); + + int res = a.exec(); + + delete serviceRegister; + delete sowatch::daemon; - return a.exec(); + return res; } diff --git a/sowatchd/service.cpp b/sowatchd/service.cpp new file mode 100644 index 0000000..0b3777c --- /dev/null +++ b/sowatchd/service.cpp @@ -0,0 +1,15 @@ +#include "global.h" +#include "service.h" + +using namespace sowatch; + +Service::Service(QObject *parent) : + QObject(parent) +{ + +} + +void Service::terminate() +{ + QCoreApplication::exit(0); +} diff --git a/sowatchd/service.h b/sowatchd/service.h new file mode 100644 index 0000000..797dc3d --- /dev/null +++ b/sowatchd/service.h @@ -0,0 +1,26 @@ +#ifndef SERVICE_H +#define SERVICE_H + +#include <QtCore/QObject> +#include <QtCore/QList> +#include <QtCore/QSettings> + +#include <sowatch.h> + +namespace sowatch +{ + +class Service : public QObject +{ + Q_OBJECT +public: + explicit Service(QObject *parent = 0); + +public slots: + void terminate(); + +}; + +} + +#endif // SERVICE_H diff --git a/sowatchd/service.xml b/sowatchd/service.xml new file mode 100644 index 0000000..b2ebc06 --- /dev/null +++ b/sowatchd/service.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<SFW version="1.1"> +<service> + <name>sowatch-service</name> + <ipcaddress>sowatchd</ipcaddress> + <description>Sowatch Service</description> + <interface> + <name>com.javispedro.sowatch.service</name> + <version>1.0</version> + <description></description> + <capabilities></capabilities> + </interface> +</service> +</SFW> diff --git a/sowatchd/sowatchd.pro b/sowatchd/sowatchd.pro index 1e02404..af13c9e 100644 --- a/sowatchd/sowatchd.pro +++ b/sowatchd/sowatchd.pro @@ -9,11 +9,13 @@ TEMPLATE = app TARGET = sowatchd QT += core gui -CONFIG += console +CONFIG += mobility CONFIG -= app_bundle +MOBILITY += serviceframework SOURCES += main.cpp \ - daemon.cpp + daemon.cpp \ + service.cpp win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../libsowatch/release/ -lsowatch else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../libsowatch/debug/ -lsowatch @@ -24,8 +26,9 @@ INCLUDEPATH += $$PWD/../libsowatch DEPENDPATH += $$PWD/../libsowatch unix { - maemo5 { - target.path = /opt/sowatch + !isEmpty(MEEGO_VERSION_MAJOR)|maemo5 { + QMAKE_RPATHDIR += /opt/sowatch/lib + target.path = /opt/sowatch/bin } else { target.path = /usr/bin } @@ -33,6 +36,12 @@ unix { } HEADERS += \ - daemon.h - - + daemon.h \ + service.h \ + global.h + +xml.path = /opt/sowatch/xml +xml.files = service.xml +dbus.path = /usr/share/dbus-1/services +dbus.files = com.javispedro.sowatch.service.sowatch-service.service +INSTALLS += xml dbus |