NepomukDaemons
main.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "nepomukserver.h"
00020 #include "nepomukserver_export.h"
00021
00022 #include <kuniqueapplication.h>
00023 #include <kapplication.h>
00024 #include <kcmdlineargs.h>
00025 #include <kaboutdata.h>
00026 #include <klocale.h>
00027 #include <kglobal.h>
00028 #include <kconfig.h>
00029 #include <kconfiggroup.h>
00030 #include <kdebug.h>
00031
00032 #include <signal.h>
00033
00034 namespace {
00035 #ifndef Q_OS_WIN
00036 void signalHandler( int signal )
00037 {
00038 switch( signal ) {
00039 case SIGHUP:
00040 case SIGQUIT:
00041 case SIGINT:
00042 if ( qApp ) {
00043 qApp->quit();
00044 }
00045 }
00046 }
00047 #endif
00048
00049 void installSignalHandler() {
00050 #ifndef Q_OS_WIN
00051 struct sigaction sa;
00052 ::memset( &sa, 0, sizeof( sa ) );
00053 sa.sa_handler = signalHandler;
00054 sigaction( SIGHUP, &sa, 0 );
00055 sigaction( SIGINT, &sa, 0 );
00056 sigaction( SIGQUIT, &sa, 0 );
00057 #endif
00058 }
00059 }
00060
00061
00062 namespace Nepomuk {
00063 class ServerApplication : public KUniqueApplication
00064 {
00065 public:
00066 ServerApplication()
00067 : KUniqueApplication(),
00068 m_server( 0 ) {
00069 }
00070
00071 int newInstance() {
00072 if ( !m_server ) {
00073 m_server = new Server( this );
00074 }
00075 return 0;
00076 }
00077
00078 private:
00079 Server* m_server;
00080 };
00081 }
00082
00083
00084 extern "C" NEPOMUK_SERVER_EXPORT int kdemain( int argc, char** argv )
00085 {
00086 KAboutData aboutData( "NepomukServer", "nepomuk",
00087 ki18n("Nepomuk Server"),
00088 "0.2",
00089 ki18n("Nepomuk Server - Manages Nepomuk storage and services"),
00090 KAboutData::License_GPL,
00091 ki18n("(c) 2008, Sebastian Trüg"),
00092 KLocalizedString(),
00093 "http://nepomuk.kde.org" );
00094 aboutData.addAuthor(ki18n("Sebastian Trüg"),ki18n("Maintainer"), "trueg@kde.org");
00095
00096 KCmdLineArgs::init( argc, argv, &aboutData );
00097
00098 KUniqueApplication::addCmdLineOptions();
00099
00100 KComponentData componentData( &aboutData );
00101
00102 if ( !KUniqueApplication::start() ) {
00103 fprintf( stderr, "Nepomuk server already running.\n" );
00104 return 0;
00105 }
00106
00107 installSignalHandler();
00108
00109 Nepomuk::ServerApplication app;
00110 app.setQuitOnLastWindowClosed( false );
00111 return app.exec();
00112 }