diff options
Diffstat (limited to 'kmrml/kmrml/server')
-rw-r--r-- | kmrml/kmrml/server/CMakeLists.txt | 39 | ||||
-rw-r--r-- | kmrml/kmrml/server/Makefile.am | 12 | ||||
-rw-r--r-- | kmrml/kmrml/server/daemonwatcher.desktop | 9 | ||||
-rw-r--r-- | kmrml/kmrml/server/watcher.cpp | 280 | ||||
-rw-r--r-- | kmrml/kmrml/server/watcher.h | 108 |
5 files changed, 0 insertions, 448 deletions
diff --git a/kmrml/kmrml/server/CMakeLists.txt b/kmrml/kmrml/server/CMakeLists.txt deleted file mode 100644 index 54dbe884..00000000 --- a/kmrml/kmrml/server/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -################################################# -# -# (C) 2010-2011 Calvin Morrison -# mutantturkey@gmail.com -# -# Improvements and feedback are welcome -# -# This file is released under GPL >= 2 -# -################################################# - -include_directories( - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/lib - ${CMAKE_BINARY_DIR} - ${TDE_INCLUDE_DIR} - ${TQT_INCLUDE_DIRS} -) - -link_directories( - ${TQT_LIBRARY_DIRS} -) - -#### other data ################################# - -tde_create_translated_desktop( - SOURCE daemonwatcher.desktop - DESTINATION ${SERVICES_INSTALL_DIR}/kded - PO_DIR kmrml-desktops -) - - -#### kded_daemonwatcher (module) ################ - -tde_add_kpart( kded_daemonwatcher AUTOMOC - SOURCES watcher.cpp watcher.skel - LINK kmrmlstuff-static tdeparts-shared tdeio-shared tdeinit_kded-shared - DESTINATION ${PLUGIN_INSTALL_DIR} -) diff --git a/kmrml/kmrml/server/Makefile.am b/kmrml/kmrml/server/Makefile.am deleted file mode 100644 index 318e8e7f..00000000 --- a/kmrml/kmrml/server/Makefile.am +++ /dev/null @@ -1,12 +0,0 @@ -kde_module_LTLIBRARIES = kded_daemonwatcher.la - -INCLUDES = $(all_includes) -kded_daemonwatcher_la_SOURCES = watcher.cpp watcher.skel -# watcher.stub -kded_daemonwatcher_la_LDFLAGS = $(all_libraries) -module -avoid-version -kded_daemonwatcher_la_LIBADD = $(LIB_TDESYCOCA) $(LIB_TDEUI) - -METASOURCES = AUTO - -servicesdir = $(kde_servicesdir)/kded -services_DATA = daemonwatcher.desktop diff --git a/kmrml/kmrml/server/daemonwatcher.desktop b/kmrml/kmrml/server/daemonwatcher.desktop deleted file mode 100644 index 8177e51e..00000000 --- a/kmrml/kmrml/server/daemonwatcher.desktop +++ /dev/null @@ -1,9 +0,0 @@ -[Desktop Entry] -Type=Service -Name=KDED KMRML Daemon Watcher -Comment=Starts daemons on demand and restarts them on failure -X-TDE-ServiceTypes=KDEDModule -X-TDE-ModuleType=Library -X-TDE-Library=daemonwatcher -X-TDE-FactoryName=daemonwatcher -X-TDE-Kded-load-on-demand=true diff --git a/kmrml/kmrml/server/watcher.cpp b/kmrml/kmrml/server/watcher.cpp deleted file mode 100644 index 67f0c69a..00000000 --- a/kmrml/kmrml/server/watcher.cpp +++ /dev/null @@ -1,280 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org> - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation, version 2. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include <dcopclient.h> - -#include <tdeapplication.h> -#include <kdebug.h> -#include <tdeversion.h> -#include <tdelocale.h> -#include <tdemessagebox.h> - -#include "watcher.h" - -using namespace KMrml; - -Watcher::Watcher( const TQCString& name ) - : KDEDModule( name ) -{ - m_daemons.setAutoDelete( true ); - - // safety, for clients that die without unregistering - TDEApplication::dcopClient()->setNotifications( true ); - connect( TDEApplication::dcopClient(), - TQT_SIGNAL( applicationRemoved( const TQCString& )), - TQT_SLOT( slotAppUnregistered( const TQCString& ))); -} - -Watcher::~Watcher() -{ - TDEApplication::dcopClient()->setNotifications( false ); -} - -bool Watcher::requireDaemon( const TQCString& clientAppId, - const TQString& daemonKey, - const TQString& commandline, - uint timeout /* seconds */, - int restartOnFailure ) -{ - if ( !TDEApplication::dcopClient()->isApplicationRegistered( clientAppId ) ) - kdWarning() << "Watcher::requireDaemon: " << daemonKey - << ": Client AppID is not registered with DCOP: " - << clientAppId << endl; - - DaemonData *daemon = m_daemons.find( daemonKey ); - - if ( daemon ) - { - if ( !daemon->apps.find( clientAppId ) ) - daemon->apps.append( clientAppId ); - - // timeout, commandline and restart values are: first come, first serve - return true; // process already running, all fine - } - - else // start daemon - { - daemon = new DaemonData( daemonKey, commandline, - timeout, restartOnFailure ); - m_daemons.insert( daemonKey, daemon ); - daemon->apps.append( clientAppId ); - -#if TDE_VERSION >= 306 - daemon->process = new TDEProcess(); - daemon->process->setUseShell( true ); -#else - daemon->process = new KShellProcess(); -#endif - daemon->process->setEnvironment( "LC_ALL", "C" ); - daemon->process->setEnvironment( "LANG", "C" ); - daemon->process->setEnvironment( "LANGUAGE", "C" ); - *daemon->process << commandline; - connect( daemon->process, TQT_SIGNAL( processExited( TDEProcess * ) ), - TQT_SLOT( slotProcExited( TDEProcess * ))); - return startDaemon( daemon ); - } -} - -void Watcher::unrequireDaemon( const TQCString& clientAppId, - const TQString& daemonKey ) -{ - unrequireDaemon( m_daemons.find( daemonKey ), clientAppId ); -} - -void Watcher::unrequireDaemon( DaemonData *daemon, - const TQCString& clientAppId ) -{ - if ( daemon ) - { - daemon->apps.remove( clientAppId.data() ); - if ( daemon->apps.isEmpty() ) - { - if ( !daemon->timer ) - { - daemon->timer = new TQTimer(); - connect( daemon->timer, TQT_SIGNAL( timeout() ), - TQT_SLOT( slotTimeout() )); - } - daemon->timer->start( daemon->timeout * 1000, true ); - } - } - else - kdWarning() << "Watcher::unrequireDaemon: daemon unknown. client: " - << clientAppId << endl; -} - -TQStringList Watcher::runningDaemons() const -{ - TQStringList result; - TQDictIterator<DaemonData> it( m_daemons ); - for ( ; it.current(); ++it ) - result.append( it.current()->commandline ); - - return result; -} - -void Watcher::slotProcExited( TDEProcess *proc ) -{ - DaemonData *daemon = findDaemonFromProcess( proc ); - - if ( proc->normalExit() ) - { - emitExited( daemon ); - return; - } - - if ( daemon ) - { - if ( --daemon->restartOnFailure <= 0 ) - { - if ( KMessageBox::questionYesNo( 0L, - i18n("<qt>The server with the command line" - "<br>%1<br>" - "is not available anymore. Do you want to " - "restart it?" ).arg( daemon->commandline ), - i18n("Service Failure"), i18n("Restart Server"), i18n("Do Not Restart") ) - == KMessageBox::Yes ) - { - daemon->restartOnFailure = 1; - } - } - - if ( daemon->restartOnFailure > 0 ) - { - startDaemon( daemon ); - return; - } - } - - emitFailure( daemon ); -} - -bool Watcher::startDaemon( DaemonData *daemon ) -{ - if ( daemon->process->start( TDEProcess::NotifyOnExit ) ) - return true; - - else - { - if ( KMessageBox::questionYesNo( 0L, - i18n("Unable to start the server with the " - "command line" - "<br>%1<br>" - "Try again?").arg( daemon->commandline ), - i18n("Service Failure"), i18n("Try Again"), i18n("Do Not Try") ) - == KMessageBox::Yes ) - { - return startDaemon( daemon ); - } - } - - return false; -} - -void Watcher::slotTimeout() -{ - TQTimer *timer = static_cast<TQTimer*>( TQT_TQOBJECT( const_cast<TQT_BASE_OBJECT_NAME*>(sender()) ) ); - DaemonData *daemon = findDaemonFromTimer( timer ); - if ( daemon ) - { - if ( daemon->apps.isEmpty() ) - { - // the daemon and TDEProcess might get deleted by killing the - // TDEProcess (through slotProcExited()), so don't dereference - // daemon after proc->kill() - TQString key = daemon->daemonKey; - - // noone registered during the timeout, so kill the daemon - if ( !daemon->process->kill() ) - daemon->process->kill( SIGKILL ); - - m_daemons.remove( key ); - } - } -} - -DaemonData * Watcher::findDaemonFromProcess( TDEProcess *proc ) -{ - DaemonData *daemon; - TQDictIterator<DaemonData> it( m_daemons ); - for ( ; (daemon = it.current()); ++it ) - { - if ( daemon->process == proc ) - return daemon; - } - - return 0L; -} - -DaemonData * Watcher::findDaemonFromTimer( TQTimer *timer ) -{ - DaemonData *daemon; - TQDictIterator<DaemonData> it( m_daemons ); - for ( ; (daemon = it.current()); ++it ) - { - if ( daemon->timer == timer ) - return daemon; - } - - return 0L; -} - -void Watcher::slotAppUnregistered( const TQCString& appId ) -{ - if ( m_daemons.isEmpty() ) - return; - - DaemonData *daemon; - TQDictIterator<DaemonData> it( m_daemons ); - for ( ; (daemon = it.current()); ++it ) - { - if ( daemon->apps.find( appId ) != -1 ) - unrequireDaemon( daemon, appId ); - } -} - -void Watcher::emitExited( DaemonData *daemon ) -{ - if ( daemon ) - { - daemonExited( daemon->daemonKey, - daemon->process->pid(), - daemon->process->exitStatus() ); - - m_daemons.remove( daemon->daemonKey ); - } -} - -void Watcher::emitFailure( DaemonData *daemon ) -{ - if ( daemon ) - { - daemonDied( daemon->daemonKey, daemon->process->pid() ); - m_daemons.remove( daemon->daemonKey ); // deletes daemon + TDEProcess - } -} - -extern "C" { - KDE_EXPORT KDEDModule *create_daemonwatcher(const TQCString & obj ) - { - return new Watcher( obj ); - } -} - - -#include "watcher.moc" diff --git a/kmrml/kmrml/server/watcher.h b/kmrml/kmrml/server/watcher.h deleted file mode 100644 index e9cc0656..00000000 --- a/kmrml/kmrml/server/watcher.h +++ /dev/null @@ -1,108 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org> - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation, version 2. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef LAUNCHER_H -#define LAUNCHER_H - -#include <tqdict.h> -#include <tqmap.h> -#include <tqstrlist.h> -#include <tqstringlist.h> -#include <tqtimer.h> - -#include <kdedmodule.h> -#include <kprocess.h> - -namespace KMrml -{ - class DaemonData - { - public: - DaemonData( const TQString& key, const TQString& cmd, - uint time, int numRestarts ) - : daemonKey( key ), - commandline( cmd ), - timeout( time ), - apps( true ), // deep copies - restartOnFailure( numRestarts ), - process( 0L ), - timer( 0L ) - { - } - ~DaemonData() - { - delete process; - delete timer; - } - TQString daemonKey; - TQString commandline; - uint timeout; - TQStrList apps; - int restartOnFailure; - TDEProcess *process; - TQTimer *timer; - }; - - class Watcher : public KDEDModule - { - Q_OBJECT -// - K_DCOP - - public: - Watcher( const TQCString& name = "daemonwatcher" ); - ~Watcher(); - - k_dcop: - virtual bool requireDaemon( const TQCString& clientAppId, - const TQString& daemonKey, - const TQString& commandline, - uint timeout = 60 /* seconds */, - int numRestarts = 5 ); - virtual void unrequireDaemon( const TQCString& clientAppId, - const TQString& daemonKey ); - virtual TQStringList runningDaemons() const; - - k_dcop_signals: - void daemonExited(const TQString& daemonKey, pid_t pid, int exitStatus); - void daemonDied( const TQString& daemonKey, pid_t pid ); - - protected: - bool startDaemon( DaemonData *daemon ); - - protected slots: - virtual void slotTimeout(); - - private: - void unrequireDaemon( DaemonData *daemon, const TQCString& clientAppId); - DaemonData *findDaemonFromProcess( TDEProcess *proc ); - DaemonData *findDaemonFromTimer( TQTimer *timer ); - - void emitExited( DaemonData *daemon ); - void emitFailure( DaemonData *daemon ); - - private slots: - void slotProcExited( TDEProcess *proc ); - void slotAppUnregistered( const TQCString& appId ); - - TQDict<DaemonData> m_daemons; - }; - -} - -#endif // LAUNCHER_H |