Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

default_resource.cpp

Go to the documentation of this file.
00001 #include "tao_pch.h"
00002 // $Id: default_resource.cpp,v 1.1.1.4.2.3 2003/04/21 19:10:25 chad Exp $
00003 
00004 
00005 #include "tao/default_resource.h"
00006 
00007 #include "tao/ORB_Core.h"
00008 #include "tao/debug.h"
00009 #include "tao/IIOP_Factory.h"
00010 
00011 #include "tao/Acceptor_Registry.h"
00012 #include "tao/Connector_Registry.h"
00013 
00014 #include "tao/Reactive_Flushing_Strategy.h"
00015 #include "tao/Block_Flushing_Strategy.h"
00016 #include "tao/Leader_Follower_Flushing_Strategy.h"
00017 
00018 #include "tao/Leader_Follower.h"
00019 #include "tao/LRU_Connection_Purging_Strategy.h"
00020 
00021 #include "tao/LF_Strategy_Complete.h"
00022 #include "tao/Codeset_Manager.h"
00023 
00024 #include "ace/TP_Reactor.h"
00025 #include "ace/Dynamic_Service.h"
00026 #include "ace/Arg_Shifter.h"
00027 #include "ace/Auto_Ptr.h"
00028 #include "ace/Memory_Pool.h"
00029 #include "ace/Malloc.h"
00030 #include "ace/Codeset_Registry.h"
00031 
00032 #if !defined (__ACE_INLINE__)
00033 # include "tao/default_resource.i"
00034 #endif /* ! __ACE_INLINE__ */
00035 
00036 ACE_RCSID (tao,
00037            default_resource,
00038            "$Id: default_resource.cpp,v 1.1.1.4.2.3 2003/04/21 19:10:25 chad Exp $")
00039 
00040 TAO_Default_Resource_Factory::TAO_Default_Resource_Factory (void)
00041   : use_locked_data_blocks_ (1)
00042   , parser_names_count_ (0)
00043   , parser_names_ (0)
00044   , protocol_factories_ ()
00045   , connection_purging_type_ (TAO_CONNECTION_PURGING_STRATEGY)
00046   , cache_maximum_ (TAO_CONNECTION_CACHE_MAXIMUM)
00047   , purge_percentage_ (TAO_PURGE_PERCENT)
00048   , max_muxed_connections_ (0)
00049   , reactor_mask_signals_ (1)
00050   , dynamically_allocated_reactor_ (0)
00051   , options_processed_ (0)
00052   , factory_disabled_ (0)
00053   , cached_connection_lock_type_ (TAO_THREAD_LOCK)
00054   , flushing_strategy_type_ (TAO_LEADER_FOLLOWER_FLUSHING)
00055   , codeset_manager_ (0)
00056 {
00057 }
00058 
00059 TAO_Default_Resource_Factory::~TAO_Default_Resource_Factory (void)
00060 {
00061   TAO_ProtocolFactorySetItor end = this->protocol_factories_.end ();
00062 
00063   for (TAO_ProtocolFactorySetItor iterator =
00064          this->protocol_factories_.begin ();
00065        iterator != end;
00066        ++iterator)
00067     delete *iterator;
00068 
00069   this->protocol_factories_.reset ();
00070 
00071   for (int i = 0;
00072        i < this->parser_names_count_;
00073        ++i)
00074     CORBA::string_free (this->parser_names_[i]);
00075 
00076   delete [] this->parser_names_;
00077 
00078   delete this->codeset_manager_;
00079 }
00080 
00081 int
00082 TAO_Default_Resource_Factory::init (int argc, ACE_TCHAR *argv[])
00083 {
00084   ACE_TRACE ("TAO_Default_Resource_Factory::init");
00085 
00086   // If this factory has already been disabled then
00087   // print a warning and exit because any options
00088   // are useless
00089   if (this->factory_disabled_) {
00090     ACE_DEBUG ((LM_DEBUG,
00091                 ACE_LIB_TEXT ("TAO (%P|%t) Warning: Resource_Factory options ignored\n")
00092                 ACE_LIB_TEXT ("Default Resource Factory is disabled\n")));
00093     return 0;
00094   }
00095   this->options_processed_ = 1;
00096 
00097   this->parser_names_count_ = 0;
00098 
00099   int curarg = 0;
00100 
00101   for (curarg = 0; curarg < argc; ++curarg)
00102   {
00103     // Parse thro' and find the number of Parsers to be loaded.
00104     if (ACE_OS::strcasecmp (argv[curarg],
00105                             ACE_LIB_TEXT("-ORBIORParser")) == 0)
00106       ++this->parser_names_count_;
00107 
00108     ++curarg;
00109 
00110     if (curarg == (argc-1) && this->parser_names_count_ != 0)
00111       {
00112         // This is the last loop..
00113         ACE_NEW_RETURN (this->parser_names_,
00114                         char *[this->parser_names_count_],
00115                         -1);
00116 
00117         for (int i = 0;
00118              i < this->parser_names_count_;
00119              ++i)
00120           this->parser_names_[i] = 0;
00121 
00122         this->index_ = 0;
00123       }
00124   }
00125 
00126   for (curarg = 0; curarg < argc; ++curarg)
00127     if (ACE_OS::strcasecmp (argv[curarg],
00128                             ACE_LIB_TEXT("-ORBResources")) == 0)
00129       {
00130         curarg++;
00131 
00132         ACE_DEBUG ((LM_DEBUG,
00133                     ACE_LIB_TEXT ("(%P|%t) This option has been deprecated \n")));
00134       }
00135 
00136     else if (ACE_OS::strcasecmp (argv[curarg],
00137                                  ACE_LIB_TEXT("-ORBReactorMaskSignals")) == 0)
00138       {
00139         curarg++;
00140         if (curarg < argc)
00141           {
00142             ACE_TCHAR* name = argv[curarg];
00143 
00144             if (ACE_OS::strcasecmp (name, ACE_LIB_TEXT("0")) == 0)
00145               this->reactor_mask_signals_ = 0;
00146             else if (ACE_OS::strcasecmp (name, ACE_LIB_TEXT("1")) == 0)
00147               this->reactor_mask_signals_= 1;
00148             else
00149               this->report_option_value_error (ACE_LIB_TEXT("-ORBReactorMaskSignals"), name);
00150           }
00151       }
00152 
00153     else if (ACE_OS::strcasecmp (argv[curarg],
00154                                  ACE_LIB_TEXT("-ORBProtocolFactory")) == 0)
00155       {
00156         TAO_ProtocolFactorySet *pset = this->get_protocol_factories ();
00157         curarg++;
00158         if (curarg < argc)
00159           {
00160             TAO_Protocol_Item *item = 0;
00161             ACE_NEW_RETURN (item,
00162                             TAO_Protocol_Item (ACE_TEXT_ALWAYS_CHAR(argv[curarg])),
00163                             -1);
00164             if (pset->insert (item) == -1)
00165               ACE_ERROR ((LM_ERROR,
00166                           ACE_LIB_TEXT ("(%P|%t) Unable to add protocol factories for %s: %p\n"),
00167                           argv[curarg]));
00168           }
00169       }
00170 
00171     /// CodeSet Translators
00172     else if (ACE_OS::strcasecmp (argv[curarg],
00173                                  ACE_LIB_TEXT("-ORBNativeCharCodeSet")) == 0)
00174     {
00175         curarg++;
00176         CONV_FRAME::CodeSetId ncs;
00177         if (ACE_Codeset_Registry::locale_to_registry (argv[curarg],
00178                                                       ncs) == 0)
00179           {
00180             char **endPtr =0;
00181             ncs = ACE_OS_String::strtoul(ACE_TEXT_ALWAYS_CHAR(argv[curarg]),
00182                                          endPtr, 0);
00183   }
00184         // Validate the CodesetId
00185         if (ACE_Codeset_Registry::get_max_bytes(ncs) == 0)
00186           {
00187             if (TAO_debug_level > 0)
00188               ACE_ERROR((LM_ERROR,
00189                          ACE_TEXT("(%P|%t) Invalid NativeCharCodeSet, %x\n"),
00190                          ncs));
00191             return -1;
00192           }
00193         TAO_Codeset_Manager *csm = this->get_codeset_manager();
00194         if (csm)
00195           csm->set_ncs_c(ncs);
00196     }
00197 
00198     else if (ACE_OS::strcasecmp (argv[curarg],
00199                                  ACE_LIB_TEXT("-ORBNativeWCharCodeSet")) == 0)
00200       {
00201         curarg++;
00202         CONV_FRAME::CodeSetId ncs;
00203         if (ACE_Codeset_Registry::locale_to_registry( argv[curarg],
00204                                                       ncs) == 0)
00205           {
00206             char **endPtr = 0;
00207             ncs = ACE_OS_String::strtoul(ACE_TEXT_ALWAYS_CHAR(argv[curarg]),
00208                                          endPtr, 0);
00209           }
00210         // Validate the CodesetId
00211         int mb = ACE_Codeset_Registry::get_max_bytes(ncs);
00212         if (mb == 0 || ACE_static_cast(size_t,mb) > sizeof (ACE_CDR::WChar))
00213           {
00214             if (TAO_debug_level > 0)
00215               ACE_ERROR((LM_ERROR,
00216                          ACE_TEXT("(%P|%t) Invalid NativeWCharCodeSet, %x\n"),
00217                          ncs));
00218             return -1;
00219           }
00220         TAO_Codeset_Manager *csm = this->get_codeset_manager();
00221         if (csm)
00222           csm->set_ncs_w(ncs,mb);
00223       }
00224 
00225     else if (ACE_OS::strcasecmp (argv[curarg],
00226                                  ACE_LIB_TEXT("-ORBCharCodesetTranslator")) == 0)
00227       {
00228         curarg++;
00229         if (curarg < argc)
00230           {
00231             TAO_Codeset_Manager *csm = this->get_codeset_manager();
00232             if (csm)
00233               if (csm->add_char_translator(argv[curarg]) == -1)
00234                 return -1;
00235           }
00236       }
00237 
00238   /// CodeSet Translators
00239     else if (ACE_OS::strcasecmp (argv[curarg],
00240                                  ACE_LIB_TEXT("-ORBWCharCodesetTranslator")) == 0)
00241       {
00242         curarg++;
00243         if (curarg < argc)
00244           {
00245             TAO_Codeset_Manager *csm = this->get_codeset_manager();
00246             if (csm)
00247               if (csm->add_wchar_translator(argv[curarg]) == -1)
00248                 return -1;
00249           }
00250       }
00251 
00252     else if (ACE_OS::strcasecmp (argv[curarg],
00253                                  ACE_LIB_TEXT("-ORBConnectionCachingStrategy")) == 0)
00254       {
00255         curarg++;
00256 
00257         // @@todo: This needs to be removed after a few betas. The
00258         // note is being written during 1.2.3 timeframe.
00259         ACE_DEBUG ((LM_DEBUG,
00260                     ACE_LIB_TEXT ("(%P|%t) This option would be deprecated \n")
00261                     ACE_LIB_TEXT ("(%P|%t) Please use -ORBConnectionPurgingStrategy instead \n")));
00262 
00263         if (curarg < argc)
00264           {
00265             ACE_TCHAR* name = argv[curarg];
00266 
00267             if (ACE_OS::strcasecmp (name,
00268                                     ACE_LIB_TEXT("lru")) == 0)
00269               this->connection_purging_type_ =
00270                 TAO_Resource_Factory::LRU;
00271             else if (ACE_OS::strcasecmp (name,
00272                                          ACE_LIB_TEXT("lfu")) == 0)
00273               this->connection_purging_type_ =
00274                 TAO_Resource_Factory::LFU;
00275             else if (ACE_OS::strcasecmp (name,
00276                                          ACE_LIB_TEXT("fifo")) == 0)
00277               this->connection_purging_type_ =
00278                 TAO_Resource_Factory::FIFO;
00279             else if (ACE_OS::strcasecmp (name,
00280                                          ACE_LIB_TEXT("null")) == 0)
00281               this->connection_purging_type_ =
00282                   TAO_Resource_Factory::NOOP;
00283             else
00284               this->report_option_value_error (ACE_LIB_TEXT("-ORBConnectionCachingStrategy"), name);
00285           }
00286       }
00287     else if (ACE_OS::strcasecmp (argv[curarg],
00288                                  ACE_LIB_TEXT("-ORBConnectionPurgingStrategy")) == 0)
00289       {
00290         curarg++;
00291 
00292         if (curarg < argc)
00293           {
00294             ACE_TCHAR* name = argv[curarg];
00295 
00296             if (ACE_OS::strcasecmp (name,
00297                                     ACE_LIB_TEXT("lru")) == 0)
00298               this->connection_purging_type_ =
00299                 TAO_Resource_Factory::LRU;
00300             else if (ACE_OS::strcasecmp (name,
00301                                          ACE_LIB_TEXT("lfu")) == 0)
00302               this->connection_purging_type_ =
00303                 TAO_Resource_Factory::LFU;
00304             else if (ACE_OS::strcasecmp (name,
00305                                          ACE_LIB_TEXT("fifo")) == 0)
00306               this->connection_purging_type_ =
00307                 TAO_Resource_Factory::FIFO;
00308             else if (ACE_OS::strcasecmp (name,
00309                                          ACE_LIB_TEXT("null")) == 0)
00310               this->connection_purging_type_ =
00311                   TAO_Resource_Factory::NOOP;
00312             else
00313               this->report_option_value_error (ACE_LIB_TEXT("-ORBConnectionPurgingStrategy"), name);
00314           }
00315       }
00316    else if (ACE_OS::strcasecmp (argv[curarg],
00317                                 ACE_LIB_TEXT("-ORBConnectionCacheMax")) == 0)
00318       {
00319         curarg++;
00320         if (curarg < argc)
00321             this->cache_maximum_ = ACE_OS::atoi (argv[curarg]);
00322         else
00323           this->report_option_value_error (ACE_LIB_TEXT("-ORBConnectionCacheMax"), argv[curarg]);
00324       }
00325 
00326    else if (ACE_OS::strcasecmp (argv[curarg],
00327                                 ACE_LIB_TEXT("-ORBConnectionCachePurgePercentage")) == 0)
00328       {
00329         curarg++;
00330         if (curarg < argc)
00331             this->purge_percentage_ = ACE_OS::atoi (argv[curarg]);
00332         else
00333           this->report_option_value_error (ACE_LIB_TEXT("-ORBConnectionCachePurgePercentage"),
00334                                            argv[curarg]);
00335       }
00336     else if (ACE_OS::strcasecmp (argv[curarg],
00337                                  ACE_LIB_TEXT("-ORBIORParser")) == 0)
00338       {
00339         curarg++;
00340 
00341         if (curarg < argc)
00342           {
00343             this->add_to_ior_parser_names (ACE_TEXT_ALWAYS_CHAR(argv[curarg]));
00344           }
00345       }
00346 
00347     else if (ACE_OS::strcasecmp (argv[curarg],
00348                                  ACE_LIB_TEXT("-ORBConnectionCacheLock")) == 0)
00349       {
00350         curarg++;
00351         if (curarg < argc)
00352           {
00353             ACE_TCHAR* name = argv[curarg];
00354 
00355             if (ACE_OS::strcasecmp (name,
00356                                     ACE_LIB_TEXT("thread")) == 0)
00357               this->cached_connection_lock_type_ = TAO_THREAD_LOCK;
00358             else if (ACE_OS::strcasecmp (name,
00359                                          ACE_LIB_TEXT("null")) == 0)
00360               {
00361                 // @@ Bug 940 :This is a sort of hack now. We need to put
00362                 // this in a common place once we get the common
00363                 // switch that is documented in bug 940...
00364                 this->use_locked_data_blocks_  = 0;
00365                 this->cached_connection_lock_type_ = TAO_NULL_LOCK;
00366               }
00367             else
00368               this->report_option_value_error (ACE_LIB_TEXT("-ORBConnectionCacheLock"), name);
00369           }
00370       }
00371     else if (ACE_OS::strcasecmp (argv[curarg],
00372                                  ACE_LIB_TEXT("-ORBFlushingStrategy")) == 0)
00373       {
00374         curarg++;
00375         if (curarg < argc)
00376           {
00377             ACE_TCHAR* name = argv[curarg];
00378 
00379             if (ACE_OS::strcasecmp (name,
00380                                     ACE_LIB_TEXT("leader_follower")) == 0)
00381               this->flushing_strategy_type_ = TAO_LEADER_FOLLOWER_FLUSHING;
00382             else if (ACE_OS::strcasecmp (name,
00383                                          ACE_LIB_TEXT("reactive")) == 0)
00384               this->flushing_strategy_type_ = TAO_REACTIVE_FLUSHING;
00385             else if (ACE_OS::strcasecmp (name,
00386                                          ACE_LIB_TEXT("blocking")) == 0)
00387               this->flushing_strategy_type_ = TAO_BLOCKING_FLUSHING;
00388             else
00389               this->report_option_value_error (ACE_LIB_TEXT("-ORBFlushingStrategy"), name);
00390           }
00391       }
00392     else if (ACE_OS::strcasecmp (argv[curarg],
00393                                  ACE_LIB_TEXT ("-ORBMuxedConnectionMax")) == 0)
00394       {
00395         curarg++;
00396         if (curarg < argc)
00397             this->max_muxed_connections_ =
00398               ACE_OS::atoi (argv[curarg]);
00399         else
00400           this->report_option_value_error ("-ORBMuxedConnectionMax",
00401                                            argv[curarg]);
00402       }
00403     else if (ACE_OS::strncmp (argv[curarg],
00404                               ACE_LIB_TEXT ("-ORB"),
00405                               4) == 0)
00406       {
00407         // Can we assume there is an argument after the option?
00408         // curarg++;
00409         ACE_ERROR ((LM_ERROR,
00410                     ACE_LIB_TEXT ("Default_Resource_Factory - ")
00411                     ACE_LIB_TEXT ("unknown option <%s>\n"),
00412                     argv[curarg]));
00413       }
00414     else
00415       {
00416         ACE_DEBUG ((LM_DEBUG,
00417                     ACE_LIB_TEXT ("Default_Resource_Factory - ")
00418                     ACE_LIB_TEXT ("ignoring option <%s>\n"),
00419                     argv[curarg]));
00420       }
00421 
00422   TAO_Codeset_Manager *csm = this->get_codeset_manager();
00423   if (csm)
00424     csm->configure_codeset_factories();
00425 
00426   return 0;
00427 }
00428 
00429 int
00430 TAO_Default_Resource_Factory::get_parser_names (char **&names,
00431                                                 int &number_of_names)
00432 {
00433   if (this->parser_names_count_ != 0)
00434     {
00435       // The user used some -ORBIORParser options, just return those.
00436       names = this->parser_names_;
00437       number_of_names = this->parser_names_count_;
00438 
00439       return 0;
00440     }
00441 
00442   // OK fallback on the hardcoded ones....
00443   this->parser_names_count_ = 5; // HOW MANY DO WE HAVE?
00444   this->parser_names_ =
00445     new char *[this->parser_names_count_];
00446 
00447   CORBA::ULong index = 0;
00448 
00449   this->parser_names_[index] = CORBA::string_dup ("DLL_Parser");
00450   index++;
00451 
00452   this->parser_names_[index] = CORBA::string_dup ("FILE_Parser");
00453   index++;
00454 
00455   this->parser_names_[index] = CORBA::string_dup ("CORBALOC_Parser");
00456   index++;
00457 
00458   this->parser_names_[index] = CORBA::string_dup ("CORBANAME_Parser");
00459   index++;
00460 
00461   this->parser_names_[index] = CORBA::string_dup ("MCAST_Parser");
00462   index++;
00463 
00464   names = this->parser_names_;
00465 
00466   number_of_names = index;
00467 
00468   return 0;
00469 }
00470 
00471 int
00472 TAO_Default_Resource_Factory::add_to_ior_parser_names (const char *curarg)
00473 {
00474   this->parser_names_[this->index_] = CORBA::string_dup (curarg);
00475 
00476   ++this->index_;
00477 
00478   return 0;
00479 }
00480 
00481 // This is virtual and protected...
00482 int
00483 TAO_Default_Resource_Factory::load_default_protocols (void)
00484 {
00485       // If the user did not list any protocols in her svc.conf file
00486       // then default to TAO's basic protocols.
00487       // You do *NOT* need modify this code to add your own protocol,
00488       // instead simply add the following to your svc.conf file:
00489       //
00490       // dynamic PP_Factory Service_Object * LIB:_make_PP_Protocol_Factory() ""
00491       // static Resource_Factory "-ORBProtocolFactory PP_Factory"
00492       //
00493       // where "PP_Factory" is the name of your protocol, i.e. the
00494       // second argument passed to the ACE_STATIC_SVC_DEFINE macro:
00495       //
00496       // ACE_STATIC_SVC_DEFINE (PP_Protocol_Factory,
00497       //                        ACE_LIB_TEXT ("PP_Factory"), ...)
00498       //
00499       // "PP_Protocol_Factory" is the name of your protocol factory
00500       // class.  A "_make_" is prepended to your protocol factory
00501       // class name by the ACE_FACTORY_DECLARE macro.  The resulting
00502       // factory function "_make_PP_Protocol_Factory()" is what should
00503       // be used in the "dynamic" line in your svc.conf file.
00504       //
00505       // LIB is the base name of the shared library that implements
00506       // the protocol.  The directory containing your library must be
00507       // in your library search path, typically defined by the
00508       // LD_LIBRARY_PATH environment variable on UNIX systems, and/or
00509       // the `/etc/ld.so.conf' file on some UNIX systems.  Remember to
00510       // run "ldconfig" if you modify `/etc/ld.so.conf'.
00511 
00512       TAO_Protocol_Factory *protocol_factory = 0;
00513       auto_ptr<TAO_Protocol_Factory> safe_protocol_factory;
00514 
00515       TAO_Protocol_Item *item = 0;
00516 
00517       // If a protocol factory is obtained from the Service
00518       // Configurator then do not transfer ownership to the
00519       // TAO_Protocol_Item.
00520       int transfer_ownership = 0;
00521 
00522       protocol_factory =
00523         ACE_Dynamic_Service<TAO_Protocol_Factory>::instance ("IIOP_Factory");
00524 
00525       if (protocol_factory == 0)
00526         {
00527           if (TAO_debug_level > 0)
00528             ACE_ERROR ((LM_WARNING,
00529                         ACE_LIB_TEXT ("TAO (%P|%t) No %s found in ")
00530                         ACE_LIB_TEXT ("Service Repository. ")
00531                         ACE_LIB_TEXT ("Using default instance IIOP ")
00532                         ACE_LIB_TEXT ("Protocol Factory.\n"),
00533                         ACE_LIB_TEXT ("IIOP Protocol Factory")));
00534 
00535           ACE_NEW_RETURN (protocol_factory,
00536                           TAO_IIOP_Protocol_Factory,
00537                           -1);
00538 
00539           ACE_AUTO_PTR_RESET (safe_protocol_factory,
00540                               protocol_factory,
00541                               TAO_Protocol_Factory);
00542 
00543           transfer_ownership = 1;
00544         }
00545       else
00546         {
00547           transfer_ownership = 0;
00548         }
00549 
00550       ACE_NEW_RETURN (item,
00551                       TAO_Protocol_Item ("IIOP_Factory"),
00552                       -1);
00553       // If the TAO_Protocol_Item retains ownership of the
00554       // TAO_Protocol_Factory then we used an auto_ptr<> above, so
00555       // release the TAO_Protocol_Factory from it.  Otherwise, we
00556       // obtained the TAO_Protocol_Factory from the Service
00557       // Configurator so an auto_ptr<> wasn't used since the Service
00558       // Configurator retains ownership, hence there was no need to
00559       // use an auto_ptr<> in this method.
00560       item->factory ((transfer_ownership ?
00561                       safe_protocol_factory.release () :
00562                       protocol_factory),
00563                      transfer_ownership);
00564 
00565       if (this->protocol_factories_.insert (item) == -1)
00566         {
00567           ACE_ERROR ((LM_ERROR,
00568                       ACE_LIB_TEXT ("TAO (%P|%t) Unable to add ")
00569                       ACE_LIB_TEXT ("<%s> to protocol factory set.\n"),
00570                       ACE_TEXT_CHAR_TO_TCHAR (item->protocol_name ().c_str ())));
00571 
00572           delete item;
00573 
00574           if (transfer_ownership == 0)
00575             delete protocol_factory;
00576 
00577           return -1;
00578         }
00579 
00580       if (TAO_debug_level > 0)
00581         {
00582           ACE_DEBUG ((LM_DEBUG,
00583                       ACE_LIB_TEXT ("TAO (%P|%t) Loaded default ")
00584                       ACE_LIB_TEXT ("protocol <IIOP_Factory>\n")));
00585         }
00586 
00587   return 0;
00588 }
00589 
00590 int
00591 TAO_Default_Resource_Factory::init_protocol_factories (void)
00592 {
00593   TAO_ProtocolFactorySetItor end = protocol_factories_.end ();
00594   TAO_ProtocolFactorySetItor factory = protocol_factories_.begin ();
00595 
00596   if (factory == end)
00597     {
00598       return this->load_default_protocols ();
00599     }
00600 
00601   for (; factory != end; factory++)
00602     {
00603       const ACE_CString &name = (*factory)->protocol_name ();
00604       (*factory)->factory (
00605         ACE_Dynamic_Service<TAO_Protocol_Factory>::instance (name.c_str ()));
00606       if ((*factory)->factory () == 0)
00607         {
00608           ACE_ERROR_RETURN ((LM_ERROR,
00609                              ACE_LIB_TEXT ("TAO (%P|%t) Unable to load ")
00610                              ACE_LIB_TEXT ("protocol <%s>, %p\n"),
00611                              ACE_TEXT_CHAR_TO_TCHAR(name.c_str ()),
00612                              ACE_LIB_TEXT ("")),
00613                             -1);
00614         }
00615 
00616       if (TAO_debug_level > 0)
00617         {
00618           ACE_DEBUG ((LM_DEBUG,
00619                       ACE_LIB_TEXT ("TAO (%P|%t) Loaded protocol <%s>\n"),
00620                       ACE_TEXT_CHAR_TO_TCHAR(name.c_str ())));
00621         }
00622     }
00623 
00624   return 0;
00625 }
00626 
00627 #if 0
00628 // @@todo: Need to go at a later date!
00629 int
00630 TAO_Default_Resource_Factory::use_tss_resources (void) const
00631 {
00632   return 0;
00633 }
00634 #endif /*if 0*/
00635 
00636 int
00637 TAO_Default_Resource_Factory::use_locked_data_blocks (void) const
00638 {
00639   return this->use_locked_data_blocks_;
00640 }
00641 
00642 TAO_ProtocolFactorySet *
00643 TAO_Default_Resource_Factory::get_protocol_factories (void)
00644 {
00645   return &protocol_factories_;
00646 }
00647 
00648 TAO_Acceptor_Registry *
00649 TAO_Default_Resource_Factory::get_acceptor_registry (void)
00650 {
00651   TAO_Acceptor_Registry *ar = 0;
00652 
00653   ACE_NEW_RETURN(ar,
00654                  TAO_Acceptor_Registry,
00655                  0);
00656 
00657   return ar;
00658 }
00659 
00660 TAO_Connector_Registry *
00661 TAO_Default_Resource_Factory::get_connector_registry (void)
00662 {
00663   TAO_Connector_Registry *cr = 0;
00664 
00665   ACE_NEW_RETURN(cr,
00666                  TAO_Connector_Registry,
00667                  0);
00668 
00669   return cr;
00670 }
00671 
00672 ACE_Reactor_Impl*
00673 TAO_Default_Resource_Factory::allocate_reactor_impl (void) const
00674 {
00675   ACE_Reactor_Impl *impl = 0;
00676 
00677   ACE_NEW_RETURN (impl, ACE_TP_Reactor ((ACE_Sig_Handler*)0,
00678                                         (ACE_Timer_Queue*)0,
00679                                         this->reactor_mask_signals_,
00680                                         ACE_Select_Reactor_Token::LIFO),
00681                   0);
00682   return impl;
00683 }
00684 
00685 ACE_Reactor *
00686 TAO_Default_Resource_Factory::get_reactor (void)
00687 {
00688   ACE_LOG_MSG->errnum (0);
00689 
00690   ACE_Reactor *reactor = 0;
00691   ACE_NEW_RETURN (reactor,
00692                   ACE_Reactor (this->allocate_reactor_impl (), 1),
00693                   0);
00694 
00695   if (ACE_LOG_MSG->errnum () != 0)
00696     {
00697       delete reactor;
00698       reactor = 0;
00699     }
00700   else
00701     this->dynamically_allocated_reactor_ = 1;
00702 
00703   return reactor;
00704 }
00705 
00706 void
00707 TAO_Default_Resource_Factory::reclaim_reactor (ACE_Reactor *reactor)
00708 {
00709   if (this->dynamically_allocated_reactor_ == 1)
00710     delete reactor;
00711 }
00712 
00713 
00714 typedef ACE_Malloc<ACE_LOCAL_MEMORY_POOL,ACE_Null_Mutex> NULL_LOCK_MALLOC;
00715 typedef ACE_Allocator_Adapter<NULL_LOCK_MALLOC> NULL_LOCK_ALLOCATOR;
00716 
00717 typedef ACE_Malloc<ACE_LOCAL_MEMORY_POOL,TAO_SYNCH_MUTEX> LOCKED_MALLOC;
00718 typedef ACE_Allocator_Adapter<LOCKED_MALLOC> LOCKED_ALLOCATOR;
00719 
00720 ACE_Allocator *
00721 TAO_Default_Resource_Factory::input_cdr_dblock_allocator (void)
00722 {
00723   ACE_Allocator *allocator = 0;
00724   ACE_NEW_RETURN (allocator,
00725                   LOCKED_ALLOCATOR,
00726                   0);
00727 
00728   return allocator;
00729 }
00730 
00731 ACE_Allocator *
00732 TAO_Default_Resource_Factory::input_cdr_buffer_allocator (void)
00733 {
00734   ACE_Allocator *allocator = 0;
00735   ACE_NEW_RETURN (allocator,
00736                   LOCKED_ALLOCATOR,
00737                   0);
00738 
00739   return allocator;
00740 }
00741 
00742 ACE_Allocator *
00743 TAO_Default_Resource_Factory::input_cdr_msgblock_allocator (void)
00744 {
00745   ACE_Allocator *allocator = 0;
00746   ACE_NEW_RETURN (allocator,
00747                   LOCKED_ALLOCATOR,
00748                   0);
00749 
00750   return allocator;
00751 }
00752 
00753 int
00754 TAO_Default_Resource_Factory::input_cdr_allocator_type_locked (void)
00755 {
00756   return 1;
00757 }
00758 
00759 ACE_Allocator*
00760 TAO_Default_Resource_Factory::output_cdr_dblock_allocator (void)
00761 {
00762   ACE_Allocator *allocator = 0;
00763   ACE_NEW_RETURN (allocator, NULL_LOCK_ALLOCATOR, 0);
00764   return allocator;
00765 }
00766 
00767 ACE_Allocator *
00768 TAO_Default_Resource_Factory::output_cdr_buffer_allocator (void)
00769 {
00770   ACE_Allocator *allocator = 0;
00771   ACE_NEW_RETURN (allocator, NULL_LOCK_ALLOCATOR, 0);
00772   return allocator;
00773 }
00774 
00775 ACE_Allocator*
00776 TAO_Default_Resource_Factory::output_cdr_msgblock_allocator (void)
00777 {
00778   ACE_Allocator *allocator = 0;
00779   ACE_NEW_RETURN (allocator, NULL_LOCK_ALLOCATOR, 0);
00780   return allocator;
00781 }
00782 
00783 int
00784 TAO_Default_Resource_Factory::cache_maximum (void) const
00785 {
00786   return this->cache_maximum_;
00787 }
00788 
00789 int
00790 TAO_Default_Resource_Factory::purge_percentage (void) const
00791 {
00792   return this->purge_percentage_;
00793 }
00794 
00795 int
00796 TAO_Default_Resource_Factory::max_muxed_connections (void) const
00797 {
00798   return this->max_muxed_connections_;
00799 }
00800 
00801 
00802 ACE_Lock *
00803 TAO_Default_Resource_Factory::create_cached_connection_lock (void)
00804 {
00805   ACE_Lock *the_lock = 0;
00806 
00807   if (this->cached_connection_lock_type_ == TAO_NULL_LOCK)
00808     ACE_NEW_RETURN (the_lock,
00809                     ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX>,
00810                     0);
00811   else
00812     ACE_NEW_RETURN (the_lock,
00813                     ACE_Lock_Adapter<TAO_SYNCH_MUTEX>,
00814                     0);
00815 
00816   return the_lock;
00817 }
00818 
00819 int
00820 TAO_Default_Resource_Factory::locked_transport_cache (void)
00821 {
00822   if (this->cached_connection_lock_type_ == TAO_NULL_LOCK)
00823     return 0;
00824 
00825   return 1;
00826 }
00827 
00828 
00829 TAO_Flushing_Strategy *
00830 TAO_Default_Resource_Factory::create_flushing_strategy (void)
00831 {
00832   TAO_Flushing_Strategy *strategy = 0;
00833   if (this->flushing_strategy_type_ == TAO_LEADER_FOLLOWER_FLUSHING)
00834     ACE_NEW_RETURN (strategy,
00835                     TAO_Leader_Follower_Flushing_Strategy,
00836                     0);
00837   else if (this->flushing_strategy_type_ == TAO_REACTIVE_FLUSHING)
00838     ACE_NEW_RETURN (strategy,
00839                     TAO_Reactive_Flushing_Strategy,
00840                     0);
00841   else
00842     ACE_NEW_RETURN (strategy,
00843                     TAO_Block_Flushing_Strategy,
00844                     0);
00845   return strategy;
00846 }
00847 
00848 TAO_Connection_Purging_Strategy *
00849 TAO_Default_Resource_Factory::create_purging_strategy (void)
00850 {
00851   TAO_Connection_Purging_Strategy *strategy = 0;
00852 
00853   if (this->connection_purging_type_ == TAO_Resource_Factory::LRU)
00854     {
00855       ACE_NEW_RETURN (strategy,
00856                       TAO_LRU_Connection_Purging_Strategy (
00857                                            this->cache_maximum ()),
00858                       0);
00859     }
00860   else
00861     {
00862       ACE_ERROR ((LM_ERROR,
00863                   ACE_LIB_TEXT ("TAO (%P|%t) - ")
00864                   ACE_LIB_TEXT ("no usable purging strategy ")
00865                   ACE_LIB_TEXT ("was found.\n")));
00866     }
00867 
00868   return strategy;
00869 }
00870 
00871 TAO_LF_Strategy *
00872 TAO_Default_Resource_Factory::create_lf_strategy (void)
00873 {
00874   TAO_LF_Strategy *strategy = 0;
00875 
00876   ACE_NEW_RETURN (strategy,
00877                   TAO_LF_Strategy_Complete,
00878                   0);
00879 
00880   return strategy;
00881 }
00882 
00883 void
00884 TAO_Default_Resource_Factory::report_option_value_error (
00885                                  const ACE_TCHAR* option_name,
00886                                  const ACE_TCHAR* option_value)
00887 {
00888   ACE_DEBUG((LM_DEBUG,
00889              ACE_LIB_TEXT ("Default_Resource_Factory - unknown argument")
00890              ACE_LIB_TEXT (" <%s> for <%s>\n"),
00891              option_value, option_name));
00892 }
00893 
00894 void
00895 TAO_Default_Resource_Factory::disable_factory (void)
00896 {
00897   this->factory_disabled_ = 1;
00898   if (this->options_processed_)
00899     {
00900       ACE_DEBUG ((LM_DEBUG,
00901                   ACE_LIB_TEXT ("TAO (%P|%t) Warning: Resource_Factory options ignored\n")
00902                   ACE_LIB_TEXT ("Default Resource Factory is disabled\n")));
00903     }
00904 }
00905 
00906 TAO_Codeset_Manager *
00907 TAO_Default_Resource_Factory::get_codeset_manager()
00908 {
00909   if (this->codeset_manager_ == 0)
00910     {
00911       ACE_NEW_RETURN (this->codeset_manager_, TAO_Codeset_Manager, 0);
00912     }
00913   return this->codeset_manager_;
00914 }
00915 
00916 // ****************************************************************
00917 
00918 ACE_STATIC_SVC_DEFINE (TAO_Default_Resource_Factory,
00919                        ACE_LIB_TEXT ("Resource_Factory"),
00920                        ACE_SVC_OBJ_T,
00921                        &ACE_SVC_NAME (TAO_Default_Resource_Factory),
00922                        ACE_Service_Type::DELETE_THIS
00923                        | ACE_Service_Type::DELETE_OBJ,
00924                        0)
00925 ACE_FACTORY_DEFINE (TAO, TAO_Default_Resource_Factory)
00926 
00927 // ****************************************************************
00928 
00929 #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
00930 
00931 template class auto_ptr<TAO_Protocol_Factory>;
00932 #  if defined (ACE_LACKS_AUTO_PTR) \
00933       || !(defined (ACE_HAS_STANDARD_CPP_LIBRARY) \
00934            && (ACE_HAS_STANDARD_CPP_LIBRARY != 0))
00935 template class ACE_Auto_Basic_Ptr<TAO_Protocol_Factory>;
00936 #  endif  /* ACE_LACKS_AUTO_PTR */
00937 
00938 #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
00939 
00940 #pragma instantiate auto_ptr<TAO_Protocol_Factory>
00941 #  if defined (ACE_LACKS_AUTO_PTR) \
00942       || !(defined (ACE_HAS_STANDARD_CPP_LIBRARY) \
00943            && (ACE_HAS_STANDARD_CPP_LIBRARY != 0))
00944 #    pragma instantiate ACE_Auto_Basic_Ptr<TAO_Protocol_Factory>
00945 #  endif  /* ACE_LACKS_AUTO_PTR */
00946 
00947 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */

Generated on Mon Jun 16 13:48:13 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002