#include <Service_Repository.h>
Collaboration diagram for ACE_Service_Repository:

Public Types | |
| enum | { DEFAULT_SIZE = ACE_DEFAULT_SERVICE_REPOSITORY_SIZE } |
Public Methods | |
| ACE_Service_Repository (void) | |
| Initialize the repository. More... | |
| ACE_Service_Repository (int size) | |
| Initialize the repository. More... | |
| int | open (int size=DEFAULT_SIZE) |
| Initialize the repository. More... | |
| ~ACE_Service_Repository (void) | |
| Close down the repository and free up dynamically allocated resources. More... | |
| int | close (void) |
| Close down the repository and free up dynamically allocated resources. More... | |
| int | fini (void) |
| Finalize all the services by calling <fini> and deleting dynamically allocated services. More... | |
| int | insert (const ACE_Service_Type *) |
| Insert a new service record. Returns -1 when the service repository is full and 0 on success. More... | |
| int | find (const ACE_TCHAR name[], const ACE_Service_Type **srp=0, int ignore_suspended=1) |
| int | remove (const ACE_TCHAR[]) |
| Remove an existing service record. More... | |
| int | resume (const ACE_TCHAR[], const ACE_Service_Type **=0) |
| Resume a service record. More... | |
| int | suspend (const ACE_TCHAR[], const ACE_Service_Type **=0) |
| Suspend a service record. More... | |
| int | current_size (void) const |
| Return the current size of the repository. More... | |
| int | total_size (void) const |
| Return the total size of the repository. More... | |
| void | dump (void) const |
| Dump the state of an object. More... | |
Static Public Methods | |
| ACE_Service_Repository * | instance (int size=ACE_Service_Repository::DEFAULT_SIZE) |
| Get pointer to a process-wide <ACE_Service_Repository>. More... | |
| ACE_Service_Repository * | instance (ACE_Service_Repository *) |
| Set pointer to a process-wide <ACE_Service_Repository> and return existing pointer. More... | |
| void | close_singleton (void) |
| Delete the dynamically allocated Singleton. More... | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. More... | |
Private Methods | |
| int | find_i (const ACE_TCHAR service_name[], const ACE_Service_Type **=0, int ignore_suspended=1) |
| Locates <service_name>. Must be called without locks being held... More... | |
Private Attributes | |
| const ACE_Service_Type ** | service_vector_ |
| Contains all the configured services. More... | |
| int | current_size_ |
| Current number of services. More... | |
| int | total_size_ |
| Maximum number of services. More... | |
Static Private Attributes | |
| ACE_Service_Repository * | svc_rep_ = 0 |
| Pointer to a process-wide <ACE_Service_Repository>. More... | |
| int | delete_svc_rep_ = 0 |
| Must delete the <svc_rep_> if non-0. More... | |
Friends | |
| class | ACE_Service_Repository_Iterator |
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 39 of file Service_Repository.h.
|
|
Definition at line 44 of file Service_Repository.h.
00045 {
00046 DEFAULT_SIZE = ACE_DEFAULT_SERVICE_REPOSITORY_SIZE
00047 };
|
|
|
Initialize the repository.
Definition at line 30 of file Service_Repository.cpp. References ACE_TRACE.
00031 : service_vector_ (0), 00032 current_size_ (0), 00033 total_size_ (0) 00034 { 00035 ACE_TRACE ("ACE_Service_Repository::ACE_Service_Repository"); 00036 } |
|
|
Initialize the repository.
Definition at line 114 of file Service_Repository.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and open.
00115 : current_size_ (0) 00116 { 00117 ACE_TRACE ("ACE_Service_Repository::ACE_Service_Repository"); 00118 00119 if (this->open (size) == -1) 00120 ACE_ERROR ((LM_ERROR, 00121 ACE_LIB_TEXT ("%p\n"), 00122 ACE_LIB_TEXT ("ACE_Service_Repository"))); 00123 } |
|
|
Close down the repository and free up dynamically allocated resources.
Definition at line 192 of file Service_Repository.cpp. References ACE_TRACE, and close.
|
|
|
Close down the repository and free up dynamically allocated resources.
Definition at line 163 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, current_size_, and service_vector_. Referenced by ~ACE_Service_Repository.
00164 {
00165 ACE_TRACE ("ACE_Service_Repository::close");
00166 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00167
00168 if (this->service_vector_ != 0)
00169 {
00170 // Delete services in reverse order. Note that if services were
00171 // removed from the middle of the repository the order won't
00172 // necessarily be maintained since the <remove> method performs
00173 // compaction. However, the common case is not to remove
00174 // services, so typically they are deleted in reverse order.
00175
00176 for (int i = this->current_size_ - 1; i >= 0; i--)
00177 {
00178 ACE_Service_Type *s = ACE_const_cast (ACE_Service_Type *,
00179 this->service_vector_[i]);
00180 --this->current_size_;
00181 delete s;
00182 }
00183
00184 delete [] this->service_vector_;
00185 this->service_vector_ = 0;
00186 this->current_size_ = 0;
00187 }
00188
00189 return 0;
00190 }
|
|
|
Delete the dynamically allocated Singleton.
Definition at line 80 of file Service_Repository.cpp. References ACE_GUARD, ACE_MT, ACE_TRACE, delete_svc_rep_, ACE_Static_Object_Lock::instance, and svc_rep_. Referenced by ACE_Service_Config::close_svcs.
00081 {
00082 ACE_TRACE ("ACE_Service_Repository::close_singleton");
00083
00084 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
00085 *ACE_Static_Object_Lock::instance ()));
00086
00087 if (ACE_Service_Repository::delete_svc_rep_)
00088 {
00089 delete ACE_Service_Repository::svc_rep_;
00090 ACE_Service_Repository::svc_rep_ = 0;
00091 ACE_Service_Repository::delete_svc_rep_ = 0;
00092 }
00093 }
|
|
|
Return the current size of the repository.
Definition at line 10 of file Service_Repository.i. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, and current_size_.
00011 {
00012 ACE_TRACE ("ACE_Service_Repository::current_size");
00013 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, (ACE_Thread_Mutex &) this->lock_, -1));
00014 return this->current_size_;
00015 }
|
|
|
Dump the state of an object.
Definition at line 25 of file Service_Repository.cpp. References ACE_TRACE.
00026 {
00027 ACE_TRACE ("ACE_Service_Repository::dump");
00028 }
|
|
||||||||||||||||
|
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. Definition at line 239 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TCHAR, ACE_TRACE, and find_i. Referenced by ACE_Service_Config::initialize, ACE_Dynamic_Service_Base::instance, ACE_Service_Config::process_directive, and ACE_Static_Node::record.
00242 {
00243 ACE_TRACE ("ACE_Service_Repository::find");
00244 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00245
00246 return this->find_i (name, srp, ignore_suspended);
00247 }
|
|
||||||||||||||||
|
Locates <service_name>. Must be called without locks being held...
Definition at line 206 of file Service_Repository.cpp. References ACE_TCHAR, ACE_TRACE, ACE_Service_Type::active, current_size_, ACE_Service_Type::fini_called, service_vector_, and ACE_OS_String::strcmp. Referenced by find, remove, resume, and suspend.
00209 {
00210 ACE_TRACE ("ACE_Service_Repository::find_i");
00211 int i;
00212
00213 for (i = 0; i < this->current_size_; i++)
00214 if (ACE_OS::strcmp (name,
00215 this->service_vector_[i]->name ()) == 0)
00216 break;
00217
00218 if (i < this->current_size_)
00219 {
00220 if (this->service_vector_[i]->fini_called ())
00221 {
00222 if (srp != 0)
00223 *srp = 0;
00224 return -1;
00225 }
00226
00227 if (srp != 0)
00228 *srp = this->service_vector_[i];
00229 if (ignore_suspended
00230 && this->service_vector_[i]->active () == 0)
00231 return -2;
00232 return i;
00233 }
00234 else
00235 return -1;
00236 }
|
|
|
Finalize all the services by calling <fini> and deleting dynamically allocated services.
Definition at line 128 of file Service_Repository.cpp. References ACE_DEBUG, ACE_GUARD_RETURN, ACE_LIB_TEXT, ACE_MT, ACE_TRACE, current_size_, ACE::debug, ACE_Service_Type::fini, LM_DEBUG, and service_vector_. Referenced by ACE_Service_Config::fini_svcs.
00129 {
00130 ACE_TRACE ("ACE_Service_Repository::fini");
00131 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00132 int retval = 0;
00133
00134 if (this->service_vector_ != 0)
00135 {
00136 // <fini> the services in reverse order. Note that if services
00137 // were removed from the middle of the repository the order
00138 // won't necessarily be maintained since the <remove> method
00139 // performs compaction. However, the common case is not to
00140 // remove services, so typically they are deleted in reverse
00141 // order.
00142
00143 for (int i = this->current_size_ - 1; i >= 0; i--)
00144 {
00145 if (ACE::debug ())
00146 ACE_DEBUG ((LM_DEBUG,
00147 ACE_LIB_TEXT ("finalizing %s\n"),
00148 this->service_vector_[i]->name ()));
00149 ACE_Service_Type *s =
00150 ACE_const_cast (ACE_Service_Type *,
00151 this->service_vector_[i]);
00152 // Collect errors.
00153 retval += s->fini ();
00154 }
00155 }
00156
00157 return (retval == 0) ? 0 : -1;
00158 }
|
|
|
Insert a new service record. Returns -1 when the service repository is full and 0 on success.
Definition at line 254 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, current_size_, ACE_Service_Type::name, service_vector_, ACE_OS_String::strcmp, and total_size_. Referenced by ACE_Service_Config::initialize, ACE_DLL_Strategy::make_svc_handler, and ACE_Service_Config::process_directive.
00255 {
00256 ACE_TRACE ("ACE_Service_Repository::insert");
00257 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00258 int i;
00259
00260 // Check to see if this is a duplicate.
00261 for (i = 0; i < this->current_size_; i++)
00262 if (ACE_OS::strcmp (sr->name (),
00263 this->service_vector_[i]->name ()) == 0)
00264 break;
00265
00266 // Replacing an existing entry
00267 if (i < this->current_size_)
00268 {
00269 // Check for self-assignment...
00270 if (sr == this->service_vector_[i])
00271 return 0;
00272 ACE_Service_Type *s = ACE_const_cast (ACE_Service_Type *,
00273 this->service_vector_[i]);
00274 delete s;
00275 this->service_vector_[i] = sr;
00276 return 0;
00277 }
00278 // Adding a new entry.
00279 else if (i < this->total_size_)
00280 {
00281 this->service_vector_[i] = sr;
00282 this->current_size_++;
00283 return 0;
00284 }
00285
00286 return -1;
00287 }
|
|
|
Set pointer to a process-wide <ACE_Service_Repository> and return existing pointer.
Definition at line 65 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, delete_svc_rep_, ACE_Static_Object_Lock::instance, and svc_rep_.
00066 {
00067 ACE_TRACE ("ACE_Service_Repository::instance");
00068 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00069 *ACE_Static_Object_Lock::instance (), 0));
00070
00071 ACE_Service_Repository *t = ACE_Service_Repository::svc_rep_;
00072 // We can't safely delete it since we don't know who created it!
00073 ACE_Service_Repository::delete_svc_rep_ = 0;
00074
00075 ACE_Service_Repository::svc_rep_ = s;
00076 return t;
00077 }
|
|
|
|
Initialize the repository.
Definition at line 98 of file Service_Repository.cpp. References ACE_NEW_RETURN, ACE_TRACE, service_vector_, and total_size_. Referenced by ACE_Service_Repository.
00099 {
00100 ACE_TRACE ("ACE_Service_Repository::open");
00101
00102 ACE_Service_Type **temp;
00103
00104 ACE_NEW_RETURN (temp,
00105 ACE_Service_Type *[size],
00106 -1);
00107
00108 this->service_vector_ = ACE_const_cast (const ACE_Service_Type **,
00109 temp);
00110 this->total_size_ = size;
00111 return 0;
00112 }
|
|
|
Remove an existing service record.
Definition at line 330 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TCHAR, ACE_TRACE, current_size_, find_i, and service_vector_. Referenced by ACE_Service_Config::initialize, and ACE_Service_Config::remove.
00331 {
00332 ACE_TRACE ("ACE_Service_Repository::remove");
00333 ACE_Service_Type *s = 0;
00334 {
00335 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00336 int i = this->find_i (name, 0, 0);
00337
00338 if (i == -1)
00339 return -1;
00340
00341 s = ACE_const_cast (ACE_Service_Type *,
00342 this->service_vector_[i]);
00343 --this->current_size_;
00344
00345 if (this->current_size_ >= 1)
00346 this->service_vector_[i]
00347 = this->service_vector_[this->current_size_];
00348 }
00349 delete s;
00350 return 0;
00351 }
|
|
||||||||||||
|
Resume a service record.
Definition at line 292 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TCHAR, ACE_TRACE, find_i, ACE_Service_Type::resume, and service_vector_. Referenced by ACE_Service_Config::resume.
00294 {
00295 ACE_TRACE ("ACE_Service_Repository::resume");
00296 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00297
00298 int i = this->find_i (name, srp, 0);
00299
00300 if (i == -1)
00301 return -1;
00302
00303 return this->service_vector_[i]->resume ();
00304 }
|
|
||||||||||||
|
Suspend a service record.
Definition at line 310 of file Service_Repository.cpp. References ACE_GUARD_RETURN, ACE_MT, ACE_TCHAR, ACE_TRACE, find_i, service_vector_, and ACE_Service_Type::suspend. Referenced by ACE_Service_Config::suspend.
00312 {
00313 ACE_TRACE ("ACE_Service_Repository::suspend");
00314 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1));
00315 int i = this->find_i (name, srp, 0);
00316
00317 if (i == -1)
00318 return -1;
00319
00320 return this->service_vector_[i]->suspend ();
00321 }
|
|
|
Return the total size of the repository.
Definition at line 21 of file Service_Repository.i. References ACE_GUARD_RETURN, ACE_MT, ACE_TRACE, and total_size_.
00022 {
00023 ACE_TRACE ("ACE_Service_Repository::total_size");
00024 ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, (ACE_Thread_Mutex &) this->lock_, -1));
00025 return this->total_size_;
00026 }
|
|
|
Definition at line 42 of file Service_Repository.h. |
|
|
Declare the dynamic allocation hooks.
Definition at line 119 of file Service_Repository.h. |
|
|
Current number of services.
Definition at line 132 of file Service_Repository.h. Referenced by ACE_Service_Repository_Iterator::advance, close, current_size, ACE_Service_Repository_Iterator::done, find_i, fini, insert, ACE_Service_Repository_Iterator::next, and remove. |
|
|
Must delete the <svc_rep_> if non-0.
Definition at line 22 of file Service_Repository.cpp. Referenced by close_singleton, and instance. |
|
|
Contains all the configured services.
Definition at line 129 of file Service_Repository.h. Referenced by ACE_Service_Repository_Iterator::advance, close, find_i, fini, insert, ACE_Service_Repository_Iterator::next, open, remove, resume, and suspend. |
|
|
Pointer to a process-wide <ACE_Service_Repository>.
Definition at line 18 of file Service_Repository.cpp. Referenced by close_singleton, and instance. |
|
|
Maximum number of services.
Definition at line 135 of file Service_Repository.h. Referenced by insert, open, and total_size. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002