Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / AVStreams / Multicast_Full_Profile / server.cpp
blob568822bd25da09a9deb2b66a0526dff93047487b
1 #include "server.h"
3 FTP_Server_FlowEndPoint::FTP_Server_FlowEndPoint (void)
4 :TAO_FlowConsumer ("Data",FTP_SERVER::instance ()->protocols (),FTP_SERVER::instance ()->format ())
6 AVStreams::protocolSpec protocols (2);
7 protocols.length (2);
8 protocols [0] = CORBA::string_dup ("TCP");
9 protocols [1] = CORBA::string_dup ("UDP");
10 try
12 this->set_protocol_restriction (protocols);
14 catch (const CORBA::Exception& ex)
16 ex._tao_print_exception (
17 "FTP_Server_FlowEndPoint::FTP_Server_FlowEndPoint");
21 int
22 FTP_Server_FlowEndPoint::get_callback (const char *,
23 TAO_AV_Callback *&callback)
25 ACE_DEBUG ((LM_DEBUG,"FTP_Server_StreamEndPoint::get_sfp_callback\n"));
26 ACE_NEW_RETURN (callback,
27 FTP_Server_Callback,
28 -1);
29 return 0;
32 int
33 FTP_Server_Callback::handle_stop (void)
35 ACE_DEBUG ((LM_DEBUG,"FTP_Server_Callback::stop\n"));
36 ACE_OS::fclose (FTP_SERVER::instance ()->file ());
37 TAO_AV_CORE::instance ()->orb ()->shutdown ();
38 return 0;
41 int
42 FTP_Server_Callback::receive_frame (ACE_Message_Block *frame,
43 TAO_AV_frame_info *,
44 const ACE_Addr &)
46 ACE_DEBUG ((LM_DEBUG,"FTP_Server_Callback::receive_frame\n"));
47 while (frame != 0)
49 int result = ACE_OS::fwrite (frame->rd_ptr (),
50 frame->length (),
52 FTP_SERVER::instance ()->file ());
53 if (result == 0)
54 ACE_ERROR_RETURN ((LM_ERROR,"FTP_Server_Flow_Handler::fwrite failed\n"),-1);
55 frame = frame->cont ();
57 return 0;
60 int
61 FTP_Server_Callback::handle_end_stream (void)
63 ACE_DEBUG ((LM_DEBUG,"FTP_SFP_Callback::end_stream\n"));
64 CORBA::ORB_var orb = TAO_AV_CORE::instance ()->orb ();
65 orb->shutdown ();
66 return 0;
69 // FTP_Server_FDev::FTP_Server_FDev (void)
70 // :TAO_FDev ("Data")
71 // {
72 // }
74 // AVStreams::FlowConsumer_ptr
75 // FTP_Server_FDev::make_consumer (AVStreams::FlowConnection_ptr the_requester,
76 // AVStreams::QoS & the_qos,
77 // CORBA::Boolean_out met_qos,
78 // char *& named_fdev,
79 //)
80 // {
81 // ACE_DEBUG ((LM_DEBUG,"FTP_Server_FDev::make_consumer"));
82 // FTP_Server_FlowEndPoint *endpoint;
83 // ACE_NEW_RETURN (endpoint,
84 // FTP_Server_FlowEndPoint,
85 // 0);
86 // return endpoint->_this ();
87 // }
89 Server::Server (void)
91 reactive_strategy_.init (TAO_AV_CORE::instance ()->orb (),
92 TAO_AV_CORE::instance ()->poa ());
95 AVStreams::protocolSpec
96 Server::protocols (void)
98 AVStreams::protocolSpec protocols (2);
99 protocols.length (2);
100 protocols [0] = CORBA::string_dup ("TCP");
101 protocols [1] = CORBA::string_dup ("UDP");
102 return protocols;
105 const char*
106 Server::format (void)
108 return "UNS:ftp";
112 Server::init (int argc, ACE_TCHAR *argv[])
116 PortableServer::POAManager_var mgr
117 = TAO_AV_CORE::instance ()->poa ()->the_POAManager ();
119 mgr->activate ();
121 int result = this->parse_args (argc, argv);
122 if (result == -1)
123 ACE_ERROR_RETURN ((LM_ERROR,"parse args failed\n"),-1);
124 // Initialize the naming services
126 if (my_naming_client_.init (TAO_AV_CORE::instance ()->orb ()) != 0)
127 ACE_ERROR_RETURN ((LM_ERROR,
128 " (%P|%t) Unable to initialize "
129 "the TAO_Naming_Client.\n"),
130 -1);
132 // Register the video mmdevice object with the ORB
133 ACE_NEW_RETURN (this->mmdevice_,
134 TAO_MMDevice (&this->reactive_strategy_),
135 -1);
137 ACE_NEW_RETURN (this->fdev_,
138 FTP_Server_FDev,
139 -1);
140 this->fdev_->flowname ("Data");
141 AVStreams::MMDevice_var mmdevice = this->mmdevice_->_this ();
142 AVStreams::FDev_var fdev = this->fdev_->_this ();
143 mmdevice->add_fdev (fdev.in ());
145 // Register the mmdevice with the naming service.
146 CosNaming::Name server_mmdevice_name (1);
147 server_mmdevice_name.length (1);
148 server_mmdevice_name [0].id = CORBA::string_dup ("Server_MMDevice1");
151 // Register the video control object with the naming server.
152 this->my_naming_client_->bind (server_mmdevice_name,
153 mmdevice.in ());
155 catch (const CosNaming::NamingContext::AlreadyBound&)
157 server_mmdevice_name [0].id = CORBA::string_dup ("Server_MMDevice2");
158 this->my_naming_client_->bind (server_mmdevice_name,
159 mmdevice.in ());
162 catch (const CORBA::Exception& ex)
164 ex._tao_print_exception ("server::init");
165 return -1;
167 return 0;
171 Server::run (void)
175 TAO_AV_CORE::instance ()->orb ()->run ();
177 catch (const CORBA::Exception& ex)
179 ex._tao_print_exception ("server::init");
180 return -1;
182 return 0;
186 Server::parse_args (int argc, ACE_TCHAR *argv[])
188 ACE_Get_Opt opts (argc, argv, ACE_TEXT("f:p:"));
190 int c;
191 while ((c = opts ()) != -1)
193 switch (c)
195 case 'f':
196 this->fp_ = ACE_OS::fopen (opts.opt_arg (),"w");
197 if (this->fp_ != 0)
199 ACE_DEBUG ((LM_DEBUG,"file opened successfully\n"));
201 break;
202 case 'p':
203 this->protocol_ = ACE_OS::strdup (ACE_TEXT_ALWAYS_CHAR (opts.opt_arg ()));
204 break;
205 default:
206 ACE_ERROR_RETURN ((LM_ERROR,"Usage: server -f filename"),-1);
209 return 0;
212 FILE*
213 Server::file (void)
215 return this->fp_;
219 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
221 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
225 CORBA::Object_var obj
226 = orb->resolve_initial_references ("RootPOA");
228 PortableServer::POA_var poa
229 = PortableServer::POA::_narrow (obj.in ());
231 TAO_AV_CORE::instance ()->init (orb.in (),
232 poa.in ());
234 catch (const CORBA::Exception& ex)
236 ex._tao_print_exception ("server::init");
237 return -1;
240 int result = 0;
241 result = FTP_SERVER::instance ()->init (argc, argv);
242 if (result < 0)
243 ACE_ERROR_RETURN ((LM_ERROR,"FTP_SERVER::init failed\n"),1);
244 result = FTP_SERVER::instance ()->run ();
245 if (result < 0)
246 ACE_ERROR_RETURN ((LM_ERROR,"FTP_SERVER::run failed\n"),1);
248 FTP_SERVER::close (); // Explicitly finalize the Unmanaged_Singleton.
250 return result;
253 #if defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION)
254 template ACE_Unmanaged_Singleton<Server, ACE_Null_Mutex> *ACE_Unmanaged_Singleton<Server, ACE_Null_Mutex>::singleton_;
255 #endif /* ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION */