• 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
  • libnepomukcore
  • service
service2.h
Go to the documentation of this file.
1 /* This file is part of the KDE Project
2  Copyright (c) 2008 Sebastian Trueg <trueg@kde.org>
3  Copyright (c) 2013 Vishesh Handa <me@vhanda.in>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef _NEPOMUK2_SERVICE2_H_
21 #define _NEPOMUK2_SERVICE2_H_
22 
23 #include "nepomuk_export.h"
24 #include "nepomukversion.h"
25 
26 #include <QtCore/QObject>
27 #include <QtCore/QCoreApplication>
28 #include <QtCore/QTextStream>
29 #include <QtDBus/QDBusConnection>
30 #include <QtDBus/QDBusConnectionInterface>
31 
32 #include <KAboutData>
33 #include <KComponentData>
34 #include <KApplication>
35 #include <KCmdLineArgs>
36 
37 namespace Nepomuk2 {
88  class NEPOMUK_EXPORT Service2 : public QObject
89  {
90  Q_OBJECT
91 
92  public:
106  template <typename T>
107  static int init( int argc, char **argv, const KAboutData& aboutData )
108  {
109  QCoreApplication app( argc, argv );
110  KComponentData data( aboutData, KComponentData::RegisterAsMainComponent );
111 
112  const QString name = aboutData.appName();
113  const QString dbusName = dbusServiceName( name );
114 
115  QTextStream s( stderr );
116  QDBusConnectionInterface* busInt = QDBusConnection::sessionBus().interface();
117  if( busInt->isServiceRegistered( dbusName ) ) {
118  s << "Service " << name << " already running." << endl;
119  return 1;
120  }
121 
122  T* service = new T();
123  if( !service->initCommon(name) )
124  return 1;
125 
126  int rv = app.exec();
127  delete service;
128  return rv;
129  }
130 
136  template <typename T>
137  static int initUI( int argc, char **argv, const KAboutData& aboutData ) {
138  KCmdLineArgs::init( argc, argv, &aboutData );
139 
140  KApplication app;
141  app.disableSessionManagement();
142 
143  // We explicitly remove the MainApplication object cause it inteferes with the ability to
144  // properly shut down the nepomuk services
145  QDBusConnection con = QDBusConnection::sessionBus();
146  con.unregisterObject( QLatin1String("/MainApplication"), QDBusConnection::UnregisterNode );
147 
148  const QString name = aboutData.appName();
149  const QString dbusName = dbusServiceName( name );
150 
151  QTextStream s( stderr );
152  QDBusConnectionInterface* busInt = QDBusConnection::sessionBus().interface();
153  if( busInt->isServiceRegistered( dbusName ) ) {
154  s << "Service " << name << " already running." << endl;
155  return 1;
156  }
157 
158  T* service = new T();
159  if( !service->initCommon(name) )
160  return 1;
161 
162  int rv = app.exec();
163  delete service;
164  return rv;
165  }
166 
170  static QString dbusServiceName( const QString& serviceName );
171 
181  Service2( QObject* parent = 0, bool delayedInitialization = false );
182 
186  virtual ~Service2();
187 
191  QString name();
192 
196  QString description();
197 
201  QString dbusServiceName();
202 
203  protected:
216  void setServiceInitialized( bool success );
217 
218  bool initCommon( const QString& name );
219  private:
220  class Private;
221  Private* const d;
222  };
223 }
224 
225 
226 #endif
Nepomuk2::Service2::init
static int init(int argc, char **argv, const KAboutData &aboutData)
Use this method in the main function of your service application to initialize your service...
Definition: service2.h:107
QObject
Nepomuk2::Service2::initUI
static int initUI(int argc, char **argv, const KAboutData &aboutData)
Similar to the init method above except that it creates an application with a UI so that you can use ...
Definition: service2.h:137
Nepomuk2::Service2
New Base class for all Nepomuk services.
Definition: service2.h:88
nepomuk_export.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