Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / lib / Notify_Test_Client.cpp
blob5b4e67bf58e687d93f1006b3ba82bf671a1c4ef1
1 #include "Notify_Test_Client.h"
2 #define NOTIFY_FACTORY_NAME "NotifyEventChannelFactory"
3 #define NAMING_SERVICE_NAME "NameService"
5 Notify_Test_Client::Notify_Test_Client ()
6 : num_clients_( 0 )
7 , done_( false )
9 // @@ Later: accept the inter filter operator as a param.
10 ifgop_ = CosNotifyChannelAdmin::OR_OP;
13 Notify_Test_Client::~Notify_Test_Client ()
15 if (!CORBA::is_nil (root_poa_.in ()) &&
16 !CORBA::is_nil (orb_.in ()))
18 try
20 root_poa_->destroy(true, true);
21 orb_->destroy();
23 catch (const CORBA::Exception& e)
25 e._tao_print_exception ("\nError: ");
30 int
31 Notify_Test_Client::init (int argc, ACE_TCHAR *argv[])
33 int status = this->init_ORB (argc, argv);
34 if (status == 0)
36 this->resolve_naming_service ();
37 this->resolve_Notify_factory ();
39 return status;
42 int
43 Notify_Test_Client::parse_args (int /*argc*/, ACE_TCHAR *[] /*argv*/)
45 return 0;
49 int
50 Notify_Test_Client::init_ORB (int argc, ACE_TCHAR *argv[])
52 this->orb_ = CORBA::ORB_init (argc, argv);
54 if (this->parse_args (argc, argv) != 0)
56 return -1;
59 CORBA::Object_var poa_object =
60 this->orb_->resolve_initial_references("RootPOA");
62 if (CORBA::is_nil (poa_object.in ()))
64 ACE_ERROR ((LM_ERROR,
65 " (%P|%t) Unable to initialize the POA.\n"));
66 return -1;
68 this->root_poa_ =
69 PortableServer::POA::_narrow (poa_object.in ());
71 PortableServer::POAManager_var poa_manager =
72 root_poa_->the_POAManager ();
74 poa_manager->activate ();
76 return 0;
79 void
80 Notify_Test_Client::resolve_naming_service ()
82 CORBA::Object_var naming_obj =
83 this->orb_->resolve_initial_references (NAMING_SERVICE_NAME);
85 // Need to check return value for errors.
86 if (CORBA::is_nil (naming_obj.in ()))
87 throw CORBA::UNKNOWN ();
89 this->naming_context_ =
90 CosNaming::NamingContext::_narrow (naming_obj.in ());
93 void
94 Notify_Test_Client::resolve_Notify_factory ()
96 CosNaming::Name name (1);
97 name.length (1);
98 name[0].id = CORBA::string_dup (NOTIFY_FACTORY_NAME);
100 CORBA::Object_var obj =
101 this->naming_context_->resolve (name);
103 this->notify_factory_ =
104 CosNotifyChannelAdmin::EventChannelFactory::_narrow (obj.in ());
108 Notify_Test_Client::ORB_run ()
110 while (! is_done())
112 ACE_Time_Value tv(0, 10 * 1000);
113 orb_->run(tv);
116 ACE_DEBUG((LM_DEBUG, "\nWaiting for stray events...\n"));
118 ACE_Time_Value tv(2);
119 orb_->run(tv);
121 return 0;
125 Notify_Test_Client::ORB_run (ACE_Time_Value& tv)
127 orb_->run(tv);
129 ACE_DEBUG((LM_DEBUG, "\nWaiting for stray events...\n"));
131 ACE_Time_Value tv2(2,0);
132 orb_->run(tv2);
134 return 0;
137 void Notify_Test_Client::consumer_start (TAO_Notify_Tests_Peer*)
139 num_clients_++;
142 void
143 Notify_Test_Client::consumer_done (TAO_Notify_Tests_Peer*)
145 int value = --num_clients_;
146 if ( value == 0 )
148 this->done_ = true;
152 bool
153 Notify_Test_Client::is_done () const
155 return this->done_;
158 CORBA::ORB_ptr
159 Notify_Test_Client::orb ()
161 return this->orb_.in ();
165 PortableServer::POA_ptr
166 Notify_Test_Client::root_poa ()
168 return this->root_poa_.in ();
171 CosNaming::NamingContext_ptr
172 Notify_Test_Client::naming_context ()
174 return this->naming_context_.in ();
177 CosNotifyChannelAdmin::EventChannelFactory_ptr
178 Notify_Test_Client::notify_factory ()
180 return this->notify_factory_.in ();
183 CosNotifyChannelAdmin::EventChannel_ptr
184 Notify_Test_Client::create_event_channel (const char* cname, bool resolve)
186 CosNotifyChannelAdmin::EventChannel_var ec;
187 CosNaming::Name name (1);
188 name.length (1);
189 name[0].id = CORBA::string_dup (cname);
191 if (resolve)
193 CORBA::Object_var obj = naming_context_->resolve (name);
194 ec = CosNotifyChannelAdmin::EventChannel::_narrow (obj.in ());
196 else
198 if (CORBA::is_nil (this->notify_factory_.in ()))
200 return CosNotifyChannelAdmin::EventChannel::_nil ();
203 CosNotifyChannelAdmin::ChannelID id;
204 CosNotification::QoSProperties initial_qos;
205 CosNotification::AdminProperties initial_admin;
207 ec = notify_factory_->create_channel (initial_qos,
208 initial_admin,
209 id);
211 naming_context_->rebind(name, ec.in());
214 return ec._retn ();