summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/ImplRepo_Service/Repository.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/orbsvcs/ImplRepo_Service/Repository.cpp')
-rw-r--r--TAO/orbsvcs/ImplRepo_Service/Repository.cpp261
1 files changed, 99 insertions, 162 deletions
diff --git a/TAO/orbsvcs/ImplRepo_Service/Repository.cpp b/TAO/orbsvcs/ImplRepo_Service/Repository.cpp
index 4f6d2303a82..37b9d4f73fe 100644
--- a/TAO/orbsvcs/ImplRepo_Service/Repository.cpp
+++ b/TAO/orbsvcs/ImplRepo_Service/Repository.cpp
@@ -1,153 +1,110 @@
/* -*- C++ -*- */
// $Id$
#include "Repository.h"
-#include "Options.h"
-#include "ace/ACE.h"
ACE_RCSID(ImplRepo_Service, Repository, "$Id$")
-Repository_Record::Repository_Record ()
-: comm_line (ACE::strnew ("")),
- env (ACE::strnew ("")),
- wdir (ACE::strnew ("")),
- host (ACE::strnew ("")),
- port (0),
- ping_ior (ACE::strnew (""))
-{
- // 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))
-{
- // Nothing
-}
-
-Repository_Record::Repository_Record (const ASYS_TCHAR *c,
- const ASYS_TCHAR *e,
- const ASYS_TCHAR *w,
- 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))
-{
-}
-
-Repository_Record::~Repository_Record ()
-{
- delete [] this->comm_line;
- delete [] this->env;
- delete [] this->wdir;
- delete [] this->host;
- delete [] this->ping_ior;
-}
-
-Repository_Record &
-Repository_Record::operator= (Repository_Record &r)
-{
- if (this == &r)
- return *this;
-
- delete [] this->comm_line;
- delete [] this->env;
- delete [] this->wdir;
- delete [] this->host;
- delete [] this->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;
-}
-
// Default Constructor
Repository::Repository ()
{
- // Nothing
+ this->repository_.open (ACE_Naming_Context::PROC_LOCAL);
}
// 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);
+Repository::add (const char *key, const Repository::Record &rec)
+{
+ char *temp; // Temporary string to hold all the variables in.
+
+ // Needs to be as long as all the lengths plus the separators and the
+ // null character (6) and then also the size that the host/port could
+ // take up.
+ ACE_NEW_RETURN (temp,
+ char [ACE_OS::strlen (rec.comm_line)
+ + ACE_OS::strlen (rec.env)
+ + ACE_OS::strlen (rec.wdir)
+ + ACE_OS::strlen (rec.ping_ior)
+ + ACE_OS::strlen (rec.host)
+ + 40],
+ -1);
+
+ // Put them all in a string
+ // Why use the extra space? Well, strtok doesn't like null strings
+ // because they show up as \n\n, which it skips past.
+ ACE_OS::sprintf (temp,
+ " %s\n %s\n %s\n %s\n %hu\n %s\n",
+ rec.comm_line,
+ rec.env,
+ rec.wdir,
+ rec.host,
+ rec.port,
+ rec.ping_ior);
// Store the record in the repository.
- return this->repository_.bind (key, new_rec);
+ int retval = this->repository_.bind (key, temp);
+
+ // Clean up and exit.
+ delete [] temp;
+
+ return retval;
}
int
-Repository::update (ACE_TString key, const Repository_Record &rec)
+Repository::update (const char *key, const Repository::Record &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;
+ this->remove (key);
+ return this->add (key, rec);
}
// Removes the server from the Repository
int
-Repository::remove (ACE_TString key)
+Repository::remove (const char *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 ());
+ return this->repository_.unbind (key);
}
// Find the key record in the Repository
int
-Repository::resolve (ACE_TString key, Repository_Record &rec)
+Repository::resolve (const char *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);
+ char *value = 0, *type = 0; // Temp variables needed for resolve
+ int retval = this->repository_.resolve (key, value, type);
if (retval == 0)
- rec = *rep_rec;
+ {
+ // +1 to get rid of the space
+ rec.comm_line = ACE::strnew (ACE_OS::strtok (value, "\n") + 1);
+ rec.env = ACE::strnew (ACE_OS::strtok (NULL, "\n") + 1);
+ rec.wdir = ACE::strnew (ACE_OS::strtok (NULL, "\n") + 1);
+ rec.host = ACE::strnew (ACE_OS::strtok (NULL, "\n") + 1);
+ ::sscanf (ACE_OS::strtok (NULL, "\n"), "%hu", &rec.port);
+ rec.ping_ior = ACE::strnew (ACE_OS::strtok (NULL, "\n") + 1);
+ }
+ else
+ {
+ retval = -1;
+ }
+
+ delete [] value;
+ delete [] type;
return retval;
}
// = Accessor methods
int
-Repository::get_comm_line (ACE_TString key, ASYS_TCHAR *&comm_line)
+Repository::get_comm_line (const char *key, char *&comm_line)
{
- Repository_Record *rec;
- int retval = this->repository_.find (key, rec);
+ Repository::Record rec;
+ int retval = this->resolve (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);
+ comm_line = rec.comm_line;
+ delete [] rec.env;
+ delete [] rec.wdir;
+ delete [] rec.ping_ior;
}
return retval;
@@ -155,60 +112,73 @@ Repository::get_comm_line (ACE_TString key, ASYS_TCHAR *&comm_line)
int
-Repository::get_env (ACE_TString key, ASYS_TCHAR *&env)
+Repository::get_env (const char *key, char *&env)
{
- Repository_Record *rec;
- int retval = this->repository_.find (key, rec);
+ Repository::Record rec;
+ int retval = this->resolve (key, rec);
if (retval == 0)
{
- ACE_NEW_RETURN (env, ASYS_TCHAR [ACE_OS::strlen (rec->env) + 1], -1);
- ACE_OS::strcpy (env, rec->env);
+ delete [] rec.comm_line;
+ env = rec.env;
+ delete [] rec.wdir;
+ delete [] rec.host;
+ delete [] rec.ping_ior;
}
return retval;
}
int
-Repository::get_wdir (ACE_TString key, ASYS_TCHAR *&wdir)
+Repository::get_wdir (const char *key, char *&wdir)
{
- Repository_Record *rec;
- int retval = this->repository_.find (key, rec);
+ Repository::Record rec;
+ int retval = this->resolve (key, rec);
if (retval == 0)
{
- ACE_NEW_RETURN (wdir, ASYS_TCHAR [ACE_OS::strlen (rec->wdir) + 1], -1);
- ACE_OS::strcpy (wdir, rec->wdir);
+ delete [] rec.comm_line;
+ delete [] rec.env;
+ wdir = rec.wdir;
+ delete [] rec.host;
+ delete [] rec.ping_ior;
}
return retval;
}
int
-Repository::get_hostport (ACE_TString key, ASYS_TCHAR *&host, unsigned short &port)
+Repository::get_hostport (const char *key, char *&host, unsigned short &port)
{
- Repository_Record *rec;
- int retval = this->repository_.find (key, rec);
+ Repository::Record rec;
+ int retval = this->resolve (key, rec);
if (retval == 0)
{
- host = rec->host;
- port = rec->port;
+ delete [] rec.comm_line;
+ delete [] rec.env;
+ delete [] rec.wdir;
+ host = rec.host;
+ port = rec.port;
+ delete [] rec.ping_ior;
}
return retval;
}
int
-Repository::get_ping_ior (ACE_TString key, ASYS_TCHAR *&ping_ior)
+Repository::get_ping_ior (const char *key, char *&ping_ior)
{
- Repository_Record *rec;
- int retval = this->repository_.find (key, rec);
+ Repository::Record rec;
+ int retval = this->resolve (key, rec);
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);
+ delete [] rec.comm_line;
+ delete [] rec.env;
+ delete [] rec.wdir;
+ delete [] rec.host;
+ ping_ior = rec.ping_ior;
}
return retval;
@@ -217,38 +187,5 @@ Repository::get_ping_ior (ACE_TString key, ASYS_TCHAR *&ping_ior)
void
Repository::dump (void)
{
- 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));
+ this->repository_.dump ();
}
-
-#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 */
-