Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends

TAO_MProfile Class Reference

This class implements the basic interface for supporting multiple profiles. More...

#include <MProfile.h>

Collaboration diagram for TAO_MProfile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TAO_MProfile (CORBA::ULong sz=0)
 TAO_MProfile (const TAO_MProfile &mprofiles)
TAO_MProfileoperator= (const TAO_MProfile &mprofiles)
 Assigment operator.
 ~TAO_MProfile (void)
int set (CORBA::ULong sz)
int set (const TAO_MProfile &mprofile)
int grow (CORBA::ULong sz)
TAO_Profileget_cnext (void)
 Treat as a circular list.
TAO_Profileget_next (void)
 Get next profile in list, return 0 at end of list.
TAO_Profileget_cprev (void)
 Assume a circular list of profiles.
TAO_Profileget_prev (void)
 Get previous profile, stop at beginning of list and return 0.
TAO_Profileget_current_profile (void)
TAO_Profileget_profile (TAO_PHandle handle)
 Return a pointer to the profile referenced by handle void.
TAO_PHandle get_current_handle (void)
 Returns the index for the current profile.
TAO_PHandle get_current_handle (void) const
 Returns the index for the current profile.
CORBA::ULong profile_count (void) const
 Returns the number of profiles stored in the list (last_+1).
CORBA::ULong size (void) const
const TAO_Profileget_profile (CORBA::ULong slot) const
void rewind (void)
 Sets the current slot back to 0.
int add_profile (TAO_Profile *pfile)
int give_profile (TAO_Profile *pfile, int share=0)
int add_profiles (TAO_MProfile *pfiles)
int remove_profile (const TAO_Profile *pfile)
 remove from this MProfile any profiles which also appear in pfiles.
int remove_profiles (const TAO_MProfile *pfiles)
 remove from this MProfile any profiles which also appear in pfiles.
void forward_from (TAO_MProfile *mprofiles)
TAO_MProfileforward_from (void)
 Returns a pointer to the profile which was forwarded.
CORBA::Boolean is_equivalent (const TAO_MProfile *rhs)
CORBA::ULong hash (CORBA::ULong max)
void policy_list (CORBA::PolicyList *policy_list)
CORBA::PolicyList * policy_list (void)

Protected Member Functions

void create_policy_list (void)
void init_policy_list (void)
 Initialize the policy list, demarsharling the policy.
TAO_Profile ** pfiles (void) const

Protected Attributes

CORBA::PolicyList * policy_list_
CORBA::Boolean is_policy_list_initialized_
TAO_SYNCH_RECURSIVE_MUTEX mutex_

Private Member Functions

void cleanup (void)
 Helper method to implement the destructor.
int give_shared_profile (TAO_Profile *pfile)

Private Attributes

TAO_MProfileforward_from_
TAO_Profile ** pfiles_
 Actual list of profiles.
TAO_PHandle current_
 Points to the next profile to be used. 0 ... size_.
TAO_PHandle size_
 Max size of array.
TAO_PHandle last_
 Index plus 1 of last valid entry! May be < size_.

Friends

class TAO_Profile
 Stores the policy list for the profile of this MProfile.

Detailed Description

This class implements the basic interface for supporting multiple profiles.

Multiple profiles can be treated either as a circular queue or a linear array of profiles. It is assumed that locking will only be required when a profile list is associated with a TAO_Stub. Thus when the TAO_Stub accepts ownership of an MProfile it also assumes responsibility for controling access (i.e. locking).

Definition at line 55 of file MProfile.h.


Constructor & Destructor Documentation

TAO_MProfile::TAO_MProfile ( CORBA::ULong  sz = 0  ) 

Definition at line 9 of file MProfile.inl.

  :  policy_list_ (0),
     is_policy_list_initialized_ (false),
     forward_from_(0),
     pfiles_ (0),
     current_ (0),
     size_ (0),
     last_ (0)
{
  this->set (sz);
}

TAO_MProfile::TAO_MProfile ( const TAO_MProfile mprofiles  ) 

**NOTE: IF mprofiles->last_ > 0, THEN this->size_ will be set to mprofiles->last_. Otherwise this->size_ - mprofiles->size_. Furthermore, current_ is set back to 0! i.e. rewound. The reference count on any profiles in mprofiles is increment when their references (i.e. pointers) are copied.

