#include <Service_Repository.h>
Collaboration diagram for ACE_Service_Repository:
Public Types | |
enum | { DEFAULT_SIZE = ACE_DEFAULT_SERVICE_REPOSITORY_SIZE } |
Public Member Functions | |
ACE_Service_Repository (void) | |
Initialize the repository. | |
ACE_Service_Repository (size_t size) | |
Initialize the repository. | |
int | open (size_t size=DEFAULT_SIZE) |
Initialize the repository. | |
~ACE_Service_Repository (void) | |
int | close (void) |
int | fini (void) |
int | insert (const ACE_Service_Type *) |
int | find (const ACE_TCHAR name[], const ACE_Service_Type **srp=0, bool ignore_suspended=true) const |
int | remove (const ACE_TCHAR[], ACE_Service_Type **sr=0) |
Completely remove a entry from the Repository and dynamically unlink it if it was originally dynamically linked. | |
int | resume (const ACE_TCHAR[], const ACE_Service_Type **=0) |
Resume a service record. | |
int | suspend (const ACE_TCHAR[], const ACE_Service_Type **=0) |
Suspend a service record. | |
size_t | current_size (void) const |
Return the current size of the repository. | |
size_t | 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 | |
ACE_Service_Repository * | instance (size_t size=ACE_Service_Repository::DEFAULT_SIZE) |
Get pointer to a process-wide ACE_Service_Repository. | |
ACE_Service_Repository * | instance (ACE_Service_Repository *) |
void | close_singleton (void) |
Delete the dynamically allocated Singleton. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Private 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, bool static_only=true) |
Relocate (static) services to another DLL. | |
Private Attributes | |
const ACE_Service_Type ** | service_vector_ |
Contains all the configured services. | |
size_t | current_size_ |
Current number of services. | |
size_t | total_size_ |
Maximum number of services. | |
Static Private Attributes | |
ACE_Service_Repository * | svc_rep_ = 0 |
Pointer to a process-wide ACE_Service_Repository. | |
int | delete_svc_rep_ = 0 |
Must delete the if non-0. | |
Friends | |
class | ACE_Service_Repository_Iterator |
class | ACE_Service_Type_Dynamic_Guard |
This class contains a vector of *'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 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 48 of file Service_Repository.h.
|
Definition at line 53 of file Service_Repository.h.
00054 { 00055 DEFAULT_SIZE = ACE_DEFAULT_SERVICE_REPOSITORY_SIZE 00056 }; |
|
Initialize the repository.
Definition at line 40 of file Service_Repository.cpp. References ACE_TRACE.
00041 : service_vector_ (0), 00042 current_size_ (0), 00043 total_size_ (0) 00044 { 00045 ACE_TRACE ("ACE_Service_Repository::ACE_Service_Repository"); 00046 } |
|
Initialize the repository.
Definition at line 123 of file Service_Repository.cpp. References ACE_ERROR, ACE_TEXT, ACE_TRACE, LM_ERROR, and open().
00124 : current_size_ (0) 00125 { 00126 ACE_TRACE ("ACE_Service_Repository::ACE_Service_Repository"); 00127 00128 if (this->open (size) == -1) 00129 ACE_ERROR ((LM_ERROR, 00130 ACE_TEXT ("%p\n"), 00131 ACE_TEXT ("ACE_Service_Repository"))); 00132 } |
|
Close down the repository and free up dynamically allocated resources. Definition at line 231 of file Service_Repository.cpp. References ACE_DEBUG, ACE_TRACE, close(), ACE::debug(), and LM_DEBUG.
00232 { 00233 ACE_TRACE ("ACE_Service_Repository::~ACE_Service_Repository"); 00234 #ifndef ACE_NLOGGING 00235 if(ACE::debug ()) 00236 ACE_DEBUG ((LM_DEBUG, "(%P|%t) SR::<dtor>, this=%@\n", this)); 00237 #endif 00238 this->close (); 00239 } |
|
Close down the repository and free up dynamically allocated resources. Definition at line 182 of file Service_Repository.cpp. References ACE_DEBUG, ACE_GUARD_RETURN, ACE_TEXT, ACE_TRACE, ACE::debug(), LM_DEBUG, and service_vector_. Referenced by ~ACE_Service_Repository().
00183 { 00184 ACE_TRACE ("ACE_Service_Repository::close"); 00185 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); 00186 00187 if (this->service_vector_ != 0) 00188 { 00189 // Delete services in reverse order. Note that if services were 00190 // removed from the middle of the repository the order won't 00191 // necessarily be maintained since the <remove> method performs 00192 // compaction. However, the common case is not to remove 00193 // services, so typically they are deleted in reverse order. 00194 00195 #ifndef ACE_NLOGGING 00196 if(ACE::debug ()) 00197 ACE_DEBUG ((LM_DEBUG, 00198 ACE_TEXT ("(%P|%t) SR::close, this=%@, size=%d\n"), 00199 this, 00200 this->current_size_)); 00201 #endif 00202 00203 // Do not be tempted to use the prefix decrement operator. We 00204 // need to use the postfix decrement operator in this case since 00205 // the index is unsigned. 00206 for (size_t i = this->current_size_; i-- != 0; ) 00207 { 00208 00209 #ifndef ACE_NLOGGING 00210 if(ACE::debug ()) 00211 ACE_DEBUG ((LM_DEBUG, 00212 ACE_TEXT ("(%P|%t) SR::close, this=%@, delete so[%d]=%@ (%s)\n"), 00213 this, i, 00214 this->service_vector_[i], 00215 this->service_vector_[i]->name ())); 00216 #endif 00217 00218 ACE_Service_Type *s = const_cast<ACE_Service_Type *> (this->service_vector_[i]); 00219 --this->current_size_; 00220 delete s; 00221 } 00222 00223 delete [] this->service_vector_; 00224 this->service_vector_ = 0; 00225 this->current_size_ = 0; 00226 } 00227 00228 return 0; 00229 } |
|
Delete the dynamically allocated Singleton.
Definition at line 90 of file Service_Repository.cpp. References ACE_GUARD, ACE_TRACE, delete_svc_rep_, and svc_rep_. Referenced by ACE_Service_Config::close_svcs().
00091 { 00092 ACE_TRACE ("ACE_Service_Repository::close_singleton"); 00093 00094 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon, 00095 *ACE_Static_Object_Lock::instance ())); 00096 00097 if (ACE_Service_Repository::delete_svc_rep_) 00098 { 00099 delete ACE_Service_Repository::svc_rep_; 00100 ACE_Service_Repository::svc_rep_ = 0; 00101 ACE_Service_Repository::delete_svc_rep_ = 0; 00102 } 00103 } |
|
Return the current size of the repository.
Definition at line 16 of file Service_Repository.inl. References ACE_GUARD_RETURN, and ACE_TRACE.
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->current_size_; 00023 } |
|
Dump the state of an object.
Definition at line 33 of file Service_Repository.cpp. References ACE_TRACE.
00034 { 00035 #if defined (ACE_HAS_DUMP) 00036 ACE_TRACE ("ACE_Service_Repository::dump"); 00037 #endif /* ACE_HAS_DUMP */ 00038 } |
|
Locate a named entry in the service table, optionally ignoring suspended entries.
Definition at line 325 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_TCHAR, ACE_TRACE, and find_i(). Referenced by ACE_Service_Gestalt::find(), ACE_Service_Gestalt::initialize(), ACE_Service_Gestalt::process_directive_i(), and ACE_Service_Gestalt::process_file().
|
|
Locate a named entry in the service table, optionally ignoring suspended entries.
Definition at line 249 of file Service_Repository.cpp. References ACE_TCHAR, ACE_TRACE, ACE_Service_Type::fini_called(), service_vector_, and ACE_OS::strcmp(). Referenced by find(), resume(), suspend(), and ACE_Service_Type_Dynamic_Guard::~ACE_Service_Type_Dynamic_Guard().
00253 { 00254 ACE_TRACE ("ACE_Service_Repository::find_i"); 00255 size_t i; 00256 00257 for (i = 0; i < this->current_size_; i++) 00258 if (ACE_OS::strcmp (name, 00259 this->service_vector_[i]->name ()) == 0) 00260 break; 00261 00262 if (i < this->current_size_) 00263 { 00264 slot = i; 00265 if (this->service_vector_[i]->fini_called ()) 00266 { 00267 if (srp != 0) 00268 *srp = 0; 00269 return -1; 00270 } 00271 00272 if (srp != 0) 00273 *srp = this->service_vector_[i]; 00274 if (ignore_suspended 00275 && this->service_vector_[i]->active () == 0) 00276 return -2; 00277 return 0; 00278 } 00279 else 00280 return -1; 00281 } |
|
Finalize all the services by calling and deleting dynamically allocated services. Definition at line 137 of file Service_Repository.cpp. References ACE_DEBUG, ACE_GUARD_RETURN, ACE_TEXT, ACE_TRACE, ACE_Service_Type::active(), ACE::debug(), ACE_Service_Type::fini(), LM_DEBUG, ACE_Service_Type::name(), ACE_Service_Type_Impl::object(), service_vector_, and ACE_Service_Type::type(). Referenced by ACE_Service_Config::fini_svcs().
00138 { 00139 ACE_TRACE ("ACE_Service_Repository::fini"); 00140 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); 00141 int retval = 0; 00142 00143 if (this->service_vector_ != 0) 00144 { 00145 // <fini> the services in reverse order. Note that if services 00146 // were removed from the middle of the repository the order 00147 // won't necessarily be maintained since the <remove> method 00148 // performs compaction. However, the common case is not to 00149 // remove services, so typically they are deleted in reverse 00150 // order. 00151 00152 // Do not be tempted to use the prefix decrement operator. We 00153 // need to use the postfix decrement operator in this case since 00154 // the index is unsigned. 00155 for (size_t i = this->current_size_; i-- != 0; ) 00156 { 00157 ACE_Service_Type *s = 00158 const_cast<ACE_Service_Type *> (this->service_vector_[i]); 00159 00160 #ifndef ACE_NLOGGING 00161 if (ACE::debug ()) 00162 ACE_DEBUG ((LM_DEBUG, 00163 ACE_TEXT ("ACE (%P|%t) SR::fini, repo=%@ [%d] (%d), ") 00164 ACE_TEXT ("name=%s, type=%@, impl=%@, object=%@, active=%d\n"), 00165 this, i, this->total_size_, s->name(), s->type (), 00166 (s->type () != 0) ? s->type ()->object () : 0, 00167 s->active ())); 00168 #endif 00169 00170 // Collect any errors. 00171 int ret = s->fini (); 00172 retval += ret; 00173 } 00174 } 00175 00176 return (retval == 0) ? 0 : -1; 00177 } |
|
Insert a new service record. Returns -1 when the service repository is full and 0 on success. Definition at line 342 of file Service_Repository.cpp. References ACE_DEBUG, ACE_GUARD_RETURN, ACE_TEXT, ACE_TRACE, ACE_Service_Type::active(), ACE::debug(), ACE_OS::last_error(), LM_DEBUG, ACE_Service_Type::name(), ACE_Service_Type_Impl::object(), service_vector_, ACE_OS::strcmp(), and ACE_Service_Type::type(). Referenced by ACE_Service_Gestalt::initialize_i(), ACE_DLL_Strategy< SVC_HANDLER >::make_svc_handler(), and ACE_Service_Gestalt::process_directive_i().
00343 { 00344 ACE_TRACE ("ACE_Service_Repository::insert"); 00345 00346 int return_value = -1; 00347 ACE_Service_Type *s = 0; 00348 size_t i = 0; 00349 00350 { 00351 // @TODO: Do we need a recursive mutex here? 00352 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); 00353 00354 // Check to see if this is a duplicate. 00355 for (i = 0; i < this->current_size_; i++) 00356 if (ACE_OS::strcmp (sr->name (), 00357 this->service_vector_[i]->name ()) == 0) 00358 break; 00359 00360 // Replacing an existing entry 00361 if (i < this->current_size_) 00362 { 00363 return_value = 0; 00364 // Check for self-assignment... 00365 if (sr != this->service_vector_[i]) 00366 { 00367 s = const_cast<ACE_Service_Type *> (this->service_vector_[i]); 00368 this->service_vector_[i] = sr; 00369 } 00370 } 00371 // Adding a new entry. 00372 else if (i < this->total_size_) 00373 { 00374 this->service_vector_[i] = sr; 00375 this->current_size_++; 00376 return_value = 0; 00377 } 00378 00379 #ifndef ACE_NLOGGING 00380 if (ACE::debug ()) 00381 ACE_DEBUG ((LM_DEBUG, 00382 ACE_TEXT ("ACE (%P|%t) SR::insert") 00383 ACE_TEXT (" - repo=%@ [%d] (%d), name=%s") 00384 ACE_TEXT (", type=%@, object=%@, active=%d\n"), 00385 this, i, this->total_size_, sr->name(), sr->type (), 00386 (sr->type () != 0) ? sr->type ()->object () : 0, 00387 sr->active ())); 00388 #endif 00389 } 00390 00391 // Delete outside the lock 00392 if (s != 0) 00393 { 00394 #ifndef ACE_NLOGGING 00395 if (ACE::debug ()) 00396 ACE_DEBUG ((LM_DEBUG, 00397 ACE_TEXT ("ACE (%P|%t) SR::insert") 00398 ACE_TEXT (" - destroying (replacing), repo=%@ [%d] (%d), name=%s") 00399 ACE_TEXT (", type=%@, object=%@, active=%d\n"), 00400 this, i, this->total_size_, s->name(), s->type (), 00401 (s->type () != 0) ? s->type ()->object () : 0, 00402 s->active ())); 00403 #endif 00404 delete s; 00405 } 00406 00407 if (return_value == -1) 00408 ACE_OS::last_error (ENOSPC); 00409 00410 return return_value; 00411 } |
|
Set pointer to a process-wide ACE_Service_Repository and return existing pointer. Definition at line 75 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_TRACE, delete_svc_rep_, and svc_rep_.
00076 { 00077 ACE_TRACE ("ACE_Service_Repository::instance"); 00078 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, 00079 *ACE_Static_Object_Lock::instance (), 0)); 00080 00081 ACE_Service_Repository *t = ACE_Service_Repository::svc_rep_; 00082 // We can't safely delete it since we don't know who created it! 00083 ACE_Service_Repository::delete_svc_rep_ = 0; 00084 00085 ACE_Service_Repository::svc_rep_ = s; 00086 return t; 00087 } |
|
Get pointer to a process-wide ACE_Service_Repository.
Definition at line 49 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_TRACE, delete_svc_rep_, ACE_Object_Manager::shutting_down(), ACE_Object_Manager::starting_up(), and svc_rep_. Referenced by ACE_Service_Config::fini_svcs(), ACE_Service_Gestalt::init_i(), ACE_Service_Config::open_i(), ACE_Service_Config::remove(), ACE_Service_Config::resume(), and ACE_Service_Config::suspend().
00050 { 00051 ACE_TRACE ("ACE_Service_Repository::instance"); 00052 00053 if (ACE_Service_Repository::svc_rep_ == 0) 00054 { 00055 // Perform Double-Checked Locking Optimization. 00056 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, 00057 *ACE_Static_Object_Lock::instance (), 0)); 00058 if (ACE_Service_Repository::svc_rep_ == 0) 00059 { 00060 if (ACE_Object_Manager::starting_up () || 00061 !ACE_Object_Manager::shutting_down ()) 00062 { 00063 ACE_NEW_RETURN (ACE_Service_Repository::svc_rep_, 00064 ACE_Service_Repository (size), 00065 0); 00066 ACE_Service_Repository::delete_svc_rep_ = 1; 00067 } 00068 } 00069 } 00070 00071 return ACE_Service_Repository::svc_rep_; 00072 } |
|
Initialize the repository.
Definition at line 108 of file Service_Repository.cpp. References ACE_NEW_RETURN, ACE_TRACE, and service_vector_. Referenced by ACE_Service_Repository().
00109 { 00110 ACE_TRACE ("ACE_Service_Repository::open"); 00111 00112 ACE_Service_Type **temp; 00113 00114 ACE_NEW_RETURN (temp, 00115 ACE_Service_Type *[size], 00116 -1); 00117 00118 this->service_vector_ = const_cast<const ACE_Service_Type **> (temp); 00119 this->total_size_ = size; 00120 return 0; 00121 } |
|
Relocate (static) services 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. Definition at line 292 of file Service_Repository.cpp. References ACE_DEBUG, ACE_SHLIB_HANDLE, ACE_SHLIB_INVALID_HANDLE, ACE_TEXT, ACE::debug(), ACE_Service_Type::dll(), ACE_DLL::get_handle(), LM_DEBUG, ACE_Service_Type::name(), and service_vector_. Referenced by ACE_Service_Type_Dynamic_Guard::~ACE_Service_Type_Dynamic_Guard().
00296 { 00297 ACE_SHLIB_HANDLE new_handle = adll.get_handle (0); 00298 00299 for (size_t i = begin; i < end; i++) 00300 { 00301 ACE_Service_Type *type = 00302 const_cast<ACE_Service_Type *> (this->service_vector_[i]); 00303 00304 ACE_SHLIB_HANDLE old_handle = type->dll ().get_handle (0); 00305 if (static_only && old_handle != ACE_SHLIB_INVALID_HANDLE) 00306 continue; 00307 00308 #ifndef ACE_NLOGGING 00309 if (ACE::debug ()) 00310 ACE_DEBUG ((LM_DEBUG, 00311 ACE_TEXT ("ACE (%P|%t) SR::relocate, repo=%@ [%d] (size=%d): name=%s - DLL from=%d to=%d\n"), 00312 this, i, this->total_size_, type->name (), 00313 old_handle, 00314 new_handle)); 00315 #else 00316 ACE_UNUSED_ARG (new_handle); 00317 #endif 00318 type->dll (adll); 00319 } 00320 00321 return 0; 00322 } |
|
Completely remove a entry from the Repository and dynamically unlink it if it was originally dynamically linked. 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. Definition at line 452 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_TCHAR, ACE_TRACE, and remove_i(). Referenced by ACE_Service_Gestalt::initialize(), ACE_Service_Gestalt::initialize_i(), ACE_Service_Gestalt::remove(), and ACE_Service_Config::remove().
00453 { 00454 ACE_TRACE ("ACE_Service_Repository::remove"); 00455 ACE_Service_Type *s = 0; 00456 { 00457 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); 00458 00459 // Not found!? 00460 if (this->remove_i (name, &s) == -1) 00461 return -1; 00462 } 00463 00464 if (ps != 0) 00465 *ps = s; 00466 else 00467 delete s; 00468 return 0; 00469 } |
|
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. Referenced by remove(), and ACE_Service_Type_Dynamic_Guard::~ACE_Service_Type_Dynamic_Guard(). |
|
Resume a service record.
Definition at line 416 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_TCHAR, ACE_TRACE, find_i(), ACE_Service_Type::resume(), and service_vector_. Referenced by ACE_Service_Gestalt::resume(), and ACE_Service_Config::resume().
00418 { 00419 ACE_TRACE ("ACE_Service_Repository::resume"); 00420 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); 00421 00422 size_t i = 0; 00423 if (-1 == this->find_i (name, i, srp, 0)) 00424 return -1; 00425 00426 return this->service_vector_[i]->resume (); 00427 } |
|
Suspend a service record.
Definition at line 433 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_TCHAR, ACE_TRACE, find_i(), service_vector_, and ACE_Service_Type::suspend(). Referenced by ACE_Service_Gestalt::suspend(), and ACE_Service_Config::suspend().
00435 { 00436 ACE_TRACE ("ACE_Service_Repository::suspend"); 00437 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); 00438 size_t i = 0; 00439 if (-1 == this->find_i (name, i, srp, 0)) 00440 return -1; 00441 00442 return this->service_vector_[i]->suspend (); 00443 } |
|
Return the total size of the repository.
Definition at line 29 of file Service_Repository.inl. References ACE_GUARD_RETURN, and ACE_TRACE.
00030 { 00031 ACE_TRACE ("ACE_Service_Repository::total_size"); 00032 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, 00033 ace_mon, 00034 (ACE_Recursive_Thread_Mutex &) this->lock_, 0)); 00035 return this->total_size_; 00036 } |
|
Definition at line 51 of file Service_Repository.h. |
|
Definition at line 145 of file Service_Repository.h. |
|
Declare the dynamic allocation hooks.
Definition at line 141 of file Service_Repository.h. |
|
Current number of services.
Definition at line 200 of file Service_Repository.h. Referenced by ACE_Service_Repository_Iterator::done(). |
|
Must delete the if non-0.
Definition at line 30 of file Service_Repository.cpp. Referenced by close_singleton(), and instance(). |
|
Contains all the configured services.
Definition at line 197 of file Service_Repository.h. Referenced by close(), find_i(), fini(), insert(), open(), relocate_i(), resume(), and suspend(). |
|
Pointer to a process-wide ACE_Service_Repository.
Definition at line 26 of file Service_Repository.cpp. Referenced by close_singleton(), and instance(). |
|
Maximum number of services.
Definition at line 203 of file Service_Repository.h. |