3 //=============================================================================
5 * @file Signal_Handler.h
7 * @author Ossama Othman <ossama@uci.edu>
9 //=============================================================================
12 #ifndef TAO_LB_SIGNAL_HANDLER_H
13 #define TAO_LB_SIGNAL_HANDLER_H
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "tao/PortableServer/PortableServer.h"
23 #include "ace/Signal.h"
26 * @class TAO_LB_Signal_Handler
28 * @brief Active object designed to handle signals synchronously.
30 * This class handles signals synchronously in the multi-threaded case,
31 * and asynchronously through a Reactor in the single-threaded case.
33 * The goal of this signal handler is to ensure proper cleanup of
34 * resources created by servants upon interruption by signals. For
35 * example, suppose a user sends a
36 * SIGINT (e.g. types CTRL-C) signal to an application. The servants
37 * in that application should be shutdown gracefully so that all
38 * resources handled by those servants are cleaned up. This is
39 * particularly important for resources that are not cleaned up
42 class TAO_LB_Signal_Handler
: public ACE_Task_Base
46 TAO_LB_Signal_Handler (CORBA::ORB_ptr orb
,
47 PortableServer::POA_ptr poa
);
49 /// Run by a daemon thread to handle signals synchronously.
52 /// Active object activation method.
54 * This override blocks all signals in the calling thread before
55 * spawning the synchronous signal handler.
57 virtual int activate (long flags
= THR_NEW_LWP
| THR_JOINABLE
,
60 long priority
= ACE_DEFAULT_THREAD_PRIORITY
,
62 ACE_Task_Base
*task
= 0,
63 ACE_hthread_t thread_handles
[] = 0,
65 size_t stack_size
[] = 0,
66 ACE_thread_t thread_ids
[] = 0,
67 const char* thr_name
[] = 0);
69 /// Called when object is signaled by OS (either via UNIX signals or
70 /// when a Win32 object becomes signaled).
71 virtual int handle_signal (int signum
, siginfo_t
* = 0, ucontext_t
* = 0);
74 /// Template method that initiates the cleanup process.
75 virtual int perform_cleanup (int signum
);
78 #ifdef ACE_HAS_THREADS
79 /// Block all signals before spawning the threads. Then, unblock
80 /// these signals when this handler is destroyed.
81 ACE_Sig_Guard signal_guard_
;
82 #endif /* ACE_HAS_THREADS */
84 /// The set of signals which this handler will handle.
87 /// Pseudo-reference to the ORB in which the LoadManager is running.
90 /// Reference to the POA within which the LoadManager servant is
92 PortableServer::POA_var poa_
;
95 #endif /* TAO_LB_SIGNAL_HANDLER_H */