AV_Core.cpp

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

Generated on Thu Nov 9 13:44:37 2006 for TAO_AV by doxygen 1.3.6