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