Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / Event_Comm / consumer.cpp
blob8eb2384e7034e98ccac42e89c2cf6debc5c86346
1 #include "Consumer_Handler.h"
2 #include "Consumer_Input_Handler.h"
4 /**
5 * Consumer driver for the Publish/Subscribe example.
7 * The Consumer holds the <Consumer_Input_Handler> and
8 * <Cosumer_Handler> objects.
9 */
10 class Consumer : public ACE_Event_Handler, public ShutdownCallback
12 public:
13 Consumer (void);
14 // Constructor.
16 ~Consumer (void);
17 // Destructor.
19 int initialize (int argc, ACE_TCHAR *argv[]);
20 // Initialization method.
22 int run (void);
23 // Execute the consumer;
25 //FUZZ: disable check_for_lack_ACE_OS
26 virtual void close (void);
27 // Shutdown the consumer.
28 //FUZZ: enable check_for_lack_ACE_OS
30 private:
31 virtual int handle_signal (int signum, siginfo_t *, ucontext_t *);
32 // Signal handler method.
34 Consumer_Input_Handler ih_;
35 // Handler for keyboard input.
37 Consumer_Handler ch_;
38 // Handler for CORBA Consumer.
41 Consumer::Consumer (void)
43 // No-Op.
46 Consumer::~Consumer (void)
48 // No-Op.
51 int
52 Consumer::handle_signal (int signum,
53 siginfo_t *,
54 ucontext_t *)
56 ACE_DEBUG ((LM_DEBUG,
57 "%S\n",
58 signum));
60 // Indicate that the consumer initiated the shutdown.
61 this->ih_.consumer_initiated_shutdown (1);
63 this->close ();
65 return 0;
68 void
69 Consumer::close (void)
71 // clean up the input handler.
72 ih_.close ();
73 // Shut down the ORB
74 ch_.close ();
77 int
78 Consumer::run (void)
80 // Run the <Consumer_Handler>'s ORB.
81 return ch_.run ();
84 int
85 Consumer::initialize (int argc, ACE_TCHAR *argv[])
87 // Initialize the <Consumer_Handler>.
88 if (this->ch_.init (argc, argv, this) == -1)
89 ACE_ERROR_RETURN ((LM_ERROR,
90 "%p\n",
91 "Consumer_Handler failed to initialize\n"),
92 -1);
93 // Initialize the <Consumer_Input_Handler>.
94 else if (this->ih_.initialize (&this->ch_) == -1)
95 ACE_ERROR_RETURN ((LM_ERROR,
96 "%p\n",
97 "Consumer_Input_Handler failed to initialize\n"),
98 -1);
99 else if (this->ch_.reactor ()->register_handler (SIGINT,
100 this) == -1)
101 ACE_ERROR_RETURN ((LM_ERROR,
102 "%p\n",
103 "register_handler"),
104 -1);
105 else
106 return 0;
110 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
112 // Initialize the supplier and consumer object references.
113 Consumer consumer;
115 if (consumer.initialize (argc, argv) == -1)
116 ACE_ERROR_RETURN ((LM_ERROR,
117 "%p\n",
118 "Consumer init failed\n"),
121 // Loop forever handling events.
122 if (consumer.run () == -1)
123 ACE_ERROR_RETURN ((LM_ERROR,
124 "%p\n",
125 "Consumer run failed\n"),
128 return 0;