1
// Framework_Component.cpp
2
// Framework_Component.cpp,v 1.13 2003/11/01 11:15:12 dhinton Exp
4
#include "ace/Framework_Component.h"
6
#if !defined (__ACE_INLINE__)
7
#include "ace/Framework_Component.inl"
8
#endif /* __ACE_INLINE__ */
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"
16
ACE_RCSID(ace, Framework_Component, "Framework_Component.cpp,v 1.13 2003/11/01 11:15:12 dhinton Exp")
18
ACE_Framework_Component::~ACE_Framework_Component (void)
20
ACE_TRACE ("ACE_Framework_Component::~ACE_Framework_Component");
22
ACE::strdelete (ACE_const_cast (ACE_TCHAR*, this->dll_name_));
23
ACE::strdelete (ACE_const_cast (ACE_TCHAR*, this->name_));
26
/***************************************************************/
28
ACE_ALLOC_HOOK_DEFINE(ACE_Framework_Repository)
30
sig_atomic_t ACE_Framework_Repository::shutting_down_ = 0;
32
// Pointer to the Singleton instance.
33
ACE_Framework_Repository *ACE_Framework_Repository::repository_ = 0;
35
ACE_Framework_Repository::~ACE_Framework_Repository (void)
37
ACE_TRACE ("ACE_Framework_Repository::~ACE_Framework_Repository");
42
ACE_Framework_Repository::open (int size)
44
ACE_TRACE ("ACE_Framework_Repository::open");
46
ACE_Framework_Component **temp;
49
ACE_Framework_Component *[size],
52
this->component_vector_ = temp;
53
this->total_size_ = size;
58
ACE_Framework_Repository::close (void)
60
ACE_TRACE ("ACE_Framework_Repository::close");
61
ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
63
this->shutting_down_ = 1;
65
if (this->component_vector_ != 0)
67
// Delete components in reverse order.
68
for (int i = this->current_size_ - 1; i >= 0; i--)
69
if (this->component_vector_[i])
71
ACE_Framework_Component *s =
72
ACE_const_cast (ACE_Framework_Component *,
73
this->component_vector_[i]);
75
this->component_vector_[i] = 0;
79
delete [] this->component_vector_;
80
this->component_vector_ = 0;
81
this->current_size_ = 0;
84
ACE_DLL_Manager::close_singleton ();
88
ACE_Framework_Repository *
89
ACE_Framework_Repository::instance (int size)
91
ACE_TRACE ("ACE_Framework_Repository::instance");
93
if (ACE_Framework_Repository::repository_ == 0)
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)
100
if (ACE_Object_Manager::starting_up () ||
101
!ACE_Object_Manager::shutting_down ())
103
ACE_NEW_RETURN (ACE_Framework_Repository::repository_,
104
ACE_Framework_Repository (size),
110
return ACE_Framework_Repository::repository_;
114
ACE_Framework_Repository::close_singleton (void)
116
ACE_TRACE ("ACE_Framework_Repository::close_singleton");
118
ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
119
*ACE_Static_Object_Lock::instance ()));
121
delete ACE_Framework_Repository::repository_;
122
ACE_Framework_Repository::repository_ = 0;
126
ACE_Framework_Repository::register_component (ACE_Framework_Component *fc)
128
ACE_TRACE ("ACE_Framework_Repository::register_component");
129
ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
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_)
137
ACE_ERROR_RETURN ((LM_ERROR,
138
ACE_LIB_TEXT ("AFR::register_component: error, ")
139
ACE_LIB_TEXT ("compenent already registered\n")),
143
if (i < this->total_size_)
145
this->component_vector_[i] = fc;
146
this->current_size_++;
154
ACE_Framework_Repository::remove_component (const ACE_TCHAR *name)
156
ACE_TRACE ("ACE_Framework_Repository::remove_component");
157
ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
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)
164
delete this->component_vector_[i];
165
this->component_vector_[i] = 0;
174
ACE_Framework_Repository::remove_dll_components (const ACE_TCHAR *dll_name)
176
ACE_TRACE ("ACE_Framework_Repository::remove_dll_components");
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));
182
return this->remove_dll_components_i (dll_name);
186
ACE_Framework_Repository::remove_dll_components_i (const ACE_TCHAR *dll_name)
188
ACE_TRACE ("ACE_Framework_Repository::remove_dll_components_i");
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)
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;
209
return retval == -1 ? -1 : 0;
213
ACE_Framework_Repository::compact (void)
215
ACE_TRACE ("ACE_Framework_Repository::compact");
223
start_hole = this->current_size_;
224
end_hole = this->current_size_;
227
for (i = 0; i < this->current_size_; ++i)
229
if (this->component_vector_[i] == 0)
231
if (start_hole == this->current_size_)
239
else if (end_hole != this->current_size_)
243
if (start_hole != this->current_size_)
245
// move the contents and reset current_size_
246
while (end_hole + 1 < this->current_size_)
248
this->component_vector_[start_hole++] =
249
this->component_vector_[++end_hole];
251
// Since start_hole is now one past the last
253
this->current_size_ = start_hole;
256
} while (start_hole != this->current_size_);
260
ACE_Framework_Repository::dump (void) const
262
#if defined (ACE_HAS_DUMP)
263
ACE_TRACE ("ACE_Framework_Repository::dump");
264
#endif /* ACE_HAS_DUMP */
267
ACE_Framework_Repository::ACE_Framework_Repository (int size)
270
ACE_TRACE ("ACE_Framework_Repository::ACE_Framework_Repository");
272
if (this->open (size) == -1)
273
ACE_ERROR ((LM_ERROR,
274
ACE_LIB_TEXT ("%p\n"),
275
ACE_LIB_TEXT ("ACE_Framework_Repository")));