diff options
author | brunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-04-14 00:31:01 +0000 |
---|---|---|
committer | brunsch <brunsch@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-04-14 00:31:01 +0000 |
commit | 9218c923e237280985f3bf9c4c7e8c00295d70ff (patch) | |
tree | 7dc17ff48b3e2bad6790a015c513b51429fa98fb | |
parent | dd98b87bdb17d9c24ca954e29ea21f945bab8688 (diff) | |
download | ATCD-9218c923e237280985f3bf9c4c7e8c00295d70ff.tar.gz |
New Repository Implementation
-rw-r--r-- | TAO/orbsvcs/ImplRepo_Service/Repository.cpp | 153 |
1 files changed, 79 insertions, 74 deletions
diff --git a/TAO/orbsvcs/ImplRepo_Service/Repository.cpp b/TAO/orbsvcs/ImplRepo_Service/Repository.cpp index de78d60c7d9..67460f8a000 100644 --- a/TAO/orbsvcs/ImplRepo_Service/Repository.cpp +++ b/TAO/orbsvcs/ImplRepo_Service/Repository.cpp @@ -1,47 +1,31 @@ /* -*- C++ -*- */ // $Id$ #include "Repository.h" +#include "Options.h" +#include "ace/ACE.h" ACE_RCSID(ImplRepo_Service, Repository, "$Id$") - ASYS_TCHAR *comm_line; - ASYS_TCHAR *env; - ASYS_TCHAR *wdir; - ASYS_TCHAR *host; - unsigned short port; - ASYS_TCHAR *ping_ior; - Repository_Record::Repository_Record () -: port (0) +: comm_line (ACE::strnew ("")), + env (ACE::strnew ("")), + wdir (ACE::strnew ("")), + host (ACE::strnew ("")), + port (0), + ping_ior (ACE::strnew ("")) { - ACE_NEW (this->comm_line, ASYS_TCHAR [1]); - ACE_NEW (this->env, ASYS_TCHAR [1]); - ACE_NEW (this->wdir, ASYS_TCHAR [1]); - ACE_NEW (this->host, ASYS_TCHAR [1]); - ACE_NEW (this->ping_ior, ASYS_TCHAR [1]); - - ACE_OS::strcpy (this->comm_line, ASYS_TEXT ("")); - ACE_OS::strcpy (this->env, ASYS_TEXT ("")); - ACE_OS::strcpy (this->wdir, ASYS_TEXT ("")); - ACE_OS::strcpy (this->host, ASYS_TEXT ("")); - ACE_OS::strcpy (this->ping_ior, ASYS_TEXT ("")); + // Nothing } Repository_Record::Repository_Record (const Repository_Record &r) +: comm_line (ACE::strnew (r.comm_line)), + env (ACE::strnew (r.env)), + wdir (ACE::strnew (r.wdir)), + host (ACE::strnew (r.host)), + port (r.port), + ping_ior (ACE::strnew (r.ping_ior)) { - ACE_NEW (this->comm_line, ASYS_TCHAR [ACE_OS::strlen (r.comm_line) + 1]); - ACE_NEW (this->env, ASYS_TCHAR [ACE_OS::strlen (r.env) + 1]); - ACE_NEW (this->wdir, ASYS_TCHAR [ACE_OS::strlen (r.wdir) + 1]); - ACE_NEW (this->host, ASYS_TCHAR [ACE_OS::strlen (r.host) + 1]); - ACE_NEW (this->ping_ior, ASYS_TCHAR [ACE_OS::strlen (r.ping_ior) + 1]); - - ACE_OS::strcpy (this->comm_line, r.comm_line); - ACE_OS::strcpy (this->env, r.env); - ACE_OS::strcpy (this->wdir, r.wdir); - ACE_OS::strcpy (this->host, r.host); - ACE_OS::strcpy (this->ping_ior, r.ping_ior); - - this->port = r.port; + // Nothing } Repository_Record::Repository_Record (const ASYS_TCHAR *c, @@ -50,20 +34,13 @@ Repository_Record::Repository_Record (const ASYS_TCHAR *c, const ASYS_TCHAR *h, const unsigned short p, const ASYS_TCHAR *pi) +: comm_line (ACE::strnew (c)), + env (ACE::strnew (e)), + wdir (ACE::strnew (w)), + host (ACE::strnew (h)), + port (p), + ping_ior (ACE::strnew (pi)) { - ACE_NEW (this->comm_line, ASYS_TCHAR [ACE_OS::strlen (c) + 1]); - ACE_NEW (this->env, ASYS_TCHAR [ACE_OS::strlen (e) + 1]); - ACE_NEW (this->wdir, ASYS_TCHAR [ACE_OS::strlen (w) + 1]); - ACE_NEW (this->host, ASYS_TCHAR [ACE_OS::strlen (h) + 1]); - ACE_NEW (this->ping_ior, ASYS_TCHAR [ACE_OS::strlen (pi) + 1]); - - ACE_OS::strcpy (this->comm_line, c); - ACE_OS::strcpy (this->env, e); - ACE_OS::strcpy (this->wdir, w); - ACE_OS::strcpy (this->host, h); - ACE_OS::strcpy (this->ping_ior, pi); - - this->port = p; } Repository_Record::~Repository_Record () @@ -87,20 +64,13 @@ Repository_Record::operator= (Repository_Record &r) delete [] this->host; delete [] this->ping_ior; - ACE_NEW_RETURN (this->comm_line, ASYS_TCHAR [ACE_OS::strlen (r.comm_line) + 1], *this); - ACE_NEW_RETURN (this->env, ASYS_TCHAR [ACE_OS::strlen (r.env) + 1], *this); - ACE_NEW_RETURN (this->wdir, ASYS_TCHAR [ACE_OS::strlen (r.wdir) + 1], *this); - ACE_NEW_RETURN (this->host, ASYS_TCHAR [ACE_OS::strlen (r.host) + 1], *this); - ACE_NEW_RETURN (this->ping_ior, ASYS_TCHAR [ACE_OS::strlen (r.ping_ior) + 1], *this); - - ACE_OS::strcpy (this->comm_line, r.comm_line); - ACE_OS::strcpy (this->env, r.env); - ACE_OS::strcpy (this->wdir, r.wdir); - ACE_OS::strcpy (this->host, r.host); - ACE_OS::strcpy (this->ping_ior, r.ping_ior); - + this->comm_line = ACE::strnew (r.comm_line); + this->env = ACE::strnew (r.env); + 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; } @@ -112,35 +82,52 @@ Repository::Repository () // Add a new server to the Repository int -Repository::add (const ASYS_TCHAR *key, const Repository_Record &rec) +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. - int retval = this->repository_.bind (key, new_rec); - - return retval; + return this->repository_.bind (key, new_rec); } int -Repository::update (const ASYS_TCHAR *key, const Repository_Record &rec) +Repository::update (ACE_TString key, const Repository_Record &rec) { - this->remove (key); - return this->add (key, rec); + if (OPTIONS::instance ()->debug () >= 2) + ACE_DEBUG ((LM_DEBUG, "Repository: Updating key %s\n", key.c_str ())); + + 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; } // Removes the server from the Repository int -Repository::remove (const ASYS_TCHAR *key) +Repository::remove (ACE_TString key) { - return this->repository_.unbind (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 ()); } // Find the key record in the Repository int -Repository::resolve (const ASYS_TCHAR *key, Repository_Record &rec) +Repository::resolve (ACE_TString key, Repository_Record &rec) { + 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); @@ -152,7 +139,7 @@ Repository::resolve (const ASYS_TCHAR *key, Repository_Record &rec) // = Accessor methods int -Repository::get_comm_line (const ASYS_TCHAR *key, ASYS_TCHAR *&comm_line) +Repository::get_comm_line (ACE_TString key, ASYS_TCHAR *&comm_line) { Repository_Record *rec; int retval = this->repository_.find (key, rec); @@ -168,7 +155,7 @@ Repository::get_comm_line (const ASYS_TCHAR *key, ASYS_TCHAR *&comm_line) int -Repository::get_env (const ASYS_TCHAR *key, ASYS_TCHAR *&env) +Repository::get_env (ACE_TString key, ASYS_TCHAR *&env) { Repository_Record *rec; int retval = this->repository_.find (key, rec); @@ -183,7 +170,7 @@ Repository::get_env (const ASYS_TCHAR *key, ASYS_TCHAR *&env) } int -Repository::get_wdir (const ASYS_TCHAR *key, ASYS_TCHAR *&wdir) +Repository::get_wdir (ACE_TString key, ASYS_TCHAR *&wdir) { Repository_Record *rec; int retval = this->repository_.find (key, rec); @@ -198,7 +185,7 @@ Repository::get_wdir (const ASYS_TCHAR *key, ASYS_TCHAR *&wdir) } int -Repository::get_hostport (const ASYS_TCHAR *key, ASYS_TCHAR *&host, unsigned short &port) +Repository::get_hostport (ACE_TString key, ASYS_TCHAR *&host, unsigned short &port) { Repository_Record *rec; int retval = this->repository_.find (key, rec); @@ -213,7 +200,7 @@ Repository::get_hostport (const ASYS_TCHAR *key, ASYS_TCHAR *&host, unsigned sho } int -Repository::get_ping_ior (const ASYS_TCHAR *key, ASYS_TCHAR *&ping_ior) +Repository::get_ping_ior (ACE_TString key, ASYS_TCHAR *&ping_ior) { Repository_Record *rec; int retval = this->repository_.find (key, rec); @@ -230,5 +217,23 @@ Repository::get_ping_ior (const ASYS_TCHAR *key, ASYS_TCHAR *&ping_ior) void Repository::dump (void) { - this->repository_.dump (); + 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)); } |