Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / LoadBalancer / Signal_Handler.h
bloba79d1cde06c5715f1595522d0fe380a7595972a6
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Signal_Handler.h
7 * @author Ossama Othman <ossama@uci.edu>
8 */
9 //=============================================================================
12 #ifndef TAO_LB_SIGNAL_HANDLER_H
13 #define TAO_LB_SIGNAL_HANDLER_H
15 #include "ace/Task.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
18 #pragma once
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include "tao/ORB.h"
22 #include "tao/PortableServer/PortableServer.h"
23 #include "ace/Signal.h"
25 /**
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.
32 * @par
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
40 * automatically.
42 class TAO_LB_Signal_Handler : public ACE_Task_Base
44 public:
46 /// Constructor.
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.
54 /**
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,
59 int n_threads = 1,
60 int force_active = 0,
61 long priority = ACE_DEFAULT_THREAD_PRIORITY,
62 int grp_id = -1,
63 ACE_Task_Base *task = 0,
64 ACE_hthread_t thread_handles[] = 0,
65 void *stack[] = 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);
74 protected:
76 /// Template method that initiates the cleanup process.
77 virtual int perform_cleanup (int signum);
79 private:
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.
88 ACE_Sig_Set sigset_;
90 /// Pseudo-reference to the ORB in which the LoadManager is running.
91 CORBA::ORB_var orb_;
93 /// Reference to the POA within which the LoadManager servant is
94 /// registered.
95 PortableServer::POA_var poa_;
99 #endif /* TAO_LB_SIGNAL_HANDLER_H */