#include <PG_FactoryRegistry.h>
Implement the PortableGroup::FactoryRegistry interface Note FactoryRegistry is not part of the OMG standard. It was added as part of the TAO implementation of Fault Tolerant CORBA
Definition at line 54 of file PG_FactoryRegistry.h.
typedef ACE_Guard<TAO_SYNCH_MUTEX> TAO::PG_FactoryRegistry::InternalGuard [private] |
Definition at line 186 of file PG_FactoryRegistry.h.
typedef ACE_Null_Mutex TAO::PG_FactoryRegistry::MapMutex [private] |
Definition at line 64 of file PG_FactoryRegistry.h.
typedef ACE_Hash_Map_Manager<ACE_CString, RoleInfo *, MapMutex> TAO::PG_FactoryRegistry::RegistryType [private] |
Definition at line 65 of file PG_FactoryRegistry.h.
typedef ACE_Hash_Map_Entry<ACE_CString, RoleInfo *> TAO::PG_FactoryRegistry::RegistryType_Entry [private] |
Definition at line 66 of file PG_FactoryRegistry.h.
typedef ACE_Hash_Map_Iterator<ACE_CString, RoleInfo *, MapMutex> TAO::PG_FactoryRegistry::RegistryType_Iterator [private] |
Definition at line 67 of file PG_FactoryRegistry.h.
anonymous enum [private] |
State of the quit process
Definition at line 235 of file PG_FactoryRegistry.h.
{LIVE, DEACTIVATED, GONE} quit_state_;
TAO::PG_FactoryRegistry::PG_FactoryRegistry | ( | const char * | name = "FactoryRegistry" |
) |
Constructor.
Definition at line 44 of file PG_FactoryRegistry.cpp.
: identity_(name) , orb_ (0) , poa_ (0) , object_id_ (0) , this_obj_ (0) , ior_output_file_(0) , ns_name_("") , naming_context_(0) , this_name_(1) , quit_on_idle_(0) , quit_state_(LIVE) , linger_(0) { }
TAO::PG_FactoryRegistry::~PG_FactoryRegistry | ( | void | ) | [virtual] |
void TAO::PG_FactoryRegistry::_remove_ref | ( | void | ) | [virtual] |
Definition at line 115 of file PG_FactoryRegistry.cpp.
{ this->quit_state_ = GONE; }
int TAO::PG_FactoryRegistry::fini | ( | void | ) |
Prepare to exit.
Definition at line 139 of file PG_FactoryRegistry.cpp.
{ if (this->ior_output_file_ != 0) { ACE_OS::unlink (this->ior_output_file_); this->ior_output_file_ = 0; } if (this->ns_name_.length () != 0) { this->naming_context_->unbind (this_name_); this->ns_name_ = ""; } return 0; }
const char * TAO::PG_FactoryRegistry::identity | ( | ) | const |
Identify this object.
Definition at line 110 of file PG_FactoryRegistry.cpp.
int TAO::PG_FactoryRegistry::idle | ( | int & | result | ) |
Processing to happen when the ORB's event loop is idle.
result | is a place to return status to be returned by the process |
Definition at line 120 of file PG_FactoryRegistry.cpp.
{ result = 0; int quit = 0; if (this->quit_state_ == GONE) { if (linger_ < 2) { ++linger_; } else { quit = 1; } } return quit; }
int TAO::PG_FactoryRegistry::init | ( | CORBA::ORB_ptr | orb | ) |
Initialize this object.
orb | our ORB -- we keep var to it. |
Definition at line 176 of file PG_FactoryRegistry.cpp.
{ int result = 0; this->orb_ = CORBA::ORB::_duplicate (orb); // Use the ROOT POA for now CORBA::Object_var poa_object = this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA); if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")), -1); // Get the POA object. this->poa_ = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (this->poa_.in())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")), -1); } PortableServer::POAManager_var poa_manager = this->poa_->the_POAManager (); poa_manager->activate (); // Register with the POA. this->object_id_ = this->poa_->activate_object (this); // find my identity as a corba object this->this_obj_ = this->poa_->id_to_reference (object_id_.in ()); // and create a ior string this->ior_ = this->orb_->object_to_string (this->this_obj_.in ()); if (this->ior_output_file_ != 0) { this->identity_ = "file:"; this->identity_ += ACE_TEXT_ALWAYS_CHAR(this->ior_output_file_); result = write_ior_file (this->ior_output_file_, this->ior_.in ()); } if (this->ns_name_.length () != 0) { this->identity_ = "name:"; this->identity_ += this->ns_name_; CORBA::Object_var naming_obj = this->orb_->resolve_initial_references ("NameService"); if (CORBA::is_nil(naming_obj.in ())){ ACE_ERROR_RETURN ((LM_ERROR, "%T %n (%P|%t) Unable to find the Naming Service\n"), 1); } this->naming_context_ = CosNaming::NamingContext::_narrow (naming_obj.in ()); this->this_name_.length (1); this->this_name_[0].id = CORBA::string_dup (this->ns_name_.c_str ()); this->naming_context_->rebind (this->this_name_, this->this_obj_.in() //CORBA::Object::_duplicate(this_obj) ); } return result; }
void TAO::PG_FactoryRegistry::init | ( | CORBA::ORB_ptr | orb, | |
PortableServer::POA_ptr | poa | |||
) |
alternative init using designated poa
Definition at line 155 of file PG_FactoryRegistry.cpp.
{ ACE_ASSERT (CORBA::is_nil (this->orb_.in ())); ACE_ASSERT (CORBA::is_nil (this->poa_.in ())); this->orb_ = CORBA::ORB::_duplicate (orb); this->poa_ = PortableServer::POA::_duplicate (poa); ACE_ASSERT ( ! CORBA::is_nil (this->orb_.in ())); ACE_ASSERT ( ! CORBA::is_nil (this->poa_.in ())); // Register with the POA. this->object_id_ = this->poa_->activate_object (this); // find my identity as a corba object this->this_obj_ = this->poa_->id_to_reference (object_id_.in ()); // and create a ior string this->ior_ = this->orb_->object_to_string (this->this_obj_.in ()); }
PortableGroup::FactoryInfos * TAO::PG_FactoryRegistry::list_factories_by_location | ( | const PortableGroup::Location & | location | ) |
Definition at line 628 of file PG_FactoryRegistry.cpp.
{ METHOD_ENTRY(TAO::PG_FactoryRegistry::list_factories_by_location); ::PortableGroup::FactoryInfos_var result; ACE_NEW_THROW_EX (result, ::PortableGroup::FactoryInfos(this->registry_.current_size()), CORBA::NO_MEMORY (TAO::VMCID, CORBA::COMPLETED_NO)); size_t result_length = 0; // iterate through the registery for (RegistryType_Iterator it = this->registry_.begin(); it != this->registry_.end(); ++it) { RegistryType_Entry & entry = *it; RoleInfo * role_info = entry.int_id_; PortableGroup::FactoryInfos & found_infos = role_info->infos_; // iterate through the entry for this type int found = 0; size_t length = found_infos.length(); for (size_t nInfo = 0; !found && nInfo < length; ++nInfo) { PortableGroup::FactoryInfo & info = found_infos[nInfo]; if (info.the_location == location) { found = 1; result_length += 1; result->length(result_length); (*result)[result_length-1] = info; } } } METHOD_RETURN(TAO::PG_FactoryRegistry::list_factories_by_location) result._retn(); }
PortableGroup::FactoryInfos * TAO::PG_FactoryRegistry::list_factories_by_role | ( | const char * | role, | |
CORBA::String_out | type_id | |||
) |
Definition at line 597 of file PG_FactoryRegistry.cpp.
{ METHOD_ENTRY(TAO::PG_FactoryRegistry::list_factories_by_role); // allocate stucture to be returned. PortableGroup::FactoryInfos_var result = 0; ACE_NEW_THROW_EX (result, ::PortableGroup::FactoryInfos(), CORBA::NO_MEMORY (TAO::VMCID, CORBA::COMPLETED_NO)); RoleInfo * role_info = 0; if (this->registry_.find(role, role_info) == 0) { type_id = CORBA::string_dup(role_info->type_id_.c_str()); (*result) = role_info->infos_; } else { type_id = CORBA::string_dup(""); ACE_ERROR(( LM_INFO, "%s: list_factories_by_role: unknown role %s\n", this->identity_.c_str(), role )); } METHOD_RETURN(TAO::PG_FactoryRegistry::list_factories_by_role) result._retn(); }
int TAO::PG_FactoryRegistry::parse_args | ( | int | argc, | |
ACE_TCHAR * | argv[] | |||
) |
Parse command line arguments.
argc | traditional C argc | |
argv | traditional C argv |
Definition at line 67 of file PG_FactoryRegistry.cpp.
{ ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:n:q")); int c; while ((c = get_opts ()) != -1) { switch (c) { case 'o': { this->ior_output_file_ = get_opts.opt_arg (); break; } case 'n': { this->ns_name_ = ACE_TEXT_ALWAYS_CHAR(get_opts.opt_arg()); break; } case 'q': { this->quit_on_idle_ = 1; break; } case '?': // fall thru default: ACE_ERROR_RETURN ((LM_ERROR, "usage: %s" " -o <registry ior file>" " -n <name to use to register with name service>" " -q{uit on idle}" "\n", argv [0]), -1); break; } } // Indicates sucessful parsing of the command line return 0; }
PortableGroup::FactoryRegistry_ptr TAO::PG_FactoryRegistry::reference | ( | ) |
An object reference to the this object. Duplicated by the call so it may (and probably should) be assigned to a _var..
Definition at line 255 of file PG_FactoryRegistry.cpp.
void TAO::PG_FactoryRegistry::register_factory | ( | const char * | role, | |
const char * | type_id, | |||
const PortableGroup::FactoryInfo & | factory_info | |||
) | [virtual] |
Definition at line 282 of file PG_FactoryRegistry.cpp.
{ METHOD_ENTRY(TAO::PG_FactoryRegistry::register_factory); RoleInfo * role_info = 0; auto_ptr<RoleInfo> safe_entry; if (this->registry_.find(role, role_info) != 0) { ACE_DEBUG(( LM_DEBUG, "%s: adding new role: %s:%s\n", this->identity_.c_str(), role, type_id)); // Note the 5. It's a guess about the number of factories // that might exist for any particular role object. // todo: make it a parameter. ACE_NEW_THROW_EX (role_info, RoleInfo(5), CORBA::NO_MEMORY()); ACE_AUTO_PTR_RESET (safe_entry, role_info, RoleInfo); role_info->type_id_ = type_id; } else { if (role_info->type_id_ != type_id) { throw PortableGroup::TypeConflict(); } } PortableGroup::FactoryInfos & infos = role_info->infos_;; size_t length = infos.length(); for (size_t nInfo = 0; nInfo < length; ++nInfo) { PortableGroup::FactoryInfo & info = infos[nInfo]; if (info.the_location == factory_info.the_location) { ACE_ERROR(( LM_ERROR, "%s: Attempt to register duplicate location %s for role: %s\n" , this->identity_.c_str(), static_cast<const char *> (info.the_location[0].id), role)); throw PortableGroup::MemberAlreadyPresent(); } } infos.length(length + 1); infos[length] = factory_info; if (safe_entry.get() != 0) { this->registry_.bind(role, safe_entry.release()); } ACE_DEBUG(( LM_DEBUG, "%s: Added factory: [%d] %s@%s\n", this->identity_.c_str(), static_cast<int> (length + 1), role, static_cast<const char *> (factory_info.the_location[0].id) )); METHOD_RETURN(TAO::PG_FactoryRegistry::register_factory); }
void TAO::PG_FactoryRegistry::unregister_factory | ( | const char * | role, | |
const PortableGroup::Location & | location | |||
) | [virtual] |
Definition at line 351 of file PG_FactoryRegistry.cpp.
{ METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory); RoleInfo * role_info = 0; if (this->registry_.find(role, role_info) == 0) { PortableGroup::FactoryInfos & infos = role_info->infos_; int found = 0; size_t length = infos.length(); for (size_t nInfo = 0; !found && nInfo < length; ++nInfo) { PortableGroup::FactoryInfo & info = infos[nInfo]; if (info.the_location == location) { found = 1; ACE_ERROR(( LM_INFO, "%s: Unregistering factory %s@%s\n", this->identity_.c_str(), role, static_cast<const char *> (location[0].id) )); if (length > 1) { // if this is not the last entry if (nInfo + 1 < length) { // move last entry into newly-emptied slot infos[nInfo] = infos[length - 1]; nInfo = length -1; } infos.length(nInfo); } else { ACE_ASSERT ( length == 1 ); if (this->registry_.unbind (role) == 0) { ACE_DEBUG(( LM_INFO, "%s: No more factories registered for %s\n", this->identity_.c_str(), role )); delete role_info; } else { ACE_ERROR ((LM_ERROR, "%s: LOGIC ERROR AT " __FILE__ " (%d): Entry to be deleted disappeared\n", this->identity_.c_str(), __LINE__)); } } } } } else { ACE_ERROR(( LM_ERROR, "%s, Attempt to unregister factory for unknown role %s\n", this->identity_.c_str(), role )); throw PortableGroup::MemberNotFound(); } ////////////////////// // request complete // check quit-on-idle if (registry_.current_size() == 0 && quit_state_ == LIVE) { ACE_ERROR(( LM_INFO, "%s is idle\n", identity() )); if (quit_on_idle_) { this->poa_->deactivate_object (this->object_id_.in ()); quit_state_ = DEACTIVATED; } } METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory); }
void TAO::PG_FactoryRegistry::unregister_factory_by_location | ( | const PortableGroup::Location & | location | ) | [virtual] |
Definition at line 485 of file PG_FactoryRegistry.cpp.
{ METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory_by_location); //////////////////////////////////////////// // a vector of roles that need to be deleted. ACE_Vector<ACE_CString> emptyRoles; // iterate through the registery for (RegistryType_Iterator it = this->registry_.begin(); it != this->registry_.end(); ++it) { RegistryType_Entry & entry = *it; ACE_CString & role = entry.ext_id_; RoleInfo * role_info = entry.int_id_; PortableGroup::FactoryInfos & infos = role_info->infos_; // ACE_ERROR((LM_INFO, "unregister_factory_by_location: Checking role %s\n", role.c_str() )); int found = 0; size_t length = infos.length(); for (size_t nInfo = 0; !found && nInfo < length; ++nInfo) { PortableGroup::FactoryInfo & info = infos[nInfo]; if (info.the_location == location) { ACE_ERROR((LM_INFO, "%s: Unregister_factory_by_location: Removing: [%d] %s@%s\n", this->identity_.c_str(), static_cast<int> (nInfo), role.c_str(), static_cast<const char *> (location[0].id) )); found = 1; if (length > 1) { while (nInfo + 1 < length) { ACE_ERROR((LM_INFO, "%s: Unregister_factory_by_location: Move: [%d] %s to [%d]\n", this->identity_.c_str(), (int)nInfo + 1, role.c_str(), (int)nInfo )); infos[nInfo] = infos[nInfo + 1]; nInfo += 1; } ACE_ERROR((LM_INFO, "%s: unregister_factory_by_location: New length [%d] %s\n", this->identity_.c_str(), (int)nInfo, role.c_str() )); infos.length(nInfo); } else { ACE_ERROR((LM_INFO, "%s: Removed all entries for %s\n", this->identity_.c_str(), role.c_str() )); ACE_ASSERT ( length == 1 ); // remember entries to be deleted emptyRoles.push_back(entry.ext_id_); } } } } // now remove any roles that became empty for (size_t nRole = 0; nRole < emptyRoles.size(); ++nRole) { ACE_ERROR((LM_INFO, "%s: Remove role %s\n", this->identity_.c_str(), emptyRoles[nRole].c_str() )); RoleInfo * role_info; if (this->registry_.unbind(emptyRoles[nRole], role_info) == 0) { delete role_info; } else { ACE_ERROR ((LM_ERROR, "%s: LOGIC ERROR AT " __FILE__ " (%d): Role to be deleted disappeared\n", this->identity_.c_str(), __LINE__)); } } ////////////////////////// // If all types are gone... if (registry_.current_size() == 0 && quit_state_ == LIVE) { ACE_ERROR(( LM_INFO, "%s is idle\n", identity() )); if (quit_on_idle_) { this->poa_->deactivate_object (this->object_id_.in ()); quit_state_ = DEACTIVATED; } } METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory_by_location); }
void TAO::PG_FactoryRegistry::unregister_factory_by_role | ( | const char * | role | ) | [virtual] |
Definition at line 440 of file PG_FactoryRegistry.cpp.
{ METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory_by_role); RoleInfo * role_info = 0; if (this->registry_.unbind(role, role_info) == 0) { ACE_DEBUG(( LM_DEBUG, "%s: Unregistering all factories for role %s\n", this->identity_.c_str(), role )); // delete the entire set of factories for this location. delete role_info; } else { ACE_ERROR(( LM_INFO, "%s: Unregister_factory_by_role: unknown role: %s\n", this->identity_.c_str(), role )); } ///////////////////// // Function complete // check quit options if (registry_.current_size() == 0 && quit_state_ == LIVE) { ACE_ERROR(( LM_INFO, "%s is idle\n", identity() )); if (quit_on_idle_) { this->poa_->deactivate_object (this->object_id_.in ()); quit_state_ = DEACTIVATED; } } METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory_by_role); }
int TAO::PG_FactoryRegistry::write_ior_file | ( | const ACE_TCHAR * | outputFile, | |
const char * | ior | |||
) | [private] |
Write this factory's IOR to a file
Definition at line 671 of file PG_FactoryRegistry.cpp.
{ int result = -1; FILE* out = ACE_OS::fopen (outputFile, "w"); if (out) { ACE_OS::fprintf (out, "%s", ior); ACE_OS::fclose (out); result = 0; } else { ACE_ERROR ((LM_ERROR, "Open failed for %s\n", outputFile )); } return result; }
ACE_CString TAO::PG_FactoryRegistry::identity_ [private] |
A human-readable string to distinguish this from other Notifiers.
Definition at line 175 of file PG_FactoryRegistry.h.
TAO_SYNCH_MUTEX TAO::PG_FactoryRegistry::internals_ [private] |
Protect internal state. Mutex should be locked by corba methods, or by external (public) methods before calling implementation methods. Implementation methods should assume the mutex is locked if necessary.
Definition at line 185 of file PG_FactoryRegistry.h.
CORBA::String_var TAO::PG_FactoryRegistry::ior_ [private] |
IOR of this object as assigned by poa.
Definition at line 211 of file PG_FactoryRegistry.h.
const ACE_TCHAR* TAO::PG_FactoryRegistry::ior_output_file_ [private] |
A file to which the factory's IOR should be written.
Definition at line 216 of file PG_FactoryRegistry.h.
int TAO::PG_FactoryRegistry::linger_ [private] |
Definition at line 237 of file PG_FactoryRegistry.h.
CosNaming::NamingContext_var TAO::PG_FactoryRegistry::naming_context_ [private] |
Definition at line 223 of file PG_FactoryRegistry.h.
ACE_CString TAO::PG_FactoryRegistry::ns_name_ [private] |
A name to be used to register the factory with the name service.
Definition at line 221 of file PG_FactoryRegistry.h.
PortableServer::ObjectId_var TAO::PG_FactoryRegistry::object_id_ [private] |
The CORBA object id assigned to this object.
Definition at line 201 of file PG_FactoryRegistry.h.
CORBA::ORB_var TAO::PG_FactoryRegistry::orb_ [private] |
The orb
Definition at line 191 of file PG_FactoryRegistry.h.
PortableServer::POA_var TAO::PG_FactoryRegistry::poa_ [private] |
The POA used to activate this object.
Definition at line 196 of file PG_FactoryRegistry.h.
int TAO::PG_FactoryRegistry::quit_on_idle_ [private] |
Quit on idle flag.
Definition at line 230 of file PG_FactoryRegistry.h.
enum { ... } TAO::PG_FactoryRegistry::quit_state_ [private] |
State of the quit process
RegistryType TAO::PG_FactoryRegistry::registry_ [private] |
Definition at line 239 of file PG_FactoryRegistry.h.
CosNaming::Name TAO::PG_FactoryRegistry::this_name_ [private] |
Definition at line 225 of file PG_FactoryRegistry.h.
CORBA::Object_var TAO::PG_FactoryRegistry::this_obj_ [private] |
This objects identity as a CORBA object.
Definition at line 206 of file PG_FactoryRegistry.h.