00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file MProfile.h 00006 * 00007 * MProfile.h,v 1.44 2006/04/26 17:12:47 mesnier_p Exp 00008 * 00009 * Keep track of profile lists 00010 * 00011 * @author Fred Kuhns <fredk@cs.wustl.edu> 00012 */ 00013 //============================================================================= 00014 00015 00016 #ifndef TAO_MPROFILE_H 00017 #define TAO_MPROFILE_H 00018 00019 #include /**/ "ace/pre.h" 00020 #include "ace/CORBA_macros.h" 00021 00022 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00023 # pragma once 00024 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00025 00026 #include "ace/Recursive_Thread_Mutex.h" 00027 00028 #include "tao/TAO_Export.h" 00029 #include "tao/Basic_Types.h" 00030 #include "tao/orbconf.h" 00031 00032 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00033 00034 // Forward declarations 00035 class TAO_Profile; 00036 namespace CORBA 00037 { 00038 class PolicyList; 00039 00040 class Environment; 00041 } 00042 00043 typedef CORBA::ULong TAO_PHandle; 00044 00045 /** 00046 * @class TAO_MProfile 00047 * 00048 * @brief This class implements the basic interface for supporting 00049 * multiple profiles. 00050 * 00051 * Multiple profiles can be treated either as a circular queue or 00052 * a linear array of profiles. 00053 * It is assumed that locking will only be required when a profile 00054 * list is associated with a TAO_Stub. Thus when the 00055 * TAO_Stub accepts ownership of an MProfile it also assumes 00056 * responsibility for controling access (i.e. locking). 00057 */ 00058 class TAO_Export TAO_MProfile 00059 { 00060 public: 00061 // = Initialization and termination methods. 00062 TAO_MProfile (CORBA::ULong sz = 0); 00063 00064 /** 00065 * **NOTE: IF mprofiles->last_ > 0, THEN this->size_ will be set to 00066 * mprofiles->last_. Otherwise this->size_ - mprofiles->size_. 00067 * Furthermore, current_ is set back to 0! i.e. rewound. 00068 * The reference count on any profiles in mprofiles is increment 00069 * when their references (i.e. pointers) are copied. 00070 */ 00071 TAO_MProfile (const TAO_MProfile &mprofiles); 00072 00073 /// Assigment operator. 00074 TAO_MProfile& operator= (const TAO_MProfile& mprofiles); 00075 00076 /// Destructor: decrements reference count on all references 00077 /// profiles! 00078 ~TAO_MProfile (void); 00079 00080 /// Inits MProfile to hold sz TAO_Profiles. 00081 /// NOT THREAD SAFE 00082 int set (CORBA::ULong sz); 00083 00084 /** 00085 * Inits this to the values of mprofile. NOTE: We use 00086 * mprofile->last_ instead of mprofile->size_ to set this->size_. 00087 * This is so we can use set () to trim a profile list!! 00088 * NOT THREAD SAFE 00089 */ 00090 int set (const TAO_MProfile &mprofile); 00091 00092 /// increase the number of profiles this object can hold. 00093 /// NOT THREAD SAFE 00094 int grow (CORBA::ULong sz); 00095 00096 /// Treat as a circular list. 00097 TAO_Profile *get_cnext (void); 00098 00099 /// Get next profile in list, return 0 at end of list. 00100 TAO_Profile *get_next (void); 00101 00102 /// Assume a circular list of profiles. 00103 TAO_Profile *get_cprev (void); 00104 00105 /// Get previous profile, stop at beginning of list and return 0. 00106 TAO_Profile *get_prev (void); 00107 00108 /// Return a pointer to the current profile, will not increment 00109 /// reference pointer. 00110 TAO_Profile *get_current_profile (void); 00111 00112 /// Return a pointer to the profile referenced by handle void. 00113 TAO_Profile *get_profile (TAO_PHandle handle); 00114 00115 // rem_profile (TAO_PHandle handle); let's wait. 00116 00117 /// Returns the index for the current profile. 00118 TAO_PHandle get_current_handle (void); 00119 00120 /// Returns the index for the current profile. 00121 TAO_PHandle get_current_handle (void) const; 00122 00123 /// Returns the number of profiles stored in the list (last_+1). 00124 CORBA::ULong profile_count (void) const; 00125 00126 /// return the maximum number of profiles that can be stored in this 00127 /// container, (size_+1) 00128 CORBA::ULong size (void) const; 00129 00130 /// Return the profile at position <slot>. If <slot> is out of range 00131 /// it returns 0. 00132 const TAO_Profile* get_profile (CORBA::ULong slot) const; 00133 00134 /// Sets the current slot back to 0. 00135 void rewind (void); 00136 00137 /// Return the index of this entry or -1 if it can not be added. 00138 /// reference count on profile in incremented! 00139 int add_profile (TAO_Profile *pfile); 00140 00141 /// Return the index of this entry or -1 if it can not be added. 00142 /// this object assumes ownership of this profile!! 00143 int give_profile (TAO_Profile *pfile, int share = 0); 00144 00145 /// append the profiles in pfiles to this object. The count 00146 /// will be incremented on the individual profile objects. 00147 int add_profiles (TAO_MProfile *pfiles); 00148 00149 /// remove from this MProfile any profiles which also appear in pfiles. 00150 int remove_profile (const TAO_Profile *pfile); 00151 00152 /// remove from this MProfile any profiles which also appear in pfiles. 00153 int remove_profiles (const TAO_MProfile *pfiles); 00154 00155 /// Set a pointer to the MProfile whose 'current' TAO_Profile was 00156 /// forwarded This object is the set of forwarding profiles. 00157 void forward_from (TAO_MProfile *mprofiles); 00158 00159 /// Returns a pointer to the profile which was forwarded. 00160 TAO_MProfile *forward_from (void); 00161 00162 /** 00163 * Returns true of there is at least one profile in first which 00164 * is_equivalent with at least one profile in second. 00165 * NON-THREAD SAFE, relies on some other entity to guarentee 00166 * the profiles will not change during the call. 00167 */ 00168 CORBA::Boolean is_equivalent (const TAO_MProfile *rhs); 00169 00170 /** 00171 * use all registered profiles. The hash() method is called on each 00172 * profile and the results are averaged together. 00173 * NON-THREAD SAFE. 00174 */ 00175 CORBA::ULong hash (CORBA::ULong max 00176 ACE_ENV_ARG_DECL); 00177 00178 protected: 00179 00180 /// This method handle the dynamic allocation of the data member 00181 /// <policy_list_>. 00182 void create_policy_list (ACE_ENV_SINGLE_ARG_DECL); 00183 00184 public: 00185 00186 /// Sets the policies list associated with the profiles 00187 /// owned by the TAO_MProfile. 00188 void policy_list (CORBA::PolicyList *policy_list); 00189 00190 /// Gets the policies list associated with the profiles 00191 /// owned by the TAO_MProfile. 00192 CORBA::PolicyList *policy_list (ACE_ENV_SINGLE_ARG_DECL); 00193 00194 protected: 00195 00196 /// Initialize the policy list, demarsharling the policy. 00197 void init_policy_list (ACE_ENV_SINGLE_ARG_DECL); 00198 00199 protected: 00200 /// Stores the policy list for the profile of this MProfile. 00201 friend class TAO_Profile; 00202 CORBA::PolicyList *policy_list_; 00203 00204 CORBA::Boolean is_policy_list_initialized_; 00205 00206 /// Mutex used to make sure that only one policy list 00207 /// is created. 00208 TAO_SYNCH_RECURSIVE_MUTEX mutex_; 00209 00210 protected: 00211 /// Return the complete list of profiles, this object retains 00212 /// ownership! 00213 TAO_Profile **pfiles (void) const; 00214 00215 00216 private: 00217 /// Helper method to implement the destructor 00218 void cleanup (void); 00219 00220 /// A helper to give_profile to be used when share is true. This 00221 /// method is used primarily to help the corbaloc parser create a 00222 /// single profile with multiple endpoints rather than constructing 00223 /// multiple profiles with 1 endpoint per. 00224 int give_shared_profile (TAO_Profile *pfile); 00225 00226 private: 00227 00228 /** 00229 * Used for chaning references when the current profile is 00230 * forwarded. Note, this will only be valid for an MProfile which 00231 * contains a list of forward_profiles for some initial or base 00232 * profile. This is a backward reference to the profile list which 00233 * received the relocate message. The actual profile what was 00234 * forwarded will be forward_from_->get_current_profile () 00235 */ 00236 TAO_MProfile *forward_from_; 00237 00238 /// Actual list of profiles. 00239 TAO_Profile **pfiles_; 00240 00241 /// Points to the next profile to be used. 0 ... size_ 00242 TAO_PHandle current_; 00243 00244 /// Max size of array 00245 TAO_PHandle size_; 00246 00247 /// Index plus 1 of last valid entry! May be < size_. 00248 TAO_PHandle last_; 00249 }; 00250 00251 TAO_END_VERSIONED_NAMESPACE_DECL 00252 00253 #if defined (__ACE_INLINE__) 00254 # include "tao/MProfile.i" 00255 #endif /*__ACE_INLINE__ */ 00256 00257 #include /**/ "ace/post.h" 00258 00259 #endif /* TAO_MPROFILE_H */