summaryrefslogtreecommitdiff
path: root/TAO/examples/Event_Comm/supplier.cpp
blob: 1abf04391b0545b1902520acf431742204b7bfdc (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
100
101
102
103
104
105
106
107
108
109
110
111
// $Id$

#include "Notifier_Handler.h"
#include "Supplier_Input_Handler.h"

ACE_RCSID(Supplier, supplier, "$Id$")

class Supplier : public ACE_Event_Handler
{
  // = TITLE
  //   Supplier driver for the TAO Publish/Subscribe example.
  //
  // = DESCRIPTION
  //    This class starts up the <Supplier_Input_Handler> and
  //    <Notifier_Handler> objects.
public:
  // Initialization and Termination methods.
  Supplier (void);
  // Constructor.

  ~Supplier (void);
  // Destructor.

  int init (int argc, char *argv[]);
  // Initialization method. returns 0 on success, -1 on error.

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

private:
  virtual int handle_signal (int signum,
			     siginfo_t *,
			     ucontext_t *);
  // Handle shutdown signals.

  Supplier_Input_Handler ih_;
  // Handler for keyboard input.

  Notifier_Handler nh_;
  // The notifier handler.
};

Supplier::Supplier (void)
{
  // No-Op.
}

Supplier::~Supplier (void)
{
  // No-Op.
}

int
Supplier::handle_signal (int signum, siginfo_t *, ucontext_t *)
{
  ACE_DEBUG ((LM_DEBUG,
              "%S\n",
              signum));

  this->ih_.handle_close ();
  this->nh_.handle_close ();

  ACE_Reactor::end_event_loop ();
  return 0;
}

void
Supplier::run (void)
{
  if (ACE_Reactor::run_event_loop () == -1)
    ACE_ERROR ((LM_ERROR,
                "%p\n",
                "run_reactor_event_loop"));
}

int
Supplier::init (int argc, char *argv[])
{
  if (this->nh_.init (argc, argv) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
		       "%p\n",
		       "Notifier_Handler did not init\n"), -1);

   if (this->ih_.initialize (&nh_) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
		       "%p\n",
		       "Supplier Input handler did not init\n"), -1);

  if (ACE_Reactor::instance ()->register_handler (SIGINT,
						  this) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
		       "%p\n",
		       "register_handler"), -1);
}

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

  if (supplier.init (argc, argv) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                "%p\n",
                "supplier init failed"), 1);

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

  return 0;
}