Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / LoadBalancer / Signal_Handler.h
blobea20382f8fc792c5c417282a87a489ee09f85ecf
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:
45 /// Constructor.
46 TAO_LB_Signal_Handler (CORBA::ORB_ptr orb,
47 PortableServer::POA_ptr poa);
49 /// Run by a daemon thread to handle signals synchronously.
50 virtual int svc ();
52 /// Active object activation method.
53 /**
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,
58 int n_threads = 1,
59 int force_active = 0,
60 long priority = ACE_DEFAULT_THREAD_PRIORITY,
61 int grp_id = -1,
62 ACE_Task_Base *task = 0,
63 ACE_hthread_t thread_handles[] = 0,
64 void *stack[] = 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);
73 protected:
74 /// Template method that initiates the cleanup process.
75 virtual int perform_cleanup (int signum);
77 private:
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.
85 ACE_Sig_Set sigset_;
87 /// Pseudo-reference to the ORB in which the LoadManager is running.
88 CORBA::ORB_var orb_;
90 /// Reference to the POA within which the LoadManager servant is
91 /// registered.
92 PortableServer::POA_var poa_;
95 #endif /* TAO_LB_SIGNAL_HANDLER_H */