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.
ACE_Recursive_Thread_Mutex lock_
 Synchronization variable for the MT_SAFE Repository.

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.

00055   {
00056     DEFAULT_SIZE = ACE_DEFAULT_SERVICE_REPOSITORY_SIZE
00057   };


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.

00111   : service_array_ (size)
00112 {
00113   ACE_TRACE ("ACE_Service_Repository::ACE_Service_Repository");
00114 }

ACE_Service_Repository::~ACE_Service_Repository ( void   ) 

Close down the repository and free up dynamically allocated resources.

Definition at line 211 of file Service_Repository.cpp.

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


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 165 of file Service_Repository.cpp.

00166 {
00167   ACE_TRACE ("ACE_Service_Repository::close");
00168   ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));
00169 
00170 #ifndef ACE_NLOGGING
00171   if(ACE::debug ())
00172     ACE_DEBUG ((LM_DEBUG,
00173                 ACE_TEXT ("ACE (%P|%t) SR::close - repo=%@, size=%d\n"),
00174                 this,
00175                 this->service_array_.size()));
00176 #endif
00177 
00178   // Do not use the prefix decrement operator since the index is
00179   // unsigned and may wrap around the 0.
00180   for (size_t i = this->service_array_.size(); i-- != 0; )
00181     {
00182       // Delete services in reverse order.
00183       ACE_Service_Type *s =
00184         const_cast<ACE_Service_Type *> (this->service_array_[i]);
00185 
00186 #ifndef ACE_NLOGGING
00187       if(ACE::debug ())
00188         {
00189           if (s == 0)
00190             ACE_DEBUG ((LM_DEBUG,
00191                         ACE_TEXT ("ACE (%P|%t) SR::close - repo=%@ [%d] -> 0\n"),
00192                         this,
00193                         i));
00194           else
00195             ACE_DEBUG ((LM_DEBUG,
00196                         ACE_TEXT ("ACE (%P|%t) SR::close - repo=%@ [%d], name=%s, object=%@\n"),
00197                         this,
00198                         i,
00199                         s->name (),
00200                         s));
00201         }
00202 #endif
00203       delete s;
00204     }
00205 
00206   this->service_array_.clear ();
00207 
00208   return 0;
00209 }

void ACE_Service_Repository::close_singleton ( void   )  [static]

Delete the dynamically allocated Singleton.

Definition at line 82 of file Service_Repository.cpp.

00083 {
00084   ACE_TRACE ("ACE_Service_Repository::close_singleton");
00085 
00086   ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
00087                      *ACE_Static_Object_Lock::instance ()));
00088 
00089   if (ACE_Service_Repository::delete_svc_rep_)
00090     {
00091       delete ACE_Service_Repository::svc_rep_;
00092       ACE_Service_Repository::svc_rep_ = 0;
00093       ACE_Service_Repository::delete_svc_rep_ = false;
00094     }
00095 }

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.

00017 {
00018   ACE_TRACE ("ACE_Service_Repository::current_size");
00019   ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex,
00020                             ace_mon,
00021                             (ACE_Recursive_Thread_Mutex &) this->lock_, 0));
00022   return this->service_array_.size ();
00023 }

void ACE_Service_Repository::dump ( void   )  const

Dump the state of an object.

Definition at line 33 of file Service_Repository.cpp.

00034 {
00035 #if defined (ACE_HAS_DUMP)
00036   ACE_TRACE ("ACE_Service_Repository::dump");
00037 #endif /* ACE_HAS_DUMP */
00038 }

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:
service_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 338 of file Service_Repository.cpp.

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

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 228 of file Service_Repository.cpp.

00232 {
00233   ACE_TRACE ("ACE_Service_Repository::find_i");
00234   size_t i = 0;
00235   array_type::const_iterator element = this->service_array_.end ();
00236 
00237   for (i = 0; i < this->service_array_.size(); i++)
00238     {
00239       array_type::const_iterator iter = this->service_array_.find (i);
00240       if (iter != this->service_array_.end ()
00241           && (*iter).second != 0 // skip any empty slots
00242           && ACE_OS::strcmp (name, (*iter).second->name ()) == 0)
00243       {
00244         element = iter;
00245         break;
00246       }
00247     }
00248 
00249   if (element != this->service_array_.end ())
00250     {
00251       slot = i;
00252       if ((*element).second->fini_called ())
00253         {
00254           if (srp != 0)
00255             *srp = 0;
00256           return -1;
00257         }
00258 
00259       if (srp != 0)
00260         *srp = (*element).second;
00261 
00262       if (ignore_suspended
00263           && (*element).second->active () == 0)
00264         return -2;
00265 
00266       return 0;
00267     }
00268 
00269   return -1;
00270 }

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 118 of file Service_Repository.cpp.

