• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • sources
  • kde-4.12
  • kdelibs
  • nepomuk-core
  • servicestub
servicecontrol.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE Project
2  Copyright (c) 2008-2011 Sebastian Trueg <trueg@kde.org>
3 
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.
7 
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.
12 
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.
17 */
18 
19 #include "servicecontrol.h"
20 #include "servicecontroladaptor.h"
21 
22 #include <QtCore/QCoreApplication>
23 #include <QtCore/QTextStream>
24 
25 #include "nepomukservice.h"
26 
27 
28 Nepomuk2::ServiceControl::ServiceControl( const QString& serviceName, const KService::Ptr& service, QObject* parent )
29  : QObject( parent ),
30  m_serviceName( serviceName ),
31  m_service( service ),
32  m_nepomukServiceModule( 0 ),
33  m_initialized( false )
34 {
35  m_description = service->comment();
36  m_readableName = service->name();
37 }
38 
39 
40 Nepomuk2::ServiceControl::~ServiceControl()
41 {
42 }
43 
44 
45 void Nepomuk2::ServiceControl::setServiceInitialized( bool success )
46 {
47  m_initialized = success;
48  emit serviceInitialized( success );
49 }
50 
51 
52 bool Nepomuk2::ServiceControl::isInitialized() const
53 {
54  return m_initialized;
55 }
56 
57 QString Nepomuk2::ServiceControl::description() const
58 {
59  return m_description;
60 }
61 
62 QString Nepomuk2::ServiceControl::name() const
63 {
64  return m_readableName;
65 }
66 
67 void Nepomuk2::ServiceControl::start()
68 {
69  QTextStream s( stderr );
70 
71  // register the service interface
72  // We need to do this before creating the module to ensure that
73  // the server can catch the serviceInitialized signal
74  // ====================================
75  (void)new ServiceControlAdaptor( this );
76  if( !QDBusConnection::sessionBus().registerObject( "/servicecontrol", this ) ) {
77  s << "Failed to register dbus service " << dbusServiceName( m_serviceName ) << "." << endl;
78  qApp->exit( ErrorFailedToStart );
79  return;
80  }
81 
82  if( !QDBusConnection::sessionBus().registerService( dbusServiceName( m_serviceName ) ) ) {
83  s << "Failed to register dbus service " << dbusServiceName( m_serviceName ) << "." << endl;
84  qApp->exit( ErrorFailedToStart );
85  return;
86  }
87 
88 
89  // start the service
90  // ====================================
91  QString startErrorDescription;
92  m_nepomukServiceModule = m_service->createInstance<Nepomuk2::Service>( this, QVariantList(), &startErrorDescription);
93  if( !m_nepomukServiceModule ) {
94  s << "Failed to start service " << m_serviceName << " ("<< startErrorDescription << ")." << endl;
95  qApp->exit( ErrorFailedToStart );
96  return;
97  }
98 
99  // register the service
100  // ====================================
101  QDBusConnection::sessionBus().registerObject( '/' + m_serviceName,
102  m_nepomukServiceModule,
103  QDBusConnection::ExportScriptableSlots |
104  QDBusConnection::ExportScriptableSignals |
105  QDBusConnection::ExportScriptableProperties |
106  QDBusConnection::ExportAdaptors);
107  // Delete the QApplication after the m_nepomukServiceModule
108  // Note: if services need QCoreApplication to hang around for
109  // longer they can disconnect this signal.
110  connect( m_nepomukServiceModule, SIGNAL( destroyed() ),
111  QCoreApplication::instance(), SLOT( quit() ) );
112 }
113 
114 
115 void Nepomuk2::ServiceControl::shutdown()
116 {
117  m_nepomukServiceModule->deleteLater();
118  m_nepomukServiceModule = 0;
119 }
120 
121 QString Nepomuk2::ServiceControl::dbusServiceName( const QString& serviceName )
122 {
123  return QString("org.kde.nepomuk.services.%1").arg(serviceName);
124 }
125 
126 #include "servicecontrol.moc"
Nepomuk2::ServiceControl::~ServiceControl
~ServiceControl()
Definition: servicecontrol.cpp:40
Nepomuk2::ServiceControl::setServiceInitialized
void setServiceInitialized(bool success)
Definition: servicecontrol.cpp:45
QObject
Nepomuk2::ServiceControl::dbusServiceName
static QString dbusServiceName(const QString &serviceName)
Definition: servicecontrol.cpp:121
Nepomuk2::ServiceControl::shutdown
void shutdown()
Definition: servicecontrol.cpp:115
Nepomuk2::ServiceControl::description
QString description() const
Definition: servicecontrol.cpp:57
Nepomuk2::ServiceControl::isInitialized
bool isInitialized() const
Definition: servicecontrol.cpp:52
servicecontrol.h
Nepomuk2::ServiceControl::ServiceControl
ServiceControl(const QString &serviceName, const KService::Ptr &service, QObject *parent=0)
Definition: servicecontrol.cpp:28
Nepomuk2::ServiceControl::name
QString name() const
Definition: servicecontrol.cpp:62
Nepomuk2::ServiceControl::start
void start()
Definition: servicecontrol.cpp:67
Nepomuk2::Service
Base class for all Nepomuk services.
Definition: nepomukservice.h:87
nepomukservice.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Nepomuk-Core

Skip menu "Nepomuk-Core"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal