1/*
2 This file is part of the Cagibi daemon.
3
4 Copyright 2011 Friedrich W. H. Kossebau <kossebau@kde.org>
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23// program
24#include "devicelistdbusadaptor.h"
25#include "devicelist.h"
26#include "controldbusadaptor.h"
27#include "control.h"
28#include "daemon.h"
29// Qt
30#include <QtCore/QSettings>
31#include <QtCore/QCoreApplication>
32
33
34namespace Cagibi
35{
36
37static const int defaultShutDownTimeout = CAGIBI_DAEMON_SHUTDOWN_SECS;
38static const int defaultSearchTimeout = CAGIBI_DAEMON_SEARCH_TIMEOUT_SECS;
39
40Daemon::Daemon( int argc, char* argv[] )
41 : QCoreApplication( argc, argv )
42{
43}
44
45
46int Daemon::exec()
47{
48 // read settings
49 QSettings::setPath( QSettings::NativeFormat, QSettings::SystemScope,
50 QLatin1String(SYSCONF_INSTALL_DIR) );
51 QSettings settings( QSettings::SystemScope, QLatin1String("cagibid") );
52 int shutDownTimeout =
53 settings.value( QLatin1String("ShutDownTimeout"),
54 defaultShutDownTimeout ).toInt();
55 const int searchTimeout =
56 settings.value( QLatin1String("SearchTimeout"),
57 defaultSearchTimeout ).toInt();
58
59 // publish service on D-Bus
60 QDBusConnection dBusConnection = QDBusConnection::systemBus();
61 dBusConnection.registerService( QLatin1String("org.kde.Cagibi") );
62
63 DeviceList deviceList( searchTimeout, shutDownTimeout );
64 connect( &deviceList, SIGNAL(gotInactiv()), SLOT(quit()) );
65 new DeviceListDBusAdaptor( &deviceList );
66 dBusConnection.registerObject( QLatin1String("/org/kde/Cagibi/DeviceList"), &deviceList );
67
68 Control control( this );
69 new ControlDBusAdaptor( &control );
70 dBusConnection.registerObject( QLatin1String("/org/kde/Cagibi/Control"), &control );
71
72 // do the mainloop
73 const int result = QCoreApplication::exec();
74
75 return result;
76}
77
78}
79