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