~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to ace/Framework_Component.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Framework_Component.cpp
2
 
// Framework_Component.cpp,v 1.13 2003/11/01 11:15:12 dhinton Exp
3
 
 
4
 
#include "ace/Framework_Component.h"
5
 
 
6
 
#if !defined (__ACE_INLINE__)
7
 
#include "ace/Framework_Component.inl"
8
 
#endif /* __ACE_INLINE__ */
9
 
 
10
 
#include "ace/Object_Manager.h"
11
 
#include "ace/Log_Msg.h"
12
 
#include "ace/DLL_Manager.h"
13
 
#include "ace/Recursive_Thread_Mutex.h"
14
 
#include "ace/OS_NS_string.h"
15
 
 
16
 
ACE_RCSID(ace, Framework_Component, "Framework_Component.cpp,v 1.13 2003/11/01 11:15:12 dhinton Exp")
17
 
 
18
 
ACE_Framework_Component::~ACE_Framework_Component (void)
19
 
{
20
 
  ACE_TRACE ("ACE_Framework_Component::~ACE_Framework_Component");
21
 
 
22
 
  ACE::strdelete (ACE_const_cast (ACE_TCHAR*, this->dll_name_));
23
 
  ACE::strdelete (ACE_const_cast (ACE_TCHAR*, this->name_));
24
 
}
25
 
 
26
 
/***************************************************************/
27
 
 
28
 
ACE_ALLOC_HOOK_DEFINE(ACE_Framework_Repository)
29
 
 
30
 
sig_atomic_t ACE_Framework_Repository::shutting_down_ = 0;
31
 
 
32
 
// Pointer to the Singleton instance.
33
 
ACE_Framework_Repository *ACE_Framework_Repository::repository_ = 0;
34
 
 
35
 
ACE_Framework_Repository::~ACE_Framework_Repository (void)
36
 
{
37
 
  ACE_TRACE ("ACE_Framework_Repository::~ACE_Framework_Repository");
38
 
  this->close ();
39
 
}
40
 
 
41
 
int
42
 
ACE_Framework_Repository::open (int size)
43
 
{
44
 
  ACE_TRACE ("ACE_Framework_Repository::open");
45
 
 
46
 
  ACE_Framework_Component **temp;
47
 
 
48
 
  ACE_NEW_RETURN (temp,
49
 
                  ACE_Framework_Component *[size],
50
 
                  -1);
51
 
 
52
 
  this->component_vector_ = temp;
53
 
  this->total_size_ = size;
54
 
  return 0;
55
 
}
56
 
 
57
 
int
58
 
ACE_Framework_Repository::close (void)
59
 
{
60
 
  ACE_TRACE ("ACE_Framework_Repository::close");
61
 
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
62
 
 
63
 
  this->shutting_down_ = 1;
64
 
 
65
 
  if (this->component_vector_ != 0)
66
 
    {
67
 
      // Delete components in reverse order.
68
 
      for (int i = this->current_size_ - 1; i >= 0; i--)
69
 
        if (this->component_vector_[i])
70
 
          {
71
 
            ACE_Framework_Component *s =
72
 
              ACE_const_cast (ACE_Framework_Component *,
73
 
                              this->component_vector_[i]);
74
 
 
75
 
            this->component_vector_[i] = 0;
76
 
            delete s;
77
 
          }
78
 
 
79
 
      delete [] this->component_vector_;
80
 
      this->component_vector_ = 0;
81
 
      this->current_size_ = 0;
82
 
    }
83
 
 
84
 
  ACE_DLL_Manager::close_singleton ();
85
 
  return 0;
86
 
}
87
 
 
88
 
ACE_Framework_Repository *
89
 
ACE_Framework_Repository::instance (int size)
90
 
{
91
 
  ACE_TRACE ("ACE_Framework_Repository::instance");
92
 
 
93
 
  if (ACE_Framework_Repository::repository_ == 0)
94
 
    {
95
 
      // Perform Double-Checked Locking Optimization.
96
 
      ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
97
 
                                *ACE_Static_Object_Lock::instance (), 0));
98
 
      if (ACE_Framework_Repository::repository_ == 0)
99
 
        {
100
 
          if (ACE_Object_Manager::starting_up () ||
101
 
              !ACE_Object_Manager::shutting_down ())
102
 
            {
103
 
              ACE_NEW_RETURN (ACE_Framework_Repository::repository_,
104
 
                              ACE_Framework_Repository (size),
105
 
                              0);
106
 
            }
107
 
        }
108
 
    }
109
 
 
110
 
  return ACE_Framework_Repository::repository_;
111
 
}
112
 
 
113
 
void
114
 
ACE_Framework_Repository::close_singleton (void)
115
 
{
116
 
  ACE_TRACE ("ACE_Framework_Repository::close_singleton");
117
 
 
118
 
  ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
119
 
                     *ACE_Static_Object_Lock::instance ()));
120
 
 
121
 
  delete ACE_Framework_Repository::repository_;
122
 
  ACE_Framework_Repository::repository_ = 0;
123
 
}
124
 
 
125
 
int
126
 
ACE_Framework_Repository::register_component (ACE_Framework_Component *fc)
127
 
{
128
 
  ACE_TRACE ("ACE_Framework_Repository::register_component");
129
 
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
130
 
  int i;
131
 
 
132
 
  // Check to see if it's already registered
133
 
  for (i = 0; i < this->current_size_; i++)
134
 
    if (this->component_vector_[i] &&
135
 
        fc->this_ == this->component_vector_[i]->this_)
136
 
      {
137
 
        ACE_ERROR_RETURN ((LM_ERROR,
138
 
                           ACE_LIB_TEXT ("AFR::register_component: error, ")
139
 
                           ACE_LIB_TEXT ("compenent already registered\n")),
140
 
                          -1);
141
 
      }
142
 
 
143
 
  if (i < this->total_size_)
144
 
    {
145
 
      this->component_vector_[i] = fc;
146
 
      this->current_size_++;
147
 
      return 0;
148
 
    }
149
 
 
150
 
  return -1;
151
 
}
152
 
 
153
 
int
154
 
ACE_Framework_Repository::remove_component (const ACE_TCHAR *name)
155
 
{
156
 
  ACE_TRACE ("ACE_Framework_Repository::remove_component");
157
 
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
158
 
  int i;
159
 
 
160
 
  for (i = 0; i < this->current_size_; i++)
161
 
    if (this->component_vector_[i] &&
162
 
        ACE_OS::strcmp (this->component_vector_[i]->name_, name) == 0)
163
 
      {
164
 
        delete this->component_vector_[i];
165
 
        this->component_vector_[i] = 0;
166
 
        this->compact ();
167
 
        return 0;
168
 
      }
169
 
 
170
 
  return -1;
171
 
}
172
 
 
173
 
int
174
 
ACE_Framework_Repository::remove_dll_components (const ACE_TCHAR *dll_name)
175
 
{
176
 
  ACE_TRACE ("ACE_Framework_Repository::remove_dll_components");
177
 
 
178
 
  if (this->shutting_down_)
179
 
    return this->remove_dll_components_i (dll_name);
180
 
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
181
 
 
182
 
  return this->remove_dll_components_i (dll_name);
183
 
}
184
 
 
185
 
int
186
 
ACE_Framework_Repository::remove_dll_components_i (const ACE_TCHAR *dll_name)
187
 
{
188
 
  ACE_TRACE ("ACE_Framework_Repository::remove_dll_components_i");
189
 
 
190
 
  int i;
191
 
  int retval = -1;
192
 
 
193
 
  for (i = 0; i < this->current_size_; i++)
194
 
    if (this->component_vector_[i] &&
195
 
        ACE_OS::strcmp (this->component_vector_[i]->dll_name_, dll_name) == 0)
196
 
      {
197
 
          if (ACE::debug ())
198
 
            ACE_DEBUG ((LM_DEBUG,
199
 
                        ACE_LIB_TEXT ("AFR::remove_dll_components_i (%s) ")
200
 
                        ACE_LIB_TEXT ("component \"%s\"\n"),
201
 
                        dll_name, this->component_vector_[i]->name_));
202
 
        delete this->component_vector_[i];
203
 
        this->component_vector_[i] = 0;
204
 
        ++retval;
205
 
      }
206
 
 
207
 
  this->compact ();
208
 
 
209
 
  return retval == -1 ? -1 : 0;
210
 
}
211
 
 
212
 
void
213
 
ACE_Framework_Repository::compact (void)
214
 
{
215
 
  ACE_TRACE ("ACE_Framework_Repository::compact");
216
 
 
217
 
  int i;
218
 
  int start_hole;
219
 
  int end_hole;
220
 
 
221
 
  do
222
 
    {
223
 
      start_hole = this->current_size_;
224
 
      end_hole = this->current_size_;
225
 
 
226
 
      // Find hole
227
 
      for (i = 0; i < this->current_size_; ++i)
228
 
        {
229
 
          if (this->component_vector_[i] == 0)
230
 
            {
231
 
              if (start_hole == this->current_size_)
232
 
                {
233
 
                  start_hole = i;
234
 
                  end_hole = i;
235
 
                }
236
 
              else
237
 
                end_hole = i;
238
 
            }
239
 
          else if (end_hole != this->current_size_)
240
 
            break;
241
 
        }
242
 
 
243
 
      if (start_hole != this->current_size_)
244
 
        {
245
 
          // move the contents and reset current_size_
246
 
          while (end_hole + 1 < this->current_size_)
247
 
            {
248
 
              this->component_vector_[start_hole++] =
249
 
                this->component_vector_[++end_hole];
250
 
            }
251
 
          // Since start_hole is now one past the last
252
 
          // active slot.
253
 
          this->current_size_ = start_hole;
254
 
        }
255
 
 
256
 
    } while (start_hole != this->current_size_);
257
 
}
258
 
 
259
 
void
260
 
ACE_Framework_Repository::dump (void) const
261
 
{
262
 
#if defined (ACE_HAS_DUMP)
263
 
  ACE_TRACE ("ACE_Framework_Repository::dump");
264
 
#endif /* ACE_HAS_DUMP */
265
 
}
266
 
 
267
 
ACE_Framework_Repository::ACE_Framework_Repository (int size)
268
 
  : current_size_ (0)
269
 
{
270
 
  ACE_TRACE ("ACE_Framework_Repository::ACE_Framework_Repository");
271
 
 
272
 
  if (this->open (size) == -1)
273
 
    ACE_ERROR ((LM_ERROR,
274
 
                ACE_LIB_TEXT ("%p\n"),
275
 
                ACE_LIB_TEXT ("ACE_Framework_Repository")));
276
 
}