2 #include "ace/Get_Opt.h"
3 #include "ace/High_Res_Timer.h"
7 // Create a singleton instance of the Sender.
9 // An Unmanaged_Singleton is used to avoid static object destruction
10 // order related problems since the underlying singleton object
11 // contains references to static TypeCodes.
12 typedef ACE_Unmanaged_Singleton
<Receiver
,ACE_Null_Mutex
> RECEIVER
;
16 Receiver_StreamEndPoint::get_callback (const char *flow_name
,
17 TAO_AV_Callback
*&callback
)
19 Receiver_Callback
*callback_
;
20 ACE_NEW_RETURN (callback_
,
24 // Return the receiver application callback to the AVStreams for
27 callback_
->flowname (flow_name
);
33 Receiver_StreamEndPoint::set_protocol_object (const char * flowname
,
34 TAO_AV_Protocol_Object
*object
)
36 // Set the sender protocol object corresponding to the transport
38 if (ACE_OS::strcmp (flowname
, "Data_Receiver1") == 0)
39 RECEIVER::instance ()->protocol_object (object
);
43 Receiver_Callback::Receiver_Callback ()
48 "Receiver_Callback::Receiver_Callback\n"));
52 Receiver_Callback::flowname (const char* flow_name
)
54 this->flowname_
= flow_name
;
56 // Make sure we have a valid <output_file>
57 this->output_file_
= ACE_OS::fopen (this->flowname_
.c_str (),
59 if (this->output_file_
== 0)
61 "Cannot open output file %C\n",
62 this->flowname_
.c_str ()));
66 "%C File Opened Successfully\n",
67 this->flowname_
.c_str ()));
72 Receiver_Callback::receive_frame (ACE_Message_Block
*frame
,
77 // Upcall from the AVStreams when there is data to be received from
81 "Receiver_Callback::receive_frame for frame %d for flow %C\n",
83 this->flowname_
.c_str ()));
87 // Write the received data to the file.
89 ACE_OS::fwrite (frame
->rd_ptr (),
94 if (result
== frame
->length ())
95 ACE_ERROR_RETURN ((LM_ERROR
,
96 "Receiver_Callback::fwrite failed\n"),
99 frame
= frame
->cont ();
106 Receiver_Callback::handle_destroy ()
108 // Called when the distributer requests the stream to be shutdown.
109 ACE_DEBUG ((LM_DEBUG
,
110 "Receiver_Callback::handle_destroy\n"));
117 Receiver::Receiver ()
126 Receiver::~Receiver ()
131 Receiver::protocol_object (TAO_AV_Protocol_Object
*object
)
133 // Set the sender protocol object corresponding to the transport
134 // protocol selected.
135 this->protocol_object_
= object
;
139 Receiver::parse_args (int argc
,
142 // Parse command line arguments
143 ACE_Get_Opt
opts (argc
, argv
, ACE_TEXT("f:r:d"));
146 while ((c
= opts ()) != -1)
151 this->filename_
= ACE_TEXT_ALWAYS_CHAR (opts
.opt_arg ());
154 this->frame_rate_
= ACE_OS::atoi (opts
.opt_arg ());
160 ACE_DEBUG ((LM_DEBUG
, "Unknown Option\n"));
168 Receiver::init (int argc
,
171 // Initialize the endpoint strategy with the orb and poa.
173 this->reactive_strategy_
.init (TAO_AV_CORE::instance ()->orb (),
174 TAO_AV_CORE::instance ()->poa ());
178 // Parse the command line arguments
180 this->parse_args (argc
,
186 // Register the receiver mmdevice object with the ORB
187 ACE_NEW_RETURN (this->mmdevice_
,
188 TAO_MMDevice (&this->reactive_strategy_
),
191 // Servant Reference Counting to manage lifetime
192 PortableServer::ServantBase_var safe_mmdevice
=
195 CORBA::Object_var mmdevice
=
196 this->mmdevice_
->_this ();
198 // Register the mmdevice with the naming service.
199 CosNaming::Name
name (1);
202 CORBA::string_dup ("Receiver");
204 // Initialize the naming services
205 if (this->naming_client_
.init (TAO_AV_CORE::instance ()->orb ()) != 0)
206 ACE_ERROR_RETURN ((LM_ERROR
,
207 "Unable to initialize "
208 "the TAO_Naming_Client\n"),
211 // Register the receiver object with the naming server.
212 this->naming_client_
->rebind (name
,
218 TAO_AV_Protocol_Object
*
219 Receiver::protocol_object ()
221 return this->protocol_object_
;
230 // Initialize the ORB first.
232 CORBA::ORB_init (argc
, argv
);
234 CORBA::Object_var obj
235 = orb
->resolve_initial_references ("RootPOA");
237 // Get the POA_var object from Object_var.
238 PortableServer::POA_var root_poa
=
239 PortableServer::POA::_narrow (obj
.in ());
241 PortableServer::POAManager_var mgr
242 = root_poa
->the_POAManager ();
246 // Initialize the AVStreams components.
247 TAO_AV_CORE::instance ()->init (orb
.in (),
251 RECEIVER::instance ()->init (argc
,
257 while (endstream
!= 2)
259 orb
->perform_work ();
267 catch (const CORBA::Exception
& ex
)
269 ex
._tao_print_exception ("receiver::init");
273 RECEIVER::close (); // Explicitly finalize the Unmanaged_Singleton.
278 #if defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION)
279 template ACE_Unmanaged_Singleton
<Receiver
, ACE_Null_Mutex
> *ACE_Unmanaged_Singleton
<Receiver
, ACE_Null_Mutex
>::singleton_
;
280 #endif /* ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION */