Public Types | Public Member Functions | Private Member Functions | Private Attributes

ACE_Naming_Context Class Reference

Maintaining accesses Name Server Databases. Allows to add NameBindings, change them, remove them and resolve NameBindings. More...

#include <Naming_Context.h>

Inheritance diagram for ACE_Naming_Context:
Inheritance graph
[legend]
Collaboration diagram for ACE_Naming_Context:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Context_Scope_Type { PROC_LOCAL, NODE_LOCAL, NET_LOCAL }

Public Member Functions

 ACE_Naming_Context (void)
 "Do-nothing" constructor.
 ACE_Naming_Context (Context_Scope_Type scope_in, int light=0)
int open (Context_Scope_Type scope_in=ACE_Naming_Context::PROC_LOCAL, int light=0)
int close (void)
int close_down (void)
 Release all resources. Gets called by destructor and fini.
 ~ACE_Naming_Context (void)
virtual int init (int argc, ACE_TCHAR *argv[])
virtual int fini (void)
 Close down the test when dynamically unlinked.
virtual int info (ACE_TCHAR **strp, size_t length) const
 Returns information about this context.
ACE_Name_Optionsname_options (void)
 Returns the ACE_Name_Options associated with the Naming_Context.
int bind (const ACE_NS_WString &name_in, const ACE_NS_WString &value_in, const char *type_in="")
 Bind a new name to a naming context (Wide character strings).
int bind (const char *name_in, const char *value_in, const char *type_in="")
 Bind a new name to a naming context ( character strings).
int rebind (const ACE_NS_WString &name_in, const ACE_NS_WString &value_in, const char *type_in="")
int rebind (const char *name_in, const char *value_in, const char *type_in="")
int unbind (const ACE_NS_WString &name_in)
int unbind (const char *name_in)
int resolve (const ACE_NS_WString &name_in, ACE_NS_WString &value_out, char *&type_out)
int resolve (const char *name_in, ACE_NS_WString &value_out, char *&type_out)
int resolve (const char *name_in, char *&value_out, char *&type_out)
int list_names (ACE_PWSTRING_SET &set_out, const ACE_NS_WString &pattern_in)
int list_names (ACE_PWSTRING_SET &set_out, const char *pattern_in)
int list_values (ACE_PWSTRING_SET &set_out, const ACE_NS_WString &pattern_in)
int list_values (ACE_PWSTRING_SET &set_out, const char *pattern_in)
int list_types (ACE_PWSTRING_SET &set_out, const ACE_NS_WString &pattern_in)
int list_types (ACE_PWSTRING_SET &set_out, const char *pattern_in)
virtual int list_name_entries (ACE_BINDING_SET &set_out, const ACE_NS_WString &pattern_in)
virtual int list_name_entries (ACE_BINDING_SET &set_out, const char *pattern_in)
virtual int list_value_entries (ACE_BINDING_SET &set_out, const ACE_NS_WString &pattern_in)
virtual int list_value_entries (ACE_BINDING_SET &set_out, const char *pattern_in)
virtual int list_type_entries (ACE_BINDING_SET &set_out, const ACE_NS_WString &pattern_in)
virtual int list_type_entries (ACE_BINDING_SET &set_out, const char *pattern_in)
void dump (void)
 Dump the state of the object.

Private Member Functions

int local (void)
 1 if we're on the same local machine as the name server, else 0.

Private Attributes

ACE_Name_Optionsname_options_
 Keep track of the options such as database name etc per Naming Context.
ACE_Name_Spacename_space_
 Name space (can be either local or remote) dynamically bound.
ACE_TCHAR hostname_ [MAXHOSTNAMELEN+1]
 Holds the local hostname.
const ACE_TCHARnetnameserver_host_
 Holds name of net name server.
int netnameserver_port_
 Holds port number of the net name server.

Detailed Description

Maintaining accesses Name Server Databases. Allows to add NameBindings, change them, remove them and resolve NameBindings.

Manages a Naming Service . That represents a persistent string to string mapping for different scopes. The scope of a ACE_Naming_Context may be either local for the calling process (Note : A process is hereby not identified by it's pid, but by it's argv[0]. So different processes (in UNIX syntax) may access the same NameBindings), global for all processes running on one host or global for all processes on the net (that know the address of the net name server socket). Strings may be plain character strings or Wide character strings. A Name Binding consists of a name string (that's the key), a value string and an optional type string (no wide chars).

Definition at line 55 of file Naming_Context.h.


Member Enumeration Documentation

Enumerator:
PROC_LOCAL 

Name lookup is local to the process.

NODE_LOCAL 

Name lookup is local to the node (host).

NET_LOCAL 

Name lookup is local to the (sub)network.

Definition at line 58 of file Naming_Context.h.

    {
      /// Name lookup is local to the process.
      PROC_LOCAL,
      /// Name lookup is local to the node (host).
      NODE_LOCAL,
      /// Name lookup is local to the (sub)network.
      NET_LOCAL
    };


Constructor & Destructor Documentation

ACE_Naming_Context::ACE_Naming_Context ( void   ) 

"Do-nothing" constructor.

Definition at line 141 of file Naming_Context.cpp.

  : name_options_ (0),
    name_space_ (0)
{
  ACE_TRACE ("ACE_Naming_Context::ACE_Naming_Context");

  ACE_NEW (this->name_options_,
           ACE_Name_Options);
}

ACE_Naming_Context::ACE_Naming_Context ( Context_Scope_Type  scope_in,
int  light = 0 
)

Specifies the scope of this namespace, opens and memory-maps the associated file (if accessible) or contacts the dedicated name server process for NET_LOCAL namespace. Note that light specifies whether or not we want to use ACE_Lite_MMap_Memory_Pool. By default we use ACE_MMap_Memory_Pool.

Definition at line 151 of file Naming_Context.cpp.

  : name_options_ (0),
    name_space_ (0),
    netnameserver_host_ (0)
{
  ACE_TRACE ("ACE_Naming_Context::ACE_Naming_Context");

  ACE_NEW (this->name_options_,
           ACE_Name_Options);

  // Initialize.
  if (this->open (scope_in, lite) == -1)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("%p\n"),
                ACE_TEXT ("ACE_Naming_Context::ACE_Naming_Context")));
}

ACE_Naming_Context::~ACE_Naming_Context ( void   ) 

destructor, do some cleanup :TBD: last dtor should "compress" file

Definition at line 381 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::~ACE_Naming_Context");

  this->close_down ();
}


Member Function Documentation

int ACE_Naming_Context::bind ( const ACE_NS_WString name_in,
const ACE_NS_WString value_in,
const char *  type_in = "" 
)

Bind a new name to a naming context (Wide character strings).

Definition at line 176 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::bind");
  return this->name_space_->bind (name_in, value_in, type_in);
}

int ACE_Naming_Context::bind ( const char *  name_in,
const char *  value_in,
const char *  type_in = "" 
)

Bind a new name to a naming context ( character strings).

Definition at line 185 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::bind");
  return this->bind (ACE_NS_WString (name_in),
                     ACE_NS_WString (value_in),
                     type_in);
}

int ACE_Naming_Context::close ( void   ) 

Deletes the instance of Name Space. Must be called before switching name spaces.

Definition at line 131 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::close");

  delete this->name_space_;
  this->name_space_ = 0;

  return 0;
}

int ACE_Naming_Context::close_down ( void   ) 

Release all resources. Gets called by destructor and fini.

Definition at line 120 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::close_down");

  delete this->name_options_;
  this->name_options_ = 0;

  return this->close ();
}

void ACE_Naming_Context::dump ( void   ) 

Dump the state of the object.

Definition at line 389 of file Naming_Context.cpp.

{
#if defined (ACE_HAS_DUMP)
  ACE_TRACE ("ACE_Naming_Context::dump");
  this->name_space_->dump();
#endif /* ACE_HAS_DUMP */
}

int ACE_Naming_Context::fini ( void   )  [virtual]

Close down the test when dynamically unlinked.

Reimplemented from ACE_Shared_Object.

Definition at line 408 of file Naming_Context.cpp.

{
  if (ACE::debug ())
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("ACE_Naming_Context::fini\n")));
  this->close_down ();
  return 0;
}

int ACE_Naming_Context::info ( ACE_TCHAR **  strp,
size_t  length 
) const [virtual]

Returns information about this context.

Reimplemented from ACE_Shared_Object.

Definition at line 34 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::info");

  ACE_TCHAR buf[BUFSIZ];

  ACE_OS::sprintf (buf,
                   ACE_TEXT ("%s\t#%s\n"),
                   ACE_TEXT ("ACE_Naming_Context"),
                   ACE_TEXT ("Proxy for making calls to a Name Server"));

  if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0)
    return -1;
  else
    ACE_OS::strsncpy (*strp, buf, length);
  return static_cast<int> (ACE_OS::strlen (buf));
}

int ACE_Naming_Context::init ( int  argc,
ACE_TCHAR argv[] 
) [virtual]

Initialize name options and naming context when dynamically linked.

Reimplemented from ACE_Shared_Object.

Definition at line 398 of file Naming_Context.cpp.

{
  if (ACE::debug ())
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("ACE_Naming_Context::init\n")));
  this->name_options_->parse_args (argc, argv);
  return this->open (this->name_options_->context ());
}

int ACE_Naming_Context::list_name_entries ( ACE_BINDING_SET set_out,
const ACE_NS_WString pattern_in 
) [virtual]

Get a set of names matching a specified pattern (wchars). Matching means the names must begin with the pattern string. Returns the complete binding associated each pattern match.

Definition at line 328 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::list_name_entries");
  return this->name_space_->list_name_entries (set_out,
                                               pattern_in);
}

int ACE_Naming_Context::list_name_entries ( ACE_BINDING_SET set_out,
const char *  pattern_in 
) [virtual]

Get a set of names matching a specified pattern (wchars). Matching means the names must begin with the pattern string. Returns the complete binding associated each pattern match.

Definition at line 337 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::list_name_entries");
  return this->list_name_entries (set_out,
                                  ACE_NS_WString (pattern_in));
}

int ACE_Naming_Context::list_names ( ACE_PWSTRING_SET set_out,
const ACE_NS_WString pattern_in 
)

Get a set of names matching a specified pattern (wchars). Matching means the names must begin with the pattern string.

Definition at line 274 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::list_names");
  return this->name_space_->list_names (set_out,
                                        pattern_in);
}

int ACE_Naming_Context::list_names ( ACE_PWSTRING_SET set_out,
const char *  pattern_in 
)

Get a set of names matching a specified pattern (chars). Matching means the names must begin with the pattern string.

Definition at line 283 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::list_names");
  return this->list_names (set_out,
                           ACE_NS_WString (pattern_in));
}

int ACE_Naming_Context::list_type_entries ( ACE_BINDING_SET set_out,
const ACE_NS_WString pattern_in 
) [virtual]

Get a set of types matching a specified pattern (wchars). Matching means the types must begin with the pattern string. Returns the complete binding associated each pattern match.

Definition at line 364 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::list_type_entries");
  return this->name_space_->list_type_entries (set_out,
                                               pattern_in);
}

int ACE_Naming_Context::list_type_entries ( ACE_BINDING_SET set_out,
const char *  pattern_in 
) [virtual]

Get a set of types matching a specified pattern (wchars). Matching means the types must begin with the pattern string. Returns the complete binding associated each pattern match.

Definition at line 373 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::list_type_entries");
  return this->list_type_entries (set_out,
                                  ACE_NS_WString (pattern_in));
}

int ACE_Naming_Context::list_types ( ACE_PWSTRING_SET set_out,
const ACE_NS_WString pattern_in 
)

Get a set of types matching a specified pattern (wchars). Matching means the types must begin with the pattern string.

Definition at line 310 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::list_types");
  return this->name_space_->list_types (set_out,
                                        pattern_in);
}

