summaryrefslogtreecommitdiff
path: root/ACE/ace/Sig_Adapter.h
blob: 903e2ddbb9ddf13f33972bda7cfeaf2a8ebde55a (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
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Sig_Adapter.h
 *
 *  @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
 */
//=============================================================================

#ifndef ACE_SIG_ADAPTER_H
#define ACE_SIG_ADAPTER_H

#include /**/ "ace/pre.h"

#include /**/ "ace/ACE_export.h"

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

#include "ace/Event_Handler.h"
#include "ace/Signal.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

/**
 * @class ACE_Sig_Adapter
 *
 * @brief Provide an adapter that transforms various types of signal
 * handlers into the scheme used by the ACE_Reactor.
 */
class ACE_Export ACE_Sig_Adapter : public ACE_Event_Handler
{
public:
  ACE_Sig_Adapter (ACE_Sig_Action &, int sigkey);
  ACE_Sig_Adapter (ACE_Event_Handler *, int sigkey);
  ACE_Sig_Adapter (ACE_Sig_Handler_Ex, int sigkey = 0);
  ~ACE_Sig_Adapter () override = default;

  /// Returns this signal key that's used to remove this from the
  /// ACE_Reactor's internal table.
  int sigkey () const;

  /// Called by the ACE_Reactor to dispatch the signal handler.
  int handle_signal (int, siginfo_t *, ucontext_t *) override;

  ACE_ALLOC_HOOK_DECLARE;

private:
  /// Key for this signal handler (used to remove it).
  int const sigkey_;

  /// Is this an external handler or an ACE handler?
  enum
  {
    /// We're just wrapping an ACE_Event_Handler.
    ACE_HANDLER,
    /// An ACE_Sig_Action.
    SIG_ACTION,
    /// A normal C function.
    C_FUNCTION
  } type_;

  /// This should be a union, but C++ won't allow that because the
  /// ACE_Sig_Action has a constructor.
  /// This is an external handler (ugh).
  ACE_Sig_Action sa_;

  /// This is an ACE event handler.
  ACE_Event_Handler *eh_ {};

  /// This is a normal C function.
  ACE_Sig_Handler_Ex sig_func_;
};

ACE_END_VERSIONED_NAMESPACE_DECL

#include /**/ "ace/post.h"

#endif /* ACE_SIG_ADAPTER_H */