Definition at line 22 of file MProfile.inl.

  :  policy_list_ (0),
     is_policy_list_initialized_ (false),
     forward_from_(0),
     pfiles_ (0),
     current_ (0),
     size_ (0),
     last_ (0)
{
  this->set (mprofiles);
}

TAO_MProfile::~TAO_MProfile ( void   ) 

Destructor: decrements reference count on all references profiles!

Definition at line 24 of file MProfile.cpp.

{
  if (this->policy_list_ != 0)
    {
      CORBA::ULong const len = this->policy_list_->length ();
      for (CORBA::ULong i = 0; i < len; ++i)
        {
          try
            {
              CORBA::Policy_ptr policy = (*this->policy_list_)[i];
              policy->destroy ();
            }
          catch (const ::CORBA::Exception&)
            {
              // Ignore all exceptions to allow other policies to be
              // destroyed.
            }
        }

      delete this->policy_list_;
    }

  this->cleanup ();
}


Member Function Documentation

int TAO_MProfile::add_profile ( TAO_Profile pfile  ) 

Return the index of this entry or -1 if it can not be added. reference count on profile in incremented!

Definition at line 179 of file MProfile.cpp.

{
  // skip by the used slots
  if (last_ == size_) // full!
    {
      if (this->grow (this->size_ + 1) < 0)
        return -1;
    }

  pfiles_[last_++] = pfile;

  if (pfile && pfile->_incr_refcnt () == 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("(%P|%t) Unable to increment reference ")
                       ACE_TEXT ("count in add_profile!\n")),
                      -1);

  return last_ - 1;
}

int TAO_MProfile::add_profiles ( TAO_MProfile pfiles  ) 

append the profiles in pfiles to this object. The count will be incremented on the individual profile objects.

Definition at line 200 of file MProfile.cpp.

{
  // this->size_ == total number of profiles we can hold
  // this->last_ == the index of the last profile
  CORBA::ULong const space = this->size_ - this->last_;

  if (space < pfiles->last_)
    {
      // we need to grow!
     if (this->grow (this->last_ + pfiles->last_) < 0)
       return -1;
    }

  // copy over profiles
  for (TAO_PHandle h = 0; h < pfiles->last_; ++h)
    {
      if (this->add_profile (pfiles->pfiles_[h]) < 0)
        return -1;
    }
  return 0;
}

void TAO_MProfile::cleanup ( void   )  [private]

Helper method to implement the destructor.

Definition at line 50 of file MProfile.cpp.

{
  if (this->pfiles_ != 0)
    {
      for (TAO_PHandle i = 0; i < this->last_; ++i)
        if (this->pfiles_[i])
          this->pfiles_[i]->_decr_refcnt ();
      delete [] this->pfiles_;
      this->pfiles_ = 0;
    }

  this->current_ = 0;
  this->size_ = 0;
  this->last_ = 0;
}

void TAO_MProfile::create_policy_list ( void   )  [protected]

This method handle the dynamic allocation of the data member <policy_list_>.

Definition at line 309 of file MProfile.cpp.

{
  ACE_NEW_THROW_EX (this->policy_list_,
                    CORBA::PolicyList,
                    CORBA::NO_MEMORY (0,
                                      CORBA::COMPLETED_NO)
                    );
}

void TAO_MProfile::forward_from ( TAO_MProfile mprofiles  ) 

Set a pointer to the MProfile whose 'current' TAO_Profile was forwarded This object is the set of forwarding profiles.

Definition at line 161 of file MProfile.inl.

{
  this->forward_from_ = from;
}

TAO_MProfile * TAO_MProfile::forward_from ( void   ) 

Returns a pointer to the profile which was forwarded.

Definition at line 168 of file MProfile.inl.

{
  return this->forward_from_;
}

TAO_Profile * TAO_MProfile::get_cnext ( void   ) 

Treat as a circular list.

Definition at line 47 of file MProfile.inl.

{
  if (last_ == 0)
    return 0;

  if (current_ == last_)
    current_ = 0;

  return pfiles_[current_++];
}

TAO_Profile * TAO_MProfile::get_cprev ( void   ) 

Assume a circular list of profiles.

Definition at line 72 of file MProfile.inl.

{
  if (last_ == 0)
    return 0;
  else if (last_ == 1)
    current_=1;
  else if (current_ > 1)
    --current_;
  else // current_ == 0 or 1, 0 => list never read before and == 1
    current_ = last_;

  return pfiles_[current_ - 1];
}

