add more spacing
[personal-kdebase.git] / runtime / nepomuk / servicestub / servicecontrol.cpp
blob2ad4f9f66a91464c21f3341fc85d2a2f887b5fd9
1 /* This file is part of the KDE Project
2 Copyright (c) 2008 Sebastian Trueg <trueg@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "servicecontrol.h"
20 #include "servicecontroladaptor.h"
22 #include <QtCore/QCoreApplication>
23 #include <QtCore/QTextStream>
25 #include <Nepomuk/Service>
28 Nepomuk::ServiceControl::ServiceControl( const QString& serviceName, const KService::Ptr& service, QObject* parent )
29 : QObject( parent ),
30 m_serviceName( serviceName ),
31 m_service( service ),
32 m_initialized( false )
37 Nepomuk::ServiceControl::~ServiceControl()
42 void Nepomuk::ServiceControl::setServiceInitialized( bool success )
44 m_initialized = success;
45 emit serviceInitialized( success );
49 bool Nepomuk::ServiceControl::isInitialized() const
51 return m_initialized;
55 void Nepomuk::ServiceControl::start()
57 QTextStream s( stderr );
59 // register the service interface
60 // We need to do this before creating the module to ensure that
61 // the server can catch the serviceInitialized signal
62 // ====================================
63 (void)new ServiceControlAdaptor( this );
64 if( !QDBusConnection::sessionBus().registerObject( "/servicecontrol", this ) ) {
65 s << "Failed to register dbus service " << dbusServiceName( m_serviceName ) << "." << endl;
66 qApp->exit( ErrorFailedToStart );
67 return;
70 if( !QDBusConnection::sessionBus().registerService( dbusServiceName( m_serviceName ) ) ) {
71 s << "Failed to register dbus service " << dbusServiceName( m_serviceName ) << "." << endl;
72 qApp->exit( ErrorFailedToStart );
73 return;
77 // start the service
78 // ====================================
79 Nepomuk::Service* module = m_service->createInstance<Nepomuk::Service>( this );
80 if( !module ) {
81 s << "Failed to start service " << m_serviceName << "." << endl;
82 qApp->exit( ErrorFailedToStart );
83 return;
86 // register the service
87 // ====================================
88 QDBusConnection::sessionBus().registerObject( '/' + m_serviceName,
89 module,
90 QDBusConnection::ExportScriptableSlots |
91 QDBusConnection::ExportScriptableProperties |
92 QDBusConnection::ExportAdaptors);
96 void Nepomuk::ServiceControl::shutdown()
98 QCoreApplication::quit();
102 QString Nepomuk::ServiceControl::dbusServiceName( const QString& serviceName )
104 return QString("org.kde.nepomuk.services.%1").arg(serviceName);
107 #include "servicecontrol.moc"