summaryrefslogtreecommitdiff
path: root/TAO/IIOP/lib/objtable.cpp
blob: 132c3032bf15c17994b47ab2d565b6ccbb633d71 (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
#include "objtable.h"

TAO_Dynamic_Hash_ObjTable::TAO_Dynamic_Hash_ObjTable (CORBA_ULong size)
{
  if (size > 0)
    this->hash_.open (size);
  // else we already have a default hash map
}

TAO_Dynamic_Hash_ObjTable::~TAO_Dynamic_Hash_ObjTable (void)
{
  this->hash_.close ();
}

int
TAO_Dynamic_Hash_ObjTable::bind (const CORBA_OctetSeq &key,
				 CORBA_Object_ptr obj)
{
  ACE_CString objkey ((char *) key.buffer);
  return this->hash_.bind (objkey, obj);
}

int
TAO_Dynamic_Hash_ObjTable::find (const CORBA_OctetSeq &key,
				 CORBA_Object_ptr &obj)
{
  ACE_CString objkey ((char *) key.buffer);
  return this->hash_.find (objkey, obj);
}

// Linear search strategy.
TAO_Linear_ObjTable::TAO_Linear_ObjTable (CORBA_ULong size)
  : next_ (0),
    tablesize_ (size),
    tbl_ (new TAO_Linear_ObjTable_Entry[size])
{
}

TAO_Linear_ObjTable::~TAO_Linear_ObjTable (void)
{
  delete [] this->tbl_;
}

// ****** we should really make sure that the same key doesn't exist
// ******

int
TAO_Linear_ObjTable::bind (const CORBA_OctetSeq &key,
			   CORBA_Object_ptr obj)
{
  CORBA_ULong i = this->next_;

  if (i < this->tablesize_)
    {
      this->tbl_[i].obj = obj;
      this->tbl_[i].key.buffer = new CORBA_Octet [key.length];
      this->tbl_[i].key.length = this->tbl_[i].key.maximum = key.length;
      ACE_OS::memcpy (this->tbl_[i].key.buffer, key.buffer, key.length);

      this->next_++;
      return 0;
    }
  return -1; // error
}

int
TAO_Linear_ObjTable::find (const CORBA_OctetSeq &key,
			   CORBA_Object_ptr &obj)
{


  ACE_ASSERT (this->next_ <= this->tablesize_);

  for (CORBA_ULong i = 0;
       i < this->next_;
       i++)
    if (!ACE_OS::memcmp (key.buffer, this->tbl_[i].key.buffer, key.length))
      {
	obj = this->tbl_[i].obj;
	return 1;
      }

  return -1;  // not found
}

TAO_Linear_ObjTable_Entry::TAO_Linear_ObjTable_Entry(void)
{
  this->key.buffer = 0;
  this->key.length = this->key.maximum = 0;
  this->obj = 0;
}

TAO_Linear_ObjTable_Entry::~TAO_Linear_ObjTable_Entry ()
{
  delete [] this->key.buffer;
  this->key.length = this->key.maximum = 0;
  this->obj = 0;  // cannot delete this as we do not own it
}

// Active Demux search strategy
TAO_Active_Demux_ObjTable::TAO_Active_Demux_ObjTable (CORBA_ULong size)
  : next_ (0),
    tablesize_ (size),
    tbl_ (new TAO_Active_Demux_ObjTable_Entry[size])
{
}

TAO_Active_Demux_ObjTable::~TAO_Active_Demux_ObjTable ()
{
  delete [] this->tbl_;
}

// ****** we should really make sure that the same key doesn't exist ******
int
TAO_Active_Demux_ObjTable::bind (const CORBA_OctetSeq &key,
				 CORBA_Object_ptr obj)
{
  CORBA_ULong i = this->next_;

  if (i < this->tablesize_)
    {
      this->tbl_[i].obj = obj;
      this->next_++;
      return 0;
    }
  return -1; // error
}

int
TAO_Active_Demux_ObjTable::find (const CORBA_OctetSeq &key,
				 CORBA_Object_ptr& obj)
{
  CORBA_ULong i = ACE_OS::atoi ((char *)key.buffer);

  ACE_ASSERT (i <= this->tablesize_);
  obj = this->tbl_[i].obj;
  return 1;
}

TAO_Active_Demux_ObjTable_Entry::TAO_Active_Demux_ObjTable_Entry (void)
{
  this->obj = 0;
}

TAO_Active_Demux_ObjTable_Entry::~TAO_Active_Demux_ObjTable_Entry (void)
{
  this->obj = 0;  // cannot delete this as we do not own it
}

#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION)
template class ACE_Hash_Map_Manager<ACE_CString, CORBA_Object_ptr, ACE_SYNCH_RW_MUTEX>;
template class ACE_Hash_Map_Entry<ACE_CString, CORBA_Object_ptr>;
template class ACE_Guard<ACE_SYNCH_RW_MUTEX>;
template class ACE_Read_Guard<ACE_SYNCH_RW_MUTEX>;
template class ACE_Write_Guard<ACE_SYNCH_RW_MUTEX>;
#endif