22 #include "nepomukversion.h"
23 #include "../../servicestub/priority.h"
25 #include <QtCore/QTimer>
26 #include <QtDBus/QDBusConnection>
27 #include <QtDBus/QDBusConnectionInterface>
37 void signalHandler(
int signal )
43 QCoreApplication::exit( 0 );
48 void installSignalHandler() {
51 ::memset( &sa, 0,
sizeof( sa ) );
52 sa.sa_handler = signalHandler;
53 sigaction( SIGHUP, &sa, 0 );
54 sigaction( SIGINT, &sa, 0 );
55 sigaction( SIGQUIT, &sa, 0 );
60 class Nepomuk2::Service2::Private
66 ServiceControl2* m_serviceControl;
68 bool delayedInitialization;
75 void configurePriority();
76 bool createDBusInterfaces();
82 d( new Private(this) )
84 d->m_serviceControl = 0;
85 d->delayedInitialization = delayedInitialization;
97 return d->readableName;
102 return d->description;
108 QMetaObject::invokeMethod( d->m_serviceControl,
109 "setServiceInitialized",
110 Qt::QueuedConnection,
111 Q_ARG(
bool, success) );
114 bool Nepomuk2::Service2::Private::loadDetails()
116 KService::Ptr servicePtr = KService::serviceByDesktopName( serviceName );
117 if( servicePtr.isNull() )
120 readableName = servicePtr->name();
121 description = servicePtr->comment();
126 void Nepomuk2::Service2::Private::configurePriority()
133 kDebug() <<
"Failed to lower priority.";
135 kDebug() <<
"Failed to lower scheduling priority.";
137 kDebug() <<
"Failed to lower io priority.";
140 bool Nepomuk2::Service2::Private::createDBusInterfaces()
142 QTextStream s( stderr );
146 QDBusConnection bus = QDBusConnection::sessionBus();
147 if( !bus.registerService( q->dbusServiceName() ) ) {
148 s <<
"Failed to register dbus service " << q->dbusServiceName() <<
"." << endl;
152 bus.registerObject(
'/' + serviceName, q,
153 QDBusConnection::ExportScriptableSlots |
154 QDBusConnection::ExportScriptableSignals |
155 QDBusConnection::ExportScriptableProperties |
156 QDBusConnection::ExportAdaptors);
158 m_serviceControl =
new ServiceControl2( q );
159 if( m_serviceControl->failedToStart() )
167 return dbusServiceName( d->serviceName );
173 return QString(
"org.kde.nepomuk.services.%1").arg(serviceName.toLower());
178 d->serviceName = name;
180 if( !d->loadDetails() )
183 d->configurePriority();
185 if( !d->createDBusInterfaces() )
188 if ( !d->delayedInitialization )
189 setServiceInitialized(
true );
191 installSignalHandler();
198 #include "service2.moc"
void setServiceInitialized(bool success)
A Nepomuk service can make use of a warmup phase in which it is not usable yet.
bool initCommon(const QString &name)
QString dbusServiceName()
Returns the DBus Service Name.
Service2(QObject *parent=0, bool delayedInitialization=false)
Create a new Service.
bool lowerSchedulingPriority()
QString name()
Return the generic service name.
QString description()
Returns the description of the service.
virtual ~Service2()
Destructor.