Go to the documentation of this file.00001
00002
00003
00004 #include "ace/Framework_Component.h"
00005
00006 #if !defined (__ACE_INLINE__)
00007 #include "ace/Framework_Component.inl"
00008 #endif
00009
00010 #include "ace/Object_Manager.h"
00011 #include "ace/Log_Msg.h"
00012 #include "ace/DLL_Manager.h"
00013 #include "ace/Recursive_Thread_Mutex.h"
00014 #include "ace/OS_NS_string.h"
00015
00016 ACE_RCSID(ace, Framework_Component, "$Id: Framework_Component.cpp 84128 2009-01-09 15:07:40Z johnnyw $")
00017
00018 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00019
00020 ACE_Framework_Component::~ACE_Framework_Component (void)
00021 {
00022 ACE_TRACE ("ACE_Framework_Component::~ACE_Framework_Component");
00023
00024 ACE::strdelete (const_cast<ACE_TCHAR*> (this->dll_name_));
00025 ACE::strdelete (const_cast<ACE_TCHAR*> (this->name_));
00026 }
00027
00028
00029
00030 ACE_ALLOC_HOOK_DEFINE(ACE_Framework_Repository)
00031
00032 sig_atomic_t ACE_Framework_Repository::shutting_down_ = 0;
00033
00034
00035 ACE_Framework_Repository *ACE_Framework_Repository::repository_ = 0;
00036
00037 ACE_Framework_Repository::~ACE_Framework_Repository (void)
00038 {
00039 ACE_TRACE ("ACE_Framework_Repository::~ACE_Framework_Repository");
00040 this->close ();
00041 }
00042
00043 int
00044 ACE_Framework_Repository::open (int size)
00045 {
00046 ACE_TRACE ("ACE_Framework_Repository::open");
00047
00048 ACE_Framework_Component **temp = 0;
00049
00050 ACE_NEW_RETURN (temp,
00051 ACE_Framework_Component *[size],
00052 -1);
00053
00054 this->component_vector_ = temp;
00055 this->total_size_ = size;
00056 return 0;
00057 }
00058
00059 int
00060 ACE_Framework_Repository::close (void)
00061 {
00062 ACE_TRACE ("ACE_Framework_Repository::close");
00063 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00064
00065 this->shutting_down_ = 1;
00066
00067 if (this->component_vector_ != 0)
00068 {
00069
00070 for (int i = this->current_size_ - 1; i >= 0; i--)
00071 if (this->component_vector_[i])
00072 {
00073 ACE_Framework_Component *s =
00074 const_cast<ACE_Framework_Component *> (
00075 this->component_vector_[i]);
00076
00077 this->component_vector_[i] = 0;
00078 delete s;
00079 }
00080
00081 delete [] this->component_vector_;
00082 this->component_vector_ = 0;
00083 this->current_size_ = 0;
00084 }
00085
00086 ACE_DLL_Manager::close_singleton ();
00087 return 0;
00088 }
00089
00090 ACE_Framework_Repository *
00091 ACE_Framework_Repository::instance (int size)
00092 {
00093 ACE_TRACE ("ACE_Framework_Repository::instance");
00094
00095 if (ACE_Framework_Repository::repository_ == 0)
00096 {
00097
00098 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00099 *ACE_Static_Object_Lock::instance (), 0));
00100 if (ACE_Framework_Repository::repository_ == 0)
00101 {
00102 if (ACE_Object_Manager::starting_up () ||
00103 !ACE_Object_Manager::shutting_down ())
00104 {
00105 ACE_NEW_RETURN (ACE_Framework_Repository::repository_,
00106 ACE_Framework_Repository (size),
00107 0);
00108 }
00109 }
00110 }
00111
00112 return ACE_Framework_Repository::repository_;
00113 }
00114
00115 void
00116 ACE_Framework_Repository::close_singleton (void)
00117 {
00118 ACE_TRACE ("ACE_Framework_Repository::close_singleton");
00119
00120 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
00121 *ACE_Static_Object_Lock::instance ()));
00122
00123 delete ACE_Framework_Repository::repository_;
00124 ACE_Framework_Repository::repository_ = 0;
00125 }
00126
00127 int
00128 ACE_Framework_Repository::register_component (ACE_Framework_Component *fc)
00129 {
00130 ACE_TRACE ("ACE_Framework_Repository::register_component");
00131 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00132 int i;
00133
00134
00135 for (i = 0; i < this->current_size_; i++)
00136 if (this->component_vector_[i] &&
00137 fc->this_ == this->component_vector_[i]->this_)
00138 {
00139 ACE_ERROR_RETURN ((LM_ERROR,
00140 "AFR::register_component: error, compenent already registered\n"),
00141 -1);
00142 }
00143
00144 if (i < this->total_size_)
00145 {
00146 this->component_vector_[i] = fc;
00147 ++this->current_size_;
00148 return 0;
00149 }
00150
00151 return -1;
00152 }
00153
00154 int
00155 ACE_Framework_Repository::remove_component (const ACE_TCHAR *name)
00156 {
00157 ACE_TRACE ("ACE_Framework_Repository::remove_component");
00158 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00159 int i;
00160
00161 for (i = 0; i < this->current_size_; i++)
00162 if (this->component_vector_[i] &&
00163 ACE_OS::strcmp (this->component_vector_[i]->name_, name) == 0)
00164 {
00165 delete this->component_vector_[i];
00166 this->component_vector_[i] = 0;
00167 this->compact ();
00168 return 0;
00169 }
00170
00171 return -1;
00172 }
00173
00174 int
00175 ACE_Framework_Repository::remove_dll_components (const ACE_TCHAR *dll_name)
00176 {
00177 ACE_TRACE ("ACE_Framework_Repository::remove_dll_components");
00178
00179 if (this->shutting_down_)
00180 return this->remove_dll_components_i (dll_name);
00181 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00182
00183 return this->remove_dll_components_i (dll_name);
00184 }
00185
00186 int
00187 ACE_Framework_Repository::remove_dll_components_i (const ACE_TCHAR *dll_name)
00188 {
00189 ACE_TRACE ("ACE_Framework_Repository::remove_dll_components_i");
00190
00191 int i;
00192 int retval = -1;
00193
00194 for (i = 0; i < this->current_size_; i++)
00195 if (this->component_vector_[i] &&
00196 ACE_OS::strcmp (this->component_vector_[i]->dll_name_, dll_name) == 0)
00197 {
00198 if (ACE::debug ())
00199 ACE_DEBUG ((LM_DEBUG,
00200 ACE_TEXT ("AFR::remove_dll_components_i (%s) ")
00201 ACE_TEXT ("component \"%s\"\n"),
00202 dll_name, this->component_vector_[i]->name_));
00203 delete this->component_vector_[i];
00204 this->component_vector_[i] = 0;
00205 ++retval;
00206 }
00207
00208 this->compact ();
00209
00210 return retval == -1 ? -1 : 0;
00211 }
00212
00213 void
00214 ACE_Framework_Repository::compact (void)
00215 {
00216 ACE_TRACE ("ACE_Framework_Repository::compact");
00217
00218 int i;
00219 int start_hole;
00220 int end_hole;
00221
00222 do
00223 {
00224 start_hole = this->current_size_;
00225 end_hole = this->current_size_;
00226
00227
00228 for (i = 0; i < this->current_size_; ++i)
00229 {
00230 if (this->component_vector_[i] == 0)
00231 {
00232 if (start_hole == this->current_size_)
00233 {
00234 start_hole = i;
00235 end_hole = i;
00236 }
00237 else
00238 end_hole = i;
00239 }
00240 else if (end_hole != this->current_size_)
00241 break;
00242 }
00243
00244 if (start_hole != this->current_size_)
00245 {
00246
00247 while (end_hole + 1 < this->current_size_)
00248 {
00249 this->component_vector_[start_hole++] =
00250 this->component_vector_[++end_hole];
00251 }
00252
00253
00254 this->current_size_ = start_hole;
00255 }
00256
00257 } while (start_hole != this->current_size_);
00258 }
00259
00260 void
00261 ACE_Framework_Repository::dump (void) const
00262 {
00263 #if defined (ACE_HAS_DUMP)
00264 ACE_TRACE ("ACE_Framework_Repository::dump");
00265 #endif
00266 }
00267
00268 ACE_Framework_Repository::ACE_Framework_Repository (int size)
00269 : current_size_ (0)
00270 {
00271 ACE_TRACE ("ACE_Framework_Repository::ACE_Framework_Repository");
00272
00273 if (this->open (size) == -1)
00274 ACE_ERROR ((LM_ERROR,
00275 ACE_TEXT ("%p\n"),
00276 ACE_TEXT ("ACE_Framework_Repository")));
00277 }
00278
00279 ACE_END_VERSIONED_NAMESPACE_DECL