📄 server_repository.cpp
字号:
}
else
{
ACE_CString filename = OPTIONS::instance ()->file_name ();
FILE *fp = ACE_OS::fopen (filename.c_str(), "r");
ACE_ASSERT(fp != 0);
ACE_TCHAR buffer[4096];
while (ACE_OS::fgets (buffer, sizeof (buffer), fp))
{
ACE_TCHAR* found = ACE_OS::strstr (buffer, POA_name.c_str ());
if (found != 0)
{
/// Found an entry for the POA_name. So, we can proceed.
this->handler_->get_running_information (POA_name,
location,
server_object_ior);
return 0;
}
}
/// If control comes here.. implies, there is no entry for the
/// POA_name.
return -1;
}
}
// Checks the starting_up_ variable in the Server_Info and
// returns the previous value or -1 if the POA_name wasn't found
int
Server_Repository::starting_up (const ACE_CString& POA_name,
int new_value)
{
int rmode = OPTIONS::instance ()->repository_mode ();
if (rmode != Options::REPO_XML_FILE)
{
Server_Info *server;
int retval = this->repository_.find (POA_name, server);
// Only fill in data if it was found
if (retval == 0)
{
ACE_ASSERT(server != 0);
retval = server->starting_up_ ? 1 : 0;
server->starting_up_ = new_value != 0;
}
return retval;
}
else
{
ACE_CString filename = OPTIONS::instance ()->file_name ();
FILE *fp = ACE_OS::fopen (filename.c_str(), "r");
ACE_ASSERT(fp != 0);
ACE_TCHAR buffer[4096];
while (ACE_OS::fgets (buffer, sizeof (buffer), fp))
{
ACE_TCHAR* found = ACE_OS::strstr (buffer, POA_name.c_str ());
if (found != 0)
{
int retval;
/// Found an entry for the POA_name. So, we can proceed.
this->handler_->get_startup_value (POA_name, retval);
this->handler_->set_startup_value (POA_name, new_value);
return retval;
}
}
/// If control comes here.. implies, there is no entry for the
/// POA_name.
return -1;
}
}
// Same as above but does not alter the value
int
Server_Repository::starting_up (const ACE_CString& POA_name)
{
int rmode = OPTIONS::instance ()->repository_mode ();
if (rmode != Options::REPO_XML_FILE)
{
Server_Info *server;
int retval = this->repository_.find (POA_name, server);
// Only fill in data if it was found
if (retval == 0)
{
ACE_ASSERT(server != 0);
retval = server->starting_up_ != 0;
}
return retval;
}
else
{
ACE_CString filename = OPTIONS::instance ()->file_name ();
FILE *fp = ACE_OS::fopen (filename.c_str(), "r");
ACE_ASSERT(fp != 0);
ACE_TCHAR buffer[4096];
while (ACE_OS::fgets (buffer, sizeof (buffer), fp))
{
ACE_TCHAR* found = ACE_OS::strstr (buffer, POA_name.c_str ());
if (found != 0)
{
int retval;
/// Found an entry for the POA_name. So, we can proceed.
this->handler_->get_startup_value (POA_name, retval);
return retval;
}
}
/// If control comes here.. implies, there is no entry for the
/// POA_name.
return -1;
}
}
// Removes the server from the Repository.
int
Server_Repository::remove (const ACE_CString& POA_name)
{
int rmode = OPTIONS::instance ()->repository_mode ();
if (rmode != Options::REPO_XML_FILE)
{
Repository_Configuration *config = OPTIONS::instance ()->config ();
ACE_ASSERT(config != 0);
// Remove the persistent configuration information
config->remove_section (this->servers_,
POA_name.c_str(),
1);
return this->repository_.unbind (POA_name);
}
else
{
ACE_CString filename = OPTIONS::instance ()->file_name ();
FILE *fp = ACE_OS::fopen (filename.c_str(), "r");
ACE_ASSERT(fp != 0);
/// Have a temporary file
CORBA::String_var temp_file = "temporary_file";
FILE *fp_temp = ACE_OS::fopen (temp_file.in (), "w");
ACE_ASSERT(fp_temp != 0);
ACE_TCHAR buffer[4096];
bool remove_section = false;
// int dtd_section = 0;
while (ACE_OS::fgets (buffer, sizeof (buffer), fp))
{
if (! remove_section)
{
ACE_TCHAR* found = ACE_OS::strstr (buffer, POA_name.c_str ());
if (found == 0)
{
ACE_OS::fprintf (fp_temp, buffer);
}
else
{
remove_section = true;
}
}
else
{
ACE_TCHAR* found = ACE_OS::strstr (buffer, "</SERVER_INFORMATION>");
if (found != 0)
remove_section = false;
}
}
ACE_OS::fclose (fp_temp);
ACE_OS::fclose (fp);
// Now copy the temporary file to the original file.
fp_temp = ACE_OS::fopen (temp_file.in (), "r");
ACE_ASSERT(fp_temp != 0);
fp = ACE_OS::fopen (filename.c_str(), "w");
ACE_ASSERT(fp != 0);
while (ACE_OS::fgets (buffer, sizeof (buffer), fp_temp))
{
ACE_OS::fprintf (fp, buffer);
}
ACE_OS::fclose (fp);
ACE_OS::fclose (fp_temp);
ACE_OS::unlink (temp_file.in ());
return 0;
}
/*
/// There is no support for DTD in the XML parser as of
/// now. Will uncomment this part when the support is
/// added.
if (dtd_section == 0)
{
found = ACE_OS::strstr (buffer, "]>");
if (found != 0)
{
dtd_section = 1;
remove_section = 0;
}
ACE_OS::fprintf (fp_temp,
buffer);
}
else
{
if (remove_section == 0)
{
found = ACE_OS::strstr (buffer, POA_name.c_str ());
if (found == 0)
{
ACE_OS::fprintf (fp_temp,
buffer);
}
else
{
remove_section = 1;
}
}
else
{
found = ACE_OS::strstr (buffer, "</SERVER_INFORMATION>");
if (found != 0)
remove_section = 0;
}
}
}
ACE_OS::fclose (fp_temp);
ACE_OS::fclose (fp);
// Now copy the temporary file to the original file.
fp_temp = ACE_OS::fopen (temp_file, "r");
fp = ACE_OS::fopen (filename, "w");
while (ACE_OS::fgets (buffer, 4096, fp_temp))
{
ACE_OS::fprintf (fp,
buffer);
}
ACE_OS::fclose (fp);
ACE_OS::fclose (fp_temp);
ACE_OS::unlink (temp_file);
}
*/
}
int
Server_Repository::write_to_xml (
const ACE_CString&,
const ACE_CString&,
const ACE_CString&,
const ImplementationRepository::EnvironmentList&,
const ACE_CString&,
const ImplementationRepository::ActivationMode&)
{
/*
ACE_TCHAR *filename = "trial.xml";
ACE_Configuration_Heap *heap = 0;
ACE_NEW_RETURN (heap, ACE_Configuration_Heap, -1);
if (heap->open (filename) != 0)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Error: Opening persistent heap file '%s'\n"),
filename));
}
heap->open_section (heap->root_section (),
"Trail_Servers",
1,
*/
return 0;
}
// Returns a new iterator that travels over the repository.
Server_Repository::HASH_IMR_MAP::ITERATOR *
Server_Repository::new_iterator (void)
{
HASH_IMR_MAP::ITERATOR *hash_iter = 0;
ACE_NEW_RETURN (hash_iter,
Server_Repository::HASH_IMR_MAP::ITERATOR (this->repository_),
0);
return hash_iter;
}
// Returns the number of entries in the repository.
size_t
Server_Repository::get_repository_size (void)
{
return this->repository_.current_size ();
}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Hash_Map_Entry<ACE_CString, Server_Info *>;
template class ACE_Hash_Map_Manager_Ex<ACE_CString, Server_Info *,ACE_Hash<ACE_CString>, ACE_Equal_To<ACE_CString>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Iterator_Base_Ex<ACE_CString, Server_Info *,ACE_Hash<ACE_CString>, ACE_Equal_To<ACE_CString>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Iterator_Ex<ACE_CString, Server_Info *,ACE_Hash<ACE_CString>, ACE_Equal_To<ACE_CString>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Reverse_Iterator_Ex<ACE_CString, Server_Info *,ACE_Hash<ACE_CString>, ACE_Equal_To<ACE_CString>, ACE_Null_Mutex>;
#if defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)
// This template is already defined in TAO, but Sun/CC 5.0 is broken
template class ACE_Equal_To<ACE_CString>;
#endif /* __SUNPRO_CC */
// Instantiate for ACE_WString because ACE_CString can be either
// ACE_CString or ACE_WString.
template class ACE_Equal_To<ACE_WString>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Hash_Map_Entry<ACE_CString, Server_Info *>
#pragma instantiate ACE_Hash_Map_Manager_Ex<ACE_CString, Server_Info *,ACE_Hash<ACE_CString>, ACE_Equal_To<ACE_CString>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<ACE_CString, Server_Info *,ACE_Hash<ACE_CString>, ACE_Equal_To<ACE_CString>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Iterator_Ex<ACE_CString, Server_Info *,ACE_Hash<ACE_CString>, ACE_Equal_To<ACE_CString>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<ACE_CString, Server_Info *,ACE_Hash<ACE_CString>, ACE_Equal_To<ACE_CString>, ACE_Null_Mutex>
#if defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)
// This template is already defined in TAO, but Sun/CC 5.0 is broken
#pragma instantiate ACE_Equal_To<ACE_CString>
#endif /* __SUNPRO_CC */
// Instantiate for ACE_WString because ACE_CString can be either
// ACE_CString or ACE_WString.
#pragma instantiate ACE_Equal_To<ACE_WString>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -