Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends

ACE_Framework_Repository Class Reference

Contains all framework components used by an application. More...

#include <Framework_Component.h>

Collaboration diagram for ACE_Framework_Repository:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { DEFAULT_SIZE = ACE_DEFAULT_FRAMEWORK_REPOSITORY_SIZE }

Public Member Functions

 ~ACE_Framework_Repository (void)
int open (int size=DEFAULT_SIZE)
 Initialize the repository.
int close (void)
int register_component (ACE_Framework_Component *fc)
int remove_component (const ACE_TCHAR *name)
int remove_dll_components (const ACE_TCHAR *dll_name)
 Remove all components associated with a particular dll.
int current_size (void) const
 Return the current size of the repository.
int total_size (void) const
 Return the total size of the repository.
void dump (void) const
 Dump the state of an object.

Static Public Member Functions

static ACE_Framework_Repositoryinstance (int size=ACE_Framework_Repository::DEFAULT_SIZE)
 Get pointer to a process-wide ACE_Framework_Repository.
static void close_singleton (void)
 Delete the dynamically allocated Singleton.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

Protected Member Functions

 ACE_Framework_Repository (int size=ACE_Framework_Repository::DEFAULT_SIZE)
 Initialize the repository.

Private Member Functions

int remove_dll_components_i (const ACE_TCHAR *dll_name)
 Actually removes the dll components, must be called with locks held.
void compact (void)
 ACE_Framework_Repository (const ACE_Framework_Repository &)
 Disallow copying and assignment.
ACE_Framework_Repositoryoperator= (const ACE_Framework_Repository &)

Private Attributes

ACE_Framework_Component ** component_vector_
 Contains all the framework components.
int current_size_
 Current number of components.
int total_size_
 Maximum number of components.

Static Private Attributes

static ACE_Framework_Repositoryrepository_ = 0
 Pointer to a process-wide ACE_Framework_Repository.
static sig_atomic_t shutting_down_ = 0

Friends

class ACE_Framework_Component

Detailed Description

Contains all framework components used by an application.

This class contains a vector of ACE_Framework_Component *'s. On destruction, framework components are destroyed in the reverse order that they were added originally.

Definition at line 101 of file Framework_Component.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
DEFAULT_SIZE 

Definition at line 107 of file Framework_Component.h.


Constructor & Destructor Documentation

ACE_Framework_Repository::~ACE_Framework_Repository ( void   ) 

Close down the repository and free up dynamically allocated resources.

Definition at line 37 of file Framework_Component.cpp.

{
  ACE_TRACE ("ACE_Framework_Repository::~ACE_Framework_Repository");
  this->close ();
}

ACE_Framework_Repository::ACE_Framework_Repository ( int  size = ACE_Framework_Repository::DEFAULT_SIZE  )  [protected]

Initialize the repository.

Definition at line 268 of file Framework_Component.cpp.

  : current_size_ (0)
{
  ACE_TRACE ("ACE_Framework_Repository::ACE_Framework_Repository");

  if (this->open (size) == -1)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("%p\n"),
                ACE_TEXT ("ACE_Framework_Repository")));
}

ACE_Framework_Repository::ACE_Framework_Repository ( const ACE_Framework_Repository  )  [private]

Disallow copying and assignment.


Member Function Documentation

int ACE_Framework_Repository::close ( void   ) 

Close down the repository and free up dynamically allocated resources, also called by dtor.

Definition at line 60 of file Framework_Component.cpp.

{
  ACE_TRACE ("ACE_Framework_Repository::close");
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));

  this->shutting_down_ = 1;

  if (this->component_vector_ != 0)
    {
      // Delete components in reverse order.
      for (int i = this->current_size_ - 1; i >= 0; i--)
        if (this->component_vector_[i])
          {
            ACE_Framework_Component *s =
              const_cast<ACE_Framework_Component *> (
                this->component_vector_[i]);

            this->component_vector_[i] = 0;
            delete s;
          }

      delete [] this->component_vector_;
      this->component_vector_ = 0;
      this->current_size_ = 0;
    }

  ACE_DLL_Manager::close_singleton ();
  return 0;
}

void ACE_Framework_Repository::close_singleton ( void   )  [static]

Delete the dynamically allocated Singleton.

Definition at line 116 of file Framework_Component.cpp.

{
  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;
}

void ACE_Framework_Repository::compact ( void   )  [private]

Compact component_vector_ after components have been removed__maintains order.

Definition at line 214 of file Framework_Component.cpp.

{
  ACE_TRACE ("ACE_Framework_Repository::compact");

  int i;
  int start_hole;
  int end_hole;

  do
    {
      start_hole = this->current_size_;
      end_hole = this->current_size_;

      // Find hole
      for (i = 0; i < this->current_size_; ++i)
        {
          if (this->component_vector_[i] == 0)
            {
              if (start_hole == this->current_size_)
                {
                  start_hole = i;
                  end_hole = i;
                }
              else
                end_hole = i;
            }
          else if (end_hole != this->current_size_)
            break;
        }

      if (start_hole != this->current_size_)
        {
          // move the contents and reset current_size_
          while (end_hole + 1 < this->current_size_)
            {
              this->component_vector_[start_hole++] =
                this->component_vector_[++end_hole];
            }
          // Since start_hole is now one past the last
          // active slot.
          this->current_size_ = start_hole;
        }

    } while (start_hole != this->current_size_);
}

