Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / Event_Comm / Consumer_Handler.cpp
blobf32b1c1ba03372aaee67e9b6cc65d2df0b046f2f
1 #include "Consumer_Handler.h"
2 #include "tao/ORB_Core.h"
4 Consumer_Handler::Consumer_Handler (void)
5 : receiver_ (0),
6 notifier_ (0),
7 shutdowncallback (0)
9 // No-Op.
12 Consumer_Handler::~Consumer_Handler (void)
14 // No-Op.
17 int
18 Consumer_Handler::init (int argc,
19 ACE_TCHAR *argv[],
20 ShutdownCallback *_shutdowncallback)
22 const char *filtering_criteria = "";
24 // First see if we have any environment variables.
25 filtering_criteria =
26 ACE_OS::getenv ("FILTERING_CRITERIA");
28 // Then override these variables with command-line arguments if
29 // necessary.
30 filtering_criteria = argc > 1 ? ACE_TEXT_ALWAYS_CHAR(argv[1]) : "";
32 try
34 // Retrieve the ORB.
35 this->orb_ = CORBA::ORB_init (argc, argv);
37 CORBA::Object_var poa_object =
38 this->orb_->resolve_initial_references ("RootPOA");
40 PortableServer::POA_var poa =
41 PortableServer::POA::_narrow (poa_object.in ());
43 PortableServer::POAManager_var poa_manager =
44 poa->the_POAManager ();
46 poa_manager->activate ();
48 // Save the Shutdown callback.
49 this->shutdowncallback = _shutdowncallback;
50 // Set the ShutdownCallback callback object
51 // in the Consumer object implementation.
52 this->receiver_i_.set (_shutdowncallback);
54 // Start the servant.
55 this->receiver_ =
56 this->receiver_i_._this ();
59 if (this->get_notifier () == -1)
60 ACE_ERROR_RETURN ((LM_ERROR,
61 " (%P|%t) Unable to get the notifier "
62 "the TAO_Naming_Client.\n"),
63 -1);
65 // Subscribe ourselves with the notifier's broker.
66 this->notifier_->subscribe (this->receiver_.in (),
67 filtering_criteria);
69 catch (const CORBA::Exception& ex)
71 ex._tao_print_exception ("Consumer_Handler::init\n");
72 return -1;
75 return 0;
78 int
79 Consumer_Handler::get_notifier (void)
81 try
83 // Initialization of the naming service.
84 if (naming_services_client_.init (orb_.in ()) != 0)
85 ACE_ERROR_RETURN ((LM_ERROR,
86 " (%P|%t) Unable to initialize "
87 "the TAO_Naming_Client.\n"),
88 -1);
90 CosNaming::Name notifier_ref_name (1);
91 notifier_ref_name.length (1);
92 notifier_ref_name[0].id = CORBA::string_dup (NOTIFIER_BIND_NAME);
94 CORBA::Object_var notifier_obj =
95 this->naming_services_client_->resolve (notifier_ref_name);
97 // The CORBA::Object_var object is downcast to Notifier_var
98 // using the <_narrow> method.
99 this->notifier_ =
100 Event_Comm::Notifier::_narrow (notifier_obj.in ());
102 catch (const CORBA::Exception& ex)
104 ex._tao_print_exception ("Consumer_Handler::get_notifier\n");
105 return -1;
108 return 0;
111 void
112 Consumer_Handler::close (void)
114 this->orb_->shutdown ();
117 void
118 Consumer_Handler::shutdown (void)
120 ACE_ASSERT (this->shutdowncallback != 0);
122 this->shutdowncallback->close ();
126 Consumer_Handler::run (void)
128 ACE_DEBUG ((LM_DEBUG,
129 "Running the Consumer...\n"));
131 // Run the ORB.
134 this->orb_->run ();
136 catch (const CORBA::Exception&)
139 return 0;
142 ACE_Reactor*
143 Consumer_Handler::reactor(void)
145 // @@ Please see if there's a way to get to the Reactor without
146 // using the TAO_ORB_Core_instance().
147 return TAO_ORB_Core_instance ()->reactor ();
150 Event_Comm::Consumer_ptr
151 Consumer_Handler::receiver (void)
153 return this->receiver_.in ();
156 Event_Comm::Notifier_ptr
157 Consumer_Handler::notifier (void)
159 return this->notifier_.in ();