summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Naming/Hash_Naming_Context.h
blob: b8bc60c8c0732cd4f89c3d46eb3f26c331072904 (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* -*- C++ -*- */
// $Id$
// ============================================================================
//
// = LIBRARY
//    cos
//
// = FILENAME
//   Hash_Naming_Context.h
//
// = AUTHOR
//    Marina Spivak <marina@cs.wustl.edu>
//
// ============================================================================

#ifndef TAO_HASH_NAMING_CONTEXT_H
#define TAO_HASH_NAMING_CONTEXT_H

#include "Naming_Context.h"
#include "Entries.h"

class TAO_ORBSVCS_Export TAO_Hash_Naming_Context : public TAO_Naming_Context_Impl
{
  // = TITLE
  //     This class plays a role of a 'ConcreteImplementor' in the
  //     Bridge pattern architecture of the Naming Service
  //     implementation.  This implementation of the NamingContext
  //     uses ACE_Hash_Map_Manager to store name bindings.
  //
  // = DESCRIPTION
  //     Extensive idl method descriptions can be found in Naming_Context.h

public:
  typedef ACE_Hash_Map_Manager<TAO_ExtId, TAO_IntId, ACE_Null_Mutex> HASH_MAP;

  // = Initialization and termination methods.
  TAO_Hash_Naming_Context (PortableServer::POA_ptr poa,
                           const char *poa_id,
                           size_t default_hash_table_size = ACE_DEFAULT_MAP_SIZE,
                           int root = 0);
  // Default constructor, which initializes the <size> of the table,
  // and sets a root flag.

  virtual ~TAO_Hash_Naming_Context (void);
  // destructor.

  // = CosNaming::NamingContext idl interface methods.
  virtual void bind (const CosNaming::Name &n,
                     CORBA::Object_ptr obj,
                     CORBA::Environment &IT_env);

  virtual void rebind (const CosNaming::Name &n,
                       CORBA::Object_ptr obj,
                       CORBA::Environment &IT_env);

  virtual void bind_context (const CosNaming::Name &n,
                             CosNaming::NamingContext_ptr nc,
                             CORBA::Environment &IT_env);

  virtual void rebind_context (const CosNaming::Name &n,
                               CosNaming::NamingContext_ptr nc,
                               CORBA::Environment &IT_env);

  virtual CORBA::Object_ptr resolve (const CosNaming::Name &n,
                                     CORBA::Environment &IT_env);

  virtual void unbind (const CosNaming::Name &n,
                       CORBA::Environment &IT_env);

  virtual CosNaming::NamingContext_ptr new_context (CORBA::Environment &IT_env);

  virtual CosNaming::NamingContext_ptr bind_new_context (const CosNaming::Name &n,
                                                         CORBA::Environment &IT_env);

  virtual void destroy (CORBA::Environment &IT_env);

  virtual void list (CORBA::ULong how_many,
                     CosNaming::BindingList_out &bl,
                     CosNaming::BindingIterator_out &bi,
                     CORBA::Environment &IT_env);

  virtual PortableServer::POA_ptr _default_POA (void);
  // Returns the Default POA of this Servant object

  void interface (TAO_Naming_Context *i);
  // Set the pointer to the 'interface' that forwards calls invoked by
  // CORBA clients to us.  See data member description for the reason
  // why we need this pointer.

  // = Helper functions.
  static int populate_binding (TAO_Hash_Naming_Context::HASH_MAP::ENTRY *hash_entry,
                               CosNaming::Binding &b);
  // Helper function used by TAO_Hash_Naming_Context and
  // TAO_BindingIterator: populate a binding <b> with info contained
  // in <hash_entry>.  Return 1 if everything went smoothly, 0 if an
  // allocation failed.

protected:
  // = These are the helper methods used by other methods.

  CosNaming::NamingContext_ptr get_context (const CosNaming::Name &name,
                                            CORBA::Environment &_env);
  // This is used by methods that need to resolve a compound name to
  // get the reference to the target context before performing the
  // actual operation (e.g. bind, unbind, etc.)  Takes a full name
  // (including the last component that doesn't need to be resolved)
  // Returns a pointer to the target context.

  PortableServer::POA_var poa_;
  // POA we are registered with.

  ACE_UINT32 counter_;
  // Counter used for generation of POA ids for objects created by
  // this context.

  ACE_CString poa_id_;
  // ID with which we are registered with <poa_>.

  HASH_MAP context_;
  // This implementation of <NamingContext> uses <ACE_Hash_Map> for
  // storage and manipulation of name-object bindings.

  int root_;
  // Flag indicating whether the context is a root or not.  It allows
  // to do things like have <destroy> be a no-op on root context.
  // Values: 1 indicates root, 0 indicates not a root.

  ACE_Lock *lock_;
  // Lock to serialize access to the underlying data structure.  This
  // is a lock adapter that hides the type of lock, which may be a
  // null lock if the ORB decides threading is not necessary.

  size_t hash_table_size_;
  // Hash table size.

  TAO_Naming_Context *interface_;
  // Pointer to the 'Abstraction' in the bridge pattern.  We need this
  // pointer so that we can clean up the Abstraction as necessary when <destroy>
  // method is called.  The reason we need to clean up as opposed to
  // the Abstraction itself is that we, the concrete implementation,  have the *knowledge* of how
  // to do this, e.g., we may have one servant serving many objects
  // and would not want to delete the servant in the <destroy> operation.
};

class TAO_ORBSVCS_Export TAO_Hash_Binding_Iterator :
  public POA_CosNaming::BindingIterator
{
  // = TITLE
  //     This class implements the <BindingIterator> interface that is
  //     part of the <CosNaming> idl module based on the Hash_Map
  //     implementation for CosNaming::NamingContext.
  //
  // = DESCRIPTION
  //     <TAO_Hash_Binding_Iterator> constructor expects a pointer to a
  //     dynamically allocated hash map iterator. Destructor
  //     deallocates hash map iterator.
public:
  // = Intialization and termination methods.
  TAO_Hash_Binding_Iterator (TAO_Hash_Naming_Context::HASH_MAP::ITERATOR *hash_iter,
                             PortableServer::POA_ptr poa,
                             ACE_Lock *lock);
  // Constructor.

  ~TAO_Hash_Binding_Iterator (void);
  // Destructor.

  // Returns the Default POA of this Servant object
  virtual PortableServer::POA_ptr _default_POA (CORBA::Environment &env);

  CORBA::Boolean next_one (CosNaming::Binding_out b,
                           CORBA::Environment &IT_env);
  // This operation returns the next binding.  If there are no more
  // bindings false is returned.

  CORBA::Boolean next_n (CORBA::ULong how_many,
                         CosNaming::BindingList_out bl,
                         CORBA::Environment &IT_env);
  // This operation returns at most the requested number of bindings.

  void destroy (CORBA::Environment &IT_env);
  // This operation destroys the iterator.

private:
  TAO_Hash_Naming_Context::HASH_MAP::ITERATOR *hash_iter_;
  // A pointer to the hash map iterator.

  ACE_Lock *lock_;
  // Lock passed on from <TAO_NamingContext> to serialize access to the
  // internal data structure.

  PortableServer::POA_var poa_;
  // Implement a different _default_POA()
};

#endif /* TAO_HASH_NAMING_CONTEXT_H */