1 #include "Consumer_Handler.h"
2 #include "tao/ORB_Core.h"
4 Consumer_Handler::Consumer_Handler (void)
12 Consumer_Handler::~Consumer_Handler (void)
18 Consumer_Handler::init (int argc
,
20 ShutdownCallback
*_shutdowncallback
)
22 const char *filtering_criteria
= "";
24 // First see if we have any environment variables.
26 ACE_OS::getenv ("FILTERING_CRITERIA");
28 // Then override these variables with command-line arguments if
30 filtering_criteria
= argc
> 1 ? ACE_TEXT_ALWAYS_CHAR(argv
[1]) : "";
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
);
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"),
65 // Subscribe ourselves with the notifier's broker.
66 this->notifier_
->subscribe (this->receiver_
.in (),
69 catch (const CORBA::Exception
& ex
)
71 ex
._tao_print_exception ("Consumer_Handler::init\n");
79 Consumer_Handler::get_notifier (void)
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"),
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.
100 Event_Comm::Notifier::_narrow (notifier_obj
.in ());
102 catch (const CORBA::Exception
& ex
)
104 ex
._tao_print_exception ("Consumer_Handler::get_notifier\n");
112 Consumer_Handler::close (void)
114 this->orb_
->shutdown ();
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"));
136 catch (const CORBA::Exception
&)
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 ();