5 #include <boost/thread/mutex.hpp> 6 #include <boost/bind.hpp> 9 #include "rms/provider/CETDDS.h" 10 #include "rms/provider/ProcessSignalHandler.h" 40 boost::unique_lock<boost::mutex> guard(
_lock);
46 boost::unique_lock<boost::mutex> guard(
_lock);
57 ProcessSignalHandler::SignalHandlerPairList ProcessSignalHandler::_signalhHandlerList;
68 ProcessSignalHandler::ProcessSignalHandler()
69 : _cleanupRequired( 1 )
79 boost::mutex::scoped_lock guard(
_listLock );
89 boost::mutex::scoped_lock guard(
_listLock );
104 struct sigaction action;
106 sigemptyset( &action.sa_mask );
124 handler !=
end;++handler ) {
125 if ( handler->first == signalNumber )
126 handler->second( signalNumber );
134 assert( handler != NULL );
139 boost::recursive_timed_mutex::scoped_lock guard(
_selfLock,boost::get_system_time() + boost::posix_time::milliseconds(250) );
149 }
else if(!guard.owns_lock())
155 boost::this_thread::sleep(boost::posix_time::milliseconds(5000));
156 }
else if (signalNumber==SIGSEGV)
158 std::cerr <<
"Warning: Program received signal SIGSEGV, Segmentation fault." <<
std::endl;
162 std::cout <<
"Finished processing signal (number=" << signalNumber <<
")." <<
std::endl;
176 boost::mutex::scoped_lock guard(
_listLock );
183 (*notifiable )->doNotify();
192 size_t activeConnectionCount=0;
195 boost::mutex::scoped_lock guard(
_listLock );
200 for (
int retryCount=10; activeConnectionCount!=0 && retryCount>0;--retryCount)
204 activeConnectionCount=0;
206 boost::mutex::scoped_lock guard(
_listLock );
211 if (! (*notifiable )->hasBeenClosed())
212 ++activeConnectionCount;
215 DDS::DomainParticipantFactory::get_instance()->delete_contained_entities();
217 if(activeConnectionCount!=0)
220 std::cout <<
"Terminating "<< activeConnectionCount <<
" RMS connections." <<
std::endl;
223 boost::mutex::scoped_lock guard(
_listLock );
229 if (! (*notifiable )->hasBeenClosed())
230 (*notifiable )->close();
237 assert( handler != NULL );
247 sigemptyset( &sigs );
248 sigaddset( &sigs, SIGTERM );
249 sigaddset( &sigs, SIGINT );
250 sigaddset( &sigs, SIGSEGV );
252 if ( pthread_sigmask( SIG_BLOCK, &sigs, 0 )) {
260 sigemptyset( &sigs );
261 sigaddset( &sigs, SIGTERM );
262 sigaddset( &sigs, SIGINT );
263 sigaddset( &sigs, SIGSEGV );
265 if ( pthread_sigmask( SIG_UNBLOCK, &sigs, 0 )) {
void disconnect_participant()
boost::recursive_timed_mutex _selfLock
struct sigaction _previousSignalHandler
void processSignal(int signalNumber, ProcessSignalHandler *handler)
static DPSingleton & Instance()
void removeFromNotificationList(base::Notifiable *notifiable)
bool equal(T *first, T *second)
void operator()(ProcessSignalHandler *handler)
NotifiableList _notificationList
const XML_Char int const XML_Char int const XML_Char * base
void terminateDDSConnections()
SignalHandlerPairList::iterator SignalHandlerPairIterator
static void customSignalHandler(int signalNumber)
std::pair< int, SignalHandler > SignalHandlerPair
volatile sig_atomic_t _cleanupRequired
void addToNotificationList(base::Notifiable *notifiable)
void closeDDSConnections()
bool hasBeenNotified() const
static SignalHandlerPairList _signalhHandlerList
assert(nhit_max >=nhit_nbins)
NotifiableList::iterator NotifiableListIterator
virtual void doNotify_impl()
boost::function< void(int) > SignalHandler
virtual bool hasBeenNotified_impl() const
bool setupSignalHandler(int signalNumber)