int ACE_Naming_Context::list_types ( ACE_PWSTRING_SET set_out,
const char *  pattern_in 
)

Get a set of types matching a specified pattern (chars). Matching means the types must begin with the pattern string.

Definition at line 319 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::list_types");
  return this->list_types (set_out,
                           ACE_NS_WString (pattern_in));
}

int ACE_Naming_Context::list_value_entries ( ACE_BINDING_SET set_out,
const char *  pattern_in 
) [virtual]

Get a set of values matching a specified pattern (wchars). Matching means the values must begin with the pattern string. Returns the complete binding associated each pattern match.

Definition at line 355 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::list_value_entries");
  return this->list_value_entries (set_out,
                                   ACE_NS_WString (pattern_in));
}

int ACE_Naming_Context::list_value_entries ( ACE_BINDING_SET set_out,
const ACE_NS_WString pattern_in 
) [virtual]

Get a set of values matching a specified pattern (wchars). Matching means the values must begin with the pattern string. Returns the complete binding associated each pattern match.

Definition at line 346 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::list_value_entries");
  return this->name_space_->list_value_entries (set_out,
                                                pattern_in);
}

int ACE_Naming_Context::list_values ( ACE_PWSTRING_SET set_out,
const ACE_NS_WString pattern_in 
)

Get a set of values matching a specified pattern (wchars). Matching means the values must begin with the pattern string.

Definition at line 292 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::list_values");
  return this->name_space_->list_values (set_out,
                                         pattern_in);
}

int ACE_Naming_Context::list_values ( ACE_PWSTRING_SET set_out,
const char *  pattern_in 
)

Get a set of values matching a specified pattern (chars). Matching means the values must begin with the pattern string.

Definition at line 301 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::list_values");
  return this->list_values (set_out,
                            ACE_NS_WString (pattern_in));
}

int ACE_Naming_Context::local ( void   )  [private]

1 if we're on the same local machine as the name server, else 0.

Definition at line 54 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::local");
  return ACE_OS::strcmp (this->netnameserver_host_,
                         ACE_TEXT ("localhost")) == 0
    || ACE_OS::strcmp (this->netnameserver_host_,
                       this->hostname_) == 0;
}

ACE_Name_Options * ACE_Naming_Context::name_options ( void   ) 

Returns the ACE_Name_Options associated with the Naming_Context.

Definition at line 170 of file Naming_Context.cpp.

{
  return this->name_options_;
}

int ACE_Naming_Context::open ( Context_Scope_Type  scope_in = ACE_Naming_Context::PROC_LOCAL,
int  light = 0 
)

Specifies the scope of this namespace, opens and memory-maps the associated file (if accessible) or contacts the dedicated name server process for NET_LOCAL namespace. Note that light specifies whether or not we want to use ACE_Lite_MMap_Memory_Pool. By default we use ACE_MMap_Memory_Pool.

Definition at line 64 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::open");
  ACE_OS::hostname (this->hostname_,
                    (sizeof this->hostname_ / sizeof (ACE_TCHAR)));

  this->netnameserver_host_ =
    this->name_options_->nameserver_host ();
  this->netnameserver_port_ =
    this->name_options_->nameserver_port ();

  // Perform factory operation to select appropriate type of
  // Name_Space subclass.

#if (defined (ACE_WIN32) && defined (ACE_USES_WCHAR))
// This only works on Win32 platforms when ACE_USES_WCHAR is turned on

  if (this->name_options_->use_registry ())
    // Use ACE_Registry
    ACE_NEW_RETURN (this->name_space_,
                    ACE_Registry_Name_Space (this->name_options_),
                    -1);
