summaryrefslogtreecommitdiff
path: root/TAO/tao/PortableServer/Operation_Table.h
blob: 34022c768ddedcf2d5b0b23baec13d10416bdf69 (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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
// This may look like C, but it's really -*- C++ -*-

//=============================================================================
/**
 *  @file    Operation_Table.h
 *
 *  $Id$
 *
 *  @author Aniruddha Gokhale
 */
//=============================================================================

#ifndef TAO_OPTABLE_H
#define TAO_OPTABLE_H

#include /**/ "ace/pre.h"

#include "portableserver_export.h"

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

#include "tao/Object.h"
#include "tao/TAO_Singleton.h"
#include "tao/Collocation_Strategy.h"
#include "ace/Synch_Traits.h"
#include "ace/Null_Mutex.h"
#include "ace/Hash_Map_Manager.h"

class TAO_ServerRequest;
class TAO_Abstract_ServantBase;

namespace CORBA
{
  class Environment;
}

typedef void (*TAO_Skeleton)(
    TAO_ServerRequest &,
    void *,
    void *
#if !defined (TAO_HAS_EXCEPTIONS) || defined (ACE_ENV_BKWD_COMPAT)
    , CORBA::Environment &
#endif
  );

typedef void (*TAO_Collocated_Skeleton)(
    TAO_Abstract_ServantBase *,
    TAO::Argument **,
    int
#if !defined (TAO_HAS_EXCEPTIONS) || defined (ACE_ENV_BKWD_COMPAT)
    , CORBA::Environment &
#endif
  );

/**
 * @class TAO_operation_db_entry
 *
 * @brief 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.
 */
class TAO_operation_db_entry
{
public:
  /// Operation name
  const char* opname_;

  /// Remote skeleton pointer
  TAO_Skeleton skel_ptr_;

  /// Collocated skeleton pointers.
  TAO_Collocated_Skeleton thruPOA_skel_ptr_;
  TAO_Collocated_Skeleton direct_skel_ptr_;
};


namespace TAO
{
  /**
   * @class Operation_Skeleton_Ptr
   *
   * @brief A logical aggregation of all the operation skeleton pointers
   * in use.
   *
   * This is not used by the IDL compiler. This is used internally
   * within different strategies.
   */
  struct Operation_Skeletons
  {
    Operation_Skeletons (void);

    /// Remote skeleton pointer
    TAO_Skeleton skel_ptr_;

    /// Collocated skeleton pointers.
    TAO_Collocated_Skeleton thruPOA_skel_ptr_;
    TAO_Collocated_Skeleton direct_skel_ptr_;
  };
}


/**
 * @class TAO_Operation_Table
 *
 * @brief Abstract class for maintaining and lookup of CORBA IDL
 * operation names.
 */
class TAO_PortableServer_Export TAO_Operation_Table
{
public:
  /**
   * Uses @a opname to look up the skeleton function and pass it back
   * in @a skelfunc.  Returns non-negative integer on success, or -1
   * on failure.
   */
  virtual int find (const char *opname,
                    TAO_Skeleton &skelfunc,
                    const unsigned int length = 0) = 0;

  /**
   * Uses @a opname to look up the collocated skeleton function and
   * pass it back in @a skelfunc.  Returns non-negative integer on
   * success, or -1 on failure.
   */
  virtual int find (const char *opname,
                    TAO_Collocated_Skeleton &skelfunc,
                    TAO::Collocation_Strategy s,
                    const unsigned int length = 0) = 0;

  /// Associate the skeleton @a skel_ptr with an operation named
  /// @a opname.  Returns -1 on failure, 0 on success, 1 on duplicate.
  virtual int bind (const char *opname,
                    const TAO::Operation_Skeletons skel_ptr) = 0;

  virtual ~TAO_Operation_Table (void);
};

/**
 * @class TAO_Operation_Table_Factory
 *
 * @brief Factory for producing operation table lookup objects based on
 * the enumerated value of strategy held by the parameters.
 */
class TAO_PortableServer_Export TAO_Operation_Table_Factory
{
public:
  /// Return an instance of the specified lookup strategy
  TAO_Operation_Table *opname_lookup_strategy (void);

  /// Constructor
  TAO_Operation_Table_Factory (void);

  /// Destructor
  ~TAO_Operation_Table_Factory (void);
};

/**
 * @class TAO_Operation_Table_Parameters
 *
 * @brief Parameters used to create the operation table.
 */
class TAO_PortableServer_Export TAO_Operation_Table_Parameters
{
public:
  /// various lookup strategies
  enum DEMUX_STRATEGY
  {
    TAO_LINEAR_SEARCH,
    TAO_DYNAMIC_HASH,
    TAO_PERFECT_HASH,
    TAO_BINARY_SEARCH,
    TAO_ACTIVE_DEMUX,
    TAO_USER_DEFINED
  };

  /// Set the lookup strategy from the list of enumerated values
  void lookup_strategy (DEMUX_STRATEGY s);

  /// Return the enumerated value for the lookup strategy. Default is
  /// Dynamic Hashing.
  DEMUX_STRATEGY lookup_strategy (void) const;

  /// Provide a data structure that will do the lookup. This is useful
  /// for user-defined lookup strategies.
  void concrete_strategy (TAO_Operation_Table *ot);

  /// Return the operation table that is being used to do the lookup.
  TAO_Operation_Table *concrete_strategy (void);

  /// Constructor.
  TAO_Operation_Table_Parameters (void);

  /// Destructor
  ~TAO_Operation_Table_Parameters (void);
private:
  /// Pointer to the object that implements a lookup strategy
  TAO_Operation_Table *strategy_;

  /// The enumerated value indicating the lookup strategy
  DEMUX_STRATEGY type_;
};

/**
 * @class TAO_Dynamic_Hash_OpTable
 *
 * @brief Dynamic Hashing scheme for CORBA IDL operation name lookup.
 */
class TAO_PortableServer_Export TAO_Dynamic_Hash_OpTable
  : public TAO_Operation_Table
{
public:
  // = Initialization and termination methods.
  /**
   * 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.  The <alloc> argument is
   * used to determine where the memory comes from (usually from
   * <ACE_Static_Allocator_Base>).
   */
  TAO_Dynamic_Hash_OpTable (const TAO_operation_db_entry *db,
                            CORBA::ULong dbsize,
                            CORBA::ULong hashtblsize,
                            ACE_Allocator *alloc);

  /// Destructor
  ~TAO_Dynamic_Hash_OpTable (void);

  /// See the documentation in the base class for details.
  virtual int bind (const char *opname,
                    const TAO::Operation_Skeletons skel_ptr);

  virtual int find (const char *opname,
                    TAO_Skeleton &skelfunc,
                    const unsigned int length = 0);

  virtual int find (const char *opname,
                    TAO_Collocated_Skeleton &skelfunc,
                    TAO::Collocation_Strategy s,
                    const unsigned int length = 0);
private:
  typedef ACE_Hash_Map_Manager_Ex<const char *,
                                  TAO::Operation_Skeletons,
                                  ACE_Hash<const char *>,
                                  ACE_Equal_To<const char *>,
                                  ACE_Null_Mutex>
        OP_MAP_MANAGER;

  /// The hash table data structure.
  OP_MAP_MANAGER hash_;
};

/**
 * @class TAO_Linear_Search_OpTable
 *
 * @brief Operation table lookup strategy based on
 * linear search.  Not efficient, but it works.
 */
class TAO_PortableServer_Export TAO_Linear_Search_OpTable
  : public TAO_Operation_Table
{
public:
  // = Initialization and termination methods.
  /// Default constructor.
  TAO_Linear_Search_OpTable (void);

  /// Destructor.
  ~TAO_Linear_Search_OpTable (void);

  /// See the documentation in the base class for details.
  virtual int find (const char *opname,
                    TAO_Skeleton &skel_ptr,
                    const unsigned int length = 0);

  virtual int find (const char *opname,
                    TAO_Collocated_Skeleton &skelfunc,
                    TAO::Collocation_Strategy s,
                    const unsigned int length = 0);

  virtual int bind (const char *opname,
                    const TAO::Operation_Skeletons skelptr);

private:
  // = Method that should defined by the subclasses. GPERF program
  //   will generate this routine routines.
  virtual const TAO_operation_db_entry* lookup (const char *str) = 0;
};

/**
 * @class TAO_Active_Demux_OpTable_Entry
 *
 * @brief Active Demux lookup table entry.
 */
class TAO_PortableServer_Export TAO_Active_Demux_OpTable_Entry
{
public:
  // = Initialization and termination methods.
  /// Constructor
  TAO_Active_Demux_OpTable_Entry (void);

  /// Destructor
  ~TAO_Active_Demux_OpTable_Entry (void);

  /// Skeleton pointer corresponding to the index.
  TAO::Operation_Skeletons op_skel_ptr_;
};

/**
 * @class TAO_Active_Demux_OpTable
 *
 * @brief Implements the active demultiplexed lookup strategy. The key is
 * assumed to provide an index directly into the internal table.
 */
class TAO_PortableServer_Export TAO_Active_Demux_OpTable
  : public TAO_Operation_Table
{
public:
  // = Initialization and termination methods.
  /// Initializes the internal table with the database of operations
  TAO_Active_Demux_OpTable (const TAO_operation_db_entry *db,
                            CORBA::ULong dbsize);

  /// Destructor.
  ~TAO_Active_Demux_OpTable (void);

  /// See the documentation in the base class fopr details.
  virtual int find (const char *opname,
                    TAO_Skeleton &skel_ptr,
                    const unsigned int length = 0);

  virtual int find (const char *opname,
                    TAO_Collocated_Skeleton &skelfunc,
                    TAO::Collocation_Strategy s,
                    const unsigned int length = 0);

  virtual int bind (const char *opname,
                    const TAO::Operation_Skeletons skelptr);

private:
  /// The next available free slot
  CORBA::ULong next_;

  /// Size of the internal table
  CORBA::ULong tablesize_;

  /// Internal lookup table
  TAO_Active_Demux_OpTable_Entry *tbl_;
};

/**
 * @class TAO_Perfect_Hash_OpTable
 *
 * @brief Helper class  for use of perfect hashing operation lookup
 * strategy.
 *
 * This class declares pure virtual methods called 'lookup ()'
 * and 'hash ()' which will be generated by the GPERF
 * program. These methods are used by 'bind ()' and 'find ()'
 * methods. Subclasses will define the lookup and hash
 * functions.
 */
class TAO_PortableServer_Export TAO_Perfect_Hash_OpTable
  : public TAO_Operation_Table
{
public:
  /// Do nothing constructor.
  TAO_Perfect_Hash_OpTable (void);

  /// Do nothing destrctor.
  virtual ~TAO_Perfect_Hash_OpTable (void);

  /// See the documentation in the base class for details.
  virtual int find (const char *opname,
                    TAO_Skeleton &skelfunc,
                    const unsigned int length = 0);

  virtual int find (const char *opname,
                    TAO_Collocated_Skeleton &skelfunc,
                    TAO::Collocation_Strategy s,
                    const unsigned int length = 0);

  virtual int bind (const char *opname,
                    const TAO::Operation_Skeletons skel_ptr);

private:
  // = Methods that should defined by the subclasses. GPERF program
  //   will generate these routines.

  virtual unsigned int hash (const char *str, unsigned int len) = 0;

  virtual const TAO_operation_db_entry* lookup (const char *str,
                                                unsigned int len) = 0;
};

/**
 * @class TAO_Binary_Search_OpTable
 *
 * @brief Helper class for using binary search operatin lookup strategy
 * in the server skeletons.
 *
 * This class declares pure virtual method called 'lookup ()'
 * which will be generated by the GPERF program. This method is
 * used by 'bind ()' and 'find ()' methods. Subclasses will
 * define the lookup method.
 */
class TAO_PortableServer_Export TAO_Binary_Search_OpTable
  : public TAO_Operation_Table
{
public:
  /// Do nothing constructor.
  TAO_Binary_Search_OpTable (void);

  /// Do nothing destrctor.
  virtual ~TAO_Binary_Search_OpTable (void);

  /// See the documentation in the base class for details.
  virtual int find (const char *opname,
                    TAO_Skeleton &skelfunc,
                    const unsigned int length = 0);

  virtual int find (const char *opname,
                    TAO_Collocated_Skeleton &skelfunc,
                    TAO::Collocation_Strategy s,
                    const unsigned int length = 0);

  virtual int bind (const char *opname,
                    const TAO::Operation_Skeletons skel_ptr);

private:
  /// Method that should defined by the subclasses. GPERF program
  /// will generate this routine routines.
  virtual const TAO_operation_db_entry* lookup (const char *str) = 0;
};


/// Define a singleton instance of operation table parameters.
typedef TAO_Singleton<TAO_Operation_Table_Parameters,
                      TAO_SYNCH_RECURSIVE_MUTEX>
        TAO_OP_TABLE_PARAMETERS;


/// Define a singleton instance of the operation table factory.
typedef TAO_Singleton<TAO_Operation_Table_Factory,
                      TAO_SYNCH_RECURSIVE_MUTEX>
        TAO_OP_TABLE_FACTORY;


#include /**/ "ace/post.h"
#endif /* TAO_OPTABLE_H */