summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Naming/Transient_Naming_Context.h
blob: 7ed16d5c5f2ecc95a7a7465ea9da5668b2371267 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* -*- C++ -*- */
// $Id$
// ============================================================================
//
// = LIBRARY
//    cos
//
// = FILENAME
//   Transient_Naming_Context.h
//
// = AUTHOR
//    Marina Spivak <marina@cs.wustl.edu>
//
// ============================================================================

#ifndef TAO_TRANSIENT_NAMING_CONTEXT_H
#define TAO_TRANSIENT_NAMING_CONTEXT_H

#include "Hash_Naming_Context.h"
#include "Entries.h"
#include "ace/Hash_Map_Manager.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

class TAO_ORBSVCS_Export TAO_Transient_Bindings_Map : public TAO_Bindings_Map
{
  // = TITLE
  //   Provides hash-table-based transient storage for name to object bindings in a
  //   Naming Context.
  //
  // = DESCRIPTION
  //   A thin wrapper on top of ACE_Hash_Map_Manager.  Supports
  //   TAO_Bindings_Map interface.  Used by TAO_Transient_Naming_Context.
public:

  typedef ACE_Hash_Map_Manager<TAO_ExtId, TAO_IntId, ACE_Null_Mutex> HASH_MAP;
  // Underlying data structure - typedef for ease of use.

  // = Initialization and termination methods.

  TAO_Transient_Bindings_Map (size_t hash_table_size);
  // Constructor.

  virtual ~TAO_Transient_Bindings_Map (void);
  // Destructor.

  // = Accessors.

  HASH_MAP &map (void);
  // Get a reference to the underlying hash map.

  size_t total_size (void);
  // Return the size of the underlying hash table.

  virtual size_t current_size (void);
  // Return current number of entries (name bindings) in the
  // underlying hash map.

  // = Name bindings manipulation methods.

  virtual int bind (const char *id,
                    const char *kind,
                    CORBA::Object_ptr obj,
                    CosNaming::BindingType type);
  // Add a binding with the specified parameters to the table.
  // Return 0 on success and -1 on failure, 1 if there already is a
  // binding with <id> and <kind>.

  virtual int rebind (const char *id,
                      const char *kind,
                      CORBA::Object_ptr obj,
                      CosNaming::BindingType type);
  // Overwrite a binding containing <id> and <kind> (or create a new
  // one if one doesn't exist) with the specified parameters.  Returns
  // -1 on failure.

  virtual int unbind (const char * id,
                      const char * kind);
  // Remove a binding containing <id> and <kind> from the table.
  // Return 0 on success and -1 on failure.

  virtual int find (const char * id,
                    const char * kind,
                    CORBA::Object_ptr & obj,
                    CosNaming::BindingType &type);
  // Find the binding containing <id> and <kind> in the table, and
  // pass binding's type and object back to the caller by reference.
  // Return 0 on success and -1 on failure.  Note: a 'duplicated' object
  // reference is assigned to <obj>, so the caller is responsible for
  // its deallocation.

private:

  int shared_bind (const char *id,
                   const char *kind,
                   CORBA::Object_ptr obj,
                   CosNaming::BindingType type,
                   int rebind);
  // Helper: factors common code from <bind> and <rebind>.

  HASH_MAP map_;
  // Hash map used for storage.
};

class TAO_ORBSVCS_Export TAO_Transient_Naming_Context : public TAO_Hash_Naming_Context
{
  // = TITLE
  //     This class plays a role of a 'ConcreteImplementor' in the
  //     Bridge pattern architecture of the CosNaming::NamingContext
  //     implementation.
  //
  // = DESCRIPTION
  //     This class provides a transient implementation of the
  //     NamingContext functionality, i.e., the state is not preserved
  //     across process boundaries.  Derives from
  //     TAO_Hash_Naming_Context and uses TAO_Transient_Bindings_Map to
  //     store name to object bindings.

public:

  typedef TAO_Transient_Bindings_Map::HASH_MAP HASH_MAP;
  // Underlying data structure - typedef for ease of use.

  // = Initialization and termination methods.

  TAO_Transient_Naming_Context (PortableServer::POA_ptr poa,
                                const char *poa_id,
                                size_t hash_table_size
                                = ACE_DEFAULT_MAP_SIZE);
  // Constructor.

  virtual ~TAO_Transient_Naming_Context (void);
  // Destructor.

  // = Methods not implemented in TAO_Hash_Naming_Context.

  virtual CosNaming::NamingContext_ptr new_context (CORBA::Environment &ACE_TRY_ENV);
  // This operation returns a new naming context implemented by the
  // same naming server in which the operation was invoked.  The
  // context is not bound.

  virtual void list (CORBA::ULong how_many,
                     CosNaming::BindingList_out &bl,
                     CosNaming::BindingIterator_out &bi,
                     CORBA::Environment &ACE_TRY_ENV);
  // Returns at most the requested number of bindings <how_many> in
  // <bl>.  If the naming context contains additional bindings, they
  // are returned with a BindingIterator.  In the naming context does
  // not contain any additional bindings <bi> returned as null.

protected:

  ACE_UINT32 counter_;
  // Counter used for generation of POA ids for children Naming
  // Contexts.

  TAO_Transient_Bindings_Map *transient_context_;
  // A pointer to the underlying data structure used to store name
  // bindings. While our superclass (TAO_Hash_Naming_Context) also
  // maintains a pointer to the data structure, keeping this pointer
  // around saves us from the need to downcast when invoking
  // non-virtual methods.
};

#endif /* TAO_TRANSIENT_NAMING_CONTEXT_H */