summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/LoadBalancer/Signal_Handler.h
blob: a79d1cde06c5715f1595522d0fe380a7595972a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// -*- C++ -*-

//=============================================================================
/**
 * @file   Signal_Handler.h
 *
 * @author Ossama Othman <ossama@uci.edu>
 */
//=============================================================================


#ifndef TAO_LB_SIGNAL_HANDLER_H
#define TAO_LB_SIGNAL_HANDLER_H

#include "ace/Task.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
#pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "tao/ORB.h"
#include "tao/PortableServer/PortableServer.h"
#include "ace/Signal.h"

/**
 * @class TAO_LB_Signal_Handler
 *
 * @brief Active object designed to handle signals synchronously.
 *
 * This class handles signals synchronously in the multi-threaded case,
 * and asynchronously through a Reactor in the single-threaded case.
 * @par
 * The goal of this signal handler is to ensure proper cleanup of
 * resources created by servants upon interruption by signals.  For
 * example, suppose a user sends a
 * SIGINT (e.g. types CTRL-C) signal to an application.  The servants
 * in that application should be shutdown gracefully so that all
 * resources handled by those servants are cleaned up.  This is
 * particularly important for resources that are not cleaned up
 * automatically.
 */
class TAO_LB_Signal_Handler : public ACE_Task_Base
{
public:

  /// Constructor.
  TAO_LB_Signal_Handler (CORBA::ORB_ptr orb,
                         PortableServer::POA_ptr poa);

  /// Run by a daemon thread to handle signals synchronously.
  virtual int svc (void);

  /// Active object activation method.
  /**
   * This override blocks all signals in the calling thread before
   * spawning the synchronous signal handler.
   */
  virtual int activate (long flags = THR_NEW_LWP | THR_JOINABLE,
                        int n_threads = 1,
                        int force_active = 0,
                        long priority = ACE_DEFAULT_THREAD_PRIORITY,
                        int grp_id = -1,
                        ACE_Task_Base *task = 0,
                        ACE_hthread_t thread_handles[] = 0,
                        void *stack[] = 0,
                        size_t stack_size[] = 0,
                        ACE_thread_t thread_ids[] = 0,
                        const char* thr_name[] = 0);

  /// Called when object is signaled by OS (either via UNIX signals or
  /// when a Win32 object becomes signaled).
  virtual int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0);

protected:

  /// Template method that initiates the cleanup process.
  virtual int perform_cleanup (int signum);

private:

#ifdef ACE_HAS_THREADS
  /// Block all signals before spawning the threads.  Then, unblock
  /// these signals when this handler is destroyed.
  ACE_Sig_Guard signal_guard_;
#endif  /* ACE_HAS_THREADS */

  /// The set of signals which this handler will handle.
  ACE_Sig_Set sigset_;

  /// Pseudo-reference to the ORB in which the LoadManager is running.
  CORBA::ORB_var orb_;

  /// Reference to the POA within which the LoadManager servant is
  /// registered.
  PortableServer::POA_var poa_;

};

#endif  /* TAO_LB_SIGNAL_HANDLER_H */