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

ACE_Service_Repository Class Reference

Contains all the services offered by a Service Configurator-based application. More...

#include <Service_Repository.h>

Collaboration diagram for ACE_Service_Repository:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { DEFAULT_SIZE = ACE_DEFAULT_SERVICE_REPOSITORY_SIZE }

Public Member Functions

 ACE_Service_Repository (size_t size=DEFAULT_SIZE)
 Initialize the repository.
int open (size_t size=DEFAULT_SIZE)
 Initialize the repository.
 ~ACE_Service_Repository (void)
int close (void)
 Close down all the services.
int fini (void)
 Finalize (call fini() and possibly delete) all the services.
int insert (const ACE_Service_Type *sr)
int find (const ACE_TCHAR name[], const ACE_Service_Type **srp=0, bool ignore_suspended=true) const
int remove (const ACE_TCHAR name[], ACE_Service_Type **sr=0)
int resume (const ACE_TCHAR name[], const ACE_Service_Type **srp=0)
 Resume a service record.
int suspend (const ACE_TCHAR name[], const ACE_Service_Type **srp=0)
 Suspend a service record.
size_t current_size (void) const
 Return the current size of the repository.
void dump (void) const
 Dump the state of an object.

Static Public Member Functions

static ACE_Service_Repositoryinstance (size_t size=ACE_Service_Repository::DEFAULT_SIZE)
 Get pointer to a process-wide ACE_Service_Repository.
static ACE_Service_Repositoryinstance (ACE_Service_Repository *)
static void close_singleton (void)
 Delete the dynamically allocated Singleton.

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

Protected Types

typedef ACE_Array_Map< size_t,
const ACE_Service_Type * > 
array_type
 The typedef of the array used to store the services.

Protected Member Functions

int remove_i (const ACE_TCHAR[], ACE_Service_Type **sr)
int find_i (const ACE_TCHAR service_name[], size_t &slot, const ACE_Service_Type **srp=0, bool ignore_suspended=true) const
int relocate_i (size_t begin, size_t end, const ACE_DLL &adll)
 Relocate (static) services to another DLL.

Protected Attributes

array_type service_array_
 Contains all the configured services.

Static Protected Attributes

static ACE_Service_Repositorysvc_rep_
 Pointer to a process-wide ACE_Service_Repository.
static bool delete_svc_rep_
 Must delete the svc_rep_ if true.

Friends

class ACE_Service_Repository_Iterator
class ACE_Service_Type_Dynamic_Guard

Detailed Description

Contains all the services offered by a Service Configurator-based application.

This class contains a vector of ACE_Service_Types *'s and allows an administrative entity to centrally manage and control the behavior of application services. Note that if services are removed from the middle of the repository the order won't necessarily be maintained since the remove method performs compaction. However, the common case is not to remove services, so typically they are deleted in the reverse order that they were added originally.

Definition at line 49 of file Service_Repository.h.


Member Typedef Documentation

The typedef of the array used to store the services.

Definition at line 190 of file Service_Repository.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
DEFAULT_SIZE 

Definition at line 54 of file Service_Repository.h.


Constructor & Destructor Documentation

ACE_Service_Repository::ACE_Service_Repository ( size_t  size = DEFAULT_SIZE  ) 

Initialize the repository.

Definition at line 110 of file Service_Repository.cpp.

  : service_array_ (size)
{
  ACE_TRACE ("ACE_Service_Repository::ACE_Service_Repository");
}

ACE_Service_Repository::~ACE_Service_Repository ( void   ) 

Close down the repository and free up dynamically allocated resources.

Definition at line 261 of file Service_Repository.cpp.

{
  ACE_TRACE ("ACE_Service_Repository::~ACE_Service_Repository");
#ifndef ACE_NLOGGING
  if(ACE::debug ())
    ACE_DEBUG ((LM_DEBUG, "ACE (%P|%t) SR::<dtor>, this=%@\n", this));
#endif
  this->close ();
}


Member Function Documentation

int ACE_Service_Repository::close ( void   ) 

Close down all the services.

Close down the repository and free up dynamically allocated resources.

Definition at line 215 of file Service_Repository.cpp.

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

#ifndef ACE_NLOGGING
  if(ACE::debug ())
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("ACE (%P|%t) SR::close - repo=%@, size=%d\n"),
                this,
                this->service_array_.size()));
#endif

  // Do not use the prefix decrement operator since the index is
  // unsigned and may wrap around the 0.
  for (size_t i = this->service_array_.size(); i-- != 0; )
    {
      // Delete services in reverse order.
      ACE_Service_Type *s =
        const_cast<ACE_Service_Type *> (this->service_array_[i]);

#ifndef ACE_NLOGGING
      if(ACE::debug ())
        {
          if (s == 0)
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("ACE (%P|%t) SR::close - repo=%@ [%d] -> 0\n"),
                        this,
                        i));
          else
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("ACE (%P|%t) SR::close - repo=%@ [%d], name=%s, object=%@\n"),
                        this,
                        i,
                        s->name (),
                        s));
        }
#endif
      delete s;
    }

  this->service_array_.clear ();

  return 0;
}

void ACE_Service_Repository::close_singleton ( void   )  [static]

Delete the dynamically allocated Singleton.

Definition at line 82 of file Service_Repository.cpp.

{
  ACE_TRACE ("ACE_Service_Repository::close_singleton");

  ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
                     *ACE_Static_Object_Lock::instance ()));

  if (ACE_Service_Repository::delete_svc_rep_)
    {
      delete ACE_Service_Repository::svc_rep_;
      ACE_Service_Repository::svc_rep_ = 0;
      ACE_Service_Repository::delete_svc_rep_ = false;
    }
}

size_t ACE_Service_Repository::current_size ( void   )  const

Return the current size of the repository.

Definition at line 16 of file Service_Repository.inl.

{
  ACE_TRACE ("ACE_Service_Repository::current_size");
  ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex,
                            ace_mon,
                            (ACE_Recursive_Thread_Mutex &) this->lock_, 0));
  return this->service_array_.size ();
}

void ACE_Service_Repository::dump ( void   )  const

Dump the state of an object.

Definition at line 33 of file Service_Repository.cpp.

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

int ACE_Service_Repository::find ( const ACE_TCHAR  name[],
const ACE_Service_Type **  srp = 0,
bool  ignore_suspended = true 
) const

Locate a named entry in the service table, optionally ignoring suspended entries.

Parameters:
name The name of the service to search for.
srp Optional; if not 0, it is a pointer to a location to receive the ACE_Service_Type pointer for the located service. Meaningless if this method returns -1.
ignore_suspended If true, the search ignores suspended services.
Return values:
0 Named service was located.
-1 Named service was not found.
-2 Named service was found, but is suspended and ignore_suspended is true.

Definition at line 388 of file Service_Repository.cpp.

{
  ACE_TRACE ("ACE_Service_Repository::find");
  ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));
  size_t ignore_location = 0;
  return this->find_i (name, ignore_location, srp, ignore_suspended);
}

int ACE_Service_Repository::find_i ( const ACE_TCHAR  name[],
size_t &  slot,
const ACE_Service_Type **  srp = 0,
bool  ignore_suspended = true 
) const [protected]

Locate a named entry in the service table, optionally ignoring suspended entries.

Parameters:
service_name The name of the service to search for.
slot Receives the position index of the service if it is found. Contents are meaningless if this method returns -1.
srp Optional; if not 0, it is a pointer to a location to receive the ACE_Service_Type pointer for the located service. Meaningless if this method returns -1.
ignore_suspended If true, the search ignores suspended services.
Return values:
0 Named service was located; index in the table is set in slot.
-1 Named service was not found.
-2 Named service was found, but is suspended and ignore_suspended is true.

Locate an entry with name in the table. If ignore_suspended is set then only consider services marked as resumed. If the caller wants the located entry, pass back a pointer to the located entry via srp. If name is not found -1 is returned. If name is found, but it is suspended and the caller wants to ignore suspended services a -2 is returned. Must be called with locks held.

Definition at line 278 of file Service_Repository.cpp.

{
  ACE_TRACE ("ACE_Service_Repository::find_i");
  size_t i = 0;
  array_type::const_iterator element = this->service_array_.end ();

  for (i = 0; i < this->service_array_.size(); i++)
    {
      array_type::const_iterator iter = this->service_array_.find (i);
      if (iter != this->service_array_.end ()
          && (*iter).second != 0 // skip any empty slots
          && ACE_OS::strcmp (name, (*iter).second->name ()) == 0)
      {
        element = iter;
        break;
      }
    }

  if (element != this->service_array_.end ())
    {
      slot = i;
      if ((*element).second->fini_called ())
        {
          if (srp != 0)
            *srp = 0;
          return -1;
        }

      if (srp != 0)
        *srp = (*element).second;

      if (ignore_suspended
          && (*element).second->active () == 0)
        return -2;

      return 0;
    }

  return -1;
}

int ACE_Service_Repository::fini ( void   ) 

Finalize (call fini() and possibly delete) all the services.

Finalize all the services by calling fini() and deleting dynamically allocated services.

Definition at line 120 of file Service_Repository.cpp.

{
  ACE_TRACE ("ACE_Service_Repository::fini");
  ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));

  int retval = 0;
  // Do not be tempted to use the prefix decrement operator.  Use
  // postfix decrement operator since the index is unsigned and may
  // wrap around the 0
  //
  // debug output for empty service entries
#ifndef ACE_NLOGGING
  if (ACE::debug ())
  {
    for (size_t i = this->service_array_.size (); i-- != 0;)
    {
      ACE_Service_Type *s =
        const_cast<ACE_Service_Type *> (this->service_array_[i]);
      if (s == 0)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("ACE (%P|%t) SR::fini, repo=%@ [%d] -> 0\n"),
                    this,
                    i));
    }
  }
#endif
  //
  // Remove all the Service_Object and Stream instances
  //
  for (size_t i = this->service_array_.size (); i-- != 0;)
  {
    // <fini> the services in reverse order.
    ACE_Service_Type *s =
      const_cast<ACE_Service_Type *> (this->service_array_[i]);

    if (s != 0 &&
        s->type () != 0 &&
        (s->type ()->service_type () != ACE_Service_Type::MODULE))
    {
#ifndef ACE_NLOGGING
      if (ACE::debug ())
      {
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("ACE (%P|%t) SR::fini, repo=%@ [%d], ")
                    ACE_TEXT ("name=%s, type=%@, object=%@, active=%d\n"),
                    this,
                    i,
                    s->name (),
                    s->type (),
                    (s->type () != 0) ? s->type ()->object () : 0,
                    s->active ()));
      }
#endif

      // Collect any errors.
      retval += s->fini ();
    }
  }
  //
  // Remove all the Module instances
  //
  for (size_t i = this->service_array_.size (); i-- != 0;)
  {
    // <fini> the services in reverse order.
    ACE_Service_Type *s =
      const_cast<ACE_Service_Type *> (this->service_array_[i]);

    if (s != 0 &&
        s->type () != 0 &&
        (s->type ()->service_type () == ACE_Service_Type::MODULE))
    {
#ifndef ACE_NLOGGING
      if (ACE::debug ())
      {
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("ACE (%P|%t) SR::fini, repo=%@ [%d], ")
                    ACE_TEXT ("name=%s, type=%@, object=%@, active=%d\n"),
                    this,
                    i,
                    s->name (),
                    s->type (),
                    (s->type () != 0) ? s->type ()->object () : 0,
                    s->active ()));
      }
#endif
      // Collect any errors.
      retval += s->fini ();
    }
  }
  return (retval == 0) ? 0 : -1;
}

int ACE_Service_Repository::insert ( const ACE_Service_Type sr  ) 

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

ACE_Service_Repository * ACE_Service_Repository::instance ( size_t  size = ACE_Service_Repository::DEFAULT_SIZE  )  [static]

Get pointer to a process-wide ACE_Service_Repository.

Definition at line 41 of file Service_Repository.cpp.

{
  ACE_TRACE ("ACE_Service_Repository::instance");

  if (ACE_Service_Repository::svc_rep_ == 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_Service_Repository::svc_rep_ == 0)
        {
          if (ACE_Object_Manager::starting_up () ||
              !ACE_Object_Manager::shutting_down ())
            {
              ACE_NEW_RETURN (ACE_Service_Repository::svc_rep_,
                              ACE_Service_Repository (size),
                              0);
              ACE_Service_Repository::delete_svc_rep_ = true;
            }
        }
    }

  return ACE_Service_Repository::svc_rep_;
}

ACE_Service_Repository * ACE_Service_Repository::instance ( ACE_Service_Repository s  )  [static]

Set pointer to a process-wide ACE_Service_Repository and return existing pointer.

Definition at line 67 of file Service_Repository.cpp.

{
  ACE_TRACE ("ACE_Service_Repository::instance");
  ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
                            *ACE_Static_Object_Lock::instance (), 0));

  ACE_Service_Repository *t = ACE_Service_Repository::svc_rep_;
  // We can't safely delete it since we don't know who created it!
  ACE_Service_Repository::delete_svc_rep_ = false;

  ACE_Service_Repository::svc_rep_ = s;
  return t;
}

int ACE_Service_Repository::open ( size_t  size = DEFAULT_SIZE  ) 

Initialize the repository.

Initialize the Repository to a clean slate.

Definition at line 99 of file Service_Repository.cpp.

{
  ACE_TRACE ("ACE_Service_Repository::open");

  // Create a new array and swap it with the local array
  array_type local_array (size);
  this->service_array_.swap (local_array);

  return 0;
}

int ACE_Service_Repository::relocate_i ( size_t  begin,
size_t  end,
const ACE_DLL adll 
) [protected]

Relocate (static) services to another DLL.

Relocate (a static) service to another DLL.

If any have been registered in the context of a "forward declaration" guard, those really aren't static services. Their code is in the DLL's code segment, or in one of the dependent DLLs. Therefore, such services need to be associated with the proper DLL in order to prevent failures upon finalization. The method locks the repo.

Works by having the service type keep a reference to a specific DLL. No locking, caller makes sure calling it is safe. You can forcefully relocate any DLLs in the given range, not only the static ones - but that will cause Very Bad Things (tm) to happen.

Works by having the service type keep a reference to a specific DLL. No locking, caller makes sure calling it is safe. You can forcefully relocate any DLLs in the given range, not only the static ones - but that will cause Very Bad Things (tm) to happen.

Definition at line 330 of file Service_Repository.cpp.

{
  ACE_SHLIB_HANDLE new_handle = adll.get_handle (0);

  for (size_t i = begin; i < end; i++)
    {
      ACE_Service_Type *type =
        const_cast<ACE_Service_Type *> (this->service_array_[i]);

      ACE_SHLIB_HANDLE old_handle = (type == 0) ? ACE_SHLIB_INVALID_HANDLE
                                                : type->dll ().get_handle (0);

#ifndef ACE_NLOGGING
      if (ACE::debug ())
        {
          if (type == 0)
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("ACE (%P|%t) SR::relocate_i - repo=%@ [%d]")
                        ACE_TEXT (": skipping empty slot\n"),
                        this,
                        i));
          else
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("ACE (%P|%t) SR::relocate_i - repo=%@ [%d]")
                        ACE_TEXT (": trying name=%s, handle: %d -> %d\n"),
                        this,
                        i,
                        type->name (),
                        old_handle,
                        new_handle));
        }
#endif

      if (type != 0  // skip any gaps
          && old_handle == ACE_SHLIB_INVALID_HANDLE
          && new_handle != old_handle)
        {
#ifndef ACE_NLOGGING
          if (ACE::debug ())
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("ACE (%P|%t) SR::relocate_i - repo=%@ [%d]")
                        ACE_TEXT (": relocating name=%s, handle: %d -> %d\n"),
                        this,
                        i,
                        type->name (),
                        old_handle,
                        new_handle));
#endif
          type->dll (adll); // ups the refcount on adll
        }
    }

  return 0;
}

int ACE_Service_Repository::remove ( const ACE_TCHAR  name[],
ACE_Service_Type **  sr = 0 
)

Remove an existing service record. If sr == 0, the service record is deleted before control is returned to the caller. If sr != 0, the service's record is removed from the repository, but not deleted; sr receives the service record pointer and the caller is responsible for properly disposing of it.

int ACE_Service_Repository::remove_i ( const   ACE_TCHAR[],
ACE_Service_Type **  sr 
) [protected]

Remove an existing service record. It requires sr != 0, which receives the service record pointer and the caller is responsible for properly disposing of it.

int ACE_Service_Repository::resume ( const ACE_TCHAR  name[],
const ACE_Service_Type **  srp = 0 
)

Resume a service record.

int ACE_Service_Repository::suspend ( const ACE_TCHAR  name[],
const ACE_Service_Type **  srp = 0 
)

Suspend a service record.


Friends And Related Function Documentation

friend class ACE_Service_Repository_Iterator [friend]

Definition at line 52 of file Service_Repository.h.

friend class ACE_Service_Type_Dynamic_Guard [friend]

Definition at line 140 of file Service_Repository.h.


Member Data Documentation

Declare the dynamic allocation hooks.

Definition at line 136 of file Service_Repository.h.

bool ACE_Service_Repository::delete_svc_rep_ [static, protected]

Must delete the svc_rep_ if true.

Definition at line 199 of file Service_Repository.h.

Contains all the configured services.

Definition at line 193 of file Service_Repository.h.

Pointer to a process-wide ACE_Service_Repository.

Definition at line 196 of file Service_Repository.h.


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