📄 pg_factoryregistry.cpp
字号:
ACE_THROW_SPEC ((CORBA::SystemException, PortableGroup::MemberNotFound))
{
METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory);
RoleInfo * role_info;
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,
ACE_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
));
ACE_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 ()
ACE_ENV_ARG_PARAMETER);
quit_state_ = DEACTIVATED;
}
}
METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory);
}
void TAO::PG_FactoryRegistry::unregister_factory_by_role (
const char * role
ACE_ENV_ARG_DECL
)
ACE_THROW_SPEC ((CORBA::SystemException))
{
METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory_by_role);
RoleInfo * role_info;
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 ()
ACE_ENV_ARG_PARAMETER);
quit_state_ = DEACTIVATED;
}
}
METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory_by_role);
}
void TAO::PG_FactoryRegistry::unregister_factory_by_location (
const PortableGroup::Location & location
ACE_ENV_ARG_DECL
)
ACE_THROW_SPEC ((CORBA::SystemException))
{
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(),
ACE_static_cast (int, nInfo),
role.c_str(),
ACE_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 ()
ACE_ENV_ARG_PARAMETER);
quit_state_ = DEACTIVATED;
}
}
METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory_by_location);
}
::PortableGroup::FactoryInfos * TAO::PG_FactoryRegistry::list_factories_by_role (
const char * role,
CORBA::String_out type_id
ACE_ENV_ARG_DECL
)
ACE_THROW_SPEC ((CORBA::SystemException))
{
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_DEFAULT_MINOR_CODE, CORBA::COMPLETED_NO));
ACE_CHECK_RETURN (0);
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();
}
::PortableGroup::FactoryInfos * TAO::PG_FactoryRegistry::list_factories_by_location (
const PortableGroup::Location & location
ACE_ENV_ARG_DECL
)
ACE_THROW_SPEC ((CORBA::SystemException))
{
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_DEFAULT_MINOR_CODE, CORBA::COMPLETED_NO));
ACE_CHECK_RETURN (0);
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();
}
//////////////////////////////
// Implementation methods
int TAO::PG_FactoryRegistry::write_ior_file(const char * outputFile, const char * ior)
{
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;
}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Hash_Map_Manager <
ACE_CString,
TAO::PG_FactoryRegistry::RoleInfo *,
TAO::PG_FactoryRegistry::MapMutex>;
template class ACE_Hash_Map_Entry <
ACE_CString,
TAO::PG_FactoryRegistry::RoleInfo *>;
template class ACE_Hash_Map_Iterator <
ACE_CString,
TAO::PG_FactoryRegistry::RoleInfo *,
TAO::PG_FactoryRegistry::MapMutex>;
template class ACE_Vector<ACE_CString>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
# pragma instantiate ACE_Hash_Map_Manager <
ACE_CString,
TAO::PG_FactoryRegistry::RoleInfo *,
TAO::PG_FactoryRegistry::MapMutex>
# pragma instantiate ACE_Hash_Map_Entry <
ACE_CString,
TAO::PG_FactoryRegistry::RoleInfo *>
# pragma instantiate ACE_Hash_Map_Iterator <
ACE_CString,
TAO::PG_FactoryRegistry::RoleInfo *,
TAO::PG_FactoryRegistry::MapMutex>
# pragma instantiate ACE_Vector<ACE_CString>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -