ServantRetentionStrategyNonRetain.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    ServantRetentionStrategyNonRetain.cpp
00006  *
00007  *  ServantRetentionStrategyNonRetain.cpp,v 1.12 2006/06/20 07:21:21 jwillemsen Exp
00008  *
00009  */
00010 //=============================================================================
00011 
00012 #include "tao/PortableServer/ServantRetentionStrategyNonRetain.h"
00013 #include "tao/PortableServer/Non_Servant_Upcall.h"
00014 #include "tao/PortableServer/Servant_Upcall.h"
00015 #include "tao/PortableServer/POA_Current_Impl.h"
00016 #include "tao/PortableServer/Root_POA.h"
00017 #include "tao/PortableServer/Servant_Base.h"
00018 #include "tao/debug.h"
00019 
00020 ACE_RCSID (PortableServer,
00021            Servant_Retention_Strategy,
00022            "ServantRetentionStrategyNonRetain.cpp,v 1.12 2006/06/20 07:21:21 jwillemsen Exp")
00023 
00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00025 
00026 namespace TAO
00027 {
00028   namespace Portable_Server
00029   {
00030     ServantRetentionStrategyNonRetain::ServantRetentionStrategyNonRetain (void) :
00031       poa_ (0)
00032     {
00033     }
00034 
00035     void
00036     ServantRetentionStrategyNonRetain::strategy_init (
00037       TAO_Root_POA *poa
00038       ACE_ENV_ARG_DECL_NOT_USED)
00039     {
00040       poa_ = poa;
00041     }
00042 
00043     void
00044     ServantRetentionStrategyNonRetain::strategy_cleanup (
00045       ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00046     {
00047       poa_ = 0;
00048     }
00049 
00050     void
00051     ServantRetentionStrategyNonRetain::deactivate_object (
00052       const PortableServer::ObjectId &/*id*/
00053       ACE_ENV_ARG_DECL)
00054     {
00055       // When using Non_Retain we don't have an active object map and we just
00056       // can't deactivate any object
00057       ACE_THROW (PortableServer::POA::WrongPolicy ());
00058     }
00059 
00060     PortableServer::Servant
00061     ServantRetentionStrategyNonRetain::find_servant (
00062       const PortableServer::ObjectId &/*system_id*/
00063       ACE_ENV_ARG_DECL)
00064     {
00065       ACE_THROW_RETURN (PortableServer::POA::WrongPolicy (),
00066                         0);
00067     }
00068 
00069     PortableServer::ObjectId *
00070     ServantRetentionStrategyNonRetain::system_id_to_object_id (
00071       const PortableServer::ObjectId &system_id
00072       ACE_ENV_ARG_DECL)
00073         ACE_THROW_SPEC ((CORBA::SystemException,
00074                          PortableServer::POA::WrongAdapter,
00075                          PortableServer::POA::WrongPolicy))
00076     {
00077       // The system id is the id (and no conversion/transformation is
00078       // needed).
00079       PortableServer::ObjectId *id = 0;
00080       ACE_NEW_THROW_EX (id,
00081                         PortableServer::ObjectId (system_id),
00082                         CORBA::NO_MEMORY ());
00083       ACE_CHECK_RETURN (0);
00084 
00085       return id;
00086     }
00087 
00088     PortableServer::Servant
00089     ServantRetentionStrategyNonRetain::user_id_to_servant (
00090       const PortableServer::ObjectId &/*id*/
00091       ACE_ENV_ARG_DECL)
00092         ACE_THROW_SPEC ((CORBA::SystemException,
00093                          PortableServer::POA::ObjectNotActive,
00094                          PortableServer::POA::WrongPolicy))
00095     {
00096       ACE_THROW_RETURN (PortableServer::POA::WrongPolicy (),
00097                         0);
00098     }
00099 
00100     CORBA::Object_ptr
00101     ServantRetentionStrategyNonRetain::id_to_reference (
00102       const PortableServer::ObjectId &/*id*/,
00103       bool /*indirect*/
00104       ACE_ENV_ARG_DECL)
00105         ACE_THROW_SPEC ((CORBA::SystemException,
00106                          PortableServer::POA::ObjectNotActive,
00107                          PortableServer::POA::WrongPolicy))
00108     {
00109       ACE_THROW_RETURN (PortableServer::POA::WrongPolicy (),
00110                         CORBA::Object::_nil ());
00111     }
00112 
00113     TAO_SERVANT_LOCATION
00114     ServantRetentionStrategyNonRetain::servant_present (
00115       const PortableServer::ObjectId &/*system_id*/,
00116       PortableServer::Servant &/*servant*/
00117       ACE_ENV_ARG_DECL_NOT_USED)
00118     {
00119       return TAO_SERVANT_NOT_FOUND;
00120     }
00121 
00122     PortableServer::Servant
00123     ServantRetentionStrategyNonRetain::find_servant (
00124       const PortableServer::ObjectId &system_id,
00125       TAO::Portable_Server::Servant_Upcall &servant_upcall,
00126       TAO::Portable_Server::POA_Current_Impl &poa_current_impl
00127       ACE_ENV_ARG_DECL_NOT_USED)
00128     {
00129       // We have the NON_RETAIN policy, user id is the system id.
00130 
00131       // Smartly copy all the data; <poa_current_impl.object_id_> does
00132       // not own the data.
00133       poa_current_impl.replace_object_id (system_id);
00134 
00135       servant_upcall.user_id (&system_id);
00136 
00137       return 0;
00138     }
00139 
00140     int
00141     ServantRetentionStrategyNonRetain::find_servant_priority (
00142         const PortableServer::ObjectId &/*system_id*/,
00143         CORBA::Short &/*priority*/
00144         ACE_ENV_ARG_DECL)
00145     {
00146       return -1;
00147     }
00148 
00149     int
00150     ServantRetentionStrategyNonRetain::is_servant_in_map (
00151       PortableServer::Servant /*servant*/,
00152       int &/*wait_occurred_restart_call*/)
00153     {
00154       return 0;
00155     }
00156 
00157     CORBA::ULong
00158     ServantRetentionStrategyNonRetain::waiting_servant_deactivation (void) const
00159     {
00160       return 0;
00161     }
00162 
00163     void
00164     ServantRetentionStrategyNonRetain::deactivate_all_objects (
00165       ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
00166         ACE_THROW_SPEC ((CORBA::SystemException,
00167                          PortableServer::POA::WrongPolicy))
00168     {
00169     }
00170 
00171     PortableServer::ObjectId *
00172     ServantRetentionStrategyNonRetain::servant_to_user_id (
00173       PortableServer::Servant /*servant*/
00174       ACE_ENV_ARG_DECL)
00175         ACE_THROW_SPEC ((CORBA::SystemException,
00176                          PortableServer::POA::ServantNotActive,
00177                          PortableServer::POA::WrongPolicy))
00178     {
00179       ACE_THROW_RETURN (PortableServer::POA::WrongPolicy (),
00180                         0);
00181     }
00182 
00183     CORBA::Object_ptr
00184     ServantRetentionStrategyNonRetain::servant_to_reference (
00185       PortableServer::Servant /*servant*/
00186       ACE_ENV_ARG_DECL)
00187         ACE_THROW_SPEC ((CORBA::SystemException,
00188                          PortableServer::POA::ServantNotActive,
00189                          PortableServer::POA::WrongPolicy))
00190     {
00191       ACE_THROW_RETURN (PortableServer::POA::WrongPolicy (),
00192                         CORBA::Object::_nil ());
00193     }
00194 
00195     PortableServer::ObjectId *
00196     ServantRetentionStrategyNonRetain::activate_object (
00197       PortableServer::Servant /*servant*/,
00198       CORBA::Short /*priority*/,
00199       int &/*wait_occurred_restart_call*/
00200       ACE_ENV_ARG_DECL)
00201         ACE_THROW_SPEC ((CORBA::SystemException,
00202                          PortableServer::POA::ServantAlreadyActive,
00203                          PortableServer::POA::WrongPolicy))
00204     {
00205       ACE_THROW_RETURN (PortableServer::POA::WrongPolicy (),
00206                         0);
00207     }
00208 
00209 #if !defined (CORBA_E_MICRO)
00210     void
00211     ServantRetentionStrategyNonRetain::activate_object_with_id (
00212       const PortableServer::ObjectId &/*id*/,
00213       PortableServer::Servant /*servant*/,
00214       CORBA::Short /*priority*/,
00215       int &/*wait_occurred_restart_call*/
00216       ACE_ENV_ARG_DECL)
00217         ACE_THROW_SPEC ((CORBA::SystemException,
00218                          PortableServer::POA::ServantAlreadyActive,
00219                          PortableServer::POA::ObjectAlreadyActive,
00220                          PortableServer::POA::WrongPolicy))
00221     {
00222       ACE_THROW (PortableServer::POA::WrongPolicy ());
00223     }
00224 #endif
00225 
00226     CORBA::Object_ptr
00227     ServantRetentionStrategyNonRetain::create_reference (
00228       const char *intf,
00229       CORBA::Short priority
00230       ACE_ENV_ARG_DECL)
00231         ACE_THROW_SPEC ((CORBA::SystemException,
00232                          PortableServer::POA::WrongPolicy))
00233     {
00234       // This operation creates an object reference that encapsulates a
00235       // POA-generated Object Id value and the specified interface
00236       // repository id. This operation does not cause an activation to
00237       // take place. The resulting reference may be passed to clients, so
00238       // that subsequent requests on those references will cause the
00239       // appropriate servant manager to be invoked, if one is
00240       // available. The generated Object Id value may be obtained by
00241       // invoking POA::reference_to_id with the created reference.
00242 
00243       PortableServer::ObjectId_var system_id;
00244       PortableServer::ObjectId user_id;
00245 
00246       // Otherwise, it is the NON_RETAIN policy.  Therefore, any ol'
00247       // object id will do (even an empty one).
00248       PortableServer::ObjectId *sys_id = 0;
00249       ACE_NEW_THROW_EX (sys_id,
00250                         PortableServer::ObjectId,
00251                         CORBA::NO_MEMORY ());
00252       ACE_CHECK_RETURN (CORBA::Object::_nil ());
00253 
00254       system_id = sys_id;
00255 
00256       // User id is the same as system id.
00257       user_id = system_id.in ();
00258 
00259       // Remember params for potentially invoking <key_to_object> later.
00260       this->poa_->key_to_object_params_.set (system_id,
00261                                              intf,
00262                                              0,
00263                                              1,
00264                                              priority,
00265                                              true);
00266 
00267       return this->poa_->invoke_key_to_object_helper_i (intf,
00268                                                         user_id
00269                                                         ACE_ENV_ARG_PARAMETER);
00270     }
00271 
00272     CORBA::Object_ptr
00273     ServantRetentionStrategyNonRetain::create_reference_with_id (
00274       const PortableServer::ObjectId &oid,
00275       const char *intf,
00276       CORBA::Short priority
00277       ACE_ENV_ARG_DECL)
00278         ACE_THROW_SPEC ((CORBA::SystemException))
00279     {
00280       // This operation creates an object reference that encapsulates the
00281       // specified Object Id and interface repository Id values. This
00282       // operation does not cause an activation to take place.  The
00283       // resulting reference may be passed to clients, so that subsequent
00284       // requests on those references will cause the object to be
00285       // activated if necessary, or the default servant used, depending on
00286       // the applicable policies.
00287 
00288       PortableServer::Servant servant = 0;
00289       PortableServer::ObjectId_var system_id;
00290 
00291       // Otherwise, it is the NON_RETAIN policy.  Therefore, user id
00292       // is the same as system id.
00293       PortableServer::ObjectId *sys_id;
00294       ACE_NEW_THROW_EX (sys_id,
00295                         PortableServer::ObjectId (oid),
00296                         CORBA::NO_MEMORY ());
00297       ACE_CHECK_RETURN (CORBA::Object::_nil ());
00298 
00299       system_id = sys_id;
00300 
00301       // Remember params for potentially invoking <key_to_object> later.
00302       this->poa_->key_to_object_params_.set (system_id,
00303                                              intf,
00304                                              servant,
00305                                              1,
00306                                              priority,
00307                                              true);
00308 
00309       return this->poa_->invoke_key_to_object_helper_i (intf,
00310                                                         oid
00311                                                         ACE_ENV_ARG_PARAMETER);
00312     }
00313 
00314     int
00315     ServantRetentionStrategyNonRetain::rebind_using_user_id_and_system_id (
00316       PortableServer::Servant /*servant*/,
00317       const PortableServer::ObjectId &/*user_id*/,
00318       const PortableServer::ObjectId &/*system_id*/,
00319       TAO::Portable_Server::Servant_Upcall &/*servant_upcall*/)
00320     {
00321       return -1;
00322     }
00323 
00324     CORBA::Boolean
00325     ServantRetentionStrategyNonRetain::servant_has_remaining_activations (
00326       PortableServer::Servant /*servant*/)
00327     {
00328       return false;
00329     }
00330 
00331     int
00332     ServantRetentionStrategyNonRetain::unbind_using_user_id (
00333       const PortableServer::ObjectId &/*user_id*/)
00334     {
00335       return 0;
00336     }
00337 
00338     ::PortableServer::ServantRetentionPolicyValue
00339     ServantRetentionStrategyNonRetain::type() const
00340     {
00341       return ::PortableServer::NON_RETAIN;
00342     }
00343 
00344   }
00345 }
00346 
00347 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 12:40:44 2006 for TAO_PortableServer by doxygen 1.3.6