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 SIGTERM:
00042 case SIGINT:
00043 if ( qApp ) {
00044 qApp->quit();
00045 }
00046 }
00047 }
00048 #endif
00049
00050 void installSignalHandler() {
00051 #ifndef Q_OS_WIN
00052 struct sigaction sa;
00053 ::memset( &sa, 0, sizeof( sa ) );
00054 sa.sa_handler = signalHandler;
00055 sigaction( SIGHUP, &sa, 0 );
00056 sigaction( SIGINT, &sa, 0 );
00057 sigaction( SIGQUIT, &sa, 0 );
00058 sigaction( SIGTERM, &sa, 0 );
00059 #endif
00060 }
00061 }
00062
00063
00064 namespace Nepomuk {
00065 class ServerApplication : public KUniqueApplication
00066 {
00067 public:
00068 ServerApplication()
00069 : KUniqueApplication(),
00070 m_server( 0 ) {
00071 }
00072
00073 int newInstance() {
00074 if ( !m_server ) {
00075 m_server = new Server( this );
00076 }
00077 return 0;
00078 }
00079
00080 private:
00081 Server* m_server;
00082 };
00083 }
00084
00085
00086 extern "C" NEPOMUK_SERVER_EXPORT int kdemain( int argc, char** argv )
00087 {
00088 KAboutData aboutData( "NepomukServer", "nepomuk",
00089 ki18n("Nepomuk Server"),
00090 "0.2",
00091 ki18n("Nepomuk Server - Manages Nepomuk storage and services"),
00092 KAboutData::License_GPL,
00093 ki18n("(c) 2008, Sebastian Trüg"),
00094 KLocalizedString(),
00095 "http://nepomuk.kde.org" );
00096 aboutData.addAuthor(ki18n("Sebastian Trüg"),ki18n("Maintainer"), "trueg@kde.org");
00097
00098 KCmdLineArgs::init( argc, argv, &aboutData );
00099
00100 KUniqueApplication::addCmdLineOptions();
00101
00102 KComponentData componentData( &aboutData );
00103
00104 if ( !KUniqueApplication::start() ) {
00105 fprintf( stderr, "Nepomuk server already running.\n" );
00106 return 0;
00107 }
00108
00109 installSignalHandler();
00110
00111 Nepomuk::ServerApplication app;
00112 app.setQuitOnLastWindowClosed( false );
00113 return app.exec();
00114 }