summaryrefslogtreecommitdiff
path: root/TAO/tao/PortableServer/Operation_Table_Dynamic_Hash.cpp
blob: 21a206d9fbadb0d6ff23521fa27f1453d51f902d (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
// $Id$

#include "tao/PortableServer/Operation_Table_Dynamic_Hash.h"
#include "tao/Timeprobe.h"
#include "ace/Log_Msg.h"

ACE_RCSID(PortableServer,
          Operation_Table_Dynamic_Hash,
          "$Id$")

#if defined (ACE_ENABLE_TIMEPROBES)

static const char *TAO_Operation_Table_Timeprobe_Description[] =
  {
    "TAO_Dynamic_Hash_OpTable::find - start",
    "TAO_Dynamic_Hash_OpTable::find - end",
  };

enum
  {
    // Timeprobe description table start key
    TAO_DYNAMIC_HASH_OPTABLE_FIND_START = 600,
    TAO_DYNAMIC_HASH_OPTABLE_FIND_END,
  };

// Setup Timeprobes
ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_Operation_Table_Timeprobe_Description,
                                  TAO_DYNAMIC_HASH_OPTABLE_FIND_START);

#endif /* ACE_ENABLE_TIMEPROBES */

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

// constructor
TAO_Dynamic_Hash_OpTable::TAO_Dynamic_Hash_OpTable (
  TAO_operation_db_entry const * db,
  CORBA::ULong dbsize,
  CORBA::ULong hashtblsize,
  ACE_Allocator *alloc)
  : hash_ (hashtblsize, alloc)
{
  // Iterate thru each entry in the database and bind the operation
  // name to its corresponding skeleton.
  for (CORBA::ULong i = 0; i < dbsize; ++i)
    {
      TAO::Operation_Skeletons s;
      s.skel_ptr = db[i].skel_ptr;
      s.thruPOA_skel_ptr = db[i].skel_ptr;
      s.direct_skel_ptr = db[i].direct_skel_ptr;

      // @@ (ASG): what happens if bind fails ???
      if (this->bind (db[i].opname, s) == -1)
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("(%P|%t) %p\n"),
                    ACE_TEXT ("bind failed")));
    }
}

TAO_Dynamic_Hash_OpTable::~TAO_Dynamic_Hash_OpTable (void)
{
  // Initialize an iterator.  We need to go thru each entry and free
  // up storage allocated to hold the external ids.  In this case,
  // these are strings.
  OP_MAP_MANAGER::ITERATOR iterator (this->hash_);

  for (OP_MAP_MANAGER::ENTRY *entry = 0;
       iterator.next (entry) != 0;
       iterator.advance ())
    {
      // We had allocated memory and stored the string. So we free the
      // memory.
      CORBA::string_free ((char *) entry->ext_id_);
      entry->ext_id_ = 0;
    }
}

int
TAO_Dynamic_Hash_OpTable::bind (const char *opname,
                                const TAO::Operation_Skeletons skel_ptr)
{
  return this->hash_.bind (CORBA::string_dup (opname),
                           skel_ptr);
}

int
TAO_Dynamic_Hash_OpTable::find (const char *opname,
                                TAO_Skeleton& skel_ptr,
                                const unsigned int )
{
  ACE_FUNCTION_TIMEPROBE (TAO_DYNAMIC_HASH_OPTABLE_FIND_START);
  TAO::Operation_Skeletons s;

  int retval =
    this->hash_.find ((const char *)opname,
                      s);

  if (retval != -1)
    {
      skel_ptr = s.skel_ptr;
    }

  return retval;
}

int
TAO_Dynamic_Hash_OpTable::find (const char *opname,
                                TAO_Collocated_Skeleton& skel_ptr,
                                TAO::Collocation_Strategy s,
                                const unsigned int )
{
  ACE_FUNCTION_TIMEPROBE (TAO_DYNAMIC_HASH_OPTABLE_FIND_START);

  TAO::Operation_Skeletons skel;

  int retval =
    this->hash_.find ((const char *)opname, skel);

  if (retval != -1)
    {
      switch (s)
        {
        case TAO::TAO_CS_DIRECT_STRATEGY:
          skel_ptr = skel.direct_skel_ptr;
          break;
        default:
          return -1;
        }
    }

  return retval;
}

TAO_END_VERSIONED_NAMESPACE_DECL