summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-04-22 21:49:31 +0000
committerbrunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-04-22 21:49:31 +0000
commitdd9a3269604b1c07276f60bd27432ba65daab594 (patch)
tree7caeae9a3fcb072e73c2930ef65e1eb0c8a8a6f1
parent409b839bc14361b8b5cad747de7f046a1982b0ee (diff)
downloadATCD-dd9a3269604b1c07276f60bd27432ba65daab594.tar.gz
Renamed and Reorganized the Repository in order to comply more with
Advanced CORBA programming book.
-rw-r--r--TAO/orbsvcs/ImplRepo_Service/Repository.cpp257
-rw-r--r--TAO/orbsvcs/ImplRepo_Service/Repository.h152
2 files changed, 200 insertions, 209 deletions
diff --git a/TAO/orbsvcs/ImplRepo_Service/Repository.cpp b/TAO/orbsvcs/ImplRepo_Service/Repository.cpp
index 25fa333406a..48952cb727b 100644
--- a/TAO/orbsvcs/ImplRepo_Service/Repository.cpp
+++ b/TAO/orbsvcs/ImplRepo_Service/Repository.cpp
@@ -6,226 +6,165 @@
ACE_RCSID(ImplRepo_Service, Repository, "$Id$")
-Repository_Record::Repository_Record ()
-: comm_line (ACE::strnew ("")),
- wdir (ACE::strnew ("")),
- host (ACE::strnew ("")),
- port (0),
- ping_ior (ACE::strnew (""))
+
+
+// Initialize the command_line and working_dir.
+
+Server_Info::Server_Info (const ACE_TString POA_name,
+ const ACE_TString logical_server_name,
+ const ACE_TString startup_command,
+ const ACE_TString working_dir)
+: logical_server_name_ (logical_server_name),
+ POA_name_ (POA_name),
+ startup_command_ (startup_command),
+ working_dir_ (working_dir),
+ host_ (""),
+ port_ (0),
+ ping_ior_ ("")
{
// Nothing
}
-Repository_Record::Repository_Record (const Repository_Record &r)
-: comm_line (ACE::strnew (r.comm_line)),
- wdir (ACE::strnew (r.wdir)),
- host (ACE::strnew (r.host)),
- port (r.port),
- ping_ior (ACE::strnew (r.ping_ior))
+
+Server_Info::~Server_Info ()
{
// Nothing
}
+
+
+// Updates information that is relevant only when an instance
+// of the server is running.
-Repository_Record::Repository_Record (const ASYS_TCHAR *c,
- const ASYS_TCHAR *w,
- const ASYS_TCHAR *h,
- const unsigned short p,
- const ASYS_TCHAR *pi)
-: comm_line (ACE::strnew (c)),
- wdir (ACE::strnew (w)),
- host (ACE::strnew (h)),
- port (p),
- ping_ior (ACE::strnew (pi))
+void
+Server_Info::update_running_info (const ACE_TString host,
+ const unsigned short port,
+ const ACE_TString ping_ior)
{
+ this->host_ = host;
+ this->port_ = port;
+ this->ping_ior_ = ping_ior;
}
-Repository_Record::~Repository_Record ()
+
+// Returns startup information.
+
+void
+Server_Info::get_startup_info (ACE_TString &logical_server_name,
+ ACE_TString &startup_command,
+ ACE_TString &working_dir)
{
- delete [] this->comm_line;
- delete [] this->wdir;
- delete [] this->host;
- delete [] this->ping_ior;
+ logical_server_name = this->logical_server_name_;
+ startup_command = this->startup_command_;
+ working_dir = this->working_dir_;
}
-Repository_Record &
-Repository_Record::operator= (Repository_Record &r)
+
+// Returns information about a running instance.
+
+void
+Server_Info::get_running_info (ACE_TString &host,
+ unsigned short &port,
+ ACE_TString &ping_ior)
{
- if (this == &r)
- return *this;
-
- delete [] this->comm_line;
- delete [] this->wdir;
- delete [] this->host;
- delete [] this->ping_ior;
-
- this->comm_line = ACE::strnew (r.comm_line);
- this->wdir = ACE::strnew (r.wdir);
- this->host = ACE::strnew (r.host);
- this->port = r.port;
- this->ping_ior = ACE::strnew (r.ping_ior);
-
- return *this;
+ host = this->host_;
+ port = this->port_;
+ ping_ior = this->ping_ior_;
}
// Default Constructor
-Repository::Repository ()
+
+Server_Repository::Server_Repository ()
{
// Nothing
}
-// Add a new server to the Repository
-int
-Repository::add (ACE_TString key, const Repository_Record &rec)
-{
- if (OPTIONS::instance ()->debug () >= 2)
- ACE_DEBUG ((LM_DEBUG, "Repository: Adding key %s\n", key.c_str ()));
-
- Repository_Record *new_rec = new Repository_Record (rec);
- // Store the record in the repository.
- return this->repository_.bind (key, new_rec);
-}
+// Add a new server to the Repository
int
-Repository::update (ACE_TString key, const Repository_Record &rec)
+Server_Repository::add (const ACE_TString POA_name,
+ const ACE_TString logical_server_name,
+ const ACE_TString startup_command,
+ const ACE_TString working_dir)
{
- if (OPTIONS::instance ()->debug () >= 2)
- ACE_DEBUG ((LM_DEBUG, "Repository: Updating key %s\n", key.c_str ()));
+ Server_Info *new_server;
+ ACE_NEW_RETURN (new_server,
+ Server_Info (POA_name, logical_server_name, startup_command, working_dir),
+ -1);
- Repository_Record *new_rec = new Repository_Record (rec);
- Repository_Record *old_rec;
-
- // Store the record in the repository.
- int retval = this->repository_.rebind (key, new_rec, old_rec);
-
- if (retval == 1)
- delete old_rec;
-
- return retval >= 0 ? 0 : -1;
+ return this->repository_.bind (POA_name, new_server);
}
-// Removes the server from the Repository
-int
-Repository::remove (ACE_TString key)
-{
- if (OPTIONS::instance ()->debug () >= 2)
- ACE_DEBUG ((LM_DEBUG, "Repository: Removing key %s\n", key.c_str ()));
- return this->repository_.unbind (key.c_str ());
-}
+// Update the associated process information.
-// Find the key record in the Repository
-int
-Repository::resolve (ACE_TString key, Repository_Record &rec)
+int
+Server_Repository::update (const ACE_TString POA_name,
+ const ACE_TString host,
+ const unsigned short port,
+ const ACE_TString ping_ior)
{
- if (OPTIONS::instance ()->debug () >= 2)
- ACE_DEBUG ((LM_DEBUG, "Repository: Resolving key %s\n", key.c_str ()));
-
- Repository_Record *rep_rec;
- int retval = this->repository_.find (key, rep_rec);
+ Server_Info *server;
+ int retval = this->repository_.find (POA_name, server);
+ // Only fill in data if it was found
if (retval == 0)
- rec = *rep_rec;
+ server->update_running_info (host, port, ping_ior);
return retval;
}
-// = Accessor methods
-int
-Repository::get_comm_line (ACE_TString key, ASYS_TCHAR *&comm_line)
-{
- Repository_Record *rec;
- int retval = this->repository_.find (key, rec);
- if (retval == 0)
- {
- ACE_NEW_RETURN (comm_line, ASYS_TCHAR [ACE_OS::strlen (rec->comm_line) + 1], -1);
- ACE_OS::strcpy (comm_line, rec->comm_line);
- }
+// Returns information related to startup.
- return retval;
-}
-
-int
-Repository::get_wdir (ACE_TString key, ASYS_TCHAR *&wdir)
+int
+Server_Repository::get_startup_info (const ACE_TString POA_name,
+ ACE_TString &logical_server_name,
+ ACE_TString &startup_command,
+ ACE_TString &working_dir)
{
- Repository_Record *rec;
- int retval = this->repository_.find (key, rec);
+ Server_Info *server;
+ int retval = this->repository_.find (POA_name, server);
+ // Only fill in data if it was found
if (retval == 0)
- {
- ACE_NEW_RETURN (wdir, ASYS_TCHAR [ACE_OS::strlen (rec->wdir) + 1], -1);
- ACE_OS::strcpy (wdir, rec->wdir);
- }
+ server->get_startup_info (logical_server_name, startup_command, working_dir);
return retval;
}
+
-int
-Repository::get_hostport (ACE_TString key, ASYS_TCHAR *&host, unsigned short &port)
-{
- Repository_Record *rec;
- int retval = this->repository_.find (key, rec);
-
- if (retval == 0)
- {
- host = rec->host;
- port = rec->port;
- }
-
- return retval;
-}
+// Returns information related to a running copy.
-int
-Repository::get_ping_ior (ACE_TString key, ASYS_TCHAR *&ping_ior)
+int
+Server_Repository::get_running_info (const ACE_TString POA_name,
+ ACE_TString &host,
+ unsigned short &port,
+ ACE_TString &ping_ior)
{
- Repository_Record *rec;
- int retval = this->repository_.find (key, rec);
+ Server_Info *server;
+ int retval = this->repository_.find (POA_name, server);
+ // Only fill in data if it was found
if (retval == 0)
- {
- ACE_NEW_RETURN (ping_ior, ASYS_TCHAR [ACE_OS::strlen (rec->ping_ior) + 1], -1);
- ACE_OS::strcpy (ping_ior, rec->ping_ior);
- }
+ server->get_running_info (host, port, ping_ior);
return retval;
}
-void
-Repository::dump (void)
+
+// Removes the server from the Repository.
+
+int
+Server_Repository::remove (const ACE_TString POA_name)
{
- ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
-
- ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("Total size: %d\n"), this->repository_.total_size ()));
- ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("Current size: %d\n"), this->repository_.current_size ()));
- HASH_IR_ENTRY *entry;
- size_t i = 0;
-
- for (HASH_IR_ITER hash_iter (this->repository_);
- hash_iter.next (entry) != 0;
- hash_iter.advance ())
- {
- ACE_DEBUG ((LM_DEBUG,
- ASYS_TEXT ("Record %d has server name \"%s\"\n"),
- i,
- ((ACE_TString) entry->ext_id_).c_str ()));
- i++;
- }
-
- ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
+ return this->repository_.unbind (POA_name);
}
+
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
-template class ACE_Hash_Map_Entry<ACE_TString, Repository_Record *>;
-template class ACE_Hash_Map_Manager_Ex<ACE_TString, Repository_Record *, ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>;
-template class ACE_Hash_Map_Iterator_Base_Ex<ACE_TString, Repository_Record *, ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>;
-template class ACE_Hash_Map_Iterator_Ex<ACE_TString, Repository_Record *, ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Reverse_Iterator_Ex<ACE_TString, Repository_Record *, ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
-#pragma instantiate ACE_Hash_Map_Entry<ACE_TString, Repository_Record *>;
-#pragma instantiate ACE_Hash_Map_Manager_Ex<ACE_TString, Repository_Record *, ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>;
-#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<ACE_TString, Repository_Record *, ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>;
-#pragma instantiate ACE_Hash_Map_Iterator_Ex<ACE_TString, Repository_Record *, ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>;
#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<ACE_TString, Repository_Record *, ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>;
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
diff --git a/TAO/orbsvcs/ImplRepo_Service/Repository.h b/TAO/orbsvcs/ImplRepo_Service/Repository.h
index 8c68b7d8e46..7387be2d484 100644
--- a/TAO/orbsvcs/ImplRepo_Service/Repository.h
+++ b/TAO/orbsvcs/ImplRepo_Service/Repository.h
@@ -22,80 +22,132 @@
#include "ace/Hash_Map_Manager.h"
#include "ace/Synch.h"
+#include "ace/SString.h"
-#if defined (UNICODE)
-#define ACE_TString ACE_WString
-#else /* UNICODE */
-#define ACE_TString ACE_CString
-#endif /* UNICODE */
-struct Repository_Record
+class Server_Info
+ // = TITLE
+ // Information about IR registered servers.
+ //
+ // = DESCRIPTION
+ // Contains all the necessary information about the server including
+ // Information on how to start it up and where it is running.
{
- // Constructors
- Repository_Record ();
- Repository_Record (const Repository_Record &);
- Repository_Record (const ASYS_TCHAR *c,
- const ASYS_TCHAR *w,
- const ASYS_TCHAR *h,
- const unsigned short p,
- const ASYS_TCHAR *pi);
-
-
- // Destructor
- ~Repository_Record ();
-
- // Assignment Operator
- Repository_Record &operator= (Repository_Record &);
-
- // Fields
- ASYS_TCHAR *comm_line;
- ASYS_TCHAR *wdir;
- ASYS_TCHAR *host;
- unsigned short port;
- ASYS_TCHAR *ping_ior;
+public:
+ // = Constructors
+
+ Server_Info (const ACE_TString POA_name,
+ const ACE_TString logical_server_name,
+ const ACE_TString startup_command,
+ const ACE_TString working_dir);
+ // Initialize the command_line and working_dir.
+
+ // = Destructors
+
+ ~Server_Info ();
+ // The only destructor there is.
+
+ void update_running_info (const ACE_TString host,
+ const unsigned short port,
+ const ACE_TString ping_ior);
+ // Updates information that is relevant only when an instance
+ // of the server is running.
+
+ void get_startup_info (ACE_TString &logical_server_name,
+ ACE_TString &startup_command,
+ ACE_TString &working_dir);
+ // Returns startup information.
+
+ void get_running_info (ACE_TString &host,
+ unsigned short &port,
+ ACE_TString &ping_ior);
+ // Returns information about a running instance.
+
+ // @@ Does this belong here?
+ // int startup ();
+ // Starts up the server based on the information.
+ // Returns: 0 if successful
+ // -1 if there is no registration command (it has to be manually restarted)
+
+private:
+ ACE_TString logical_server_name_;
+ // Which server process this poa is grouped in.
+
+ ACE_TString POA_name_;
+ // The name of the POA.
+
+ ACE_TString startup_command_;
+ // The command line startup command (program and arguments).
+
+ ACE_TString working_dir_;
+ // The working directory.
+
+ ACE_TString host_;
+ // Current hostname used by the server.
+
+ unsigned short port_;
+ // Current port used by the server.
+
+ ACE_TString ping_ior_;
+ // IOR of the ping object in the server.
+
+ // No copying allowed.
+ void operator= (Server_Info &);
+ Server_Info (Server_Info &);
};
-class Repository
+class Server_Repository
+ // = TITLE
+ // Repository of Server_Infos.
+ //
+ // = DESCRIPTION
+ // Handles the storage, updating, and startup of servers.
{
public:
- Repository ();
+ Server_Repository ();
// Default Constructor
typedef ACE_Hash_Map_Entry<ACE_TString,
- Repository_Record *> HASH_IR_ENTRY;
+ Server_Info *> HASH_IR_ENTRY;
typedef ACE_Hash_Map_Manager_Ex<ACE_TString,
- Repository_Record *,
+ Server_Info *,
ACE_Hash<ACE_TString>,
ACE_Equal_To<ACE_TString>,
ACE_Null_Mutex> HASH_IR_MAP;
typedef ACE_Hash_Map_Iterator_Ex<ACE_TString,
- Repository_Record *,
+ Server_Info *,
ACE_Hash<ACE_TString>,
ACE_Equal_To<ACE_TString>,
ACE_Null_Mutex> HASH_IR_ITER;
- int add (ACE_TString key, const Repository_Record &rec);
+ int add (const ACE_TString POA_name,
+ const ACE_TString logical_server_name,
+ const ACE_TString startup_command,
+ const ACE_TString working_dir);
// Add a new server to the Repository
- int update (ACE_TString key, const Repository_Record &rec);
- // Updates an existing key with <rec>
+ int update (const ACE_TString POA_name,
+ const ACE_TString host,
+ const unsigned short port,
+ const ACE_TString ping_ior);
+ // Update the associated process information.
+
+ int get_startup_info (const ACE_TString POA_name,
+ ACE_TString &logical_server_name,
+ ACE_TString &startup_command,
+ ACE_TString &working_dir);
+ // Returns information related to startup.
- int remove (ACE_TString key);
- // Removes the server from the Repository
-
- int resolve (ACE_TString key, Repository_Record &rec);
- // Find the key record in the Repository
-
- // = Accessor methods
- int get_comm_line (ACE_TString key, ASYS_TCHAR *&comm_line);
- int get_wdir (ACE_TString key, ASYS_TCHAR *&wdir);
- int get_ping_ior (ACE_TString key, ASYS_TCHAR *&ping_ior);
- int get_hostport (ACE_TString key, ASYS_TCHAR *&host, unsigned short &port);
-
- // Dump method
- void dump (void);
+ int get_running_info (const ACE_TString POA_name,
+ ACE_TString &host,
+ unsigned short &port,
+ ACE_TString &ping_ior);
+ // Returns information related to a running copy.
+
+ int remove (const ACE_TString POA_name);
+ // Removes the server from the Repository.
private:
HASH_IR_MAP repository_;