int ACE_Framework_Repository::current_size ( void   )  const [inline]

Return the current size of the repository.

Definition at line 24 of file Framework_Component.inl.

{
  ACE_TRACE ("ACE_Framework_Repository::current_size");
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, (ACE_Thread_Mutex &) this->lock_, -1));
  return this->current_size_;
}

void ACE_Framework_Repository::dump ( void   )  const

Dump the state of an object.

Definition at line 261 of file Framework_Component.cpp.

{
#if defined (ACE_HAS_DUMP)
  ACE_TRACE ("ACE_Framework_Repository::dump");
#endif /* ACE_HAS_DUMP */
}

ACE_Framework_Repository * ACE_Framework_Repository::instance ( int  size = ACE_Framework_Repository::DEFAULT_SIZE  )  [static]

Get pointer to a process-wide ACE_Framework_Repository.

Definition at line 91 of file Framework_Component.cpp.

{
  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_;
}

int ACE_Framework_Repository::open ( int  size = DEFAULT_SIZE  ) 

Initialize the repository.

Definition at line 44 of file Framework_Component.cpp.

{
  ACE_TRACE ("ACE_Framework_Repository::open");

  ACE_Framework_Component **temp = 0;

  ACE_NEW_RETURN (temp,
                  ACE_Framework_Component *[size],
                  -1);

  this->component_vector_ = temp;
  this->total_size_ = size;
  return 0;
}

ACE_Framework_Repository& ACE_Framework_Repository::operator= ( const ACE_Framework_Repository  )  [private]
int ACE_Framework_Repository::register_component ( ACE_Framework_Component fc  ) 

Insert a new component. Returns -1 when the repository is full and 0 on success.

Definition at line 128 of file Framework_Component.cpp.

{
  ACE_TRACE ("ACE_Framework_Repository::register_component");
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
  int i;

  // Check to see if it's already registered
  for (i = 0; i < this->current_size_; i++)
    if (this->component_vector_[i] &&
        fc->this_ == this->component_vector_[i]->this_)
      {
        ACE_ERROR_RETURN ((LM_ERROR,
          "AFR::register_component: error, compenent already registered\n"),
                          -1);
      }

  if (i < this->total_size_)
    {
      this->component_vector_[i] = fc;
      ++this->current_size_;
      return 0;
    }

  return -1;
}

int ACE_Framework_Repository::remove_component ( const ACE_TCHAR name  ) 

Remove a component. Returns -1 on error or if component not found and 0 on success.

Definition at line 155 of file Framework_Component.cpp.

{
  ACE_TRACE ("ACE_Framework_Repository::remove_component");
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
  int i;

  for (i = 0; i < this->current_size_; i++)
    if (this->component_vector_[i] &&
        ACE_OS::strcmp (this->component_vector_[i]->name_, name) == 0)
      {
        delete this->component_vector_[i];
        this->component_vector_[i] = 0;
        this->compact ();
        return 0;
      }

  return -1;
}

int ACE_Framework_Repository::remove_dll_components ( const ACE_TCHAR dll_name  ) 

Remove all components associated with a particular dll.

Definition at line 175 of file Framework_Component.cpp.

{
  ACE_TRACE ("ACE_Framework_Repository::remove_dll_components");

  if (this->shutting_down_)
    return this->remove_dll_components_i (dll_name);
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));

  return this->remove_dll_components_i (dll_name);
}

int ACE_Framework_Repository::remove_dll_components_i ( const ACE_TCHAR dll_name  )  [private]

Actually removes the dll components, must be called with locks held.

Definition at line 187 of file Framework_Component.cpp.

{
  ACE_TRACE ("ACE_Framework_Repository::remove_dll_components_i");

  int i;
  int retval = -1;

  for (i = 0; i < this->current_size_; i++)
    if (this->component_vector_[i] &&
        ACE_OS::strcmp (this->component_vector_[i]->dll_name_, dll_name) == 0)
      {
          if (ACE::debug ())
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("AFR::remove_dll_components_i (%s) ")
                        ACE_TEXT ("component \"%s\"\n"),
                        dll_name, this->component_vector_[i]->name_));
        delete this->component_vector_[i];
        this->component_vector_[i] = 0;
        ++retval;
      }

  this->compact ();

  return retval == -1 ? -1 : 0;
}

int ACE_Framework_Repository::total_size ( void   )  const [inline]

Return the total size of the repository.

Definition at line 32 of file Framework_Component.inl.

{
  ACE_TRACE ("ACE_Framework_Repository::total_size");
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, (ACE_Thread_Mutex &) this->lock_, -1));
  return this->total_size_;
}


Friends And Related Function Documentation

friend class ACE_Framework_Component [friend]

Definition at line 105 of file Framework_Component.h.


Member Data Documentation

Declare the dynamic allocation hooks.

Definition at line 153 of file Framework_Component.h.

Contains all the framework components.

Definition at line 176 of file Framework_Component.h.

Current number of components.

Definition at line 179 of file Framework_Component.h.

Pointer to a process-wide ACE_Framework_Repository.

Definition at line 185 of file Framework_Component.h.

Flag set when repository is the process of shutting down. This is necessary to keep from self-deadlocking since some of the components might make calls back to the repository to unload their components, e.g., ACE_DLL_Manager.

Definition at line 191 of file Framework_Component.h.

Maximum number of components.

Definition at line 182 of file Framework_Component.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines