4 FTP_Client_Callback::FTP_Client_Callback (void)
10 FTP_Client_Callback::handle_end_stream (void)
12 TAO_AV_CORE::instance ()->orb ()->shutdown ();
17 FTP_Client_Callback::get_timeout (ACE_Time_Value
*&tv
,
20 ACE_Time_Value
*timeout
;
27 FTP_Client_Callback::handle_timeout (void *)
29 ACE_Message_Block
mb (BUFSIZ
);
30 ACE_DEBUG ((LM_DEBUG
,"FTP_Client_Callback::get_frame\n"));
31 char *buf
= mb
.rd_ptr ();
33 int n
= ACE_OS::fread(buf
,1,mb
.size (),CLIENT::instance ()->file ());
36 ACE_ERROR_RETURN ((LM_ERROR
,"FTP_Client_Flow_Handler::fread end of file\n"),-1);
40 if (feof (CLIENT::instance ()->file ()))
42 // wait for sometime for the data to be flushed to the other side.
44 if (this->count_
== 2)
48 ACE_DEBUG ((LM_DEBUG
,"handle_timeout:End of file\n"));
49 AVStreams::flowSpec
stop_spec (1);
50 ACE_DEBUG ((LM_DEBUG
, "Just before Orb Shutdown\n"));
51 TAO_AV_CORE::instance ()->orb ()->shutdown (0);
54 catch (const CORBA::Exception
& ex
)
56 ex
._tao_print_exception (
57 "FTP_Client_Callback::handle_timeout\n");
65 ACE_ERROR_RETURN ((LM_ERROR
,"FTP_Client_Flow_Handler::fread error\n"),-1);
68 int result
= this->protocol_object_
->send_frame (&mb
);
70 ACE_ERROR_RETURN ((LM_ERROR
,"send failed:%p","FTP_Client_Flow_Handler::send\n"),-1);
71 ACE_DEBUG ((LM_DEBUG
,"handle_timeout::buffer sent successfully\n"));
75 FTP_Client_Producer::FTP_Client_Producer (void)
76 :TAO_FlowProducer ("Data",CLIENT::instance ()->protocols (),CLIENT::instance ()->format ())
81 FTP_Client_Producer::set_protocol_object (const char *,
82 TAO_AV_Protocol_Object
*object
)
84 this->callback_
->set_protocol_object (object
);
89 FTP_Client_Producer::get_callback (const char *,
90 TAO_AV_Callback
*&callback
)
92 ACE_NEW_RETURN (this->callback_
,
95 callback
= this->callback_
;
100 Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
102 ACE_Get_Opt
opts (argc
, argv
, ACE_TEXT("f:a:p:sd"));
106 while ((c
= opts ()) != -1)
111 this->filename_
= opts
.opt_arg ();
114 this->address_
= ACE_OS::strdup (ACE_TEXT_ALWAYS_CHAR (opts
.opt_arg ()));
117 this->protocol_
= ACE_OS::strdup (ACE_TEXT_ALWAYS_CHAR (opts
.opt_arg ()));
126 ACE_DEBUG ((LM_DEBUG
,"Unknown option\n"));
141 Client::flowname (void)
143 return this->flowname_
;
146 AVStreams::protocolSpec
147 Client::protocols (void)
149 AVStreams::protocolSpec
protocols (1);
150 protocols
.length (1);
152 ACE_OS::sprintf (buf
, "%s=%s", this->protocol_
, this->address_
);
153 protocols
[0] = CORBA::string_dup (buf
);
158 Client::format (void)
164 Client::address (void)
167 return this->address_
;
171 Client::streamctrl (void)
173 return &this->streamctrl_
;
176 Client::Client (void)
177 : client_mmdevice_ (&endpoint_strategy_
),
179 address_ (ACE_OS::strdup ("224.9.9.2:10002")),
181 protocol_ (ACE_OS::strdup ("UDP"))
183 endpoint_strategy_
.init (TAO_AV_CORE::instance ()->orb (), TAO_AV_CORE::instance ()->poa ());
189 Client::bind_to_server (const char *name
)
193 // Initialize the naming services
194 if (my_naming_client_
.init (TAO_AV_CORE::instance ()->orb ()) != 0)
195 ACE_ERROR_RETURN ((LM_ERROR
,
196 " (%P|%t) Unable to initialize "
197 "the TAO_Naming_Client.\n"),
200 CosNaming::Name
server_mmdevice_name (1);
201 server_mmdevice_name
.length (1);
202 server_mmdevice_name
[0].id
= name
;
203 CORBA::Object_var server_mmdevice_obj
=
204 my_naming_client_
->resolve (server_mmdevice_name
);
206 this->server_mmdevice_
=
207 AVStreams::MMDevice::_narrow (server_mmdevice_obj
.in ());
209 if (CORBA::is_nil (this->server_mmdevice_
.in ()))
210 ACE_ERROR_RETURN ((LM_ERROR
,
211 " could not resolve Server_Mmdevice in Naming service <%C>\n",
215 catch (const CORBA::Exception
& ex
)
217 ex
._tao_print_exception (
218 "Command_Handler::resolve_reference");
225 Client::init (int argc
, ACE_TCHAR
*argv
[])
232 PortableServer::POAManager_var mgr
233 = TAO_AV_CORE::instance ()->poa ()->the_POAManager ();
237 this->parse_args (this->argc_
, this->argv_
);
239 ACE_DEBUG ((LM_DEBUG
, "(%N,%l) Parsed Address %C\n", this->address_
));
241 ACE_NEW_RETURN (this->fdev_
,
245 ACE_NEW_RETURN (this->flowname_
,
248 ACE_OS::sprintf (this->flowname_
,
250 this->fdev_
->flowname (this->flowname ());
251 AVStreams::MMDevice_var mmdevice
= this->client_mmdevice_
._this ();
252 AVStreams::FDev_var fdev
= this->fdev_
->_this ();
253 mmdevice
->add_fdev (fdev
.in ());
255 if (this->my_naming_client_
.init (TAO_AV_CORE::instance ()->orb ()) != 0)
256 ACE_ERROR_RETURN ((LM_ERROR
,
257 " (%P|%t) Unable to initialize "
258 "the TAO_Naming_Client.\n"),
261 this->fp_
= ACE_OS::fopen (this->filename_
, "r");
264 ACE_DEBUG ((LM_DEBUG
,"file opened successfully\n"));
267 catch (const CORBA::Exception
& ex
)
269 ex
._tao_print_exception ("Client::init");
280 char flow_protocol_str
[BUFSIZ
];
282 ACE_OS::strcpy (flow_protocol_str
, "sfp:1.0");
284 ACE_OS::strcpy (flow_protocol_str
, "");
285 AVStreams::streamQoS_var
the_qos (new AVStreams::streamQoS
);
286 AVStreams::flowSpec
flow_spec (1);
287 // Bind the client and server mmdevices.
288 ACE_DEBUG ((LM_DEBUG
, "(%N,%l) Parsed Address %C\n", this->address_
));
289 ACE_INET_Addr
*addr
= new ACE_INET_Addr(this->address_
);
290 TAO_Forward_FlowSpec_Entry
entry (this->flowname_
,
296 ACE_DEBUG ((LM_DEBUG
, "(%N,%l) flowspec: %C\n", entry
.entry_to_string() ));
297 flow_spec
.length (1);
298 flow_spec
[0] = CORBA::string_dup (entry
.entry_to_string ());
300 AVStreams::MMDevice_var client_mmdevice
=
301 this->client_mmdevice_
._this ();
303 CORBA::Boolean result
=
304 this->streamctrl_
.bind_devs (client_mmdevice
.in (),
305 AVStreams::MMDevice::_nil (),
310 ACE_ERROR_RETURN ((LM_ERROR
,"streamctrl::bind_devs for client_mmdevice failed\n"),-1);
311 if (this->bind_to_server ("Server_MMDevice1") == -1)
312 ACE_ERROR_RETURN ((LM_ERROR
,
313 "(%P|%t) Error binding to the naming service\n"),
315 result
= this->streamctrl_
.bind_devs (AVStreams::MMDevice::_nil (),
316 this->server_mmdevice_
.in (),
321 ACE_ERROR_RETURN ((LM_ERROR
,"(%N,%l) streamctrl::bind_devs for mmdevice 1 failed\n"),-1);
322 if (this->bind_to_server ("Server_MMDevice2") == -1)
323 ACE_ERROR_RETURN ((LM_ERROR
,
324 "(%P|%t) Error binding to the naming service\n"),
326 result
= this->streamctrl_
.bind_devs (AVStreams::MMDevice::_nil (),
327 this->server_mmdevice_
.in (),
332 ACE_ERROR_RETURN ((LM_ERROR
,"(%N,%l) streamctrl::bind_devs for mmdevice 2 failed\n"),-1);
333 AVStreams::flowSpec
start_spec (1);
334 start_spec
.length (1);
335 start_spec
[0] = CORBA::string_dup (this->flowname_
);
336 this->streamctrl_
.start (start_spec
);
337 // Schedule a timer for the for the flow handler.
338 //TAO_AV_CORE::instance ()->run ();
340 ACE_Time_Value
tv (10000,0);
341 TAO_AV_CORE::instance ()->orb ()->run (tv
);
343 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
345 ACE_DEBUG ((LM_DEBUG
, "Exited the TAO_AV_Core::run\n"));
347 catch (const CORBA::Exception
& ex
)
349 ex
._tao_print_exception ("Client::run");
356 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
360 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
362 CORBA::Object_var obj
363 = orb
->resolve_initial_references ("RootPOA");
365 PortableServer::POA_var poa
366 = PortableServer::POA::_narrow (obj
.in ());
368 TAO_AV_CORE::instance ()->init (orb
.in (),
371 catch (const CORBA::Exception
& ex
)
373 ex
._tao_print_exception ("server::init");
378 result
= CLIENT::instance ()->init (argc
, argv
);
380 ACE_ERROR_RETURN ((LM_ERROR
,"client::init failed\n"),1);
381 result
= CLIENT::instance ()->run ();
383 ACE_ERROR_RETURN ((LM_ERROR
,"client::run failed\n"),1);
385 CLIENT::close (); // Explicitly finalize the Unmanaged_Singleton.
390 #if defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION)
391 template ACE_Unmanaged_Singleton
<Client
, ACE_Null_Mutex
> *ACE_Unmanaged_Singleton
<Client
, ACE_Null_Mutex
>::singleton_
;
392 #endif /* ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION */