• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

NepomukDaemons

servicecontrol.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE Project
00002    Copyright (c) 2008 Sebastian Trueg <trueg@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include "servicecontrol.h"
00020 #include "servicecontroladaptor.h"
00021 
00022 #include <QtCore/QCoreApplication>
00023 #include <QtCore/QTextStream>
00024 
00025 #include <Nepomuk/Service>
00026 
00027 
00028 Nepomuk::ServiceControl::ServiceControl( const QString& serviceName, const KService::Ptr& service, QObject* parent )
00029     : QObject( parent ),
00030       m_serviceName( serviceName ),
00031       m_service( service ),
00032       m_initialized( false )
00033 {
00034 }
00035 
00036 
00037 Nepomuk::ServiceControl::~ServiceControl()
00038 {
00039 }
00040 
00041 
00042 void Nepomuk::ServiceControl::setServiceInitialized( bool success )
00043 {
00044     m_initialized = success;
00045     emit serviceInitialized( success );
00046 }
00047 
00048 
00049 bool Nepomuk::ServiceControl::isInitialized() const
00050 {
00051     return m_initialized;
00052 }
00053 
00054 
00055 void Nepomuk::ServiceControl::start()
00056 {
00057     QTextStream s( stderr );
00058 
00059     // register the service interface
00060     // We need to do this before creating the module to ensure that
00061     // the server can catch the serviceInitialized signal
00062     // ====================================
00063     (void)new ServiceControlAdaptor( this );
00064     if( !QDBusConnection::sessionBus().registerObject( "/servicecontrol", this ) ) {
00065         s << "Failed to register dbus service " << dbusServiceName( m_serviceName ) << "." << endl;
00066         qApp->exit( ErrorFailedToStart );
00067         return;
00068     }
00069 
00070     if( !QDBusConnection::sessionBus().registerService( dbusServiceName( m_serviceName ) ) ) {
00071         s << "Failed to register dbus service " << dbusServiceName( m_serviceName ) << "." << endl;
00072         qApp->exit( ErrorFailedToStart );
00073         return;
00074     }
00075 
00076 
00077     // start the service
00078     // ====================================
00079     Nepomuk::Service* module = m_service->createInstance<Nepomuk::Service>( this );
00080     if( !module ) {
00081         s << "Failed to start service " << m_serviceName << "." << endl;
00082         qApp->exit( ErrorFailedToStart );
00083         return;
00084     }
00085 
00086     // register the service
00087     // ====================================
00088     QDBusConnection::sessionBus().registerObject( '/' + m_serviceName,
00089                                                   module,
00090                                                   QDBusConnection::ExportScriptableSlots |
00091                                                   QDBusConnection::ExportScriptableProperties |
00092                                                   QDBusConnection::ExportAdaptors);
00093 }
00094 
00095 
00096 void Nepomuk::ServiceControl::shutdown()
00097 {
00098     QCoreApplication::quit();
00099 }
00100 
00101 
00102 QString Nepomuk::ServiceControl::dbusServiceName( const QString& serviceName )
00103 {
00104     return QString("org.kde.nepomuk.services.%1").arg(serviceName);
00105 }
00106 
00107 #include "servicecontrol.moc"

NepomukDaemons

Skip menu "NepomukDaemons"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KCMShell
  • KNotify
  • KStyles
  • Nepomuk Daemons
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal