summaryrefslogtreecommitdiff
path: root/TAO/ORB_Services/Naming_Service/NS_CosNaming.h
blob: c347854ef8fe93e541d56175db8131f8e34e6379 (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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/* -*- C++ -*- */

// ============================================================================
//
// = LIBRARY
//    cos
// 
// = FILENAME
//   NS_CosNaming.h
//
// = AUTHOR
//    Marina Spivak <marina@cs.wustl.edu>
// 
// ============================================================================

#if !defined (NS_COSNAMING_H)
#define NS_COSNAMING_H

#include "CosNaming.hh"
#include "ace/Hash_Map_Manager.h"
#include "ace/Synch.h"
#include "ace/SString.h"

class NS_IntId 
  // = TITLE
  //     Stores information a context keeps for each bound name
  //     (object reference and the type of binding).
  //
  // = DESCRIPTION
  //
  //
  //
  //
{
public:
  // = Initialization and termination methods.
  NS_IntId (void);
  // default constructor.

  NS_IntId (CORBA::Object_ptr obj,
	    CosNaming::BindingType type = CosNaming::nobject);
  // constructor.
  
  NS_IntId (const NS_IntId & rhs);
  // copy constructor

  ~NS_IntId (void);
  // destructor 

  void operator= (const NS_IntId & rhs);
  // Assignment operator (does copy memory).

  CORBA::Object_ptr ref_;   
  // CORBA object reference of the bound object.

  CosNaming::BindingType type_;  
  // Indicator of whether the object is a NamingContext that should
  // participate in name resolution when compound names are used.
};

class NS_ExtId 
  // = TITLE
  //    Stores the name to which an object is bound.
  //
  // = DESCRIPTION
  //
  //
  //
  //
{
public:
  // = Initialization and termination methods.
  NS_ExtId (void);
  // default constructor.

  NS_ExtId (const char *id, 
	    const char *kind);
  // constructor.
  
  NS_ExtId (const NS_ExtId & rhs);
  // copy constructor

  ~NS_ExtId (void);
  // destructor 

  void operator= (const NS_ExtId & rhs);
  // Assignment operator (does copy memory).

  int operator== (const NS_ExtId &rhs) const;
  // Equality comparison operator (must match both id_ and kind_).

  int operator!= (const NS_ExtId &rhs) const;
  // Inequality comparison operator.

  u_long hash (void) const;
  // This class has to have a hash for use with ACE_Hash_Map_Manager.

  ACE_CString kind_;  
  // any information user wants to store (not used by Naming Service).

  ACE_CString id_;  
  // any information user wants to store (not used by Naming Service).
};

class NS_NamingContext 
  // = TITLE
  //     This class implements the NamingContext interface that is part of the 
  //     CosNaming idl module.  
  //
  // = DESCRIPTION
  //     Extensive comments can be found in the idl file. 
{
public:
  
  enum
  {
    NS_MAP_SIZE = 23
    // The size of hash map for a NS_NamingContext object.
  };

  typedef ACE_Hash_Map_Manager<NS_ExtId, NS_IntId, ACE_Null_Mutex> HASH_MAP;
         
  NS_NamingContext (void);
  // default constructor.

  ~NS_NamingContext (void);
  // destructor.

  void bind (const CosNaming::Name &n, 
	     CORBA::Object_ptr obj, 
	     CORBA::Environment &IT_env = CORBA::default_environment) 
     throw (CORBA::SystemException, 
	    CosNaming::NamingContext::NotFound, 
	    CosNaming::NamingContext::CannotProceed, 
	    CosNaming::NamingContext::InvalidName, 
	    CosNaming::NamingContext::AlreadyBound);
                
  void rebind (const CosNaming::Name &n, 
	       CORBA::Object_ptr obj, 
	       CORBA::Environment &IT_env = CORBA::default_environment) 
    throw (CORBA::SystemException, 
	   CosNaming::NamingContext::NotFound, 
	   CosNaming::NamingContext::CannotProceed, 
	   CosNaming::NamingContext::InvalidName);
                
  void bind_context (const CosNaming::Name &n, 
		     CosNaming::NamingContext_ptr nc, 
		     CORBA::Environment &IT_env = CORBA::default_environment) 
    throw (CORBA::SystemException, 
	   CosNaming::NamingContext::NotFound, 
	   CosNaming::NamingContext::CannotProceed, 
	   CosNaming::NamingContext::InvalidName, 
	   CosNaming::NamingContext::AlreadyBound);
                
  void rebind_context (const CosNaming::Name &n, 
		       CosNaming::NamingContext_ptr nc, 
		       CORBA::Environment &IT_env = CORBA::default_environment)
    throw (CORBA::SystemException, 
	   CosNaming::NamingContext::NotFound, 
	   CosNaming::NamingContext::CannotProceed, 
	   CosNaming::NamingContext::InvalidName);
                
  CORBA::Object_ptr resolve (const CosNaming::Name &n, 
			     CORBA::Environment &IT_env = CORBA::default_environment) 
    throw (CORBA::SystemException, 
	   CosNaming::NamingContext::NotFound, 
	   CosNaming::NamingContext::CannotProceed, 
	   CosNaming::NamingContext::InvalidName);
                
  void unbind (const CosNaming::Name &n, 
	       CORBA::Environment &IT_env = CORBA::default_environment) 
    throw (CORBA::SystemException, 
	   CosNaming::NamingContext::NotFound, 
	   CosNaming::NamingContext::CannotProceed, 
	   CosNaming::NamingContext::InvalidName);
                
  CosNaming::NamingContext_ptr new_context (CORBA::Environment &IT_env = CORBA::default_environment) 
    throw (CORBA::SystemException);
                
  CosNaming::NamingContext_ptr bind_new_context (const CosNaming::Name &n, 
						 CORBA::Environment &IT_env = CORBA::default_environment) 
    throw (CORBA::SystemException, 
	   CosNaming::NamingContext::NotFound, 
	   CosNaming::NamingContext::AlreadyBound, 
	   CosNaming::NamingContext::CannotProceed, 
	   CosNaming::NamingContext::InvalidName);
                
  void destroy (CORBA::Environment &IT_env = CORBA::default_environment) 
    throw (CORBA::SystemException, 
	   CosNaming::NamingContext::NotEmpty);
                
  void list (CORBA::ULong how_many, 
	     CosNaming::BindingList *&bl, 
	     CosNaming::BindingIterator_ptr &bi, 
	     CORBA::Environment &IT_env = CORBA::default_environment) 
    throw (CORBA::SystemException);


  void initialize (CosNaming::NamingContext_ptr tie_ref);
  // This method is called after context constructor.  It provides the
  // implementation object with the reference to its TIE object. (This
  // is needed for implementation of destroy method)

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

  CosNaming::NamingContext_ptr get_context (const CosNaming::Name &name)
       throw (CORBA::SystemException, 
	      CosNaming::NamingContext::NotFound, 
	      CosNaming::NamingContext::CannotProceed, 
	      CosNaming::NamingContext::AlreadyBound);
  // 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.

private:    
  
  HASH_MAP context_;
  // This implementation of NamingContext uses ACE thread-safe Hash
  // Map for storage and manipulation of name-object bindings.

  CosNaming::NamingContext_ptr tie_ref_;
  // Stores CORBA object reference to the TIE object this object
  // implements.  This is needed to implement the <destroy> method.
};

class NS_BindingIterator
  // = TITLE
  //     This class implements the BindingIterator interface 
  //     that is part of the CosNaming idl module.
  //
  // = DESCRIPTION
  //     NS_BindingIterator constructor expects a pointer to a
  //     DYNAMICALLY allocated hash map iterator. Destructor
  //     deallocates hash map iterator.
{
public:
  // = Intialization and termination methods.
  NS_BindingIterator (NS_NamingContext::HASH_MAP::ITERATOR *hash_iter);
  // constructor.

  ~NS_BindingIterator (void);
  // destructor.

  void initialize (CosNaming::BindingIterator_ptr tie_ref);
  // This method is called after the constructor.  It provides
  // implementation object with the reference to the TIE object it
  // implements.

  // Marina, please add comments.
  CORBA::Boolean next_one (CosNaming::Binding *&b, 
			   CORBA::Environment &IT_env = CORBA::default_environment) 
     throw (CORBA::SystemException);
 
  CORBA::Boolean next_n (CORBA::ULong how_many, 
			 CosNaming::BindingList *&bl, 
			 CORBA::Environment &IT_env = CORBA::default_environment) 
    throw (CORBA::SystemException);

    
  void destroy (CORBA::Environment &IT_env = CORBA::default_environment) 
    throw (CORBA::SystemException);

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

  CosNaming::BindingIterator_ptr tie_ref_;
  // A reference to the TIE object this object implements.  this is
  // used for implementation of <destroy>.
};

DEF_TIE_CosNaming_NamingContext (NS_NamingContext)
DEF_TIE_CosNaming_BindingIterator (NS_BindingIterator)

#endif /* NS_COSNAMING_H */