AV_Core.cpp

Go to the documentation of this file.
00001 // $Id: AV_Core.cpp 76589 2007-01-25 18:04:11Z elliott_c $
00002 
00003 #include "orbsvcs/AV/AV_Core.h"
00004 #include "orbsvcs/AV/FlowSpec_Entry.h"
00005 #include "orbsvcs/AV/Transport.h"
00006 #include "orbsvcs/AV/Protocol_Factory.h"
00007 #include "orbsvcs/AV/UDP.h"
00008 #include "orbsvcs/AV/TCP.h"
00009 #include "orbsvcs/AV/RTP.h"
00010 #include "orbsvcs/AV/RTCP.h"
00011 #include "orbsvcs/AV/sfp.h"
00012 #include "orbsvcs/AV/default_resource.h"
00013 
00014 #if defined (ACE_HAS_RAPI) || defined (ACE_HAS_WINSOCK2_GQOS)
00015 #include "orbsvcs/AV/QoS_UDP.h"
00016 #endif /* ACE_HAS_RAPI || ACE_HAS_WINSOCK2_GQOS */
00017 
00018 #if defined (ACE_HAS_SCTP)
00019 #include "orbsvcs/AV/SCTP_SEQ.h"
00020 #endif // ACE_HAS_SCTP
00021 
00022 #include "tao/debug.h"
00023 #include "tao/ORB_Core.h"
00024 
00025 #include "ace/Dynamic_Service.h"
00026 
00027 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00028 
00029 //------------------------------------------------------------
00030 // TAO_AV_Core
00031 //------------------------------------------------------------
00032 
00033 TAO_AV_Core::TAO_AV_Core (void)
00034   :connector_registry_ (0),
00035    acceptor_registry_ (0)
00036 {
00037   ACE_NEW (this->connector_registry_,
00038            TAO_AV_Connector_Registry
00039            );
00040   ACE_NEW (this->acceptor_registry_,
00041            TAO_AV_Acceptor_Registry
00042            );
00043 }
00044 
00045 TAO_AV_Core::~TAO_AV_Core (void)
00046 {
00047   delete this->connector_registry_;
00048   delete this->acceptor_registry_;
00049 
00050   TAO_AV_TransportFactorySetItor transport_iter =
00051       this->transport_factories_.begin();
00052 
00053   while (transport_iter != this->transport_factories_.end())
00054     {
00055       if ((*transport_iter)->factory()->ref_count != 1)
00056         {
00057           delete (*transport_iter)->factory();
00058         }
00059       delete (*transport_iter);
00060       transport_iter++;
00061     }
00062 
00063   TAO_AV_Flow_ProtocolFactorySetItor flow_iter =
00064       this->flow_protocol_factories_.begin();
00065 
00066   while (flow_iter != this->flow_protocol_factories_.end())
00067     {
00068       if ((*flow_iter)->factory()->ref_count != 1)
00069         {
00070           delete (*flow_iter)->factory();
00071         }
00072       delete (*flow_iter);
00073 
00074       flow_iter++;
00075     }
00076 }
00077 
00078 CORBA::ORB_ptr
00079 TAO_AV_Core::orb (void)
00080 {
00081   return this->orb_.in ();
00082 }
00083 
00084 void
00085 TAO_AV_Core::orb (CORBA::ORB_ptr orb)
00086 {
00087   this->orb_ = orb;
00088 }
00089 
00090 PortableServer::POA_ptr
00091 TAO_AV_Core::poa (void)
00092 {
00093   return this->poa_.in ();
00094 }
00095 
00096 void
00097 TAO_AV_Core::poa (PortableServer::POA_ptr poa)
00098 {
00099   this->poa_ = poa;
00100 }
00101 
00102 TAO_AV_Connector_Registry*
00103 TAO_AV_Core::connector_registry (void)
00104 {
00105   return this->connector_registry_;
00106 }
00107 
00108 TAO_AV_Acceptor_Registry*
00109 TAO_AV_Core::acceptor_registry (void)
00110 {
00111   return this->acceptor_registry_;
00112 }
00113 
00114 TAO_AV_TransportFactorySet *
00115 TAO_AV_Core::transport_factories (void)
00116 {
00117   return &this->transport_factories_;
00118 }
00119 
00120 TAO_AV_Flow_ProtocolFactorySet*
00121 TAO_AV_Core::flow_protocol_factories (void)
00122 {
00123   return &this->flow_protocol_factories_;
00124 }
00125 
00126 int
00127 TAO_AV_Core::stop_run (void)
00128 {
00129   this->stop_run_ = 1;
00130   return 0;
00131 }
00132 
00133 int
00134 TAO_AV_Core::run (void)
00135 {
00136   this->stop_run_ = 0;
00137   while (!this->stop_run_ && this->orb_->work_pending ())
00138     this->orb_->perform_work ();
00139   return 0;
00140 }
00141 
00142 void
00143 TAO_AV_Core::reactor (ACE_Reactor *r)
00144 {
00145   this->reactor_ = r;
00146 }
00147 
00148 ACE_Reactor *
00149 TAO_AV_Core::reactor (void)
00150 {
00151   return this->reactor_;
00152 }
00153 
00154 
00155 int
00156 TAO_AV_Core::init (CORBA::ORB_ptr orb,
00157                    PortableServer::POA_ptr poa)
00158 {
00159   if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"TAO_AV_Core::init "));
00160   this->orb_ = CORBA::ORB::_duplicate (orb);
00161   this->poa_ = PortableServer::POA::_duplicate (poa);
00162   this->reactor (this->orb_->orb_core ()->reactor ());
00163   this->init_transport_factories ();
00164   this->init_flow_protocol_factories ();
00165   return 0;
00166 }
00167 
00168 int
00169 TAO_AV_Core::init_forward_flows (TAO_Base_StreamEndPoint *endpoint,
00170                                  TAO_AV_FlowSpecSet &flow_spec_set,
00171                                  TAO_AV_Core::EndPoint direction,
00172                                  AVStreams::flowSpec &flow_spec)
00173 {
00174   if (TAO_debug_level > 0)
00175     ACE_DEBUG ((LM_DEBUG,
00176                 "TAO_AV_Core::init_forward_flows\n"));
00177 
00178   TAO_AV_FlowSpecSet address_flow_set;
00179   TAO_AV_FlowSpecSet flow_set;
00180   TAO_AV_FlowSpecSetItor end = flow_spec_set.end ();
00181   for (TAO_AV_FlowSpecSetItor start = flow_spec_set.begin ();
00182        start != end; ++start)
00183     {
00184       TAO_FlowSpec_Entry *entry = (*start);
00185       switch (direction)
00186         {
00187         case TAO_AV_Core::TAO_AV_ENDPOINT_B:
00188           {
00189             switch (entry->direction ())
00190               {
00191               case TAO_FlowSpec_Entry::TAO_AV_DIR_IN:
00192                 {
00193                   entry->role (TAO_FlowSpec_Entry::TAO_AV_CONSUMER);
00194                   break;
00195                 }
00196               case TAO_FlowSpec_Entry::TAO_AV_DIR_OUT:
00197                 {
00198                   entry->role (TAO_FlowSpec_Entry::TAO_AV_PRODUCER);
00199                   break;
00200                 }
00201               }
00202             break;
00203           }
00204         case TAO_AV_Core::TAO_AV_ENDPOINT_A:
00205           {
00206             switch (entry->direction ())
00207               {
00208               case TAO_FlowSpec_Entry::TAO_AV_DIR_IN:
00209                 entry->role (TAO_FlowSpec_Entry::TAO_AV_PRODUCER);
00210                 break;
00211               case TAO_FlowSpec_Entry::TAO_AV_DIR_OUT:
00212                 entry->role (TAO_FlowSpec_Entry::TAO_AV_CONSUMER);
00213                 break;
00214               }
00215             break;
00216           }
00217         default:
00218           break;
00219         }
00220       ACE_Addr *address = entry->address ();
00221       if (address != 0)
00222         {
00223           if (TAO_debug_level > 0)
00224             ACE_DEBUG ((LM_DEBUG,
00225                         "address given for flow %s\n",
00226                         entry->flowname ()));
00227 
00228           address_flow_set.insert (entry);
00229         }
00230       else
00231         flow_set.insert (entry);
00232     } //End of For Loop
00233 
00234 
00235   int result = -1;
00236   switch (direction)
00237     {
00238     case TAO_AV_Core::TAO_AV_ENDPOINT_A:
00239       if (address_flow_set.size () > 0)
00240         {
00241           result = this->acceptor_registry_->open (endpoint,
00242                                                    this,
00243                                                    address_flow_set);
00244           if (result < 0)
00245             ACE_ERROR_RETURN ((LM_ERROR,
00246                                "TAO_AV_Core::init_forward_flows::acceptor_registry::open failed\n"),
00247                               -1);
00248           TAO_AV_FlowSpecSetItor end = address_flow_set.end ();
00249           for (TAO_AV_FlowSpecSetItor start = address_flow_set.begin ();
00250                start != end; ++start)
00251             {
00252               TAO_FlowSpec_Entry *entry = (*start);
00253               switch (entry->direction ())
00254                 {
00255                 case TAO_FlowSpec_Entry::TAO_AV_DIR_IN:
00256                   {
00257                     if (entry->handler () != 0)
00258                       {
00259                         //Yamuna:PLEASE CHECK THIS LATER
00260 #if defined ACE_HAS_RAPI || defined (ACE_HAS_WINSOCK2_GQOS)
00261                         // For IN flows on the A side we should remove the handlers from the reactor.
00262                         ACE_Event_Handler *event_handler = entry->handler ()->event_handler ();
00263 
00264                         if (event_handler->reactor () != 0)
00265                           {
00266                             result = event_handler->reactor ()->remove_handler (event_handler,
00267                                                                                 ACE_Event_Handler::READ_MASK);
00268 
00269                             if (result < 0)
00270                               if (TAO_debug_level > 0)
00271                                 ACE_DEBUG ((LM_DEBUG,
00272                                             "TAO_AV_Core::init_forward_flows: remove_handler failed\n"));
00273                           }
00274 #endif //ACE_HAS_RAPI || ACE_HAS_WINSOCK2_GQOS
00275                       }
00276                   }
00277                 default:
00278                   break;
00279                 }
00280               // Now if the address_set has been changed due to the addition of a control entry we should
00281               // add that to the flow_spec_set also.
00282               if (flow_spec_set.find (entry) < 0)
00283                 {
00284                   // entry doesn't exist so add it.
00285                   flow_spec_set.insert (entry);
00286                   //                   size_t len = flow_spec.length ();
00287                   //                   flow_spec.length (len+1);
00288                   //                   flow_spec [len] = entry->entry_to_string ();
00289                 }
00290             }
00291         }
00292       break;
00293     case TAO_AV_Core::TAO_AV_ENDPOINT_B:
00294       {
00295         if (address_flow_set.size () > 0)
00296           {
00297             ACE_DEBUG ((LM_DEBUG,
00298                         "(%N,%l) This connector registry is called\n"));
00299 
00300             result = this->connector_registry_->open (endpoint,
00301                                                       this,
00302                                                       address_flow_set);
00303             if (result == -1)
00304               ACE_ERROR_RETURN ((LM_ERROR,"TAO_AV_Core::init_Forward_flows: connector_registry open failed\n"),-1);
00305             TAO_AV_FlowSpecSetItor end = address_flow_set.end ();
00306             for (TAO_AV_FlowSpecSetItor start = address_flow_set.begin ();
00307                  start != end; ++start)
00308               {
00309                 TAO_FlowSpec_Entry *entry = (*start);
00310                 switch (entry->direction ())
00311                   {
00312                   case TAO_FlowSpec_Entry::TAO_AV_DIR_OUT:
00313                     {
00314                       if (entry->handler () != 0)
00315                         {
00316                           // @@Naga: This wont be called in the case of Full Profile.
00317                           // For IN flows on the A side we should remove the handlers from the reactor.
00318                           ACE_Event_Handler *event_handler = entry->handler ()->event_handler ();
00319                           result = event_handler->reactor ()->remove_handler (event_handler,
00320                                                                               ACE_Event_Handler::READ_MASK);
00321                           if (result < 0)
00322                             if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"TAO_AV_Core::init_forward_flows: remove_handler failed\n"));
00323                         }
00324                     }
00325                   default:
00326                     break;
00327                   }
00328                 // Now if the address_set has been changed due to the addition of a control entry we should
00329                 // add that to the flow_spec_set also.
00330                 if (flow_spec_set.find (entry) < 0)
00331                   {
00332                     // entry doesn't exist so add it.
00333                     flow_spec_set.insert (entry);
00334                   }
00335               }
00336           }
00337         if (flow_set.size () > 0)
00338           {
00339             TAO_AV_FlowSpecSet tmp_flow_set (flow_set);
00340             flow_set.reset ();
00341             TAO_AV_FlowSpecSetItor end = tmp_flow_set.end ();
00342             TAO_AV_FlowSpecSetItor start = tmp_flow_set.begin ();
00343             for (; start != end; ++start)
00344               {
00345                 TAO_FlowSpec_Entry *entry = *start;
00346                 TAO_FlowSpec_Entry *new_entry;
00347                 ACE_CString dir;
00348                 if (entry->direction () == 0)
00349                   dir += "IN";
00350                 else if (entry->direction () == 1)
00351                   dir += "OUT";
00352                 if (entry->get_peer_addr () != 0)
00353                   {
00354                     ACE_NEW_RETURN (new_entry,
00355                                     TAO_Forward_FlowSpec_Entry (entry->flowname (),
00356                                                                 dir.c_str (),
00357                                                                 entry->format (),
00358                                                                 entry->flow_protocol_str (),
00359                                                                 entry->carrier_protocol_str (),
00360                                                                 entry->get_peer_addr (),
00361                                                                 entry->control_address ()),
00362                                     -1);
00363                   }
00364                 else
00365                   {
00366                     ACE_NEW_RETURN (new_entry,
00367                                     TAO_Forward_FlowSpec_Entry (entry->flowname (),
00368                                                                 dir.c_str (),
00369                                                                 entry->format (),
00370                                                                 entry->flow_protocol_str (),
00371                                                                 entry->carrier_protocol_str (),
00372                                                                 entry->address (),
00373                                                                 entry->control_address ()),
00374                                     -1);
00375                   }
00376                 flow_set.insert (new_entry);
00377               }
00378             result = this->acceptor_registry_->open (endpoint,
00379                                                      this,
00380                                                      flow_set);
00381             if (result == -1)
00382               ACE_ERROR_RETURN ((LM_ERROR,"TAO_AV_Core::init_Forward_flows: Acceptor_registry open failed\n"),-1);
00383             end = address_flow_set.end ();
00384             start = address_flow_set.begin ();
00385             for (; start != end; ++start)
00386               {
00387                 TAO_FlowSpec_Entry *entry = (*start);
00388                 switch (entry->direction ())
00389                   {
00390                   case TAO_FlowSpec_Entry::TAO_AV_DIR_OUT:
00391                     {
00392                       if (entry->handler () != 0)
00393                         {
00394                           // For IN flows on the A side we should remove the handlers from the reactor.
00395                           ACE_Event_Handler *event_handler = entry->handler ()->event_handler ();
00396                           result = event_handler->reactor ()->remove_handler (event_handler,
00397                                                                               ACE_Event_Handler::READ_MASK);
00398                           if (result < 0)
00399                             if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"TAO_AV_Core::init_forward_flows: remove_handler failed\n"));
00400                         }
00401                     }
00402                   default:
00403                     break;
00404                   }
00405                 // Now if the address_set has been changed due to the addition of a control entry we should
00406                 // add that to the flow_spec_set also.
00407                 if (flow_spec_set.find (entry) < 0)
00408                   {
00409                     // entry doesn't exist so add it.
00410                     flow_spec_set.insert (entry);
00411                   }
00412               }
00413           }
00414 
00415         AVStreams::flowSpec new_flowspec (static_cast<CORBA::ULong> (flow_spec_set.size ()));
00416         int i=0;
00417         TAO_AV_FlowSpecSetItor connect_end = address_flow_set.end ();
00418         TAO_AV_FlowSpecSetItor connect = address_flow_set.begin ();
00419         for (;connect != connect_end;  ++connect)
00420           {
00421             ACE_Addr *local_addr;
00422             ACE_Addr *local_control_addr;
00423             local_addr = (*connect)->get_local_addr ();
00424             local_control_addr = (*connect)->get_local_control_addr ();
00425             if (local_addr != 0)
00426               {
00427                 TAO_Reverse_FlowSpec_Entry entry ((*connect)->flowname (),
00428                                                   (*connect)->direction_str (),
00429                                                   (*connect)->format (),
00430                                                   (*connect)->flow_protocol_str (),
00431                                                   (*connect)->carrier_protocol_str (),
00432                                                   local_addr,
00433                                                   local_control_addr);
00434                 /*
00435                   ACE_Addr *addr;
00436                   if ((addr = (*connect)->get_peer_addr ()) != 0)
00437                   {
00438                   entry.set_peer_addr (addr);
00439                   };
00440                 */
00441                 int len = new_flowspec.length ();
00442                 if (i == len)
00443                   new_flowspec.length (len+1);
00444                 new_flowspec [i++] = entry.entry_to_string ();
00445                 if (TAO_debug_level > 0)
00446                   ACE_DEBUG ((LM_DEBUG, "reverse Flow Spec Is %s\n", entry.entry_to_string ()));
00447               }
00448           }
00449         connect_end = flow_set.end ();
00450         for (connect = flow_set.begin ();
00451              connect != connect_end;  ++connect)
00452           {
00453             ACE_Addr *local_addr;
00454             ACE_Addr *local_control_addr;
00455             local_addr = (*connect)->get_local_addr ();
00456             local_control_addr = (*connect)->get_local_control_addr ();
00457             if (local_addr != 0)
00458               {
00459                 TAO_Reverse_FlowSpec_Entry entry ((*connect)->flowname (),
00460                                                   (*connect)->direction_str (),
00461                                                   (*connect)->format (),
00462                                                   (*connect)->flow_protocol_str (),
00463                                                   (*connect)->carrier_protocol_str (),
00464                                                   local_addr,
00465                                                   local_control_addr);
00466 
00467                 int len = new_flowspec.length ();
00468                 if (i == len)
00469                   new_flowspec.length (len+1);
00470                 new_flowspec [i++] = entry.entry_to_string ();
00471               }
00472           }
00473         // Change the reverse flow spec to be sent.
00474         //        int index = flow_spec.length () + 1;
00475         int index = new_flowspec.length ();
00476         flow_spec.length (index);
00477         for (i = 0; i < index; i++)
00478           {
00479             flow_spec [i] = new_flowspec [i];
00480           }
00481       }
00482       break;
00483     default:
00484       break;
00485     }
00486   return 0;
00487 }
00488 
00489 int
00490 TAO_AV_Core::init_reverse_flows (TAO_Base_StreamEndPoint *endpoint,
00491                                  TAO_AV_FlowSpecSet &forward_flow_spec_set,
00492                                  TAO_AV_FlowSpecSet &reverse_flow_spec_set,
00493                                  TAO_AV_Core::EndPoint direction)
00494 {
00495   if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"(%P|%t)TAO_AV_Core::init_reverse_flows\n"));
00496   TAO_AV_FlowSpecSet acceptor_flow_set;
00497   TAO_AV_FlowSpecSet connector_flow_set;
00498   TAO_AV_FlowSpecSetItor end = reverse_flow_spec_set.end ();
00499   TAO_AV_FlowSpecSetItor start = reverse_flow_spec_set.begin ();
00500   for (;start != end; ++start)
00501     {
00502       TAO_FlowSpec_Entry *entry = (*start);
00503       ACE_Addr *address = entry->address ();
00504       switch (direction)
00505         {
00506         case TAO_AV_Core::TAO_AV_ENDPOINT_B:
00507           {
00508             switch (entry->direction ())
00509               {
00510               case TAO_FlowSpec_Entry::TAO_AV_DIR_IN:
00511                 entry->role (TAO_FlowSpec_Entry::TAO_AV_CONSUMER);
00512                 break;
00513               case TAO_FlowSpec_Entry::TAO_AV_DIR_OUT:
00514                 entry->role (TAO_FlowSpec_Entry::TAO_AV_PRODUCER);
00515                 break;
00516               }
00517             break;
00518           }
00519         case TAO_AV_Core::TAO_AV_ENDPOINT_A:
00520           {
00521             switch (entry->direction ())
00522               {
00523               case TAO_FlowSpec_Entry::TAO_AV_DIR_IN:
00524                 entry->role (TAO_FlowSpec_Entry::TAO_AV_PRODUCER);
00525                 break;
00526               case TAO_FlowSpec_Entry::TAO_AV_DIR_OUT:
00527                 entry->role (TAO_FlowSpec_Entry::TAO_AV_CONSUMER);
00528                 break;
00529               }
00530             break;
00531           }
00532         default: break;
00533         }
00534 
00535       if (address != 0)
00536         {
00537           if (this->get_acceptor (entry->flowname ())!= 0)
00538             {
00539               ACE_Addr *address = entry->address ();
00540               TAO_FlowSpec_Entry *forward_entry =
00541                 this->get_flow_spec_entry (forward_flow_spec_set,
00542                                            entry->flowname ());
00543               if (forward_entry != 0)
00544                 forward_entry->set_peer_addr (address);
00545             }
00546           else
00547             connector_flow_set.insert (entry);
00548         }
00549     }
00550   int result = -1;
00551   switch (direction)
00552     {
00553 
00554     case TAO_AV_Core::TAO_AV_ENDPOINT_A:
00555       {
00556         result = this->connector_registry_->open (endpoint,
00557                                                   this,
00558                                                   connector_flow_set);
00559       }
00560         break;
00561     default:
00562       break;
00563     }
00564   if (result == -1)
00565     ACE_ERROR_RETURN ((LM_ERROR,"acceptor_registry::open"),-1);
00566   return 0;
00567 }
00568 
00569 TAO_FlowSpec_Entry *
00570 TAO_AV_Core::get_flow_spec_entry (TAO_AV_FlowSpecSet &flow_spec_set,
00571                                   const char *flowname)
00572 {
00573   TAO_AV_FlowSpecSetItor end = flow_spec_set.end ();
00574   TAO_AV_FlowSpecSetItor begin = flow_spec_set.begin ();
00575   for (;
00576        begin != end;
00577        ++begin)
00578     {
00579       if (ACE_OS::strcmp ((*begin)->flowname (),flowname) == 0)
00580         return (*begin);
00581     }
00582   return 0;
00583 }
00584 
00585 TAO_AV_Acceptor*
00586 TAO_AV_Core::get_acceptor (const char *flowname)
00587 {
00588 
00589   try
00590     {
00591 
00592       TAO_AV_AcceptorSetItor acceptor =  this->acceptor_registry_->begin ();
00593 
00594       TAO_AV_AcceptorSetItor end =
00595         this->acceptor_registry_->end ();
00596 
00597       for (;acceptor != end; ++acceptor)
00598         {
00599           if (ACE_OS::strcmp ((*acceptor)->flowname (),flowname) == 0)
00600             return *acceptor;
00601         }
00602     }
00603   catch (const CORBA::Exception& ex)
00604     {
00605       ex._tao_print_exception ("TAO_AV_Core::get_acceptor");
00606     }
00607   return 0;
00608 }
00609 
00610 int
00611 TAO_AV_Core::remove_acceptor (const char *flowname)
00612 {
00613 
00614   try
00615     {
00616 
00617       TAO_AV_AcceptorSetItor acceptor =  this->acceptor_registry_->begin ();
00618 
00619       TAO_AV_AcceptorSetItor end =
00620         this->acceptor_registry_->end ();
00621 
00622       for (;acceptor != end; ++acceptor)
00623         {
00624           if (ACE_OS::strcmp ((*acceptor)->flowname (),flowname) == 0)
00625             {
00626               this->acceptor_registry_->close (*acceptor);
00627               return 0;
00628             }
00629         }
00630     }
00631   catch (const CORBA::Exception& ex)
00632     {
00633       ex._tao_print_exception ("TAO_AV_Core::get_acceptor");
00634     }
00635   return -1;
00636 }
00637 
00638 TAO_AV_Connector*
00639 TAO_AV_Core::get_connector (const char *flowname)
00640 {
00641   TAO_AV_ConnectorSetItor connector =
00642     this->connector_registry_->begin ();
00643   TAO_AV_ConnectorSetItor end =
00644     this->connector_registry_->end ();
00645 
00646   for (;connector != end; ++connector)
00647     {
00648       if (ACE_OS::strcmp ((*connector)->flowname (),flowname) == 0)
00649         return *connector;
00650     }
00651   return 0;
00652 }
00653 
00654 int
00655 TAO_AV_Core::remove_connector (const char *flowname)
00656 {
00657   TAO_AV_ConnectorSetItor connector =
00658     this->connector_registry_->begin ();
00659   TAO_AV_ConnectorSetItor end =
00660     this->connector_registry_->end ();
00661 
00662   for (;connector != end; ++connector)
00663     {
00664       if (ACE_OS::strcmp ((*connector)->flowname (),flowname) == 0)
00665         {
00666           this->connector_registry_->close (*connector);
00667           return 0;
00668         }
00669     }
00670   return -1;
00671 }
00672 
00673 TAO_AV_Flow_Protocol_Factory *
00674 TAO_AV_Core::get_flow_protocol_factory(const char *flow_protocol)
00675 {
00676   if (flow_protocol == 0)
00677     return 0;
00678 
00679   for (TAO_AV_Flow_ProtocolFactorySetItor control_flow_factory =
00680          this->flow_protocol_factories_.begin ();
00681        control_flow_factory !=
00682          this->flow_protocol_factories_.end ();
00683        ++control_flow_factory)
00684     {
00685       if ((*control_flow_factory)->factory ()->match_protocol (flow_protocol))
00686         {
00687           return (*control_flow_factory)->factory ();
00688         }
00689     }
00690 
00691   // Not found.
00692   return 0;
00693 }
00694 
00695 TAO_AV_Transport_Factory *
00696 TAO_AV_Core::get_transport_factory(const char *transport_protocol)
00697 {
00698   if (transport_protocol == 0)
00699     return 0;
00700 
00701   for (TAO_AV_TransportFactorySetItor transport_factory =
00702          this->transport_factories_.begin ();
00703        transport_factory != this->transport_factories_.end ();
00704        ++transport_factory)
00705     {
00706       if ((*transport_factory)->factory ()->match_protocol (transport_protocol))
00707         {
00708           return (*transport_factory)->factory ();
00709         }
00710     }
00711 
00712   // Not found.
00713   return 0;
00714 }
00715 
00716 int
00717 TAO_AV_Core::load_default_transport_factories (void)
00718 {
00719   const char *udp_factory_str = "UDP_Factory";
00720   const char *tcp_factory_str = "TCP_Factory";
00721 
00722   TAO_AV_Transport_Factory *udp_factory = 0;
00723   TAO_AV_Transport_Item *udp_item = 0;
00724 
00725   udp_factory =
00726     ACE_Dynamic_Service<TAO_AV_Transport_Factory>::instance (udp_factory_str);
00727   if (udp_factory == 0)
00728     {
00729       if (TAO_debug_level)
00730         ACE_ERROR ((LM_WARNING,
00731                     "(%P|%t) WARNING - No %s found in Service Repository."
00732                     "  Using default instance.\n",
00733                     "UDP Factory"));
00734 
00735       ACE_NEW_RETURN (udp_factory,
00736                       TAO_AV_UDP_Factory,
00737                       -1);
00738     }
00739   else udp_factory->ref_count = 1;
00740 
00741   ACE_NEW_RETURN (udp_item, TAO_AV_Transport_Item ("UDP_Factory"), -1);
00742   udp_item->factory (udp_factory);
00743 
00744   this->transport_factories_.insert (udp_item);
00745 
00746   TAO_AV_Transport_Factory *tcp_factory = 0;
00747   TAO_AV_Transport_Item *tcp_item = 0;
00748 
00749   tcp_factory =
00750     ACE_Dynamic_Service<TAO_AV_Transport_Factory>::instance (tcp_factory_str);
00751   if (tcp_factory == 0)
00752     {
00753       if (TAO_debug_level)
00754         ACE_ERROR ((LM_WARNING,
00755                     "(%P|%t) WARNING - No %s found in Service Repository."
00756                     "  Using default instance.\n",
00757                     "TCP Factory"));
00758 
00759       ACE_NEW_RETURN (tcp_factory,
00760                       TAO_AV_TCP_Factory,
00761                           -1);
00762     }
00763   else tcp_factory->ref_count = 1;
00764 
00765   ACE_NEW_RETURN (tcp_item, TAO_AV_Transport_Item ("TCP_Factory"), -1);
00766   tcp_item->factory (tcp_factory);
00767 
00768   this->transport_factories_.insert (tcp_item);
00769 
00770 #if defined (ACE_HAS_RAPI) || defined (ACE_HAS_WINSOCK2_GQOS)
00771   const char *udp_qos_factory_str = "UDP_QoS_Factory";
00772 
00773   TAO_AV_Transport_Factory *udp_qos_factory = 0;
00774   TAO_AV_Transport_Item *udp_qos_item = 0;
00775 
00776   udp_qos_factory =
00777         ACE_Dynamic_Service<TAO_AV_Transport_Factory>::instance (udp_qos_factory_str);
00778   if (udp_qos_factory == 0)
00779     {
00780       if (TAO_debug_level)
00781         ACE_ERROR ((LM_WARNING,
00782                     "(%P|%t) WARNING - No %s found in Service Repository."
00783                     "  Using default instance.\n",
00784                     "UDP QoS Factory"));
00785 
00786           ACE_NEW_RETURN (udp_qos_factory,
00787                           TAO_AV_UDP_QoS_Factory,
00788                           -1);
00789     }
00790   else udp_qos_factory->ref_count = 1;
00791 
00792   ACE_NEW_RETURN (udp_qos_item,
00793                   TAO_AV_Transport_Item ("UDP_QoS_Factory"),
00794                   -1);
00795 
00796   udp_qos_item->factory (udp_qos_factory);
00797 
00798   this->transport_factories_.insert (udp_qos_item);
00799 #endif /* ACE_HAS_RAPI || ACE_HAS_WINSOCK2_GQOS */
00800 
00801 #if defined ACE_HAS_SCTP
00802   const char *sctp_seq_factory_str = "SCTP_SEQ_Factory";
00803 
00804   TAO_AV_Transport_Factory *sctp_seq_factory = 0;
00805   TAO_AV_Transport_Item *sctp_seq_item = 0;
00806 
00807   sctp_seq_factory =
00808         ACE_Dynamic_Service<TAO_AV_Transport_Factory>::instance (sctp_seq_factory_str);
00809   if (sctp_seq_factory == 0)
00810     {
00811       if (TAO_debug_level)
00812         ACE_ERROR ((LM_WARNING,
00813                     "(%P|%t) WARNING - No %s found in Service Repository."
00814                     "  Using default instance.\n",
00815                     "SCTP SEQ Factory"));
00816 
00817       ACE_NEW_RETURN (sctp_seq_factory,
00818                       TAO_AV_SCTP_SEQ_Factory,
00819                       -1);
00820     }
00821   else sctp_seq_factory->ref_count = 1;
00822 
00823   ACE_NEW_RETURN (sctp_seq_item,
00824                   TAO_AV_Transport_Item ("SCTP_SEQ_Factory"),
00825                   -1);
00826 
00827   sctp_seq_item->factory (sctp_seq_factory);
00828 
00829   this->transport_factories_.insert (sctp_seq_item);
00830 #endif /* ACE_HAS_SCTP */
00831 
00832   return 0;
00833 }
00834 
00835 int
00836 TAO_AV_Core::init_transport_factories (void)
00837 {
00838   TAO_AV_TransportFactorySetItor end = this->transport_factories_.end ();
00839   TAO_AV_TransportFactorySetItor factory = this->transport_factories_.begin ();
00840 
00841 
00842   if (factory == end)
00843     {
00844       if (TAO_debug_level > 0)
00845         ACE_DEBUG ((LM_DEBUG,
00846                     "Loading default transport protocols\n"));
00847       this->load_default_transport_factories ();
00848     }
00849   else
00850     {
00851       for (; factory != end; factory++)
00852         {
00853           const ACE_CString &name = (*factory)->name ();
00854           if (TAO_debug_level > 0)
00855             ACE_DEBUG ((LM_DEBUG,
00856                         "%s \n",
00857                         name.c_str ()));
00858 
00859           (*factory)->factory (
00860                                ACE_Dynamic_Service<TAO_AV_Transport_Factory>::instance (name.c_str ()));
00861           if ((*factory)->factory () == 0)
00862             {
00863               ACE_ERROR_RETURN ((LM_ERROR,
00864                                  ACE_TEXT ("TAO (%P|%t) Unable to load ")
00865                                  ACE_TEXT ("protocol <%s>, %p\n"),
00866                                  name.c_str (), ""),
00867                                 -1);
00868             }
00869           (*factory)->factory ()->ref_count = 1;
00870 
00871           if (TAO_debug_level > 0)
00872             {
00873               ACE_DEBUG ((LM_DEBUG,
00874                           ACE_TEXT ("TAO (%P|%t) Loaded protocol <%s>\n"),
00875                           name.c_str ()));
00876             }
00877         }
00878     }
00879 
00880   return 0;
00881 }
00882 
00883 int
00884 TAO_AV_Core::load_default_flow_protocol_factories (void)
00885 {
00886   const char *udp_flow = "UDP_Flow_Factory";
00887   const char *tcp_flow = "TCP_Flow_Factory";
00888   const char *rtp_flow = "RTP_Flow_Factory";
00889   const char *rtcp_flow = "RTCP_Flow_Factory";
00890   const char *sfp_flow = "SFP_Flow_Factory";
00891 
00892   TAO_AV_Flow_Protocol_Factory *udp_flow_factory = 0;
00893   TAO_AV_Flow_Protocol_Item *udp_item = 0;
00894 
00895   udp_flow_factory =
00896     ACE_Dynamic_Service<TAO_AV_Flow_Protocol_Factory>::instance (udp_flow);
00897   if (udp_flow_factory == 0)
00898     {
00899       if (TAO_debug_level)
00900         ACE_ERROR ((LM_WARNING,
00901                     "(%P|%t) WARNING - No %s found in Service Repository."
00902                     "  Using default instance.\n",
00903                     "UDP Flow Factory"));
00904 
00905       ACE_NEW_RETURN (udp_flow_factory,
00906                       TAO_AV_UDP_Flow_Factory,
00907                       -1);
00908     }
00909   else udp_flow_factory->ref_count = 1;
00910 
00911   ACE_NEW_RETURN (udp_item, TAO_AV_Flow_Protocol_Item ("UDP_Flow_Factory"), -1);
00912   udp_item->factory (udp_flow_factory);
00913 
00914   this->flow_protocol_factories_.insert (udp_item);
00915 
00916 #if defined (ACE_HAS_RAPI) || defined (ACE_HAS_WINSOCK2_GQOS)
00917 
00918   const char *udp_qos_flow = "UDP_QoS_Flow_Factory";
00919   TAO_AV_Flow_Protocol_Factory *udp_qos_flow_factory = 0;
00920   TAO_AV_Flow_Protocol_Item *udp_qos_flow_item = 0;
00921 
00922   udp_qos_flow_factory =
00923     ACE_Dynamic_Service<TAO_AV_Flow_Protocol_Factory>::instance (udp_qos_flow);
00924   if (udp_qos_flow_factory == 0)
00925     {
00926       if (TAO_debug_level)
00927         ACE_ERROR ((LM_WARNING,
00928                     "(%P|%t) WARNING - No %s found in Service Repository."
00929                     "  Using default instance.\n",
00930                     "UDP QoS Flow Factory"));
00931 
00932       ACE_NEW_RETURN (udp_qos_flow_factory,
00933                       TAO_AV_UDP_QoS_Flow_Factory,
00934                       -1);
00935     }
00936   else udp_qos_flow_factory->ref_count = 1;
00937 
00938   ACE_NEW_RETURN (udp_qos_flow_item, TAO_AV_Flow_Protocol_Item ("UDP_QoS_Flow_Factory"), -1);
00939   udp_qos_flow_item->factory (udp_qos_flow_factory);
00940 
00941   this->flow_protocol_factories_.insert (udp_qos_flow_item);
00942 
00943 #endif /* defined (ACE_HAS_RAPI) || defined (ACE_HAS_WINSOCK2_GQOS) */
00944 
00945 #if defined ACE_HAS_SCTP
00946 
00947   const char *sctp_seq_flow = "SCTP_SEQ_Flow_Factory";
00948   TAO_AV_Flow_Protocol_Factory *sctp_seq_flow_factory = 0;
00949   TAO_AV_Flow_Protocol_Item *sctp_seq_flow_item = 0;
00950 
00951   sctp_seq_flow_factory =
00952     ACE_Dynamic_Service<TAO_AV_Flow_Protocol_Factory>::instance (sctp_seq_flow);
00953   if (sctp_seq_flow_factory == 0)
00954     {
00955       if (TAO_debug_level)
00956         ACE_ERROR ((LM_WARNING,
00957                     "(%P|%t) WARNING - No %s found in Service Repository."
00958                     "  Using default instance.\n",
00959                     "SCTP SEQ Flow Factory"));
00960 
00961       ACE_NEW_RETURN (sctp_seq_flow_factory,
00962                       TAO_AV_SCTP_SEQ_Flow_Factory,
00963                       -1);
00964     }
00965   else sctp_seq_flow_factory->ref_count = 1;
00966 
00967   ACE_NEW_RETURN (sctp_seq_flow_item, TAO_AV_Flow_Protocol_Item ("SCTP_SEQ_Flow_Factory"), -1);
00968   sctp_seq_flow_item->factory (sctp_seq_flow_factory);
00969 
00970   this->flow_protocol_factories_.insert (sctp_seq_flow_item);
00971 
00972 #endif /* ACE_HAS_SCTP */
00973 
00974   TAO_AV_Flow_Protocol_Factory *tcp_flow_factory = 0;
00975   TAO_AV_Flow_Protocol_Item *tcp_item = 0;
00976 
00977   tcp_flow_factory =
00978     ACE_Dynamic_Service<TAO_AV_Flow_Protocol_Factory>::instance (tcp_flow);
00979   if (tcp_flow_factory == 0)
00980     {
00981       if (TAO_debug_level)
00982         ACE_ERROR ((LM_WARNING,
00983                     "(%P|%t) WARNING - No %s found in Service Repository."
00984                     "  Using default instance.\n",
00985                     "TCP Flow Factory"));
00986 
00987       ACE_NEW_RETURN (tcp_flow_factory,
00988                       TAO_AV_TCP_Flow_Factory,
00989                       -1);
00990     }
00991   else tcp_flow_factory->ref_count = 1;
00992 
00993   ACE_NEW_RETURN (tcp_item, TAO_AV_Flow_Protocol_Item ("TCP_Flow_Factory"), -1);
00994   tcp_item->factory (tcp_flow_factory);
00995 
00996   this->flow_protocol_factories_.insert (tcp_item);
00997 
00998   TAO_AV_Flow_Protocol_Factory *rtp_flow_factory = 0;
00999   TAO_AV_Flow_Protocol_Item *rtp_item = 0;
01000 
01001   rtp_flow_factory =
01002     ACE_Dynamic_Service<TAO_AV_Flow_Protocol_Factory>::instance (rtp_flow);
01003   if (rtp_flow_factory == 0)
01004     {
01005       if (TAO_debug_level)
01006         ACE_ERROR ((LM_WARNING,
01007                     "(%P|%t) WARNING - No %s found in Service Repository."
01008                     "  Using default instance.\n",
01009                     "RTP Flow Factory"));
01010 
01011       ACE_NEW_RETURN (rtp_flow_factory,
01012                       TAO_AV_RTP_Flow_Factory,
01013                       -1);
01014     }
01015   else rtp_flow_factory->ref_count = 1;
01016 
01017   ACE_NEW_RETURN (rtp_item, TAO_AV_Flow_Protocol_Item ("RTP_Flow_Factory"), -1);
01018   rtp_item->factory (rtp_flow_factory);
01019 
01020   this->flow_protocol_factories_.insert (rtp_item);
01021 
01022   TAO_AV_Flow_Protocol_Factory *rtcp_flow_factory = 0;
01023   TAO_AV_Flow_Protocol_Item *rtcp_item = 0;
01024 
01025   rtcp_flow_factory =
01026     ACE_Dynamic_Service<TAO_AV_Flow_Protocol_Factory>::instance (rtcp_flow);
01027   if (rtcp_flow_factory == 0)
01028     {
01029       if (TAO_debug_level)
01030         ACE_ERROR ((LM_WARNING,
01031                     "(%P|%t) WARNING - No %s found in Service Repository."
01032                     "  Using default instance.\n",
01033                     "RTCP Flow Factory"));
01034 
01035       ACE_NEW_RETURN (rtcp_flow_factory,
01036                       TAO_AV_RTCP_Flow_Factory,
01037                       -1);
01038     }
01039   else rtcp_flow_factory->ref_count = 1;
01040 
01041   ACE_NEW_RETURN (rtcp_item, TAO_AV_Flow_Protocol_Item ("RTCP_Flow_Factory"), -1);
01042   rtcp_item->factory (rtcp_flow_factory);
01043 
01044   this->flow_protocol_factories_.insert (rtcp_item);
01045 
01046   TAO_AV_Flow_Protocol_Factory *sfp_flow_factory = 0;
01047   TAO_AV_Flow_Protocol_Item *sfp_item = 0;
01048 
01049   sfp_flow_factory =
01050     ACE_Dynamic_Service<TAO_AV_Flow_Protocol_Factory>::instance (sfp_flow);
01051   if (sfp_flow_factory == 0)
01052     {
01053       if (TAO_debug_level)
01054         ACE_ERROR ((LM_WARNING,
01055                     "(%P|%t) WARNING - No %s found in Service Repository."
01056                     "  Using default instance.\n",
01057                     "SFP Flow Factory"));
01058 
01059       ACE_NEW_RETURN (sfp_flow_factory,
01060                       TAO_AV_SFP_Factory,
01061                       -1);
01062     }
01063   else sfp_flow_factory->ref_count = 1;
01064 
01065   ACE_NEW_RETURN (sfp_item, TAO_AV_Flow_Protocol_Item ("SFP_Flow_Factory"), -1);
01066   sfp_item->factory (sfp_flow_factory);
01067 
01068   this->flow_protocol_factories_.insert (sfp_item);
01069 
01070   return 0;
01071 }
01072 
01073 int
01074 TAO_AV_Core::init_flow_protocol_factories (void)
01075 {
01076   TAO_AV_Flow_ProtocolFactorySetItor end = this->flow_protocol_factories_.end ();
01077   TAO_AV_Flow_ProtocolFactorySetItor factory = this->flow_protocol_factories_.begin ();
01078 
01079   if (factory == end)
01080     {
01081       ACE_DEBUG ((LM_DEBUG,
01082                   "Loading default flow protocol factories\n"));
01083 
01084       this->load_default_flow_protocol_factories ();
01085     }
01086   else
01087     {
01088       for (; factory != end; factory++)
01089         {
01090           const ACE_CString &name = (*factory)->name ();
01091           if (TAO_debug_level > 0)
01092             ACE_DEBUG ((LM_DEBUG,
01093                         "%s \n",
01094                         name.c_str ()));
01095 
01096           (*factory)->factory (
01097                                ACE_Dynamic_Service<TAO_AV_Flow_Protocol_Factory>::instance (name.c_str ()));
01098           if ((*factory)->factory () == 0)
01099             {
01100               ACE_ERROR_RETURN ((LM_ERROR,
01101                                  ACE_TEXT ("TAO (%P|%t) Unable to load ")
01102                                  ACE_TEXT ("protocol <%s>, %p\n"),
01103                                  name.c_str (), ""),
01104                                 -1);
01105             }
01106 
01107           (*factory)->factory ()->ref_count = 1;
01108 
01109           if (TAO_debug_level > 0)
01110             {
01111               ACE_DEBUG ((LM_DEBUG,
01112                           ACE_TEXT ("TAO (%P|%t) Loaded protocol <%s>\n"),
01113                           name.c_str ()));
01114             }
01115         }
01116     }
01117 
01118   return 0;
01119 }
01120 
01121 /* static */
01122 int
01123 TAO_AV_Core::deactivate_servant (PortableServer::Servant servant)
01124 {
01125   // Because of reference counting, the POA will automatically delete
01126   // the servant when all pending requests on this servant are
01127   // complete.
01128 
01129   try
01130     {
01131       PortableServer::POA_var poa = servant->_default_POA ();
01132 
01133       PortableServer::ObjectId_var id = poa->servant_to_id (servant);
01134 
01135       poa->deactivate_object (id.in ());
01136     }
01137   catch (const CORBA::Exception& ex)
01138     {
01139       ex._tao_print_exception ("deactivate_servant");
01140       return -1;
01141     }
01142   return 0;
01143 }
01144 
01145 /* static */
01146 char *
01147 TAO_AV_Core::get_flowname (const char *flow_spec_entry_str)
01148 {
01149   ACE_CString flow_spec_entry (flow_spec_entry_str);
01150   ACE_CString::size_type slash_pos = flow_spec_entry.find ('\\');
01151   ACE_CString flow_name;
01152   if (slash_pos != flow_spec_entry.npos)
01153     flow_name = flow_spec_entry.substring (0, slash_pos);
01154   else
01155     flow_name = flow_spec_entry_str;
01156   return CORBA::string_dup (flow_name.c_str ());
01157 }
01158 
01159 ACE_CString
01160 TAO_AV_Core::get_control_flowname(const char *flowname)
01161 {
01162   ACE_CString control_flowname;
01163   control_flowname = "c_";
01164   control_flowname = control_flowname + flowname;
01165 
01166   return flowname;
01167 }
01168 
01169 #if defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION)
01170 template ACE_Singleton<TAO_AV_Core, ACE_Null_Mutex> *ACE_Singleton<TAO_AV_Core, ACE_Null_Mutex>::singleton_;
01171 #endif /* ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION */
01172 
01173 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Sun Jan 27 16:05:15 2008 for TAO_AV by doxygen 1.3.6