TAO_PHandle TAO_MProfile::get_current_handle ( void   ) 

Returns the index for the current profile.

Definition at line 122 of file MProfile.inl.

{
  if (current_ > 0)
    return current_ - 1;
  else
    return 0;
}

TAO_PHandle TAO_MProfile::get_current_handle ( void   )  const

Returns the index for the current profile.

Definition at line 131 of file MProfile.inl.

{
  if (current_ > 0)
    return current_ - 1;
  else
    return 0;
}

TAO_Profile * TAO_MProfile::get_current_profile ( void   ) 

Return a pointer to the current profile, will not increment reference pointer.

Definition at line 110 of file MProfile.inl.

{
  if (last_ == 0)
    return 0;
  if (current_ == 0)
    // means list has not been read before.
    current_ = 1;

  return pfiles_[current_ - 1];
}

TAO_Profile * TAO_MProfile::get_next ( void   ) 

Get next profile in list, return 0 at end of list.

Definition at line 62 of file MProfile.inl.

{
  // Nolist or EndOfList
  if (last_ == 0 || current_ == last_)
    return 0;
  else
    return pfiles_[current_++];
}

TAO_Profile * TAO_MProfile::get_prev ( void   ) 

Get previous profile, stop at beginning of list and return 0.

Definition at line 87 of file MProfile.inl.

{
  if (last_ == 0 || current_ <= 1)
    // No List of BeginningOfList
    return 0;
  if (current_ > 1)
    --current_;

  return pfiles_[current_ - 1];
}

TAO_Profile * TAO_MProfile::get_profile ( TAO_PHandle  handle  ) 

Return a pointer to the profile referenced by handle void.

Definition at line 101 of file MProfile.inl.

{
  if (handle < last_)
    return pfiles_[handle];
  else
    return 0;
}

const TAO_Profile * TAO_MProfile::get_profile ( CORBA::ULong  slot  )  const

Return the profile at position <slot>. If <slot> is out of range it returns 0.

Definition at line 186 of file MProfile.inl.

{
  if (slot >= this->last_)
    return 0;
  return this->pfiles_[slot];
}

int TAO_MProfile::give_profile ( TAO_Profile pfile,
int  share = 0 
)

Return the index of this entry or -1 if it can not be added. this object assumes ownership of this profile!!

Definition at line 146 of file MProfile.inl.

{
  if (share)
    return this->give_shared_profile(pfile);
  // skip by the used slots
  if (last_ == size_) // full!
    return -1;

  pfiles_[last_++] = pfile;

  return last_ - 1;
}

int TAO_MProfile::give_shared_profile ( TAO_Profile pfile  )  [private]

A helper to give_profile to be used when share is true. This method is used primarily to help the corbaloc parser create a single profile with multiple endpoints rather than constructing multiple profiles with 1 endpoint per.

Definition at line 357 of file MProfile.cpp.

{
  for (unsigned i = 0; i < this->last_; i++)
    if (pfile->tag() == this->pfiles_[i]->tag() &&
        pfile->compare_key(this->pfiles_[i]))
      {
        this->pfiles_[i]->add_generic_endpoint(pfile->endpoint());
        pfile->_decr_refcnt();
        return i;
      }
  return this->give_profile(pfile, 0);
}

int TAO_MProfile::grow ( CORBA::ULong  sz  ) 

increase the number of profiles this object can hold. NOT THREAD SAFE

Definition at line 150 of file MProfile.cpp.

{
  if (sz <= this->size_)
    return 0;

  // get the additional space
  TAO_Profile **new_pfiles = 0;
  TAO_Profile **old_pfiles = 0;
  ACE_NEW_RETURN (new_pfiles,
                  TAO_Profile *[sz],
                  -1);

  old_pfiles = this->pfiles_;

  // got it, now copy profiles
  for (TAO_PHandle h = 0; h < this->size_; ++h)
    {
      new_pfiles[h] = old_pfiles[h];
      old_pfiles[h] = 0;
    }

  this->pfiles_ = new_pfiles;
  this->size_ = sz;
  delete [] old_pfiles;

  return 0;
}

CORBA::ULong TAO_MProfile::hash ( CORBA::ULong  max  ) 

use all registered profiles. The hash() method is called on each profile and the results are averaged together. NON-THREAD SAFE.

Definition at line 289 of file MProfile.cpp.

{
  CORBA::ULong hashval = 0;

  if (this->last_ == 0)
    return 0;

  for (TAO_PHandle h = 0; h < this->last_ ; ++h)
    {
      hashval += pfiles_[h]->hash (max);
    }

  // The above hash function return an ULong between 0 and max here we
  // simply take the average value and round.
  //return hashval / this->last_;
  // Changed to a mod value instead of an average.
  return hashval % max;
}

void TAO_MProfile::init_policy_list ( void   )  [protected]

Initialize the policy list, demarsharling the policy.

Definition at line 319 of file MProfile.cpp.

{
  // The first time this method is called
  // it causes the initialization of the policies
  // for the current profile.

  this->get_current_profile ()->get_policies (*this->policy_list_);

  this->is_policy_list_initialized_ = true;
}

CORBA::Boolean TAO_MProfile::is_equivalent ( const TAO_MProfile rhs  ) 

Returns true of there is at least one profile in first which is_equivalent with at least one profile in second. NON-THREAD SAFE, relies on some other entity to guarentee the profiles will not change during the call.

Definition at line 275 of file MProfile.cpp.

{
  // Two profile lists are equivalent iff at least one of the profiles
  // from the first list is_equivalent to at least one of the profiles
  // from the second list!!
  for (TAO_PHandle h1 = 0; h1 < this->last_; ++h1)
    for (TAO_PHandle h2 = 0; h2 < rhs->last_; ++h2)
      if (this->pfiles_[h1]->is_equivalent (rhs->pfiles_[h2]))
        return 1;

  return 0;
}

TAO_MProfile & TAO_MProfile::operator= ( const TAO_MProfile mprofiles  ) 

Assigment operator.

Definition at line 35 of file MProfile.inl.

{
  if (this == &rhs)
    return *this;

  this->set (rhs);
  return *this;
}

TAO_Profile ** TAO_MProfile::pfiles ( void   )  const [protected]

Return the complete list of profiles, this object retains ownership!

Definition at line 194 of file MProfile.inl.

{
  return this->pfiles_;
}

void TAO_MProfile::policy_list ( CORBA::PolicyList *  policy_list  ) 

Sets the policies list associated with the profiles owned by the TAO_MProfile.

Definition at line 200 of file MProfile.inl.

{
  this->policy_list_ = policy_list;
}

CORBA::PolicyList * TAO_MProfile::policy_list ( void   ) 

Gets the policies list associated with the profiles owned by the TAO_MProfile.

Definition at line 331 of file MProfile.cpp.

{
  if (!this->is_policy_list_initialized_)
    {
      ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
                        guard,
                        this->mutex_,
                        0);

      if (this->policy_list_ == 0)
        {
          this->create_policy_list ();

          this->init_policy_list ();
        }
    }
  CORBA::PolicyList *ret_val = 0;
  ACE_NEW_THROW_EX (ret_val,
                    CORBA::PolicyList (*this->policy_list_),
                    CORBA::NO_MEMORY (0,
                                      CORBA::COMPLETED_NO));

  return ret_val;
}

CORBA::ULong TAO_MProfile::profile_count ( void   )  const

Returns the number of profiles stored in the list (last_+1).

Definition at line 174 of file MProfile.inl.

{
  return this->last_;
}

int TAO_MProfile::remove_profile ( const TAO_Profile pfile  ) 

remove from this MProfile any profiles which also appear in pfiles.

Definition at line 235 of file MProfile.cpp.

{
  TAO_PHandle h;
  int found = 0;
  for (h = 0; h < this->last_; ++h)
    {
      if (this->pfiles_[h]->is_equivalent (pfile))
        { // remove it!
          TAO_Profile *old = this->pfiles_[h];
          this->pfiles_[h] = 0;
          old->_decr_refcnt ();
          // shift other profiles up one
          // note, if h == last_ - 1 then do nothing.
          for (TAO_PHandle inner = h; inner < this->last_ - 1; ++inner)
            {
              this->pfiles_[inner] = this->pfiles_[inner + 1];
            }
          // subtract 1 from last_ to indicate we have one fewer profiles
          this->last_--;
          found = 1;
          break;
        }
    }
  if ( found == 0)
    return -1; // profile not found.
  return 0;
}

