Endpoint_Strategy_T.cpp

Go to the documentation of this file.
00001 // $Id: Endpoint_Strategy_T.cpp 78820 2007-07-07 20:06:46Z sowayaa $
00002 
00003 #ifndef TAO_AV_ENDPOINT_STRATEGY_T_CPP
00004 #define TAO_AV_ENDPOINT_STRATEGY_T_CPP
00005 
00006 #include "orbsvcs/AV/Endpoint_Strategy_T.h"
00007 
00008 #include "tao/debug.h"
00009 
00010 #include "ace/Process_Semaphore.h"
00011 #include "ace/OS_NS_unistd.h"
00012 
00013 
00014 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00015 
00016 // ----------------------------------------------------------------------
00017 // TAO_AV_Endpoint_Reactive_Strategy
00018 // ----------------------------------------------------------------------
00019 
00020 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00021 TAO_AV_Endpoint_Reactive_Strategy <T_StreamEndpoint, T_VDev, T_MediaCtrl>::TAO_AV_Endpoint_Reactive_Strategy (void)
00022    :  stream_endpoint_a_servant_(0), stream_endpoint_b_servant_(0), vdev_servant_(0),
00023       media_ctrl_servant_(0)
00024 {
00025 }
00026 
00027 template <class T_StreamEndpoint, class T_VDev, class T_MediaCtrl>
00028 TAO_AV_Endpoint_Reactive_Strategy <T_StreamEndpoint, T_VDev, T_MediaCtrl>::~TAO_AV_Endpoint_Reactive_Strategy (void)
00029 {
00030   // Do not allow exceptions to escape from the destructor
00031   try
00032     {
00033       if(this->stream_endpoint_a_servant_ )
00034         {
00035           stream_endpoint_a_servant_->_remove_ref ();
00036         }
00037 
00038       if(this->stream_endpoint_b_servant_)
00039         {
00040           stream_endpoint_b_servant_->_remove_ref ();
00041         }
00042 
00043       if(this->vdev_servant_)
00044         {
00045           vdev_servant_->_remove_ref ();
00046         }
00047 
00048       if(this->media_ctrl_servant_)
00049         {
00050           media_ctrl_servant_->_remove_ref ();
00051         }
00052     }
00053   catch (const CORBA::Exception&)
00054     {
00055     }
00056 
00057 }
00058 
00059 // Create, activate the objects with the POA
00060 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00061 int
00062 TAO_AV_Endpoint_Reactive_Strategy <T_StreamEndpoint, T_VDev, T_MediaCtrl>::activate (void)
00063 {
00064   try
00065     {
00066       this->activate_stream_endpoint ();
00067       if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"(%P|%t)TAO_AV_Endpoint_Reactive_Strategy::activated stream_endpoint\n"));
00068 
00069       this->activate_vdev ();
00070       if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"(%P|%t)TAO_AV_Endpoint_Reactive_Strategy::activated vdev\n"));
00071 
00072       this->activate_mediactrl ();
00073       if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"(%P|%t)TAO_AV_Endpoint_Reactive_Strategy::activated mediactrl\n"));
00074     }
00075   catch (const CORBA::Exception& ex)
00076     {
00077       ex._tao_print_exception (
00078         "TAO_Endpoint_Reactive_Strategy::activate");
00079       return -1;
00080     }
00081   return 0;
00082 }
00083 
00084 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00085 char *
00086 TAO_AV_Endpoint_Reactive_Strategy <T_StreamEndpoint, T_VDev, T_MediaCtrl>::activate_with_poa (PortableServer::Servant servant)
00087 {
00088 
00089   PortableServer::ObjectId_var id =
00090     this->poa_->activate_object (servant);
00091 
00092   CORBA::Object_var obj =
00093     this->poa_->id_to_reference (id.in ());
00094 
00095   CORBA::String_var str =
00096     this->orb_->object_to_string (obj.in ());
00097 
00098   return str._retn ();
00099 }
00100 
00101 
00102 // Activate VDev into the POA
00103 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00104 int
00105 TAO_AV_Endpoint_Reactive_Strategy <T_StreamEndpoint, T_VDev, T_MediaCtrl>::activate_vdev (void)
00106 {
00107   try
00108     {
00109       // Bridge pattern. Allow subclasses to override this behavior
00110       T_VDev *vdev = 0;
00111       if (this->make_vdev (vdev) == -1)
00112         return -1;
00113 
00114       // Activate the object under the root poa.
00115 //      CORBA::String_var vdev_ior = this->activate_with_poa (vdev,
00116 //);
00117 //      if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"(%P|%t)TAO_AV_Endpoint_Reactive_Strategy::activate_vdev, vdev ior is:%s\n",
00118 //                  vdev_ior. in ()));
00119 
00120       // Save the object reference, so that create_A can return it
00121       this->vdev_ = vdev->_this ();
00122     }
00123   catch (const CORBA::Exception& ex)
00124     {
00125       ex._tao_print_exception (
00126         "TAO_AV_Endpoint_Reactive_Strategy::activate_vdev");
00127       return -1;
00128     }
00129   return 0;
00130 }
00131 
00132 
00133 // Activate the media_controller
00134 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00135 int
00136 TAO_AV_Endpoint_Reactive_Strategy <T_StreamEndpoint, T_VDev, T_MediaCtrl>::activate_mediactrl (void)
00137 {
00138   try
00139     {
00140       // Bridge pattern. Subclasses can override this
00141       if (this->make_mediactrl ( media_ctrl_servant_ ) == -1)
00142         return -1;
00143 
00144       // Associate the media controller object reference with the vdev, as per the OMG spec
00145       CORBA::Any anyval;
00146       media_ctrl_obj_
00147         = media_ctrl_servant_->_this ();
00148 
00149       anyval <<= media_ctrl_obj_.in();
00150 
00151 
00152      this->vdev_->define_property ("Related_MediaCtrl",
00153                                    anyval);
00154 
00155     }
00156   catch (const CORBA::Exception& ex)
00157     {
00158       ex._tao_print_exception (
00159         "TAO_AV_Endpoint_Reactive_Strategy::activate_mediactrl");
00160       return -1;
00161     }
00162   return 0;
00163 }
00164 
00165 // Bridge method
00166 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00167 int
00168 TAO_AV_Endpoint_Reactive_Strategy<T_StreamEndpoint, T_VDev, T_MediaCtrl>::make_stream_endpoint (T_StreamEndpoint *&stream_endpoint)
00169 {
00170   ACE_NEW_RETURN (stream_endpoint,
00171                   T_StreamEndpoint,
00172                   -1);
00173   return 0;
00174 }
00175 
00176 // Bridge method
00177 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00178 int
00179 TAO_AV_Endpoint_Reactive_Strategy<T_StreamEndpoint, T_VDev, T_MediaCtrl>::make_vdev (T_VDev *&vdev)
00180 {
00181   ACE_NEW_RETURN (vdev,
00182                   T_VDev,
00183                   -1);
00184   return 0;
00185 }
00186 
00187 // Bridge method
00188 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00189 int
00190 TAO_AV_Endpoint_Reactive_Strategy<T_StreamEndpoint, T_VDev, T_MediaCtrl>::make_mediactrl (T_MediaCtrl *&media_ctrl)
00191 {
00192   ACE_NEW_RETURN (media_ctrl,
00193                   T_MediaCtrl,
00194                   -1);
00195   return 0;
00196 }
00197 
00198 
00199 // ----------------------------------------------------------------------
00200 
00201 // ----------------------------------------------------------------------
00202 // TAO_AV_Endpoint_Reactive_Strategy_A
00203 // ----------------------------------------------------------------------
00204 
00205 //Constructor
00206 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00207 TAO_AV_Endpoint_Reactive_Strategy_A <T_StreamEndpoint, T_VDev, T_MediaCtrl>::TAO_AV_Endpoint_Reactive_Strategy_A (void)
00208 {
00209 }
00210 
00211 
00212 // Destructor
00213 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00214 TAO_AV_Endpoint_Reactive_Strategy_A <T_StreamEndpoint, T_VDev, T_MediaCtrl>::~TAO_AV_Endpoint_Reactive_Strategy_A (void)
00215 {
00216 }
00217 
00218 
00219 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00220 int
00221 TAO_AV_Endpoint_Reactive_Strategy_A <T_StreamEndpoint, T_VDev, T_MediaCtrl>::init (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
00222 {
00223   this->orb_ = CORBA::ORB::_duplicate (orb);
00224   this->poa_ = PortableServer::POA::_duplicate (poa);
00225   return 0;
00226 }
00227 
00228 // Creates an "A" type streamendpoint, and a vdev and returns the
00229 // object references
00230 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00231 int
00232 TAO_AV_Endpoint_Reactive_Strategy_A<T_StreamEndpoint, T_VDev, T_MediaCtrl>::create_A (AVStreams::StreamEndPoint_A_ptr &stream_endpoint,
00233                                                                                       AVStreams::VDev_ptr &vdev)
00234 {
00235   if (this->activate () == -1)
00236     ACE_ERROR_RETURN ((LM_ERROR,
00237                        "(%P|%t) TAO_AV_Endpoint_Reactive_Strategy_A: Error in activate ()\n"),
00238                       -1);
00239 
00240   stream_endpoint = AVStreams::StreamEndPoint_A::_duplicate( this->stream_endpoint_a_.in() );
00241   vdev = AVStreams::VDev::_duplicate( this->vdev_.in() );
00242   return 0;
00243 
00244 }
00245 
00246 // Put the stream_endpoint into the POA
00247 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00248 int
00249 TAO_AV_Endpoint_Reactive_Strategy_A <T_StreamEndpoint, T_VDev, T_MediaCtrl>::activate_stream_endpoint (void)
00250 {
00251   try
00252     {
00253 
00254       // Use the bridge method
00255       if (this->make_stream_endpoint (this->stream_endpoint_a_servant_) == -1)
00256         return -1;
00257 
00258       // Save the object references, so that create_a can return them
00259       this->stream_endpoint_a_ = this->stream_endpoint_a_servant_->_this ();
00260     }
00261   catch (const CORBA::Exception& ex)
00262     {
00263       ex._tao_print_exception (
00264         "TAO_AV_Endpoint_Reactive_Strategy_A::activate_stream_endpoint");
00265       return -1;
00266     }
00267   return 0;
00268 }
00269 
00270 // ----------------------------------------------------------------------
00271 // TAO_AV_Endpoint_Reactive_Strategy_B
00272 // ----------------------------------------------------------------------
00273 
00274 
00275 // Constructor
00276 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00277 TAO_AV_Endpoint_Reactive_Strategy_B <T_StreamEndpoint, T_VDev, T_MediaCtrl>::TAO_AV_Endpoint_Reactive_Strategy_B (void)
00278 {
00279 }
00280 
00281 // Destructor
00282 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00283 TAO_AV_Endpoint_Reactive_Strategy_B <T_StreamEndpoint, T_VDev, T_MediaCtrl>::~TAO_AV_Endpoint_Reactive_Strategy_B (void)
00284 {
00285 }
00286 
00287 
00288 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00289 int
00290 TAO_AV_Endpoint_Reactive_Strategy_B <T_StreamEndpoint, T_VDev, T_MediaCtrl>::init (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
00291 {
00292   this->orb_ = CORBA::ORB::_duplicate (orb);
00293   this->poa_ = PortableServer::POA::_duplicate (poa);
00294   return 0;
00295 }
00296 
00297 // Activate stream_endpoint
00298 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00299 int
00300 TAO_AV_Endpoint_Reactive_Strategy_B <T_StreamEndpoint, T_VDev, T_MediaCtrl>::activate_stream_endpoint (void)
00301 {
00302   try
00303     {
00304       if (this->make_stream_endpoint ( this->stream_endpoint_b_servant_ ) == -1)
00305         return -1;
00306 
00307       this->stream_endpoint_b_ = this->stream_endpoint_b_servant_->_this ();
00308     }
00309   catch (const CORBA::Exception& ex)
00310     {
00311       ex._tao_print_exception (
00312         "TAO_AV_Endpoint_Reactive_Strategy_B::activate_stream_endpoint");
00313       return -1;
00314     }
00315   return 0;
00316 }
00317 
00318 // Returns a "B" type stream_endpoint and a vdev
00319 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00320 int
00321 TAO_AV_Endpoint_Reactive_Strategy_B<T_StreamEndpoint, T_VDev, T_MediaCtrl>::create_B (AVStreams::StreamEndPoint_B_ptr &stream_endpoint,
00322                                                                                       AVStreams::VDev_ptr &vdev)
00323 {
00324   if (this->activate () == -1)
00325     ACE_ERROR_RETURN ((LM_ERROR,
00326                        "(%P|%t) TAO_AV_Endpoint_Reactive_Strategy_B: Error in activate ()\n"),
00327                       -1);
00328 
00329   stream_endpoint = AVStreams::StreamEndPoint_B::_duplicate( this->stream_endpoint_b_.in() );
00330   vdev = AVStreams::VDev::_duplicate( this->vdev_.in() );
00331 
00332   return 0;
00333 }
00334 
00335 // ----------------------------------------------------------------------
00336 // TAO_AV_Child_Process
00337 // ----------------------------------------------------------------------
00338 
00339 // Constructor
00340 template <class T_StreamEndpoint_B, class T_VDev , class T_MediaCtrl>
00341 TAO_AV_Child_Process <T_StreamEndpoint_B, T_VDev, T_MediaCtrl>::TAO_AV_Child_Process ()
00342   : stream_endpoint_name_ (0),
00343     pid_ (-1)
00344 {
00345   this->pid_ = ACE_OS::getpid ();
00346   if (this->pid_ == 0)
00347     ACE_ERROR ((LM_ERROR,"getpid () failed\n"));
00348   ACE_OS::hostname (this->host_,
00349                     sizeof this->host_);
00350 }
00351 
00352 // Initializes the ORB, activates the objects, and release the semaphore
00353 template <class T_StreamEndpoint_B, class T_VDev , class T_MediaCtrl>
00354 int
00355 TAO_AV_Child_Process  <T_StreamEndpoint_B, T_VDev, T_MediaCtrl>::init (int argc,
00356                                                                        char **argv,
00357                                                                        CORBA::ORB_ptr orb,
00358                                                                        PortableServer::POA_ptr poa)
00359 {
00360   try
00361     {
00362       this->orb_ = orb;
00363 
00364       this->poa_ = poa;
00365 
00366       // create the objects and activate them in the poa
00367       this->activate_objects (argc,
00368                               argv);
00369 
00370       // Get ourselves a naming_service object reference
00371       this->bind_to_naming_service ();
00372 
00373       // Register the vdev with the naming service
00374       this->register_vdev ();
00375 
00376       // register the stream_endpoing with the naming_service
00377       this->register_stream_endpoint ();
00378     }
00379   catch (const CORBA::Exception& ex)
00380     {
00381       ex._tao_print_exception ("TAO_Child_Process");
00382       return -1;
00383     }
00384 
00385   // release the semaphore the parent is waiting on
00386   if (this->release_semaphore () == -1)
00387     ACE_ERROR_RETURN ((LM_ERROR,
00388                        "(%P|%t) Error releasing semaphores\n"),
00389                       -1);
00390 
00391   return 0;
00392 }
00393 
00394 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00395 char *
00396 TAO_AV_Child_Process <T_StreamEndpoint, T_VDev, T_MediaCtrl>::activate_with_poa (PortableServer::Servant servant)
00397 {
00398 
00399   PortableServer::ObjectId_var id =
00400     this->poa_->activate_object (servant);
00401 
00402   CORBA::Object_var obj =
00403     this->poa_->id_to_reference (id.in ());
00404 
00405   CORBA::String_var str =
00406     this->orb_->object_to_string (obj.in ());
00407 
00408   return str._retn ();
00409 }
00410 
00411 // initializes the orb, and activates the objects
00412 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00413 int
00414 TAO_AV_Child_Process  <T_StreamEndpoint, T_VDev, T_MediaCtrl>::activate_objects (int /*argc*/,
00415                                                                                  char ** /*argv*/)
00416 {
00417   try
00418     {
00419       // bridge method to make a new stream endpoint
00420       if (this->make_stream_endpoint (this->stream_endpoint_) == -1)
00421         return -1;
00422 
00423       // bridge method to make a new vdev
00424       if (this->make_vdev (this->vdev_) == -1)
00425         return -1;
00426 
00427       // bridge method to make a new media controller
00428       if (this->make_mediactrl (this->media_ctrl_) == -1)
00429         return -1;
00430 
00431       // activate the stream_endpoint
00432       CORBA::String_var stream_endpoint_ior = this->activate_with_poa (this->stream_endpoint_);
00433       if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,
00434                                            "(%P|%t)TAO_AV_Child_Process::activate_objects,stream_endpoint_ior :%s\n",
00435                                            stream_endpoint_ior.in ()));
00436 
00437       // activate the vdev
00438       CORBA::String_var vdev_ior = this->activate_with_poa (this->vdev_);
00439       if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,
00440                                            "(%P|%t)TAO_AV_Child_Process::activate_objects, vdev ior is :%s\n",
00441                                            vdev_ior.in ()));
00442 
00443       // activate the media controller
00444       CORBA::String_var media_ctrl_ior = this->activate_with_poa (this->media_ctrl_);
00445 
00446       if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"(%P|%t)TAO_AV_Child_Process::activate_objects,media_ctrl_ior is: %s\n",media_ctrl_ior.in ()));
00447     }
00448   catch (const CORBA::Exception& ex)
00449     {
00450       ex._tao_print_exception ("TAO_AV_Child_Process::init ");
00451       return -1;
00452     }
00453   return 0;
00454 }
00455 
00456 // Bind to the namingservice
00457 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00458 int
00459 TAO_AV_Child_Process  <T_StreamEndpoint, T_VDev, T_MediaCtrl>::bind_to_naming_service (void)
00460 {
00461   try
00462     {
00463       CORBA::Object_var naming_obj =
00464         this->orb_->resolve_initial_references ("NameService");
00465       if (CORBA::is_nil (naming_obj.in ()))
00466         ACE_ERROR_RETURN ((LM_ERROR,
00467                            " (%P|%t) Unable to resolve the Name Service.\n"),
00468                           -1);
00469       //  if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG, "(%P|%t) %s:%d\n", __FILE__, __LINE__));
00470       this->naming_context_ =
00471         CosNaming::NamingContext::_narrow (naming_obj.in ());
00472     }
00473   catch (const CORBA::Exception& ex)
00474     {
00475       ex._tao_print_exception (
00476         "TAO_AV_Child_Process::bind_to_naming_service");
00477       return -1;
00478     }
00479   return 0;
00480 }
00481 
00482 // register the vdev with the naming service
00483 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00484 int
00485 TAO_AV_Child_Process  <T_StreamEndpoint, T_VDev, T_MediaCtrl>::register_vdev (void)
00486 {
00487   try
00488     {
00489       char vdev_name [BUFSIZ];
00490       ACE_OS::sprintf (vdev_name,
00491                        "%s:%s:%ld",
00492                        "VDev",
00493                        this->host_,
00494                        static_cast<long> (this->pid_));
00495 
00496       if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"(%P|%t)%s\n",vdev_name));
00497       // create the name
00498       this->vdev_name_.length (1);
00499       this->vdev_name_ [0].id = CORBA::string_dup (vdev_name);
00500 
00501       // make the media controller a property of the vdev
00502       CORBA::Any media_ctrl_property;
00503       media_ctrl_obj_ =
00504         this->media_ctrl_->_this ();
00505 
00506       this->vdev_->define_property ("Related_MediaCtrl",
00507                                     media_ctrl_obj_.in());
00508 
00509       vdev_obj_ = this->vdev_->_this ();
00510 
00511       try
00512         {
00513           // Register the vdev with the naming server.
00514           this->naming_context_->bind (this->vdev_name_,
00515                                        vdev_obj_.in());
00516         }
00517       catch (const CosNaming::NamingContext::AlreadyBound& )
00518         {
00519           // If the object was already there, replace the older reference
00520           // with this one
00521           this->naming_context_->rebind (this->vdev_name_,
00522                                          vdev_obj_.in());
00523         }
00524       catch (const CORBA::Exception& ex)
00525         {
00526           ex._tao_print_exception (
00527             "TAO_AV_Child_Process::register_vdev");
00528           return -1;
00529         }
00530     }
00531   catch (const CORBA::Exception& ex)
00532     {
00533       ex._tao_print_exception (
00534         "TAO_AV_Child_Process::register_vdev");
00535       return -1;
00536     }
00537   return 0;
00538 }
00539 
00540 // run the orb event look
00541 template <class T_StreamEndpoint_B, class T_VDev , class T_MediaCtrl>
00542 int
00543 TAO_AV_Child_Process  <T_StreamEndpoint_B, T_VDev, T_MediaCtrl>::run (ACE_Time_Value *tv)
00544 {
00545   try
00546     {
00547       this->orb_->run (tv);
00548     }
00549   catch (const CORBA::Exception& ex)
00550     {
00551       ex._tao_print_exception ("orb.run ()");
00552       return -1;
00553     }
00554   return 0;
00555 }
00556 
00557 // release the semaphore the parent is waiting on
00558 template <class T_StreamEndpoint_B, class T_VDev , class T_MediaCtrl>
00559 int
00560 TAO_AV_Child_Process  <T_StreamEndpoint_B, T_VDev, T_MediaCtrl>::release_semaphore ()
00561 {
00562   char sem_str [BUFSIZ];
00563 
00564   long pid = this->pid_;
00565   ACE_OS::sprintf (sem_str,
00566                    "%s:%s:%ld",
00567                    "TAO_AV_Process_Semaphore",
00568                    this->host_,
00569                    pid);
00570 
00571   if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,
00572               "(%P|%t) semaphore is %s\n",
00573               sem_str));
00574 
00575   // Release the lock on which the server is waiting
00576   ACE_Process_Semaphore semaphore (0, // 0 means that the semaphore is
00577                                    // initially locked
00578                                    sem_str);
00579 
00580   if (semaphore.release () == -1)
00581     ACE_ERROR_RETURN ((LM_ERROR,
00582                        "(%P|%t) Error releasing semaphore %s: %p\n",
00583                        sem_str,
00584                        "semaphore.release ()"),
00585                       -1);
00586 
00587   return 0;
00588 }
00589 
00590 // register the stream_endpoint with the naming service
00591 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00592 int
00593 TAO_AV_Child_Process  <T_StreamEndpoint, T_VDev, T_MediaCtrl>::register_stream_endpoint (void)
00594 {
00595   CORBA::Object_ptr stream_endpoint_obj = CORBA::Object::_nil ();
00596   try
00597     {
00598       stream_endpoint_obj = this->stream_endpoint_->_this ();
00599 
00600       // Create a name for the video control object
00601       // subclasses can define their own name for the streamendpoint
00602       // Register the stream endpoint object with the naming server.
00603       this->naming_context_->bind (this->stream_endpoint_name_,
00604                                    stream_endpoint_obj);
00605     }
00606   catch (const CosNaming::NamingContext::AlreadyBound& )
00607     {
00608       // if the name was already there, replace the reference with the new one
00609       this->naming_context_->rebind (this->stream_endpoint_name_,
00610                                      stream_endpoint_obj);
00611     }
00612   catch (const CORBA::Exception& ex)
00613     {
00614       ex._tao_print_exception (
00615         "TAO_Endpoint_Reactive_Strategy::activate");
00616       return -1;
00617     }
00618   return 0;
00619 }
00620 
00621 // Bridge method to make a new stream_endpoint
00622 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00623 int
00624 TAO_AV_Child_Process<T_StreamEndpoint, T_VDev, T_MediaCtrl>::make_stream_endpoint (T_StreamEndpoint *&stream_endpoint)
00625 {
00626   ACE_NEW_RETURN (stream_endpoint,
00627                   T_StreamEndpoint,
00628                   -1);
00629   return 0;
00630 }
00631 
00632 // Bridge method to make a new vdev
00633 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00634 int
00635 TAO_AV_Child_Process<T_StreamEndpoint, T_VDev, T_MediaCtrl>::make_vdev (T_VDev *&vdev)
00636 {
00637   ACE_NEW_RETURN (vdev,
00638                   T_VDev,
00639                   -1);
00640   return 0;
00641 }
00642 
00643 // Bridge method to make a new media controller
00644 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00645 int
00646 TAO_AV_Child_Process<T_StreamEndpoint, T_VDev, T_MediaCtrl>::make_mediactrl (T_MediaCtrl *&media_ctrl)
00647 {
00648   if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"(%P|%t) TAO_AV_Child_Process::make_mediactrl ()\n"));
00649   ACE_NEW_RETURN (media_ctrl,
00650                   T_MediaCtrl,
00651                   -1);
00652   return 0;
00653 }
00654 
00655 
00656 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00657 int
00658 TAO_AV_Child_Process<T_StreamEndpoint, T_VDev, T_MediaCtrl>::unbind_names (void)
00659 {
00660   // Remove the names from the naming service
00661   try
00662     {
00663       if (CORBA::is_nil (this->naming_context_.in ()) == 0)
00664         return 0;
00665       this->naming_context_->unbind (this->stream_endpoint_name_);
00666 
00667       this->naming_context_->unbind (this->vdev_name_);
00668     }
00669   catch (const CORBA::Exception& ex)
00670     {
00671       ex._tao_print_exception (
00672         "TAO_Endpoint_Process_Strategy::activate");
00673       return -1;
00674     }
00675   return 0;
00676 }
00677 
00678 // %% its not clear whether we should be deleting the objects, since
00679 // if the application overrides the make_mediactrl methods etc.,
00680 // then, we may not own these objects.
00681 // For now, we dont delete the objects, since they exist for the
00682 // lifetime of the process anyway
00683 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00684 TAO_AV_Child_Process<T_StreamEndpoint, T_VDev, T_MediaCtrl>::~TAO_AV_Child_Process ()
00685 {
00686   this->unbind_names ();
00687 }
00688 
00689 // ----------------------------------------------------------------------
00690 // TAO_AV_Child_Process_A
00691 // ----------------------------------------------------------------------
00692 
00693 // Define the name of the stream_endpoint, as used to register with
00694 // the  naming service
00695 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00696 TAO_AV_Child_Process_A<T_StreamEndpoint, T_VDev, T_MediaCtrl>::TAO_AV_Child_Process_A ()
00697 {
00698   char stream_endpoint_name[BUFSIZ];
00699   ACE_OS::sprintf (stream_endpoint_name,
00700                    "%s:%s:%ld",
00701                    "Stream_Endpoint_A",
00702                    this->host_,
00703                    static_cast<long> (this->pid_));
00704 
00705   if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"(%P|%t)%s\n",stream_endpoint_name));
00706   this->stream_endpoint_name_.length (1);
00707   this->stream_endpoint_name_ [0].id = CORBA::string_dup (stream_endpoint_name);
00708 }
00709 
00710 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00711 TAO_AV_Child_Process_A  <T_StreamEndpoint, T_VDev, T_MediaCtrl>::~TAO_AV_Child_Process_A ()
00712 {
00713 }
00714 
00715 // ----------------------------------------------------------------------
00716 // TAO_AV_Child_Process_B
00717 // ----------------------------------------------------------------------
00718 
00719 // Define the name of the stream_endpoint, as used to register with
00720 // the  naming service
00721 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00722 TAO_AV_Child_Process_B<T_StreamEndpoint, T_VDev, T_MediaCtrl>::TAO_AV_Child_Process_B ()
00723 {
00724   char stream_endpoint_name[BUFSIZ];
00725   ACE_OS::sprintf (stream_endpoint_name,
00726                    "%s:%s:%ld",
00727                    "Stream_Endpoint_B",
00728                    this->host_,
00729                    static_cast<long> (this->pid_));
00730 
00731   if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"(%P|%t)%s\n",stream_endpoint_name));
00732   this->stream_endpoint_name_.length (1);
00733   this->stream_endpoint_name_ [0].id = CORBA::string_dup (stream_endpoint_name);
00734 }
00735 
00736 template <class T_StreamEndpoint, class T_VDev , class T_MediaCtrl>
00737 TAO_AV_Child_Process_B<T_StreamEndpoint, T_VDev, T_MediaCtrl>::~TAO_AV_Child_Process_B ()
00738 {
00739 }
00740 
00741 TAO_END_VERSIONED_NAMESPACE_DECL
00742 
00743 #endif /* TAO_AV_ENDPOINT_STRATEGY_T_CPP */

Generated on Tue Feb 2 17:47:49 2010 for TAO_AV by  doxygen 1.4.7