POA_Helper.cpp

Go to the documentation of this file.
00001 // POA_Helper.cpp,v 1.10 2006/03/14 06:14:34 jtc Exp
00002 
00003 #include "orbsvcs/Notify/POA_Helper.h"
00004 
00005 #if ! defined (__ACE_INLINE__)
00006 #include "orbsvcs/Notify/POA_Helper.inl"
00007 #endif /* __ACE_INLINE__ */
00008 
00009 ACE_RCSID(RT_Notify, TAO_Notify_POA_Helper, "POA_Helper.cpp,v 1.10 2006/03/14 06:14:34 jtc Exp")
00010 
00011 #include "tao/debug.h"
00012 //#define DEBUG_LEVEL 10
00013 #ifndef DEBUG_LEVEL
00014 # define DEBUG_LEVEL TAO_debug_level
00015 #endif // DEBUG_LEVEL
00016 
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018 
00019 TAO_Notify_POA_Helper::TAO_Notify_POA_Helper (void)
00020 {
00021 }
00022 
00023 TAO_Notify_POA_Helper::~TAO_Notify_POA_Helper ()
00024 {
00025 }
00026 
00027 ACE_CString
00028 TAO_Notify_POA_Helper::get_unique_id (void)
00029 {
00030   /// Factory for generating unique ids for the POAs.
00031   static TAO_Notify_ID_Factory poa_id_factory;
00032 
00033   char buf[32];
00034   ACE_OS::itoa (poa_id_factory.id (), buf, 10);
00035 
00036   return ACE_CString (buf);
00037 }
00038 
00039 void
00040 TAO_Notify_POA_Helper::init (PortableServer::POA_ptr parent_poa, const char* poa_name ACE_ENV_ARG_DECL)
00041 {
00042   CORBA::PolicyList policy_list (2);
00043 
00044   this->set_policy (parent_poa, policy_list ACE_ENV_ARG_PARAMETER);
00045   ACE_CHECK;
00046 
00047   this->create_i (parent_poa, poa_name, policy_list ACE_ENV_ARG_PARAMETER);
00048 }
00049 
00050 void
00051 TAO_Notify_POA_Helper::init (PortableServer::POA_ptr parent_poa ACE_ENV_ARG_DECL)
00052 {
00053   ACE_CString child_poa_name = this->get_unique_id ();
00054 
00055   this->init (parent_poa, child_poa_name.c_str () ACE_ENV_ARG_PARAMETER);
00056 }
00057 
00058 void
00059 TAO_Notify_POA_Helper::set_policy (PortableServer::POA_ptr parent_poa, CORBA::PolicyList &policy_list ACE_ENV_ARG_DECL)
00060 {
00061   policy_list.length (2);
00062 
00063   policy_list[0] =
00064     parent_poa->create_id_uniqueness_policy (PortableServer::UNIQUE_ID
00065                                              ACE_ENV_ARG_PARAMETER);
00066   ACE_CHECK;
00067 
00068   policy_list[1] =
00069     parent_poa->create_id_assignment_policy (PortableServer::USER_ID
00070                                              ACE_ENV_ARG_PARAMETER);
00071   ACE_CHECK;
00072 }
00073 
00074 
00075 void
00076 TAO_Notify_POA_Helper::create_i (PortableServer::POA_ptr parent_poa, const char* poa_name, CORBA::PolicyList &policy_list ACE_ENV_ARG_DECL)
00077 {
00078   PortableServer::POAManager_var manager =
00079     parent_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
00080   ACE_CHECK;
00081 
00082   // Create the child POA.
00083   this->poa_ = parent_poa->create_POA (poa_name,
00084                                        manager.in (),
00085                                        policy_list
00086                                        ACE_ENV_ARG_PARAMETER);
00087   ACE_CHECK;
00088 
00089   if (DEBUG_LEVEL > 0)
00090     ACE_DEBUG ((LM_DEBUG, "Created POA : %s\n", this->poa_->the_name ()));
00091   /*
00092   // Destroy the policies
00093   for (CORBA::ULong index = 0; index < policy_list.length (); ++index)
00094     {
00095       policy_list[index]->destroy ();
00096     }
00097   */
00098 }
00099 
00100 PortableServer::ObjectId *
00101 TAO_Notify_POA_Helper::long_to_ObjectId (CORBA::Long id ACE_ENV_ARG_DECL) const
00102 {
00103   // Modified code from string_to_ObjectId ..
00104   //
00105 
00106   CORBA::ULong buffer_size = 4;
00107 
00108   // Create the buffer for the Id
00109   CORBA::Octet *buffer = PortableServer::ObjectId::allocbuf (buffer_size);
00110 
00111   // Copy the contents
00112   ACE_OS::memcpy (buffer, (char*)&id, buffer_size);
00113 
00114   // @@ Pradeep: TAO guarantees that Long is 4 bytes wide, but the
00115   // standard only guarantees that it is at least 4 bytes wide. You
00116   // may want to think about that....
00117 
00118   // Create and return a new ID
00119   PortableServer::ObjectId *obj_id = 0;
00120   ACE_NEW_THROW_EX (obj_id,
00121                     PortableServer::ObjectId (buffer_size,
00122                                               buffer_size,
00123                                               buffer,
00124                                               1),
00125                     CORBA::NO_MEMORY ());
00126 
00127   return obj_id;
00128 }
00129 
00130 CORBA::Object_ptr
00131 TAO_Notify_POA_Helper::activate (PortableServer::Servant servant, CORBA::Long& id ACE_ENV_ARG_DECL)
00132 {
00133   // Generate a new ID.
00134   id = this->id_factory_.id ();
00135 
00136   if (DEBUG_LEVEL > 0)
00137     ACE_DEBUG ((LM_DEBUG, "Activating object with id = %d in  POA : %s\n", id, this->poa_->the_name ()));
00138 
00139   // Convert CORBA::Long to ObjectId
00140   PortableServer::ObjectId_var oid =
00141     this->long_to_ObjectId (id ACE_ENV_ARG_PARAMETER);
00142   ACE_CHECK_RETURN (CORBA::Object::_nil ());
00143 
00144   poa_->activate_object_with_id (oid.in (),
00145                                  servant
00146                                  ACE_ENV_ARG_PARAMETER);
00147   ACE_CHECK_RETURN (CORBA::Object::_nil ());
00148 
00149   return poa_->id_to_reference (oid.in ()
00150                                 ACE_ENV_ARG_PARAMETER);
00151 }
00152 
00153 CORBA::Object_ptr
00154 TAO_Notify_POA_Helper::activate_with_id (PortableServer::Servant servant, CORBA::Long id ACE_ENV_ARG_DECL)
00155 {
00156   if (DEBUG_LEVEL > 0)
00157     ACE_DEBUG ((LM_DEBUG, "Activating object with existing id = %d in  POA : %s\n", id, this->poa_->the_name ()));
00158   this->id_factory_.set_last_used (id);
00159 
00160   // Convert CORBA::Long to ObjectId
00161   PortableServer::ObjectId_var oid =
00162     this->long_to_ObjectId (id ACE_ENV_ARG_PARAMETER);
00163   ACE_CHECK_RETURN (CORBA::Object::_nil ());
00164 
00165   poa_->activate_object_with_id (oid.in (),
00166                                  servant
00167                                  ACE_ENV_ARG_PARAMETER);
00168   ACE_CHECK_RETURN (CORBA::Object::_nil ());
00169 
00170   return poa_->id_to_reference (oid.in ()
00171                                 ACE_ENV_ARG_PARAMETER);
00172 }
00173 
00174 void
00175 TAO_Notify_POA_Helper::deactivate (CORBA::Long id ACE_ENV_ARG_DECL) const
00176 {
00177   // Convert CORBA::Long to ObjectId
00178   PortableServer::ObjectId_var oid =
00179     this->long_to_ObjectId (id ACE_ENV_ARG_PARAMETER);
00180   ACE_CHECK;
00181 
00182   poa_->deactivate_object (oid.in () ACE_ENV_ARG_PARAMETER);
00183 }
00184 
00185 CORBA::Object_ptr
00186 TAO_Notify_POA_Helper::id_to_reference (CORBA::Long id ACE_ENV_ARG_DECL) const
00187 {
00188   // Convert CORBA::Long to ObjectId
00189   PortableServer::ObjectId_var oid =
00190     this->long_to_ObjectId (id ACE_ENV_ARG_PARAMETER);
00191   ACE_CHECK_RETURN (CORBA::Object::_nil ());
00192 
00193   return poa_->id_to_reference (oid.in ()
00194                                 ACE_ENV_ARG_PARAMETER);
00195 }
00196 
00197 PortableServer::ServantBase *
00198 TAO_Notify_POA_Helper::reference_to_servant (CORBA::Object_ptr ptr ACE_ENV_ARG_DECL) const
00199 {
00200   return poa_->reference_to_servant (ptr ACE_ENV_ARG_PARAMETER);
00201 }
00202 
00203 CORBA::Object_ptr
00204 TAO_Notify_POA_Helper::servant_to_reference (
00205     PortableServer::ServantBase * servant  ACE_ENV_ARG_DECL) const
00206 {
00207   return poa_->servant_to_reference (servant ACE_ENV_ARG_PARAMETER);
00208 }
00209 
00210 
00211 void
00212 TAO_Notify_POA_Helper::destroy (ACE_ENV_SINGLE_ARG_DECL)
00213 {
00214   poa_->destroy (1,0 ACE_ENV_ARG_PARAMETER);
00215  // The <wait_for_completion> flag = 0
00216 }
00217 
00218 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 13:24:13 2006 for TAO_CosNotification by doxygen 1.3.6