Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / examples / Event_Comm / Consumer_Handler.cpp
blobdf271e744cae524139ebe9d9578f08a7eff10bc4
1 #include "Consumer_Handler.h"
2 #include "tao/ORB_Core.h"
4 Consumer_Handler::Consumer_Handler ()
5 : receiver_ (0),
6 notifier_ (0),
7 shutdowncallback (0)
9 // No-Op.
12 int
13 Consumer_Handler::init (int argc,
14 ACE_TCHAR *argv[],
15 ShutdownCallback *_shutdowncallback)
17 const char *filtering_criteria = "";
19 // First see if we have any environment variables.
20 filtering_criteria =
21 ACE_OS::getenv ("FILTERING_CRITERIA");
23 // Then override these variables with command-line arguments if
24 // necessary.
25 filtering_criteria = argc > 1 ? ACE_TEXT_ALWAYS_CHAR(argv[1]) : "";
27 try
29 // Retrieve the ORB.
30 this->orb_ = CORBA::ORB_init (argc, argv);
32 CORBA::Object_var poa_object =
33 this->orb_->resolve_initial_references ("RootPOA");
35 PortableServer::POA_var poa =
36 PortableServer::POA::_narrow (poa_object.in ());
38 PortableServer::POAManager_var poa_manager =
39 poa->the_POAManager ();
41 poa_manager->activate ();
43 // Save the Shutdown callback.
44 this->shutdowncallback = _shutdowncallback;
45 // Set the ShutdownCallback callback object
46 // in the Consumer object implementation.
47 this->receiver_i_.set (_shutdowncallback);
49 // Start the servant.
50 this->receiver_ =
51 this->receiver_i_._this ();
54 if (this->get_notifier () == -1)
55 ACE_ERROR_RETURN ((LM_ERROR,
56 " (%P|%t) Unable to get the notifier "
57 "the TAO_Naming_Client.\n"),
58 -1);
60 // Subscribe ourselves with the notifier's broker.
61 this->notifier_->subscribe (this->receiver_.in (),
62 filtering_criteria);
64 catch (const CORBA::Exception& ex)
66 ex._tao_print_exception ("Consumer_Handler::init\n");
67 return -1;
70 return 0;
73 int
74 Consumer_Handler::get_notifier ()
76 try
78 // Initialization of the naming service.
79 if (naming_services_client_.init (orb_.in ()) != 0)
80 ACE_ERROR_RETURN ((LM_ERROR,
81 " (%P|%t) Unable to initialize "
82 "the TAO_Naming_Client.\n"),
83 -1);
85 CosNaming::Name notifier_ref_name (1);
86 notifier_ref_name.length (1);
87 notifier_ref_name[0].id = CORBA::string_dup (NOTIFIER_BIND_NAME);
89 CORBA::Object_var notifier_obj =
90 this->naming_services_client_->resolve (notifier_ref_name);
92 // The CORBA::Object_var object is downcast to Notifier_var
93 // using the <_narrow> method.
94 this->notifier_ =
95 Event_Comm::Notifier::_narrow (notifier_obj.in ());
97 catch (const CORBA::Exception& ex)
99 ex._tao_print_exception ("Consumer_Handler::get_notifier\n");
100 return -1;
103 return 0;
106 void
107 Consumer_Handler::close ()
109 this->orb_->shutdown ();
112 void
113 Consumer_Handler::shutdown ()
115 ACE_ASSERT (this->shutdowncallback != 0);
117 this->shutdowncallback->close ();
121 Consumer_Handler::run ()
123 ACE_DEBUG ((LM_DEBUG,
124 "Running the Consumer...\n"));
126 // Run the ORB.
129 this->orb_->run ();
131 catch (const CORBA::Exception&)
134 return 0;
137 ACE_Reactor*
138 Consumer_Handler::reactor()
140 // @@ Please see if there's a way to get to the Reactor without
141 // using the TAO_ORB_Core_instance().
142 return TAO_ORB_Core_instance ()->reactor ();
145 Event_Comm::Consumer_ptr
146 Consumer_Handler::receiver ()
148 return this->receiver_.in ();
151 Event_Comm::Notifier_ptr
152 Consumer_Handler::notifier ()
154 return this->notifier_.in ();