Go to the documentation of this file.00001
00002
00003 #include "orbsvcs/Notify/POA_Helper.h"
00004
00005 #if ! defined (__ACE_INLINE__)
00006 #include "orbsvcs/Notify/POA_Helper.inl"
00007 #endif
00008
00009 ACE_RCSID(RT_Notify, TAO_Notify_POA_Helper, "$Id: POA_Helper.cpp 85185 2009-04-28 08:53:12Z johnnyw $")
00010
00011 #include "tao/debug.h"
00012
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 (void)
00024 {
00025 }
00026
00027 ACE_CString
00028 TAO_Notify_POA_Helper::get_unique_id (void)
00029 {
00030
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)
00041 {
00042 CORBA::PolicyList policy_list (2);
00043
00044 this->set_policy (parent_poa, policy_list);
00045
00046 this->create_i (parent_poa, poa_name, policy_list);
00047 }
00048
00049 #if !defined (CORBA_E_MICRO)
00050 void
00051 TAO_Notify_POA_Helper::init_persistent (PortableServer::POA_ptr parent_poa, const char* poa_name)
00052 {
00053 CORBA::PolicyList policy_list (2);
00054
00055 this->set_persistent_policy (parent_poa, policy_list);
00056
00057 this->create_i (parent_poa, poa_name, policy_list);
00058 }
00059 #endif
00060
00061 void
00062 TAO_Notify_POA_Helper::init (PortableServer::POA_ptr parent_poa)
00063 {
00064 ACE_CString child_poa_name = this->get_unique_id ();
00065
00066 this->init (parent_poa, child_poa_name.c_str ());
00067 }
00068
00069 void
00070 TAO_Notify_POA_Helper::set_policy (PortableServer::POA_ptr parent_poa, CORBA::PolicyList &policy_list)
00071 {
00072 policy_list.length (2);
00073
00074 policy_list[0] =
00075 parent_poa->create_id_uniqueness_policy (PortableServer::UNIQUE_ID);
00076
00077 policy_list[1] =
00078 parent_poa->create_id_assignment_policy (PortableServer::USER_ID);
00079 }
00080
00081
00082 #if !defined (CORBA_E_MICRO)
00083 void
00084 TAO_Notify_POA_Helper::set_persistent_policy (PortableServer::POA_ptr parent_poa, CORBA::PolicyList &policy_list)
00085 {
00086 policy_list.length (2);
00087
00088 policy_list[0] =
00089 parent_poa->create_lifespan_policy (PortableServer::PERSISTENT);
00090
00091 policy_list[1] =
00092 parent_poa->create_id_assignment_policy (PortableServer::USER_ID);
00093 }
00094 #endif
00095
00096
00097 void
00098 TAO_Notify_POA_Helper::create_i (
00099 PortableServer::POA_ptr parent_poa,
00100 const char* poa_name,
00101 CORBA::PolicyList &policy_list)
00102 {
00103 PortableServer::POAManager_var manager =
00104 parent_poa->the_POAManager ();
00105
00106
00107 this->poa_ = parent_poa->create_POA (poa_name, manager.in (), policy_list);
00108
00109 if (DEBUG_LEVEL > 0)
00110 {
00111 CORBA::String_var the_name = this->poa_->the_name ();
00112 ACE_DEBUG ((LM_DEBUG, "Created POA : %C\n", the_name.in ()));
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122 }
00123
00124 PortableServer::ObjectId *
00125 TAO_Notify_POA_Helper::long_to_ObjectId (CORBA::Long id) const
00126 {
00127
00128
00129
00130 CORBA::ULong buffer_size = 4;
00131
00132
00133 CORBA::Octet *buffer = PortableServer::ObjectId::allocbuf (buffer_size);
00134
00135
00136 ACE_OS::memcpy (buffer, (char*)&id, buffer_size);
00137
00138
00139
00140
00141
00142
00143 PortableServer::ObjectId *obj_id = 0;
00144 ACE_NEW_THROW_EX (obj_id,
00145 PortableServer::ObjectId (buffer_size,
00146 buffer_size,
00147 buffer,
00148 1),
00149 CORBA::NO_MEMORY ());
00150
00151 return obj_id;
00152 }
00153
00154 CORBA::Object_ptr
00155 TAO_Notify_POA_Helper::activate (PortableServer::Servant servant, CORBA::Long& id)
00156 {
00157
00158 id = this->id_factory_.id ();
00159
00160 if (DEBUG_LEVEL > 0)
00161 {
00162 CORBA::String_var the_name = this->poa_->the_name ();
00163 ACE_DEBUG ((LM_DEBUG,
00164 ACE_TEXT ("(%P|%t) POA_Helper Activating object with ")
00165 ACE_TEXT ("id = %d in POA : %C\n"),
00166 id, the_name.in ()
00167 ));
00168 }
00169
00170
00171 PortableServer::ObjectId_var oid = this->long_to_ObjectId (id);
00172
00173 poa_->activate_object_with_id (oid.in (), servant);
00174
00175 return poa_->id_to_reference (oid.in ());
00176 }
00177
00178 CORBA::Object_ptr
00179 TAO_Notify_POA_Helper::activate_with_id (PortableServer::Servant servant, CORBA::Long id)
00180 {
00181 if (DEBUG_LEVEL > 0)
00182 {
00183 CORBA::String_var the_name = this->poa_->the_name ();
00184 ACE_DEBUG ((LM_DEBUG,
00185 ACE_TEXT ("(%P|%t) POA_Helper Activating object with ")
00186 ACE_TEXT ("existing id = %d in POA : %C\n"),
00187 id, the_name.in ()
00188 ));
00189 }
00190 this->id_factory_.set_last_used (id);
00191
00192
00193 PortableServer::ObjectId_var oid = this->long_to_ObjectId (id);
00194
00195 poa_->activate_object_with_id (oid.in (), servant);
00196
00197 return poa_->id_to_reference (oid.in ());
00198 }
00199
00200 void
00201 TAO_Notify_POA_Helper::deactivate (CORBA::Long id) const
00202 {
00203
00204 PortableServer::ObjectId_var oid = this->long_to_ObjectId (id);
00205
00206 if (DEBUG_LEVEL > 0)
00207 {
00208 CORBA::String_var the_name = this->poa_->the_name ();
00209 ACE_DEBUG ((LM_DEBUG,
00210 ACE_TEXT ("(%P|%t) POA_Helper Deactivating object with")
00211 ACE_TEXT ("id = %d in POA : %C\n"),
00212 id, the_name.in ()));
00213 }
00214 poa_->deactivate_object (oid.in ());
00215 }
00216
00217 CORBA::Object_ptr
00218 TAO_Notify_POA_Helper::id_to_reference (CORBA::Long id) const
00219 {
00220
00221 PortableServer::ObjectId_var oid = this->long_to_ObjectId (id);
00222
00223 return poa_->id_to_reference (oid.in ());
00224 }
00225
00226 PortableServer::ServantBase *
00227 TAO_Notify_POA_Helper::reference_to_servant (CORBA::Object_ptr ptr) const
00228 {
00229 return poa_->reference_to_servant (ptr);
00230 }
00231
00232 CORBA::Object_ptr
00233 TAO_Notify_POA_Helper::servant_to_reference (
00234 PortableServer::ServantBase * servant) const
00235 {
00236 return poa_->servant_to_reference (servant);
00237 }
00238
00239
00240 void
00241 TAO_Notify_POA_Helper::destroy (void)
00242 {
00243 poa_->destroy (true, false);
00244
00245 }
00246
00247 TAO_END_VERSIONED_NAMESPACE_DECL