00119 {
00120   ACE_TRACE ("ACE_Service_Repository::fini");
00121   ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));
00122 
00123   int retval = 0;
00124 
00125   // Do not be tempted to use the prefix decrement operator.  Use
00126   // postfix decrement operator since the index is unsigned and may
00127   // wrap around the 0
00128   for (size_t i = this->service_array_.size(); i-- != 0; )
00129     {
00130       // <fini> the services in reverse order.
00131       ACE_Service_Type *s =
00132         const_cast<ACE_Service_Type *> (this->service_array_[i]);
00133 
00134 #ifndef ACE_NLOGGING
00135       if (ACE::debug ())
00136         {
00137           if (s != 0)
00138             ACE_DEBUG ((LM_DEBUG,
00139                         ACE_TEXT ("ACE (%P|%t) SR::fini, repo=%@ [%d], ")
00140                         ACE_TEXT ("name=%s, type=%@, object=%@, active=%d\n"),
00141                         this,
00142                         i,
00143                         s->name(),
00144                         s->type (),
00145                         (s->type () != 0) ? s->type ()->object () : 0,
00146                         s->active ()));
00147           else
00148             ACE_DEBUG ((LM_DEBUG,
00149                         ACE_TEXT ("ACE (%P|%t) SR::fini, repo=%@ [%d] -> 0\n"),
00150                         this,
00151                         i));
00152         }
00153 #endif
00154 
00155       // Collect any errors.
00156       if (s != 0)
00157         retval += s->fini ();
00158     }
00159 
00160   return (retval == 0) ? 0 : -1;
00161 }

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 ( 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.

00068 {
00069   ACE_TRACE ("ACE_Service_Repository::instance");
00070   ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00071                             *ACE_Static_Object_Lock::instance (), 0));
00072 
00073   ACE_Service_Repository *t = ACE_Service_Repository::svc_rep_;
00074   // We can't safely delete it since we don't know who created it!
00075   ACE_Service_Repository::delete_svc_rep_ = false;
00076 
00077   ACE_Service_Repository::svc_rep_ = s;
00078   return t;
00079 }

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.

00042 {
00043   ACE_TRACE ("ACE_Service_Repository::instance");
00044 
00045   if (ACE_Service_Repository::svc_rep_ == 0)
00046     {
00047       // Perform Double-Checked Locking Optimization.
00048       ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00049                                 *ACE_Static_Object_Lock::instance (), 0));
00050       if (ACE_Service_Repository::svc_rep_ == 0)
00051         {
00052           if (ACE_Object_Manager::starting_up () ||
00053               !ACE_Object_Manager::shutting_down ())
00054             {
00055               ACE_NEW_RETURN (ACE_Service_Repository::svc_rep_,
00056                               ACE_Service_Repository (size),
00057                               0);
00058               ACE_Service_Repository::delete_svc_rep_ = true;
00059             }
00060         }
00061     }
00062 
00063   return ACE_Service_Repository::svc_rep_;
00064 }

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.

00100 {
00101   ACE_TRACE ("ACE_Service_Repository::open");
00102 
00103   // Create a new array and swap it with the local array
00104   array_type local_array (size);
00105   this->service_array_.swap (local_array);
00106 
00107   return 0;
00108 }

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 280 of file Service_Repository.cpp.

00283 {
00284   ACE_SHLIB_HANDLE new_handle = adll.get_handle (0);
00285 
00286   for (size_t i = begin; i < end; i++)
00287     {
00288       ACE_Service_Type *type =
00289         const_cast<ACE_Service_Type *> (this->service_array_[i]);
00290 
00291       ACE_SHLIB_HANDLE old_handle = (type == 0) ? ACE_SHLIB_INVALID_HANDLE
00292                                                 : type->dll ().get_handle (0);
00293 
00294 #ifndef ACE_NLOGGING
00295       if (ACE::debug ())
00296         {
00297           if (type == 0)
00298             ACE_DEBUG ((LM_DEBUG,
00299                         ACE_TEXT ("ACE (%P|%t) SR::relocate_i - repo=%@ [%d]")
00300                         ACE_TEXT (": skipping empty slot\n"),
00301                         this,
00302                         i));
00303           else
00304             ACE_DEBUG ((LM_DEBUG,
00305                         ACE_TEXT ("ACE (%P|%t) SR::relocate_i - repo=%@ [%d]")
00306                         ACE_TEXT (": trying name=%s, handle: %d -> %d\n"),
00307                         this,
00308                         i,
00309                         type->name (),
00310                         old_handle,
00311                         new_handle));
00312         }
00313 #endif
00314 
00315       if (type != 0  // skip any gaps
00316           && old_handle == ACE_SHLIB_INVALID_HANDLE
00317           && new_handle != old_handle)
00318         {
00319 #ifndef ACE_NLOGGING
00320           if (ACE::debug ())
00321             ACE_DEBUG ((LM_DEBUG,
00322                         ACE_TEXT ("ACE (%P|%t) SR::relocate_i - repo=%@ [%d]")
00323                         ACE_TEXT (": relocating name=%s, handle: %d -> %d\n"),
00324                         this,
00325                         i,
00326                         type->name (),
00327                         old_handle,
00328                         new_handle));
00329 #endif
00330           type->dll (adll); // ups the refcount on adll
00331         }
00332     }
00333 
00334   return 0;
00335 }

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.

Synchronization variable for the MT_SAFE Repository.

Definition at line 203 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

Generated on Sat Nov 21 23:18:05 2009 for ACE by  doxygen 1.6.1