int TAO_MProfile::remove_profiles ( const TAO_MProfile pfiles  ) 

remove from this MProfile any profiles which also appear in pfiles.

Definition at line 264 of file MProfile.cpp.

{
  for (TAO_PHandle h = 0; h < pfiles->last_; ++h)
    {
      if (this->remove_profile (pfiles->pfiles_[h]) < 0)
        return -1;
    }
  return 0;
}

void TAO_MProfile::rewind ( void   ) 

Sets the current slot back to 0.

Definition at line 140 of file MProfile.inl.

{
  current_ = 0;
}

int TAO_MProfile::set ( const TAO_MProfile mprofile  ) 

Inits this to the values of mprofile. NOTE: We use mprofile->last_ instead of mprofile->size_ to set this->size_. This is so we can use set () to trim a profile list!! NOT THREAD SAFE

Definition at line 122 of file MProfile.cpp.

{
  // NOTE: We use mprofile->last_ instead of mprofile->size_ to set
  // this->size_.  This is so we can use set () to trim a profile
  // list!!

  this->set (mprofile.last_);

  // set indexes ...
  this->last_ = mprofile.last_;

  // These are set in set (ULong);
  // this->current_ = 0;
  // this->forward_from_ = 0;

  // Now reference all profiles.
  for (TAO_PHandle h = 0; h < this->last_; ++h)
    {
      this->pfiles_[h] = mprofile.pfiles_[h];
      if (this->pfiles_[h] != 0)
        this->pfiles_[h]->_incr_refcnt ();
    }

  return 1;
}

int TAO_MProfile::set ( CORBA::ULong  sz  ) 

Inits MProfile to hold sz TAO_Profiles. NOT THREAD SAFE

Definition at line 67 of file MProfile.cpp.

{
  if (sz == 0)
    {
      this->cleanup ();
      return 0;
    }

  // See if we already have an existing profile list or if we need to
  // get ridof what we have.
  if (this->size_ != 0)
    {
      // Release all of our profiles.

      for (TAO_PHandle h = 0;
           h < this->size_;
           ++h)
        if (this->pfiles_[h])
          {
            this->pfiles_[h]->_decr_refcnt ();
            this->pfiles_[h] = 0;
          }

      // Next see if we can reuse our profile list memory
      if (this->size_ < sz)
        {
          // we cant reuse memory since the current array is too small!
          delete [] this->pfiles_;

          ACE_NEW_RETURN (this->pfiles_,
                          TAO_Profile *[sz],
                          -1);
          this->size_ = sz;
        }
      // else , leave this->size and this->pfiles alone!
    }
  else
    {
      // first time, initialize!
      ACE_NEW_RETURN (this->pfiles_,
                      TAO_Profile *[sz],
                      -1);
      this->size_ = sz;
    }

  this->last_ = 0;
  this->current_ = 0;

  for (TAO_PHandle i = 0; i != this->size_; ++i)
    this->pfiles_[i] = 0;

  return this->size_;
}

CORBA::ULong TAO_MProfile::size ( void   )  const

return the maximum number of profiles that can be stored in this container, (size_+1)

Definition at line 180 of file MProfile.inl.

{
  return this->size_;
}


Friends And Related Function Documentation

friend class TAO_Profile [friend]

Stores the policy list for the profile of this MProfile.

Definition at line 197 of file MProfile.h.


Member Data Documentation

Points to the next profile to be used. 0 ... size_.

Definition at line 238 of file MProfile.h.

Used for chaning references when the current profile is forwarded. Note, this will only be valid for an MProfile which contains a list of forward_profiles for some initial or base profile. This is a backward reference to the profile list which received the relocate message. The actual profile what was forwarded will be forward_from_->get_current_profile ()

Definition at line 232 of file MProfile.h.

Definition at line 200 of file MProfile.h.

Index plus 1 of last valid entry! May be < size_.

Definition at line 244 of file MProfile.h.

TAO_SYNCH_RECURSIVE_MUTEX TAO_MProfile::mutex_ [protected]

Mutex used to make sure that only one policy list is created.

Definition at line 204 of file MProfile.h.

Actual list of profiles.

Definition at line 235 of file MProfile.h.

CORBA::PolicyList* TAO_MProfile::policy_list_ [protected]

Definition at line 198 of file MProfile.h.

Max size of array.

Definition at line 241 of file MProfile.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines