#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, int ignore_suspended=1) 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 | find_i (const ACE_TCHAR service_name[], const ACE_Service_Type **=0, int ignore_suspended=1) const |
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 |
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 47 of file Service_Repository.h.
|
Definition at line 52 of file Service_Repository.h.
00053 { 00054 DEFAULT_SIZE = ACE_DEFAULT_SERVICE_REPOSITORY_SIZE 00055 }; |
|
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 124 of file Service_Repository.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and open().
00125 : current_size_ (0) 00126 { 00127 ACE_TRACE ("ACE_Service_Repository::ACE_Service_Repository"); 00128 00129 if (this->open (size) == -1) 00130 ACE_ERROR ((LM_ERROR, 00131 ACE_LIB_TEXT ("%p\n"), 00132 ACE_LIB_TEXT ("ACE_Service_Repository"))); 00133 } |
|
Close down the repository and free up dynamically allocated resources. Definition at line 226 of file Service_Repository.cpp. References ACE_DEBUG, ACE_TRACE, close(), ACE::debug(), and LM_DEBUG.
00227 { 00228 ACE_TRACE ("ACE_Service_Repository::~ACE_Service_Repository"); 00229 if(ACE::debug ()) 00230 ACE_DEBUG ((LM_DEBUG, "(%P|%t) SR::<dtor>, this=%@\n", this)); 00231 this->close (); 00232 } |
|
Close down the repository and free up dynamically allocated resources. Definition at line 184 of file Service_Repository.cpp. References ACE_DEBUG, ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_TRACE, ACE::debug(), LM_DEBUG, and service_vector_. Referenced by ~ACE_Service_Repository().
00185 { 00186 ACE_TRACE ("ACE_Service_Repository::close"); 00187 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); 00188 00189 if (this->service_vector_ != 0) 00190 { 00191 // Delete services in reverse order. Note that if services were 00192 // removed from the middle of the repository the order won't 00193 // necessarily be maintained since the <remove> method performs 00194 // compaction. However, the common case is not to remove 00195 // services, so typically they are deleted in reverse order. 00196 00197 if(ACE::debug ()) 00198 ACE_DEBUG ((LM_DEBUG, 00199 ACE_LIB_TEXT ("(%P|%t) SR::close, this=%@, size=%d\n"), 00200 this, 00201 this->current_size_)); 00202 00203 for (int i = this->current_size_ - 1; i >= 0; i--) 00204 { 00205 if(ACE::debug ()) 00206 ACE_DEBUG ((LM_DEBUG, 00207 ACE_LIB_TEXT ("(%P|%t) SR::close, this=%@, delete so[%d]=%@ (%s)\n"), 00208 this, 00209 i, 00210 this->service_vector_[i], 00211 this->service_vector_[i]->name ())); 00212 00213 ACE_Service_Type *s = const_cast<ACE_Service_Type *> (this->service_vector_[i]); 00214 --this->current_size_; 00215 delete s; 00216 } 00217 00218 delete [] this->service_vector_; 00219 this->service_vector_ = 0; 00220 this->current_size_ = 0; 00221 } 00222 00223 return 0; 00224 } |
|
Delete the dynamically allocated Singleton.
Definition at line 91 of file Service_Repository.cpp. References ACE_GUARD, ACE_TRACE, delete_svc_rep_, and svc_rep_. Referenced by ACE_Service_Config::close_svcs().
00092 { 00093 ACE_TRACE ("ACE_Service_Repository::close_singleton"); 00094 00095 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon, 00096 *ACE_Static_Object_Lock::instance ())); 00097 00098 if (ACE_Service_Repository::delete_svc_rep_) 00099 { 00100 delete ACE_Service_Repository::svc_rep_; 00101 ACE_Service_Repository::svc_rep_ = 0; 00102 ACE_Service_Repository::delete_svc_rep_ = 0; 00103 } 00104 } |
|
Return the current size of the repository.
Definition at line 16 of file Service_Repository.inl. References ACE_GUARD_RETURN, ACE_Recursive_Thread_Mutex, 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 an entry with in the table. If 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 . If is not found, -1 is returned. If is found, but it is suspended and the caller wants to ignore suspended services a -2 is returned. Definition at line 275 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(), ACE_Service_Gestalt::process_file(), and ACE_Service_Type_Forward_Declaration_Guard::~ACE_Service_Type_Forward_Declaration_Guard().
00278 { 00279 ACE_TRACE ("ACE_Service_Repository::find"); 00280 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); 00281 00282 return this->find_i (name, srp, ignore_suspended); 00283 } |
|
Locates . Must be called without locks being held... Definition at line 242 of file Service_Repository.cpp. References ACE_TCHAR, ACE_TRACE, ACE_Service_Type::fini_called(), service_vector_, and ACE_OS::strcmp(). Referenced by find(), remove(), resume(), and suspend().
00245 { 00246 ACE_TRACE ("ACE_Service_Repository::find_i"); 00247 size_t i; 00248 00249 for (i = 0; i < this->current_size_; i++) 00250 if (ACE_OS::strcmp (name, 00251 this->service_vector_[i]->name ()) == 0) 00252 break; 00253 00254 if (i < this->current_size_) 00255 { 00256 if (this->service_vector_[i]->fini_called ()) 00257 { 00258 if (srp != 0) 00259 *srp = 0; 00260 return -1; 00261 } 00262 00263 if (srp != 0) 00264 *srp = this->service_vector_[i]; 00265 if (ignore_suspended 00266 && this->service_vector_[i]->active () == 0) 00267 return -2; 00268 return i; 00269 } 00270 else 00271 return -1; 00272 } |
|
Finalize all the services by calling and deleting dynamically allocated services. Definition at line 138 of file Service_Repository.cpp. References ACE_DEBUG, ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_TRACE, ACE::debug(), ACE_Service_Type::dump(), ACE_Service_Type::fini(), LM_DEBUG, and service_vector_. Referenced by ACE_Service_Config::fini_svcs().
00139 { 00140 ACE_TRACE ("ACE_Service_Repository::fini"); 00141 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); 00142 int retval = 0; 00143 00144 if (this->service_vector_ != 0) 00145 { 00146 // <fini> the services in reverse order. Note that if services 00147 // were removed from the middle of the repository the order 00148 // won't necessarily be maintained since the <remove> method 00149 // performs compaction. However, the common case is not to 00150 // remove services, so typically they are deleted in reverse 00151 // order. 00152 00153 for (int i = this->current_size_ - 1; i >= 0; i--) 00154 { 00155 ACE_Service_Type *s = 00156 const_cast<ACE_Service_Type *> (this->service_vector_[i]); 00157 00158 if (ACE::debug ()) 00159 { 00160 ACE_DEBUG ((LM_DEBUG, 00161 ACE_LIB_TEXT ("(%P|%t) SR::fini, %@ [%d] (%d): "), 00162 this, i, this->total_size_)); 00163 s->dump(); 00164 } 00165 00166 // Collect any errors. 00167 int ret = s->fini (); 00168 if (ACE::debug ()>1) 00169 { 00170 ACE_DEBUG ((LM_DEBUG, 00171 ACE_LIB_TEXT ("(%P|%t) SR::fini, returned %d\n"), 00172 ret)); 00173 } 00174 retval += ret; 00175 } 00176 } 00177 00178 return (retval == 0) ? 0 : -1; 00179 } |
|
Insert a new service record. Returns -1 when the service repository is full and 0 on success. Definition at line 292 of file Service_Repository.cpp. References ACE_DEBUG, ACE_GUARD_RETURN, ACE_TRACE, ACE::debug(), ACE_Service_Type::dump(), ACE_OS::last_error(), LM_DEBUG, ACE_Service_Type::name(), service_vector_, and ACE_OS::strcmp(). Referenced by ACE_Service_Gestalt::initialize_i(), ACE_DLL_Strategy< SVC_HANDLER >::make_svc_handler(), and ACE_Service_Gestalt::process_directive_i().
00293 { 00294 ACE_TRACE ("ACE_Service_Repository::insert"); 00295 00296 int return_value = -1; 00297 ACE_Service_Type *s = 0; 00298 00299 { 00300 // @TODO: Do we need a recursive mutex here? 00301 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); 00302 size_t i; 00303 00304 // Check to see if this is a duplicate. 00305 for (i = 0; i < this->current_size_; i++) 00306 if (ACE_OS::strcmp (sr->name (), 00307 this->service_vector_[i]->name ()) == 0) 00308 break; 00309 00310 // Replacing an existing entry 00311 if (i < this->current_size_) 00312 { 00313 return_value = 0; 00314 // Check for self-assignment... 00315 if (sr != this->service_vector_[i]) 00316 { 00317 s = const_cast<ACE_Service_Type *> (this->service_vector_[i]); 00318 this->service_vector_[i] = sr; 00319 } 00320 } 00321 // Adding a new entry. 00322 else if (i < this->total_size_) 00323 { 00324 this->service_vector_[i] = sr; 00325 this->current_size_++; 00326 return_value = 0; 00327 } 00328 00329 if (ACE::debug ()) 00330 { 00331 ACE_DEBUG ((LM_DEBUG, 00332 "(%P|%t) SR::insert, repo=%@ [%d] (size=%d): ", 00333 this, 00334 i, 00335 this->total_size_)); 00336 sr->dump(); 00337 } 00338 } 00339 00340 // Delete outside the lock 00341 if (s != 0) 00342 { 00343 if (ACE::debug () > 1) 00344 { 00345 ACE_DEBUG ((LM_DEBUG, 00346 "(%P|%t) SR::insert, repo=%@ - destroying : ", 00347 this)); 00348 s->dump(); 00349 } 00350 delete s; 00351 } 00352 00353 if (return_value == -1) 00354 ACE_OS::last_error (ENOSPC); 00355 00356 return return_value; 00357 } |
|
Set pointer to a process-wide ACE_Service_Repository and return existing pointer. Definition at line 76 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_TRACE, delete_svc_rep_, and svc_rep_.
00077 { 00078 ACE_TRACE ("ACE_Service_Repository::instance"); 00079 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, 00080 *ACE_Static_Object_Lock::instance (), 0)); 00081 00082 ACE_Service_Repository *t = ACE_Service_Repository::svc_rep_; 00083 // We can't safely delete it since we don't know who created it! 00084 ACE_Service_Repository::delete_svc_rep_ = 0; 00085 00086 ACE_Service_Repository::svc_rep_ = s; 00087 return t; 00088 } |
|
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_Gestalt::ACE_Service_Gestalt(), ACE_Service_Config::fini_svcs(), 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 // ACE_ASSERT (ACE_Service_Repository::svc_rep_ != 0); 00072 return ACE_Service_Repository::svc_rep_; 00073 } |
|
Initialize the repository.
Definition at line 109 of file Service_Repository.cpp. References ACE_NEW_RETURN, ACE_TRACE, and service_vector_. Referenced by ACE_Service_Repository().
00110 { 00111 ACE_TRACE ("ACE_Service_Repository::open"); 00112 00113 ACE_Service_Type **temp; 00114 00115 ACE_NEW_RETURN (temp, 00116 ACE_Service_Type *[size], 00117 -1); 00118 00119 this->service_vector_ = const_cast<const ACE_Service_Type **> (temp); 00120 this->total_size_ = size; 00121 return 0; 00122 } |
|
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 410 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_TCHAR, ACE_TRACE, find_i(), and service_vector_. Referenced by ACE_Service_Gestalt::initialize(), ACE_Service_Gestalt::initialize_i(), ACE_Service_Gestalt::remove(), ACE_Service_Config::remove(), and ACE_Service_Type_Forward_Declaration_Guard::~ACE_Service_Type_Forward_Declaration_Guard().
00411 { 00412 ACE_TRACE ("ACE_Service_Repository::remove"); 00413 ACE_Service_Type *s = 0; 00414 { 00415 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); 00416 int i = this->find_i (name, 0, 0); 00417 00418 // Not found 00419 if (i == -1) 00420 return -1; 00421 00422 // We need the old ptr to be delete outside the lock 00423 s = const_cast<ACE_Service_Type *> (this->service_vector_[i]); 00424 00425 // Pack the array 00426 --this->current_size_; 00427 for (size_t j = i; j < this->current_size_; j++) 00428 this->service_vector_[j] = this->service_vector_[j+1]; 00429 } 00430 00431 if (ps != 0) 00432 *ps = s; 00433 else 00434 delete s; 00435 return 0; 00436 } |
|
Resume a service record.
Definition at line 362 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().
00364 { 00365 ACE_TRACE ("ACE_Service_Repository::resume"); 00366 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); 00367 00368 int i = this->find_i (name, srp, 0); 00369 00370 if (i == -1) 00371 return -1; 00372 00373 return this->service_vector_[i]->resume (); 00374 } |
|
Suspend a service record.
Definition at line 380 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().
00382 { 00383 ACE_TRACE ("ACE_Service_Repository::suspend"); 00384 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1)); 00385 int i = this->find_i (name, srp, 0); 00386 00387 if (i == -1) 00388 return -1; 00389 00390 return this->service_vector_[i]->suspend (); 00391 } |
|
Return the total size of the repository.
Definition at line 29 of file Service_Repository.inl. References ACE_GUARD_RETURN, ACE_Recursive_Thread_Mutex, 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 50 of file Service_Repository.h. |
|
Declare the dynamic allocation hooks.
Definition at line 132 of file Service_Repository.h. |
|
Current number of services.
Definition at line 145 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 142 of file Service_Repository.h. Referenced by close(), find_i(), fini(), insert(), ACE_Service_Repository_Iterator::next(), open(), remove(), resume(), suspend(), and ACE_Service_Repository_Iterator::valid(). |
|
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 148 of file Service_Repository.h. |