summaryrefslogtreecommitdiff
path: root/TAO/examples/Event_Comm/notifier.cpp
blob: b583931699ff2063cc02cc736fce7fa407627d91 (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
// $Id$

#include "Notifier_Server.h"

ACE_RCSID(Notifier, notifier, "$Id$")

class Notifier : public ACE_Event_Handler
{
  // = TITLE
  //   Notifier driver for the TAO Publish/Subscribe example.
  //
  // = DESCRIPTION
  //    The driver class for the <Event_Comm::Notifier> object.
public:
  // = Initialization and termination methods.
  Notifier (int argc, char *argv[]);
  // Constructor.

  ~Notifier (void);
  // Destructor.

  void run (void);
  // Execute the notifier.

private:
  virtual int handle_signal (int signum,
			     siginfo_t *,
			     ucontext_t *);
  // Handle signals that shut us down.

  Notifier_Server ns_;
  // The notifier server.
};

int
Notifier::handle_signal (int signum, siginfo_t *, ucontext_t *)
{
  ACE_DEBUG ((LM_DEBUG,
              "got signal in handle_signal %S\n",
              signum));

  // Tell the <Notifier_Server> to shut down the ORB.
  ns_.close ();
  return 0;
}

void
Notifier::run (void)
{
  TAO_TRY
    {
      ns_.run (TAO_TRY_ENV);
      TAO_CHECK_ENV;
    }
  TAO_CATCHANY
    {
      return;
    }
  TAO_ENDTRY;
}

Notifier::Notifier (int argc, char *argv[])
{
  TAO_TRY
    {
      ns_.init (argc, argv, TAO_TRY_ENV);
    }
  TAO_CATCHANY
    {
      TAO_TRY_ENV.print_exception ("Notifier_Server.init failed\n ");
    }
  TAO_ENDTRY;

  // Register with the ORB's Reactor to receive a signal to shut us
  // down.
  if (ns_.reactor ()->register_handler (SIGINT, this) == -1)
    ACE_ERROR ((LM_ERROR,
                "%p\n",
                "register_handler"));
}

Notifier::~Notifier (void)
{
  // Cleanup.
  this->ns_.close ();
}

int
main (int argc, char *argv[])
{
  // Initialize server daemon.
  Notifier notifier (argc, argv);

  // Loop forever handling events.
  notifier.run ();

  return 0;
}