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
|
// This may look like C, but it's really -*- C++ -*-
//
// ============================================================================
//
// = LIBRARY
// TAO
//
// = FILENAME
// optable.h
//
// = AUTHOR
// Aniruddha Gokhale
//
// ============================================================================
#if !defined (TAO_OPTABLE_H)
#define TAO_OPTABLE_H
struct TAO_operation_db_entry
// = TITLE
// Define a table entry that holds an operation name and its
// corresponding skeleton. A table of such entries is used to
// initialize the different lookup strategies.
{
CORBA::String opname_;
// operation name
TAO_Skeleton skel_ptr_;
// skeleton pointer
};
class TAO_Export TAO_Operation_Table
// = TITLE
// Abstract class for maintaining and lookup of CORBA IDL
// operation names.
{
public:
virtual int find (const CORBA::String &opname,
TAO_Skeleton &skelfunc) = 0;
// Uses <{opname}> to look up the skeleton function and pass it back
// in <{skelfunc}>. Returns non-negative integer on success, or -1
// on failure.
virtual int bind (const CORBA::String &opname,
const TAO_Skeleton skel_ptr) = 0;
// Associate the skeleton <{skel_ptr}> with an operation named
// <{opname}>. Returns -1 on failure, 0 on success, 1 on duplicate.
virtual ~TAO_Operation_Table (void);
};
// Dynamic hashing. We use template specialization here to use const
// char* as the external ID. The template specialization is needed
// since the "hash" method is not defined on type "char *".
typedef ACE_Hash_Map_Manager<const char *, TAO_Skeleton, ACE_SYNCH_NULL_MUTEX>
OP_MAP_MANAGER;
class TAO_Export TAO_Dynamic_Hash_OpTable : public TAO_Operation_Table
// = TITLE
// Dynamic Hashing scheme for CORBA IDL operation name lookup
{
public:
TAO_Dynamic_Hash_OpTable (const TAO_operation_db_entry *db,
CORBA::ULong dbsize,
CORBA::ULong hashtblsize = 0);
// Constructor.
// Initialize the dynamic hash operation table with a database of operation
// names. The hash table size may be different from the size of the
// database. Hence we use the third argument to specify the size of the
// internal hash table.
~TAO_Dynamic_Hash_OpTable (void);
// destructor
virtual int bind (const CORBA::String &opname,
const TAO_Skeleton skel_ptr);
// Associate the skeleton <{skel_ptr}> with an operation named
// <{opname}>. Returns -1 on failure, 0 on success, 1 on duplicate.
virtual int find (const CORBA::String &opname,
TAO_Skeleton &skelfunc);
// Uses <{opname}> to look up the skeleton function and pass it back
// in <{skelfunc}>. Returns non-negative integer on success, or -1
// on failure.
private:
OP_MAP_MANAGER hash_;
// The hash table data structure
};
struct TAO_Export TAO_Linear_OpTable_Entry
// = TITLE
// Table entry for linear search lookup strategy.
{
CORBA::String opname_;
// holds the operation name
TAO_Skeleton skel_ptr_;
// holds a pointer to the skeleton corresponding to the operation name
TAO_Linear_OpTable_Entry (void);
// constructor.
~TAO_Linear_OpTable_Entry (void);
// destructor
};
class TAO_Export TAO_Linear_OpTable : public TAO_Operation_Table
{
// = TITLE
// Operation table lookup strategy based on
// linear search. Not efficient, but it works.
public:
TAO_Linear_OpTable (const TAO_operation_db_entry *db, CORBA::ULong dbsize);
// constructor.
// Initialize the linear search operation table with a database of operation
// names
~TAO_Linear_OpTable (void);
// destructor
virtual int find (const CORBA::String &opname,
TAO_Skeleton &skel_ptr);
// Uses <{opname}> to look up the skeleton function and pass it back
// in <{skelfunc}>. Returns non-negative integer on success, or -1
// on failure.
virtual int bind (const CORBA::String &opname,
const TAO_Skeleton skelptr);
// Associate the skeleton <{skel_ptr}> with an operation named
// <{opname}>. Returns -1 on failure, 0 on success, 1 on duplicate.
private:
CORBA::ULong next_;
// keeps track of the next available slot to be filled.
CORBA::ULong tablesize_;
// size of the internal table
TAO_Linear_OpTable_Entry *tbl_;
// the table itself
};
struct TAO_Export TAO_Active_Demux_OpTable_Entry
// = TITLE
// Active Demux lookup table entry.
{
TAO_Skeleton skel_ptr_;
// skeleton pointer corresponding to the index
TAO_Active_Demux_OpTable_Entry (void);
// constructor
~TAO_Active_Demux_OpTable_Entry (void);
// destructor
};
class TAO_Export TAO_Active_Demux_OpTable : public TAO_Operation_Table
// = TITLE
// Implements the active demultiplexed lookup strategy. The key is
// assumed to provide an index directly into the internal table.
{
public:
TAO_Active_Demux_OpTable (const TAO_operation_db_entry *db, CORBA::ULong dbsize);
// Constructor
// Initializes the internal table with the database of operations
~TAO_Active_Demux_OpTable (void);
// destructor
virtual int find (const CORBA::String &opname,
TAO_Skeleton &skel_ptr);
// Uses <{opname}> to look up the skeleton function and pass it back
// in <{skelfunc}>. Returns non-negative integer on success, or -1
// on failure.
virtual int bind (const CORBA::String &opname,
const TAO_Skeleton skelptr);
// Associate the skeleton <{skel_ptr}> with an operation named
// <{opname}>. Returns -1 on failure, 0 on success, 1 on duplicate.
private:
CORBA::ULong next_;
// the next available free slot
CORBA::ULong tablesize_;
// size of the internal table
TAO_Active_Demux_OpTable_Entry *tbl_;
// internal lookup table
};
class TAO_Export TAO_Perfect_Hash_OpTable : public TAO_Operation_Table
{
};
class TAO_Export TAO_Operation_Table_Parameters
{
// = TITLE
// Parameters used to create the operation table.
public:
enum DEMUX_STRATEGY
{
// various lookup strategies
TAO_LINEAR,
TAO_DYNAMIC_HASH,
TAO_PERFECT_HASH,
TAO_ACTIVE_DEMUX,
TAO_USER_DEFINED
};
void lookup_strategy (DEMUX_STRATEGY s);
// set the lookup strategy from the list of enumerated values
DEMUX_STRATEGY lookup_strategy (void) const;
// return the enumerated value for the lookup strategy. Default is Dynamic
// Hashing.
void concrete_strategy (TAO_Operation_Table *ot);
// Provide a data structure that will do the lookup. This is useful for
// user-defined lookup strategies.
TAO_Operation_Table *concrete_strategy (void);
// return the
TAO_Operation_Table_Parameters (void);
// constructor
~TAO_Operation_Table_Parameters (void);
// destructor
private:
TAO_Operation_Table *strategy_;
// pointer to the object that implements a lookup strategy
DEMUX_STRATEGY type_;
// the enumerated value indicating the lookup strategy
};
// Define a singleton instance of operation table parameters.
typedef ACE_Singleton<TAO_Operation_Table_Parameters, ACE_SYNCH_RECURSIVE_MUTEX>
TAO_OP_TABLE_PARAMETERS;
class TAO_Export TAO_Operation_Table_Factory
// = TITLE
// Factory for producing operation table lookup objects based on
// the enumerated value of strategy held by the parameters.
{
public:
TAO_Operation_Table *opname_lookup_strategy (void);
// return an instance of the specified lookup strategy
TAO_Operation_Table_Factory (void);
// constructor
~TAO_Operation_Table_Factory (void);
// destructor
};
// Define a singleton instance of the operation table factory.
typedef ACE_Singleton<TAO_Operation_Table_Factory, ACE_SYNCH_RECURSIVE_MUTEX>
TAO_OP_TABLE_FACTORY;
#endif /* TAO_OPTABLE_H */
|