summaryrefslogtreecommitdiff
path: root/apps/Orbix-Examples/Event_Comm/Supplier/supplier.cpp
blob: ecae0c45eb2a0e4b8424f4b9bc216d970e2b72b1 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// $Id$

#include "ace/Service_Config.h"

#include "Notifier_Handler.h"
#include "Input_Handler.h"

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

#if defined (ACE_HAS_ORBIX) && (ACE_HAS_ORBIX != 0)

class Supplier : public ACE_Event_Handler
{
  // = TITLE
  //   Supplier driver for the Orbix Publish/Subscribe example.
  //
  // = DESCRIPTION
  //   The executable file generated from this code should be
  //   registered (under the name 'logger') using the 'putit' command.
public:
  Supplier (int argc, char *argv[]);
  ~Supplier (void);

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

private:
  virtual int handle_signal (int signum, siginfo_t *, ucontext_t *);

  virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask);

  Input_Handler *ih_;
  // Handler for keyboard input.

  Notifier_Handler *nh_;
  // Handler for CORBA Notifier.

  ACE_Service_Config daemon_;
  // ACE server event-loop mechanism.
};

int
Supplier::handle_close (ACE_HANDLE, ACE_Reactor_Mask)
{
  ACE_DEBUG ((LM_DEBUG,
              "closing down Supplier\n"));
  return 0;
}

int 
Supplier::handle_signal (int signum, siginfo_t *, ucontext_t *)
{
  ACE_DEBUG ((LM_DEBUG,
              "%S\n",
              signum));
  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"));
}

Supplier::Supplier (int argc, char *argv[])
  : ih_ (0), 
    nh_ (0)
{
  // Initialize the server.
  if (this->daemon_.open (argc, argv) == -1)
    {
      if (errno == ENOENT) // There's no svc.conf file, so use static linking...
	{
	  ACE_DEBUG ((LM_DEBUG,
                      "no config file, using static binding\n"));
	  // The constructor registers the handlers...
	  int putit = argc > 1 ? 1 : 0;

          // Pass in program exec name to use a service_location!
	  ACE_NEW (this->nh_,
                   Notifier_Handler (argv[0],
                                     "notifier",
                                     putit));
	  ACE_NEW (this->ih_,
                   Input_Handler (this->nh_));
	}
      else
	ACE_ERROR ((LM_ERROR,
                    "%p\n%a",
                    "open",
                    1));
    }

  ACE_DEBUG ((LM_DEBUG,
              "starting up server %s\n",
	     CORBA::Orbix.myImplementationName ()));

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

Supplier::~Supplier (void)
{
  // Free up the handlers if they were statically bound.
  this->ih_->handle_close ();
  this->nh_->handle_close ();
}

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

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

  return 0;
}
#else /* !defined ACE_HAS_ORBIX */
int
main (int argc, char *argv[])
{
  ACE_ERROR_RETURN ((LM_ERROR,
                     "you must have Orbix to run application %s\n",
                     argv[0]),
                    1);
}
#endif /* ACE_HAS_ORBIX */