Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / MProfile.h
blob882306374e3d7bf3fcd2d40e090c0094781d93ec
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file MProfile.h
7 * Keep track of profile lists
9 * @author Fred Kuhns <fredk@cs.wustl.edu>
11 //=============================================================================
14 #ifndef TAO_MPROFILE_H
15 #define TAO_MPROFILE_H
17 #include /**/ "ace/pre.h"
18 #include "ace/Recursive_Thread_Mutex.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 # pragma once
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 #include /**/ "tao/TAO_Export.h"
26 #include "tao/Basic_Types.h"
27 #include "tao/orbconf.h"
29 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
31 // Forward declarations
32 class TAO_Profile;
33 namespace CORBA
35 class PolicyList;
38 typedef CORBA::ULong TAO_PHandle;
40 /**
41 * @class TAO_MProfile
43 * @brief This class implements the basic interface for supporting
44 * multiple profiles.
46 * Multiple profiles can be treated either as a circular queue or
47 * a linear array of profiles.
48 * It is assumed that locking will only be required when a profile
49 * list is associated with a TAO_Stub. Thus when the
50 * TAO_Stub accepts ownership of an MProfile it also assumes
51 * responsibility for controling access (i.e. locking).
53 class TAO_Export TAO_MProfile
55 public:
56 TAO_MProfile (CORBA::ULong sz = 0);
58 /**
59 * **NOTE: IF mprofiles->last_ > 0, THEN this->size_ will be set to
60 * mprofiles->last_. Otherwise this->size_ - mprofiles->size_.
61 * Furthermore, current_ is set back to 0! i.e. rewound.
62 * The reference count on any profiles in mprofiles is increment
63 * when their references (i.e. pointers) are copied.
65 TAO_MProfile (const TAO_MProfile &mprofiles);
67 /// Assigment operator.
68 TAO_MProfile& operator= (const TAO_MProfile& mprofiles);
70 /// Destructor: decrements reference count on all references
71 /// profiles!
72 ~TAO_MProfile ();
74 /// Inits MProfile to hold sz TAO_Profiles.
75 /// NOT THREAD SAFE
76 int set (CORBA::ULong sz);
78 /**
79 * Inits this to the values of mprofile. NOTE: We use
80 * mprofile->last_ instead of mprofile->size_ to set this->size_.
81 * This is so we can use set () to trim a profile list!!
82 * NOT THREAD SAFE
84 int set (const TAO_MProfile &mprofile);
86 /// increase the number of profiles this object can hold.
87 /// NOT THREAD SAFE
88 int grow (CORBA::ULong sz);
90 /// Treat as a circular list.
91 TAO_Profile *get_cnext ();
93 /// Get next profile in list, return 0 at end of list.
94 TAO_Profile *get_next ();
96 /// Assume a circular list of profiles.
97 TAO_Profile *get_cprev ();
99 /// Get previous profile, stop at beginning of list and return 0.
100 TAO_Profile *get_prev ();
102 /// Return a pointer to the current profile, will not increment
103 /// reference pointer.
104 TAO_Profile *get_current_profile ();
106 /// Return a pointer to the profile referenced by handle void.
107 TAO_Profile *get_profile (TAO_PHandle handle);
109 // rem_profile (TAO_PHandle handle); let's wait.
111 /// Returns the index for the current profile.
112 TAO_PHandle get_current_handle ();
114 /// Returns the index for the current profile.
115 TAO_PHandle get_current_handle () const;
117 /// Returns the number of profiles stored in the list (last_+1).
118 CORBA::ULong profile_count () const;
120 /// return the maximum number of profiles that can be stored in this
121 /// container, (size_+1)
122 CORBA::ULong size () const;
124 /// Return the profile at position <slot>. If <slot> is out of range
125 /// it returns 0.
126 const TAO_Profile* get_profile (CORBA::ULong slot) const;
128 /// Sets the current slot back to 0.
129 void rewind ();
131 /// Return the index of this entry or -1 if it can not be added.
132 /// reference count on profile in incremented!
133 int add_profile (TAO_Profile *pfile);
135 /// Return the index of this entry or -1 if it can not be added.
136 /// this object assumes ownership of this profile!!
137 int give_profile (TAO_Profile *pfile, int share = 0);
139 /// append the profiles in pfiles to this object. The count
140 /// will be incremented on the individual profile objects.
141 int add_profiles (TAO_MProfile *pfiles);
143 /// remove from this MProfile any profiles which also appear in pfiles.
144 int remove_profile (const TAO_Profile *pfile);
146 /// remove from this MProfile any profiles which also appear in pfiles.
147 int remove_profiles (const TAO_MProfile *pfiles);
149 /// Set a pointer to the MProfile whose 'current' TAO_Profile was
150 /// forwarded This object is the set of forwarding profiles.
151 void forward_from (TAO_MProfile *mprofiles);
153 /// Returns a pointer to the profile which was forwarded.
154 TAO_MProfile *forward_from ();
157 * Returns true of there is at least one profile in first which
158 * is_equivalent with at least one profile in second.
159 * NON-THREAD SAFE, relies on some other entity to guarentee
160 * the profiles will not change during the call.
162 CORBA::Boolean is_equivalent (const TAO_MProfile *rhs);
165 * use all registered profiles. The hash() method is called on each
166 * profile and the results are averaged together.
167 * NON-THREAD SAFE.
169 CORBA::ULong hash (CORBA::ULong max);
171 protected:
172 /// This method handle the dynamic allocation of the data member
173 /// <policy_list_>.
174 void create_policy_list ();
176 public:
177 /// Sets the policies list associated with the profiles
178 /// owned by the TAO_MProfile.
179 void policy_list (CORBA::PolicyList *policy_list);
181 /// Gets the policies list associated with the profiles
182 /// owned by the TAO_MProfile.
183 CORBA::PolicyList *policy_list ();
185 protected:
186 /// Initialize the policy list, demarsharling the policy.
187 void init_policy_list ();
189 protected:
190 /// Stores the policy list for the profile of this MProfile.
191 friend class TAO_Profile;
192 CORBA::PolicyList *policy_list_;
194 CORBA::Boolean is_policy_list_initialized_;
196 /// Mutex used to make sure that only one policy list
197 /// is created.
198 TAO_SYNCH_RECURSIVE_MUTEX mutex_;
200 protected:
201 /// Return the complete list of profiles, this object retains
202 /// ownership!
203 TAO_Profile **pfiles () const;
206 private:
207 /// Helper method to implement the destructor
208 void cleanup ();
210 /// A helper to give_profile to be used when share is true. This
211 /// method is used primarily to help the corbaloc parser create a
212 /// single profile with multiple endpoints rather than constructing
213 /// multiple profiles with 1 endpoint per.
214 int give_shared_profile (TAO_Profile *pfile);
216 private:
218 * Used for chaning references when the current profile is
219 * forwarded. Note, this will only be valid for an MProfile which
220 * contains a list of forward_profiles for some initial or base
221 * profile. This is a backward reference to the profile list which
222 * received the relocate message. The actual profile what was
223 * forwarded will be forward_from_->get_current_profile ()
225 TAO_MProfile *forward_from_;
227 /// Actual list of profiles.
228 TAO_Profile **pfiles_;
230 /// Points to the next profile to be used. 0 ... size_
231 TAO_PHandle current_;
233 /// Max size of array
234 TAO_PHandle size_;
236 /// Index plus 1 of last valid entry! May be < size_.
237 TAO_PHandle last_;
240 TAO_END_VERSIONED_NAMESPACE_DECL
242 #if defined (__ACE_INLINE__)
243 # include "tao/MProfile.inl"
244 #endif /*__ACE_INLINE__ */
246 #include /**/ "ace/post.h"
248 #endif /* TAO_MPROFILE_H */