diff options
author | dhinton <dhinton@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2002-01-19 22:44:52 +0000 |
---|---|---|
committer | dhinton <dhinton@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2002-01-19 22:44:52 +0000 |
commit | 56e6438faa1788e9adcc7bd60c993d6477d64221 (patch) | |
tree | f537a376a1c9ef6b3c9a0f095bd34052ae5f7a3c /ace/Framework_Component.cpp | |
parent | 5e137489af90e2ad7f9dd19c2b1b372ea9b6a2b3 (diff) | |
download | ATCD-56e6438faa1788e9adcc7bd60c993d6477d64221.tar.gz |
ChangeLogTag: Sat Jan 19 22:30:26 UTC 2002 Don Hinton <dhinton@ieee.org>
Diffstat (limited to 'ace/Framework_Component.cpp')
-rw-r--r-- | ace/Framework_Component.cpp | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/ace/Framework_Component.cpp b/ace/Framework_Component.cpp new file mode 100644 index 00000000000..427c4614dea --- /dev/null +++ b/ace/Framework_Component.cpp @@ -0,0 +1,156 @@ +// Framework_Component.cpp +// $Id$ + +#include "ace/Framework_Component.h" +#include "ace/Object_Manager.h" +#include "ace/Log_Msg.h" + +#if !defined (__ACE_INLINE__) +#include "ace/Framework_Component.inl" +#endif /* __ACE_INLINE__ */ + +ACE_RCSID(ace, Framework_Component, "$Id$") + +ACE_Framework_Component:: ~ACE_Framework_Component (void) +{ + ACE_TRACE ("ACE_Framework_Component::dtor"); +} + +/***************************************************************/ + +ACE_ALLOC_HOOK_DEFINE(ACE_Framework_Repository) + +// Pointer to the Singleton instance. +ACE_Framework_Repository *ACE_Framework_Repository::repository_ = 0; + +ACE_Framework_Repository::~ACE_Framework_Repository (void) +{ + ACE_TRACE ("ACE_Framework_Repository::~ACE_Framework_Repository"); + this->close (); +} + +int +ACE_Framework_Repository::open (int size) +{ + ACE_TRACE ("ACE_Framework_Repository::open"); + + ACE_Framework_Component **temp; + + ACE_NEW_RETURN (temp, + ACE_Framework_Component *[size], + -1); + + this->component_vector_ = ACE_const_cast (const ACE_Framework_Component **, + temp); + this->total_size_ = size; + return 0; +} + +int +ACE_Framework_Repository::close (void) +{ + ACE_TRACE ("ACE_Framework_Repository::close"); + ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); + + if (this->component_vector_ != 0) + { + // Delete components in reverse order. + for (int i = this->current_size_ - 1; i >= 0; i--) + { + ACE_Framework_Component *s = ACE_const_cast (ACE_Framework_Component *, + this->component_vector_[i]); + --this->current_size_; + delete s; + } + + delete [] this->component_vector_; + this->component_vector_ = 0; + this->current_size_ = 0; + } + + return 0; +} + +ACE_Framework_Repository * +ACE_Framework_Repository::instance (int size) +{ + ACE_TRACE ("ACE_Framework_Repository::instance"); + + if (ACE_Framework_Repository::repository_ == 0) + { + // Perform Double-Checked Locking Optimization. + ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, + *ACE_Static_Object_Lock::instance (), 0)); + if (ACE_Framework_Repository::repository_ == 0) + { + if (ACE_Object_Manager::starting_up () || + !ACE_Object_Manager::shutting_down ()) + { + ACE_NEW_RETURN (ACE_Framework_Repository::repository_, + ACE_Framework_Repository (size), + 0); + } + } + } + + return ACE_Framework_Repository::repository_; +} + +void +ACE_Framework_Repository::close_singleton (void) +{ + ACE_TRACE ("ACE_Framework_Repository::close_singleton"); + + ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon, + *ACE_Static_Object_Lock::instance ())); + + delete ACE_Framework_Repository::repository_; + ACE_Framework_Repository::repository_ = 0; +} + +int +ACE_Framework_Repository::register_component (const ACE_Framework_Component *fc) +{ + ACE_TRACE ("ACE_Framework_Repository::register_component"); + ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); + int i; + + ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT("register_component\n"))); + + // Check to see if it's already registered + for (i = 0; i < this->current_size_; i++) + if (fc->this_ == this->component_vector_[i]->this_) + { + ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("Component already registered.\n"))); + // Delete it since it's already here and component adapter was newed. + delete fc; + return 0; + } + + if (i < this->total_size_) + { + ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("Component registered.\n"))); + this->component_vector_[i] = fc; + this->current_size_++; + return 0; + } + + return -1; +} + +void +ACE_Framework_Repository::dump (void) const +{ + ACE_TRACE ("ACE_Framework_Repository::dump"); +} + +ACE_Framework_Repository::ACE_Framework_Repository (int size) + : current_size_ (0) +{ + ACE_TRACE ("ACE_Framework_Repository::ctor"); + + if (this->open (size) == -1) + ACE_ERROR ((LM_ERROR, + ACE_LIB_TEXT ("%p\n"), + ACE_LIB_TEXT ("ACE_Framework_Repository"))); +} |