Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / AVStreams / Pluggable_Flow_Protocol / receiver.cpp
blob77b08b6b15458cade18de5aaaae7afa0b674713a
1 #include "receiver.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/High_Res_Timer.h"
5 static FILE *output_file = 0;
6 // File handle of the file into which received data is written.
8 static const ACE_TCHAR *output_file_name = ACE_TEXT ("output");
9 // File name of the file into which received data is written.
11 int endstream = 0;
13 int
14 Receiver_StreamEndPoint::get_callback (const char *,
15 TAO_AV_Callback *&callback)
17 // Return the receiver application callback to the AVStreams for
18 // future upcalls.
19 callback = &this->callback_;
20 return 0;
23 Receiver_Callback::Receiver_Callback ()
24 : frame_count_ (1)
28 int
29 Receiver_Callback::receive_frame (ACE_Message_Block *frame,
30 TAO_AV_frame_info *,
31 const ACE_Addr &)
34 // Upcall from the AVStreams when there is data to be received from
35 // the sender.
37 ACE_DEBUG ((LM_DEBUG,
38 "Receiver_Callback::receive_frame for frame %d\n",
39 this->frame_count_++));
41 int frame_size = BUFSIZ;
43 // Write the received data to the file.
44 size_t result =
45 ACE_OS::fwrite (frame->rd_ptr (),
46 frame_size,
48 output_file);
50 if (result == frame->length ())
51 ACE_ERROR_RETURN ((LM_ERROR,
52 "Receiver_Callback::fwrite failed\n"),
53 -1);
54 frame->rd_ptr (frame_size);
56 ACE_hrtime_t stamp;
57 ACE_OS::memcpy (&stamp, frame->rd_ptr (), sizeof (stamp));
59 ACE_UINT64 usec = stamp;
60 ACE_UINT32 val_1 = ACE_CU64_TO_CU32 (usec);
62 ACE_DEBUG ((LM_DEBUG,
63 "Time Stamp %u\n",
64 val_1));
66 frame->reset ();
67 return 0;
70 int
71 Receiver_Callback::handle_destroy ()
73 // Called when the distributer requests the stream to be shutdown.
74 ACE_DEBUG ((LM_DEBUG,
75 "Receiver_Callback::end_stream\n"));
77 endstream = 1;
78 return 0;
81 Receiver::Receiver ()
82 : mmdevice_ (0)
86 Receiver::~Receiver ()
90 int
91 Receiver::init (int,
92 ACE_TCHAR *[])
94 // Initialize the endpoint strategy with the orb and poa.
95 int result =
96 this->reactive_strategy_.init (TAO_AV_CORE::instance ()->orb (),
97 TAO_AV_CORE::instance ()->poa ());
98 if (result != 0)
99 return result;
101 // Register the receiver mmdevice object with the ORB
102 ACE_NEW_RETURN (this->mmdevice_,
103 TAO_MMDevice (&this->reactive_strategy_),
104 -1);
106 // Servant Reference Counting to manage lifetime
107 PortableServer::ServantBase_var safe_mmdevice =
108 this->mmdevice_;
110 CORBA::Object_var mmdevice =
111 this->mmdevice_->_this ();
113 // Register the mmdevice with the naming service.
114 CosNaming::Name name (1);
115 name.length (1);
116 name [0].id =
117 CORBA::string_dup ("Receiver");
119 // Initialize the naming services
120 if (this->naming_client_.init (TAO_AV_CORE::instance ()->orb ()) != 0)
121 ACE_ERROR_RETURN ((LM_ERROR,
122 "Unable to initialize "
123 "the TAO_Naming_Client\n"),
124 -1);
126 // Register the receiver object with the naming server.
127 this->naming_client_->rebind (name,
128 mmdevice.in ());
130 return 0;
134 parse_args (int argc,
135 ACE_TCHAR *argv[])
137 // Parse the command line arguments
138 ACE_Get_Opt opts (argc,
139 argv,
140 "f:");
142 int c;
143 while ((c = opts ()) != -1)
145 switch (c)
147 case 'f':
148 output_file_name = opts.opt_arg ();
149 break;
150 default:
151 ACE_ERROR_RETURN ((LM_ERROR,
152 "Usage: receiver -f filename"),
153 -1);
157 return 0;
161 ACE_TMAIN (int argc,
162 ACE_TCHAR *argv[])
166 ACE_High_Res_Timer::global_scale_factor ();
168 // Initialize the ORB first.
169 CORBA::ORB_var orb =
170 CORBA::ORB_init (argc, argv);
172 CORBA::Object_var obj
173 = orb->resolve_initial_references ("RootPOA");
175 // Get the POA_var object from Object_var.
176 PortableServer::POA_var root_poa =
177 PortableServer::POA::_narrow (obj.in ());
179 PortableServer::POAManager_var mgr
180 = root_poa->the_POAManager ();
182 mgr->activate ();
184 // Initialize the AVStreams components.
185 TAO_AV_CORE::instance ()->init (orb.in (),
186 root_poa.in ());
188 int result =
189 parse_args (argc,
190 argv);
192 if (result == -1)
193 return -1;
195 // Make sure we have a valid <output_file>
196 output_file = ACE_OS::fopen (output_file_name,
197 "w");
198 if (output_file == 0)
199 ACE_ERROR_RETURN ((LM_DEBUG,
200 "Cannot open output file %s\n",
201 output_file_name),
202 -1);
204 else
205 ACE_DEBUG ((LM_DEBUG,
206 "File Opened Successfully\n"));
208 Receiver receiver;
209 result =
210 receiver.init (argc,
211 argv);
213 if (result != 0)
214 return result;
216 while (!endstream)
218 orb->perform_work ();
221 // Hack for now....
222 ACE_OS::sleep (1);
224 orb->destroy ();
226 catch (const CORBA::Exception& ex)
228 ex._tao_print_exception ("receiver::init");
229 return -1;
232 ACE_OS::fclose (output_file);
234 return 0;