#endif /* ACE_WIN32 && ACE_USES_WCHAR */
  if (!this->name_options_->use_registry ())
    {
      if (scope_in == ACE_Naming_Context::NET_LOCAL && this->local () == 0)
        {
          // Use NET_LOCAL name space, set up connection with remote server.
          ACE_NEW_RETURN (this->name_space_,
                          ACE_Remote_Name_Space (this->netnameserver_host_,
                                                 (u_short) this->netnameserver_port_),
                          -1);
        }
      else   // Use NODE_LOCAL or PROC_LOCAL name space.
        {
          if (lite)
            ACE_NEW_RETURN (this->name_space_,
                            LITE_LOCAL_NAME_SPACE (scope_in,
                                                   this->name_options_),
                            -1);
          else
            ACE_NEW_RETURN (this->name_space_,
                            LOCAL_NAME_SPACE (scope_in,
                                              this->name_options_),
                            -1);
        }
    }

  if (ACE_LOG_MSG->op_status () != 0 || this->name_space_ == 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("NAME_SPACE::NAME_SPACE\n")),
                      -1);
  return 0;
}

int ACE_Naming_Context::rebind ( const ACE_NS_WString name_in,
const ACE_NS_WString value_in,
const char *  type_in = "" 
)

Overwrite the value or type of an existing name in a ACE_Naming_Context or bind a new name to the context, if it didn't exist yet. (Wide charcter strings interface).

Definition at line 196 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::rebind");
  return this->name_space_->rebind (name_in,
                                    value_in,
                                    type_in);
}

int ACE_Naming_Context::rebind ( const char *  name_in,
const char *  value_in,
const char *  type_in = "" 
)

Overwrite the value or type of an existing name in a ACE_Naming_Context or bind a new name to the context, if it didn't exist yet. ( charcter strings interface)

Definition at line 207 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::rebind");
  return rebind (ACE_NS_WString (name_in),
                 ACE_NS_WString (value_in),
                 type_in);
}

int ACE_Naming_Context::resolve ( const char *  name_in,
ACE_NS_WString value_out,
char *&  type_out 
)

Get value and type of a given name binding (Wide chars output). The caller is responsible for deleting both value_out and type_out!

Definition at line 229 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::resolve");
  return this->resolve (ACE_NS_WString (name_in),
                        value_out,
                        type_out);
}

int ACE_Naming_Context::resolve ( const char *  name_in,
char *&  value_out,
char *&  type_out 
)

Get value and type of a given name binding ( chars ). The caller is responsible for deleting both value_out and type_out!

Definition at line 240 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::resolve");
  ACE_NS_WString val_str;

  if (this->resolve (ACE_NS_WString (name_in),
                     val_str,
                     type_out) == -1)
    return -1;

  // Note that <char_rep> *allocates* the memory!  Thus, caller is
  // responsible for deleting it!
  value_out = val_str.char_rep ();

  return value_out == 0 ? -1 : 0;
}

int ACE_Naming_Context::resolve ( const ACE_NS_WString name_in,
ACE_NS_WString value_out,
char *&  type_out 
)

Get value and type of a given name binding (Wide chars). The caller is responsible for deleting both value_out> and type_out!

Definition at line 218 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::resolve");
  return this->name_space_->resolve (name_in,
                                     value_out,
                                     type_out);
}

int ACE_Naming_Context::unbind ( const char *  name_in  ) 

Delete a name from a ACE_Naming_Context (character strings interface).

Definition at line 267 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::unbind");
  return this->unbind (ACE_NS_WString (name_in));
}

int ACE_Naming_Context::unbind ( const ACE_NS_WString name_in  ) 

Delete a name from a ACE_Naming_Context (Wide charcter strings Interface).

Definition at line 260 of file Naming_Context.cpp.

{
  ACE_TRACE ("ACE_Naming_Context::unbind");
  return this->name_space_->unbind (name_in);
}


Member Data Documentation

ACE_TCHAR ACE_Naming_Context::hostname_[MAXHOSTNAMELEN+1] [private]

Holds the local hostname.

Definition at line 262 of file Naming_Context.h.

Keep track of the options such as database name etc per Naming Context.

Definition at line 256 of file Naming_Context.h.

Name space (can be either local or remote) dynamically bound.

Definition at line 259 of file Naming_Context.h.

Holds name of net name server.

Definition at line 265 of file Naming_Context.h.

Holds port number of the net name server.

Definition at line 268 of file Naming_Context.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines