summaryrefslogtreecommitdiff
path: root/TAO/tao/MProfile.cpp
blob: 963f4becb7730c01647b3ad1cadfafb16affd44f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// This may look like C, but it's really -*- C++ -*-
// $Id$

#include "tao/MProfile.h"
#include "tao/Pluggable.h"

ACE_RCSID(tao, MProfile, "$Id$")

#if !defined (__ACE_INLINE__)
# include "tao/MProfile.i"
#endif /* __ACE_INLINE__ */

int
TAO_MProfile::set (CORBA::ULong sz)
{
  if (sz == 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;
          }

      if (this->size_)
        delete [] this->pfiles_;
  
      if (forward_from_)
        delete forward_from_;
  
      pfiles_ = 0;
      current_ = 0;
      size_ = 0;
      last_= 0;

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

      return 0;
    }

  // See if we already have an existing profile list or if we need to
  // get ridof what we have.  @@ Fred, please be consistent with your
  // use of this-> as a prefix for data members.
  if (size_)
    {
      // Release all of our profiles.

      for (TAO_PHandle h = 0;
           h < 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 Since
      if (this->size_ != sz)
        {
          // we cant reuse memory since the array sized are different!
          delete [] this->pfiles_;

          ACE_NEW_RETURN (this->pfiles_,
                          TAO_Profile_ptr[sz],
                          -1);
        }
    }
  else
    // first time, initialize!
    ACE_NEW_RETURN (this->pfiles_,
                    TAO_Profile_ptr [sz],
                    -1);
  // this->pfiles_

  ACE_OS::memset (this->pfiles_,
                  0,
                  sizeof (TAO_Profile_ptr) * sz);
  size_ = sz;
  this->last_ = 0;
  this->current_ = 0;

  // @@ since we are being reset, get rid of forward references!
  if (forward_from_)
    delete forward_from_;

  return size_;
}

int
TAO_MProfile::set (TAO_MProfile *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!!

  if (mprofile == 0)
    return this->set ((CORBA::ULong) 0);

  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->size_;
       h++)
    if (mprofile->pfiles_[h])
      {
        this->pfiles_[h] = mprofile->pfiles_[h];
        this->pfiles_[h]->_incr_refcnt ();
      }

  if (mprofile->forward_from_)
    this->forward_from_ = mprofile->forward_from_;

  return 1;
}