Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / AVStreams / Modify_QoS / receiver.cpp
blob0cab42145e8e25ad3865a3e963b935edbf99da29
1 #include "receiver.h"
2 #include "ace/Get_Opt.h"
4 static FILE *output_file = 0;
5 // File handle of the file into which received data is written.
7 static const ACE_TCHAR *output_file_name = ACE_TEXT ("output");
8 // File name of the file into which received data is written.
10 int
11 Receiver_StreamEndPoint::get_callback (const char *,
12 TAO_AV_Callback *&callback)
14 // Return the receiver application callback to the AVStreams for
15 // future upcalls.
16 callback = &this->callback_;
19 // Get the stream controller for this stream.
20 try
22 CORBA::Any_ptr streamctrl_any =
23 this->get_property_value ("Related_StreamCtrl");
25 AVStreams::StreamCtrl_ptr streamctrl;
26 *streamctrl_any >>= streamctrl;
28 // Store the stream control for the stream with the callback.
29 this->callback_.streamctrl (streamctrl);
31 catch (const CORBA::Exception& ex)
33 ex._tao_print_exception ("Sender_StreamEndPoint::get_callback failed");
35 return -1;
38 return 0;
41 Receiver_Callback::Receiver_Callback ()
42 : frame_count_ (0)
46 void
47 Receiver_Callback::streamctrl (AVStreams::StreamCtrl_ptr streamctrl)
49 // Set the sender protocol object corresponding to the transport
50 // protocol selected.
51 this->streamctrl_ = streamctrl;
55 int
56 Receiver_Callback::receive_frame (ACE_Message_Block *frame,
57 TAO_AV_frame_info *,
58 const ACE_Addr &)
61 // Upcall from the AVStreams when there is data to be received from
62 // the sender.
64 ACE_DEBUG ((LM_DEBUG,
65 "Receiver_Callback::receive_frame for frame %d\n",
66 ++this->frame_count_));
69 if (this->streamctrl_ != 0)
71 // Modify QoS after receiving 20 frames
72 if (frame_count_ == 20)
74 // Specify the flow for which the qos needs to be changed.
75 TAO_Forward_FlowSpec_Entry entry ("Data_Receiver",
76 "IN",
77 "",
78 "",
79 0);
81 AVStreams::flowSpec flow_spec (1);
82 flow_spec.length (1);
83 flow_spec [0] = CORBA::string_dup (entry.entry_to_string ());
85 // Initialize the qos parameter(s) that need to be changed
86 // with the corresponding value.
87 AVStreams::streamQoS qos;
88 qos.length (1);
90 // The QoS Type that needs to be changed.
91 qos [0].QoSType = CORBA::string_dup ("video_qos");
93 qos [0].QoSParams.length (1);
94 qos [0].QoSParams [0].property_name = CORBA::string_dup ("video_frame_rate");
95 qos [0].QoSParams [0].property_value <<= (CORBA::Short) 30;
98 // Initiate the modifying of the qos for the flows.
99 this->streamctrl_->modify_QoS (qos, flow_spec);
101 ACE_DEBUG ((LM_DEBUG,
102 "Stream Ctrl available....Modify QoS called\n"));
105 else ACE_DEBUG ((LM_DEBUG,
106 "No Stream Ctrl\n"));
108 while (frame != 0)
110 // Write the received data to the file.
111 size_t result =
112 ACE_OS::fwrite (frame->rd_ptr (),
113 frame->length (),
115 output_file);
117 if (result == frame->length ())
118 ACE_ERROR_RETURN ((LM_ERROR,
119 "Receiver_Callback::fwrite failed\n"),
120 -1);
122 frame = frame->cont ();
125 return 0;
129 Receiver_Callback::handle_destroy ()
131 // Called when the distributer requests the stream to be shutdown.
132 ACE_DEBUG ((LM_DEBUG,
133 "Receiver_Callback::end_stream\n"));
137 TAO_AV_CORE::instance ()->orb ()->shutdown (0);
139 catch (const CORBA::Exception& ex)
141 ex._tao_print_exception ("Receiver_Callback::handle_destroy Failed\n");
142 return -1;
145 return 0;
148 Receiver::Receiver ()
149 : mmdevice_ (0)
153 Receiver::~Receiver ()
159 Receiver::init (int,
160 ACE_TCHAR *[])
162 // Initialize the endpoint strategy with the orb and poa.
163 int result =
164 this->reactive_strategy_.init (TAO_AV_CORE::instance ()->orb (),
165 TAO_AV_CORE::instance ()->poa ());
166 if (result != 0)
167 return result;
169 // Register the receiver mmdevice object with the ORB
170 ACE_NEW_RETURN (this->mmdevice_,
171 TAO_MMDevice (&this->reactive_strategy_),
172 -1);
174 // Servant Reference Counting to manage lifetime
175 PortableServer::ServantBase_var safe_mmdevice =
176 this->mmdevice_;
178 CORBA::Object_var mmdevice =
179 this->mmdevice_->_this ();
181 // Register the mmdevice with the naming service.
182 CosNaming::Name name (1);
183 name.length (1);
184 name [0].id =
185 CORBA::string_dup ("Receiver");
187 // Initialize the naming services
188 if (this->naming_client_.init (TAO_AV_CORE::instance ()->orb ()) != 0)
189 ACE_ERROR_RETURN ((LM_ERROR,
190 "Unable to initialize "
191 "the TAO_Naming_Client\n"),
192 -1);
194 // Register the receiver object with the naming server.
195 this->naming_client_->rebind (name,
196 mmdevice.in ());
198 return 0;
202 parse_args (int argc,
203 ACE_TCHAR *argv[])
205 // Parse the command line arguments
206 ACE_Get_Opt opts (argc,
207 argv,
208 "f:");
210 int c;
211 while ((c = opts ()) != -1)
213 switch (c)
215 case 'f':
216 output_file_name = opts.opt_arg ();
217 break;
218 default:
219 ACE_ERROR_RETURN ((LM_ERROR,
220 "Usage: receiver -f filename"),
221 -1);
225 return 0;
229 ACE_TMAIN (int argc,
230 ACE_TCHAR *argv[])
234 // Initialize the ORB first.
235 CORBA::ORB_var orb =
236 CORBA::ORB_init (argc, argv);
238 CORBA::Object_var obj
239 = orb->resolve_initial_references ("RootPOA");
241 // Get the POA_var object from Object_var.
242 PortableServer::POA_var root_poa =
243 PortableServer::POA::_narrow (obj.in ());
245 PortableServer::POAManager_var mgr
246 = root_poa->the_POAManager ();
248 mgr->activate ();
250 // Initialize the AVStreams components.
251 TAO_AV_CORE::instance ()->init (orb.in (),
252 root_poa.in ());
254 int result =
255 parse_args (argc,
256 argv);
258 if (result == -1)
259 return -1;
261 // Make sure we have a valid <output_file>
262 output_file = ACE_OS::fopen (output_file_name,
263 "w");
264 if (output_file == 0)
265 ACE_ERROR_RETURN ((LM_DEBUG,
266 "Cannot open output file %s\n",
267 output_file_name),
268 -1);
270 else
271 ACE_DEBUG ((LM_DEBUG,
272 "File Opened Successfully\n"));
274 Receiver receiver;
275 result =
276 receiver.init (argc,
277 argv);
279 if (result != 0)
280 return result;
282 orb->run ();
284 // Hack for now....
285 ACE_OS::sleep (1);
287 orb->destroy ();
289 catch (const CORBA::Exception& ex)
291 ex._tao_print_exception ("receiver::init");
292 return -1;
295 ACE_OS::fclose (output_file);
297 return 0;