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
47 TAO_LB_Signal_Handler (CORBA::ORB_ptr orb
,
48 PortableServer::POA_ptr poa
);
50 /// Run by a daemon thread to handle signals synchronously.
51 virtual int svc (void);
53 /// Active object activation method.
55 * This override blocks all signals in the calling thread before
56 * spawning the synchronous signal handler.
58 virtual int activate (long flags
= THR_NEW_LWP
| THR_JOINABLE
,
61 long priority
= ACE_DEFAULT_THREAD_PRIORITY
,
63 ACE_Task_Base
*task
= 0,
64 ACE_hthread_t thread_handles
[] = 0,
66 size_t stack_size
[] = 0,
67 ACE_thread_t thread_ids
[] = 0,
68 const char* thr_name
[] = 0);
70 /// Called when object is signaled by OS (either via UNIX signals or
71 /// when a Win32 object becomes signaled).
72 virtual int handle_signal (int signum
, siginfo_t
* = 0, ucontext_t
* = 0);
76 /// Template method that initiates the cleanup process.
77 virtual int perform_cleanup (int signum
);
81 #ifdef ACE_HAS_THREADS
82 /// Block all signals before spawning the threads. Then, unblock
83 /// these signals when this handler is destroyed.
84 ACE_Sig_Guard signal_guard_
;
85 #endif /* ACE_HAS_THREADS */
87 /// The set of signals which this handler will handle.
90 /// Pseudo-reference to the ORB in which the LoadManager is running.
93 /// Reference to the POA within which the LoadManager servant is
95 PortableServer::POA_var poa_
;
99 #endif /* TAO_LB_SIGNAL_HANDLER_H */