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

default_client.cpp

Go to the documentation of this file.
00001 #include "tao_pch.h"
00002 // $Id: default_client.cpp,v 1.1.1.4.2.1 2003/03/14 16:05:16 chad Exp $
00003 
00004 #include "default_client.h"
00005 #include "ORB_Core.h"
00006 #include "Wait_On_Read.h"
00007 #include "Wait_On_Reactor.h"
00008 #include "Wait_On_Leader_Follower.h"
00009 #include "Exclusive_TMS.h"
00010 #include "Muxed_TMS.h"
00011 #include "Blocked_Connect_Strategy.h"
00012 #include "Reactive_Connect_Strategy.h"
00013 #include "LF_Connect_Strategy.h"
00014 
00015 
00016 #if !defined (__ACE_INLINE__)
00017 # include "tao/default_client.i"
00018 #endif /* ! __ACE_INLINE__ */
00019 
00020 ACE_RCSID(tao, default_client, "$Id: default_client.cpp,v 1.1.1.4.2.1 2003/03/14 16:05:16 chad Exp $")
00021 
00022 TAO_Default_Client_Strategy_Factory::TAO_Default_Client_Strategy_Factory (void)
00023   : profile_lock_type_ (TAO_THREAD_LOCK)
00024 {
00025   // Use single thread client connection handler
00026 #if defined (TAO_USE_ST_CLIENT_CONNECTION_HANDLER)
00027   this->wait_strategy_ = TAO_WAIT_ON_REACTOR;
00028 #else
00029   this->wait_strategy_ = TAO_WAIT_ON_LEADER_FOLLOWER;
00030 #endif /* TAO_USE_ST_CLIENT_CONNECTION_HANDLER */
00031 
00032 #if TAO_USE_MUXED_TRANSPORT_MUX_STRATEGY == 1
00033   this->transport_mux_strategy_ = TAO_MUXED_TMS;
00034 #else
00035   this->transport_mux_strategy_ = TAO_EXCLUSIVE_TMS;
00036 #endif /* TAO_USE_MUXED_TRANSPORT_MUX_STRATEGY */
00037 
00038   // @@todo: will be changed when other strategies are implemented.
00039   this->connect_strategy_ = TAO_LEADER_FOLLOWER_CONNECT;
00040 }
00041 
00042 TAO_Default_Client_Strategy_Factory::~TAO_Default_Client_Strategy_Factory (void)
00043 {
00044 }
00045 
00046 int
00047 TAO_Default_Client_Strategy_Factory::init (int argc, ACE_TCHAR* argv[])
00048 {
00049   return this->parse_args (argc, argv);
00050 }
00051 
00052 int
00053 TAO_Default_Client_Strategy_Factory::parse_args (int argc, ACE_TCHAR* argv[])
00054 {
00055   ACE_TRACE ("TAO_Default_Client_Strategy_Factory::parse_args");
00056 
00057   int curarg;
00058 
00059   for (curarg = 0; curarg < argc && argv[curarg]; ++curarg)
00060     {
00061       if (ACE_OS::strcasecmp (argv[curarg],
00062                               ACE_LIB_TEXT("-ORBProfileLock")) == 0)
00063         {
00064         curarg++;
00065         if (curarg < argc)
00066           {
00067             ACE_TCHAR* name = argv[curarg];
00068 
00069             if (ACE_OS::strcasecmp (name,
00070                                     ACE_LIB_TEXT("thread")) == 0)
00071               this->profile_lock_type_ = TAO_THREAD_LOCK;
00072             else if (ACE_OS::strcasecmp (name,
00073                                          ACE_LIB_TEXT("null")) == 0)
00074               this->profile_lock_type_ = TAO_NULL_LOCK;
00075             else
00076               this->report_option_value_error (ACE_LIB_TEXT("-ORBProfileLock"), name);
00077           }
00078         }
00079 
00080       else if (ACE_OS::strcasecmp (argv[curarg],
00081                                    ACE_LIB_TEXT("-ORBIIOPProfileLock")) == 0)
00082         {
00083           ACE_DEBUG ((LM_DEBUG,
00084                       ACE_TEXT ("WARNING: The -ORBIIOPProfileLock option")
00085                       ACE_TEXT (" is deprecated and will be removed.\n")
00086                       ACE_TEXT ("         Please use -ORBProfileLock instead\n")));
00087           curarg++;
00088           if (curarg < argc)
00089             {
00090               ACE_TCHAR* name = argv[curarg];
00091 
00092               if (ACE_OS::strcasecmp (name,
00093                                       ACE_LIB_TEXT("thread")) == 0)
00094                 this->profile_lock_type_ = TAO_THREAD_LOCK;
00095               else if (ACE_OS::strcasecmp (name,
00096                                            ACE_LIB_TEXT("null")) == 0)
00097                 this->profile_lock_type_ = TAO_NULL_LOCK;
00098             }
00099         }
00100 
00101       else if (ACE_OS::strcasecmp (argv[curarg],
00102                                    ACE_LIB_TEXT("-ORBClientConnectionHandler")) == 0)
00103         {
00104           curarg++;
00105           if (curarg < argc)
00106             {
00107               ACE_TCHAR* name = argv[curarg];
00108 
00109               if (ACE_OS::strcasecmp (name,
00110                                       ACE_LIB_TEXT("MT")) == 0)
00111                 this->wait_strategy_ = TAO_WAIT_ON_LEADER_FOLLOWER;
00112               else if (ACE_OS::strcasecmp (name,
00113                                            ACE_LIB_TEXT("ST")) == 0)
00114                 this->wait_strategy_ = TAO_WAIT_ON_REACTOR;
00115               else if (ACE_OS::strcasecmp (name,
00116                                            ACE_LIB_TEXT("RW")) == 0)
00117                 this->wait_strategy_ = TAO_WAIT_ON_READ;
00118               else
00119                 this->report_option_value_error (ACE_LIB_TEXT("-ORBClientConnectionHandler"), name);
00120             }
00121         }
00122       else if (ACE_OS::strcmp (argv[curarg],
00123                                ACE_LIB_TEXT("-ORBTransportMuxStrategy")) == 0)
00124         {
00125           curarg++;
00126           if (curarg < argc)
00127             {
00128               ACE_TCHAR* name = argv[curarg];
00129 
00130               if (ACE_OS::strcasecmp (name,
00131                                       ACE_LIB_TEXT("MUXED")) == 0)
00132                 this->transport_mux_strategy_ = TAO_MUXED_TMS;
00133               else if (ACE_OS::strcasecmp (name,
00134                                            ACE_LIB_TEXT("EXCLUSIVE")) == 0)
00135                 this->transport_mux_strategy_ = TAO_EXCLUSIVE_TMS;
00136               else
00137                 this->report_option_value_error (ACE_LIB_TEXT("-ORBTransportMuxStrategy"), name);
00138             }
00139         }
00140       else if (ACE_OS::strcmp (argv[curarg],
00141                                ACE_LIB_TEXT("-ORBConnectStrategy")) == 0)
00142         {
00143           curarg++;
00144           if (curarg < argc)
00145             {
00146               ACE_TCHAR* name = argv[curarg];
00147 
00148               if (ACE_OS::strcasecmp (name,
00149                                       ACE_LIB_TEXT("Blocked")) == 0)
00150                 this->connect_strategy_ = TAO_BLOCKED_CONNECT;
00151               else if (ACE_OS::strcasecmp (name,
00152                                            ACE_LIB_TEXT("Reactive")) == 0)
00153                 this->connect_strategy_ = TAO_REACTIVE_CONNECT;
00154               else if (ACE_OS::strcasecmp (name,
00155                                            ACE_LIB_TEXT("LF")) == 0)
00156                 this->connect_strategy_ = TAO_LEADER_FOLLOWER_CONNECT;
00157               else
00158                 this->report_option_value_error (ACE_LIB_TEXT("-ORBTransportMuxStrategy"), name);
00159             }
00160         }
00161       else if (ACE_OS::strncmp (argv[curarg], ACE_LIB_TEXT("-ORB"), 4) == 0)
00162         {
00163           // Can we assume there is an argument after the option?
00164           // curarg++;
00165           ACE_ERROR ((LM_ERROR,
00166                       "Client_Strategy_Factory - "
00167                       "unknown option <%s>\n",
00168                       argv[curarg]));
00169         }
00170       else
00171         {
00172           ACE_DEBUG ((LM_DEBUG,
00173                       "Client_Strategy_Factory - "
00174                       "ignoring option <%s>\n",
00175                       argv[curarg]));
00176         }
00177 
00178 
00179     }
00180   return 0;
00181 }
00182 
00183 ACE_Lock *
00184 TAO_Default_Client_Strategy_Factory::create_profile_lock (void)
00185 {
00186   ACE_Lock *the_lock = 0;
00187 
00188   if (this->profile_lock_type_ == TAO_NULL_LOCK)
00189     ACE_NEW_RETURN (the_lock,
00190                     ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX> (),
00191                     0);
00192   else
00193     ACE_NEW_RETURN (the_lock,
00194                     ACE_Lock_Adapter<TAO_SYNCH_MUTEX> (),
00195                     0);
00196 
00197   return the_lock;
00198 }
00199 
00200 // @@ Alex: implement the WS and TMS methods here, similar to the
00201 //    create_profile_lock above...
00202 // @@ Alex: remember your idea of using the
00203 //    -ORBclientconnectionhandler option to implement the WS factory,
00204 //    but you need new options for the TMS...
00205 
00206 // Create the correct client transport muxing strategy.
00207 TAO_Transport_Mux_Strategy *
00208 TAO_Default_Client_Strategy_Factory::create_transport_mux_strategy (TAO_Transport *transport)
00209 {
00210   TAO_Transport_Mux_Strategy *tms = 0;
00211 
00212   if (this->transport_mux_strategy_ == TAO_MUXED_TMS)
00213     ACE_NEW_RETURN (tms,
00214                     TAO_Muxed_TMS (transport),
00215                     0);
00216   else
00217     ACE_NEW_RETURN (tms,
00218                     TAO_Exclusive_TMS (transport),
00219                     0);
00220 
00221   return tms;
00222 }
00223 
00224 TAO_Wait_Strategy *
00225 TAO_Default_Client_Strategy_Factory::create_wait_strategy (TAO_Transport *transport)
00226 {
00227   TAO_Wait_Strategy *ws = 0;
00228 
00229   if (this->wait_strategy_ == TAO_WAIT_ON_READ)
00230     ACE_NEW_RETURN (ws,
00231                     TAO_Wait_On_Read (transport),
00232                     0);
00233   else if (this->wait_strategy_ == TAO_WAIT_ON_REACTOR)
00234     ACE_NEW_RETURN (ws,
00235                     TAO_Wait_On_Reactor (transport),
00236                     0);
00237   else
00238     {
00239       // = Leader follower model.
00240 
00241       ACE_NEW_RETURN (ws,
00242                       TAO_Wait_On_Leader_Follower (transport),
00243                       0);
00244     }
00245 
00246   return ws;
00247 }
00248 
00249 TAO_Connect_Strategy *
00250 TAO_Default_Client_Strategy_Factory::create_connect_strategy (TAO_ORB_Core *orb_core)
00251 {
00252   TAO_Connect_Strategy *cs = 0;
00253 
00254   if (this->connect_strategy_ == TAO_BLOCKED_CONNECT)
00255     ACE_NEW_RETURN (cs,
00256                     TAO_Blocked_Connect_Strategy (orb_core),
00257                     0);
00258   else if (this->connect_strategy_ == TAO_REACTIVE_CONNECT)
00259     ACE_NEW_RETURN (cs,
00260                     TAO_Reactive_Connect_Strategy (orb_core),
00261                     0);
00262   else
00263     {
00264       // = Leader follower model.
00265 
00266       ACE_NEW_RETURN (cs,
00267                       TAO_LF_Connect_Strategy (orb_core),
00268                       0);
00269     }
00270 
00271   return cs;
00272 }
00273 
00274 
00275 int
00276 TAO_Default_Client_Strategy_Factory::allow_callback (void)
00277 {
00278   return (this->wait_strategy_ != TAO_WAIT_ON_READ);
00279 }
00280 
00281 ACE_Lock *
00282 TAO_Default_Client_Strategy_Factory::create_ft_service_retention_id_lock (void)
00283 {
00284   ACE_Lock *the_lock = 0;
00285 
00286   ACE_NEW_RETURN (the_lock,
00287                   ACE_Lock_Adapter<TAO_SYNCH_MUTEX>,
00288                   0);
00289 
00290   return the_lock;
00291 }
00292 
00293 void
00294 TAO_Default_Client_Strategy_Factory::report_option_value_error (
00295                                  const ACE_TCHAR* option_name,
00296                                  const ACE_TCHAR* option_value)
00297 {
00298   ACE_DEBUG((LM_DEBUG,
00299              ACE_TEXT ("Client_Strategy_Factory - unknown argument")
00300              ACE_TEXT (" <%s> for <%s>\n"),
00301              option_value, option_name));
00302 }
00303 
00304 // ****************************************************************
00305 
00306 ACE_STATIC_SVC_DEFINE (TAO_Default_Client_Strategy_Factory,
00307                        ACE_TEXT ("Client_Strategy_Factory"),
00308                        ACE_SVC_OBJ_T,
00309                        &ACE_SVC_NAME (TAO_Default_Client_Strategy_Factory),
00310                        ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00311                        0)
00312 ACE_FACTORY_DEFINE (TAO, TAO_Default_Client_Strategy_Factory)

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