00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Service_Repository.h 00006 * 00007 * Service_Repository.h,v 4.33 2006/05/24 23:22:16 jeliazkov_i Exp 00008 * 00009 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef ACE_SERVICE_REPOSITORY_H 00014 #define ACE_SERVICE_REPOSITORY_H 00015 00016 #include /**/ "ace/pre.h" 00017 00018 #include "ace/ACE_export.h" 00019 00020 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00021 # pragma once 00022 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00023 00024 #include "ace/Default_Constants.h" 00025 #include "ace/Recursive_Thread_Mutex.h" 00026 00027 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00028 00029 class ACE_Service_Type; 00030 00031 #define ACE_Component_Repository ACE_Service_Repository 00032 /** 00033 * @class ACE_Service_Repository 00034 * 00035 * @brief Contains all the services offered by a Service 00036 * Configurator-based application. 00037 * 00038 * This class contains a vector of <ACE_Service_Types> *'s and 00039 * allows an administrative entity to centrally manage and 00040 * control the behavior of application services. Note that if 00041 * services are removed from the middle of the repository the 00042 * order won't necessarily be maintained since the <remove> 00043 * method performs compaction. However, the common case is not 00044 * to remove services, so typically they are deleted in the 00045 * reverse order that they were added originally. 00046 */ 00047 class ACE_Export ACE_Service_Repository 00048 { 00049 public: 00050 friend class ACE_Service_Repository_Iterator; 00051 00052 enum 00053 { 00054 DEFAULT_SIZE = ACE_DEFAULT_SERVICE_REPOSITORY_SIZE 00055 }; 00056 00057 // = Initialization and termination methods. 00058 /// Initialize the repository. 00059 ACE_Service_Repository (void); 00060 00061 /// Initialize the repository. 00062 ACE_Service_Repository (size_t size); 00063 00064 /// Initialize the repository. 00065 int open (size_t size = DEFAULT_SIZE); 00066 00067 /// Close down the repository and free up dynamically allocated 00068 /// resources. 00069 ~ACE_Service_Repository (void); 00070 00071 /// Close down the repository and free up dynamically allocated 00072 /// resources. 00073 int close (void); 00074 00075 /// Finalize all the services by calling <fini> and deleting 00076 /// dynamically allocated services. 00077 int fini (void); 00078 00079 /// Get pointer to a process-wide ACE_Service_Repository. 00080 static ACE_Service_Repository * instance 00081 (size_t size = ACE_Service_Repository::DEFAULT_SIZE); 00082 00083 /// Set pointer to a process-wide ACE_Service_Repository and return 00084 /// existing pointer. 00085 static ACE_Service_Repository *instance (ACE_Service_Repository *); 00086 00087 /// Delete the dynamically allocated Singleton. 00088 static void close_singleton (void); 00089 00090 // = Search structure operations (all acquire locks as necessary). 00091 00092 /// Insert a new service record. Returns -1 when the service repository 00093 /// is full and 0 on success. 00094 int insert (const ACE_Service_Type *); 00095 00096 /** 00097 * Locate an entry with <name> in the table. If <ignore_suspended> 00098 * is set then only consider services marked as resumed. If the 00099 * caller wants the located entry, pass back a pointer to the 00100 * located entry via <srp>. If <name> is not found, -1 is returned. 00101 * If <name> is found, but it is suspended and the caller wants to 00102 * ignore suspended services a -2 is returned. 00103 */ 00104 int find (const ACE_TCHAR name[], 00105 const ACE_Service_Type **srp = 0, 00106 int ignore_suspended = 1) const; 00107 00108 /// Remove an existing service record. If @a sr == 0, the service record 00109 /// is deleted before control is returned to the caller. If @a sr != 0, 00110 /// the service's record is removed from the repository, but not deleted; 00111 /// *sr receives the service record pointer and the caller is responsible 00112 /// for properly disposing of it. 00113 int remove (const ACE_TCHAR[], ACE_Service_Type **sr = 0); 00114 00115 // = Liveness control 00116 /// Resume a service record. 00117 int resume (const ACE_TCHAR[], const ACE_Service_Type ** = 0); 00118 00119 /// Suspend a service record. 00120 int suspend (const ACE_TCHAR[], const ACE_Service_Type ** = 0); 00121 00122 /// Return the current size of the repository. 00123 size_t current_size (void) const; 00124 00125 /// Return the total size of the repository. 00126 size_t total_size (void) const; 00127 00128 /// Dump the state of an object. 00129 void dump (void) const; 00130 00131 /// Declare the dynamic allocation hooks. 00132 ACE_ALLOC_HOOK_DECLARE; 00133 00134 private: 00135 /// Locates <service_name>. Must be called without locks being 00136 /// held... 00137 int find_i (const ACE_TCHAR service_name[], 00138 const ACE_Service_Type ** = 0, 00139 int ignore_suspended = 1) const; 00140 00141 /// Contains all the configured services. 00142 const ACE_Service_Type **service_vector_; 00143 00144 /// Current number of services. 00145 size_t current_size_; 00146 00147 /// Maximum number of services. 00148 size_t total_size_; 00149 00150 /// Pointer to a process-wide ACE_Service_Repository. 00151 static ACE_Service_Repository *svc_rep_; 00152 00153 /// Must delete the <svc_rep_> if non-0. 00154 static int delete_svc_rep_; 00155 00156 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00157 /// Synchronization variable for the MT_SAFE Repository 00158 mutable ACE_Recursive_Thread_Mutex lock_; 00159 #endif /* ACE_MT_SAFE */ 00160 }; 00161 00162 /** 00163 * @class ACE_Service_Repository_Iterator 00164 * 00165 * @brief Iterate through the ACE_Service_Repository. 00166 * 00167 * Make sure not to delete entries as the iteration is going on 00168 * since this class is not designed as a robust iterator. 00169 */ 00170 class ACE_Export ACE_Service_Repository_Iterator 00171 { 00172 public: 00173 // = Initialization and termination methods. 00174 /// Constructor initializes the iterator. 00175 ACE_Service_Repository_Iterator (ACE_Service_Repository &sr, 00176 int ignored_suspended = 1); 00177 00178 /// Destructor. 00179 ~ACE_Service_Repository_Iterator (void); 00180 00181 // = Iteration methods. 00182 00183 /// Pass back the <next_item> that hasn't been seen in the repository. 00184 /// Returns 0 when all items have been seen, else 1. 00185 int next (const ACE_Service_Type *&next_item); 00186 00187 /// Returns 1 when all items have been seen, else 0. 00188 int done (void) const; 00189 00190 /// Move forward by one element in the repository. Returns 0 when all the 00191 /// items in the set have been seen, else 1. 00192 int advance (void); 00193 00194 /// Dump the state of an object. 00195 void dump (void) const; 00196 00197 /// Declare the dynamic allocation hooks. 00198 ACE_ALLOC_HOOK_DECLARE; 00199 00200 private: 00201 bool valid (void) const; 00202 ACE_Service_Repository_Iterator (const ACE_Service_Repository_Iterator&); 00203 00204 private: 00205 /// Reference to the Service Repository we are iterating over. 00206 ACE_Service_Repository &svc_rep_; 00207 00208 /// Next index location that we haven't yet seen. 00209 size_t next_; 00210 00211 /// Are we ignoring suspended services? 00212 int ignore_suspended_; 00213 }; 00214 00215 ACE_END_VERSIONED_NAMESPACE_DECL 00216 00217 #if defined (__ACE_INLINE__) 00218 #include "ace/Service_Repository.inl" 00219 #endif /* __ACE_INLINE__ */ 00220 00221 #include /**/ "ace/post.h" 00222 00223 #endif /* _SERVICE_REPOSITORY_H */