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