summaryrefslogtreecommitdiff
path: root/TAO/tao/Stub.i
blob: 8d691419ca171f4c8cfe862c99888714d245006f (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
// $Id$

// @@ Get rid of profile specific stuff, it is now in it's own class and
// file. fredk
#include <tao/debug.h>

ACE_INLINE
TAO_Profile *
STUB_Object::set_profile_in_use_i (TAO_Profile *pfile)
{
  TAO_Profile *old = this->profile_in_use_;

  // Since we are actively using this profile we dont want
  // it to disappear, so increase the reference count by one!!
  if (pfile && (pfile->_incr_refcnt () == 0))
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                        "(%P|%t) unable to increment profile ref!\n"),
                        0);
    }

  this->profile_in_use_ = pfile;

  if (old)
    old->_decr_refcnt ();

  return this->profile_in_use_;
}

ACE_INLINE
void 
STUB_Object::reset_first_locate_request (void)
{
  first_locate_request_ = 1;
}

ACE_INLINE
void
STUB_Object::reset_base (void)
{
  this->base_profiles_.rewind ();
  reset_first_locate_request ();
  profile_success_ = 0;

  set_profile_in_use_i (base_profiles_.get_next ());
}

ACE_INLINE
void
STUB_Object::forward_back_one (void)
{
  TAO_MProfile *from = forward_profiles_->forward_from ();

  delete forward_profiles_;

  // the current profile in this profile list is no
  // longer being forwarded, so set the reference to zero.
  if (from == &base_profiles_)
    {
      base_profiles_.get_current_profile ()->forward_to (0);
      forward_profiles_ = 0;
    }
  else
    {
      from->get_current_profile ()->forward_to (0);
      forward_profiles_ = from;
    }

}

ACE_INLINE
void
STUB_Object::reset_forward (void)
{
  while (forward_profiles_)
    forward_back_one ();

  forward_profiles_ = 0;
}

ACE_INLINE
void
STUB_Object::reset_profiles (void)
{
  ACE_MT (ACE_GUARD (ACE_Lock,
                     guard,
                     *this->profile_lock_ptr_));
  reset_forward ();
  reset_base ();
}

ACE_INLINE
STUB_Object::~STUB_Object (void)
{
  assert (this->refcount_ == 0);

  if (forward_profiles_)
    reset_profiles ();

  if (this->profile_in_use_ != 0) 
    {
      this->profile_in_use_->reset_hint ();
      // decrease reference count on profile
      this->profile_in_use_->_decr_refcnt ();   
      this->profile_in_use_ = 0;
    }

  if (this->profile_lock_ptr_)
    delete this->profile_lock_ptr_; 

}

ACE_INLINE
TAO_Profile *
STUB_Object::profile_in_use (void)
{
  return this->profile_in_use_;
}

ACE_INLINE
void 
STUB_Object::use_locate_requests (CORBA::Boolean use_it)
{
  if (use_it)
    {
      this->first_locate_request_ = 1;
      this->use_locate_request_ = 1;
    }
  else 
    {
      // Don't use it.
      this->first_locate_request_ = 0;
      this->use_locate_request_ = 0;
    }   
} 

ACE_INLINE
TAO_MProfile * 
STUB_Object::get_profiles (void)
{
  return new TAO_MProfile (&base_profiles_);
}

ACE_INLINE
TAO_Profile *
STUB_Object::next_forward_profile (void)
{
  TAO_Profile *pfile_next = 0;

  while (forward_profiles_ && (pfile_next = forward_profiles_->get_next ()) == 0)
    // that was the last profile.  Now we clean up our forward profiles.
    // since we own the forward MProfiles, we must delete them when done.
    forward_back_one ();

  return pfile_next;
}

ACE_INLINE
TAO_Profile *
STUB_Object::next_profile (void)
{

  ACE_MT (ACE_GUARD_RETURN (ACE_Lock,
                            guard,
                            *this->profile_lock_ptr_,
                            0));

  TAO_Profile *pfile_next = 0;
  if (forward_profiles_)
    {
      pfile_next = next_forward_profile ();
      if (pfile_next == 0)
        pfile_next = base_profiles_.get_next ();
    }
  else
    pfile_next = base_profiles_.get_next ();

  if (pfile_next == 0)
    reset_base ();
  else
    set_profile_in_use_i (pfile_next);

  return pfile_next;
}

ACE_INLINE
void
STUB_Object::set_valid_profile (void)
{
  profile_success_ = 1;
}

ACE_INLINE
CORBA::Boolean
STUB_Object::valid_profile (void)
{
  return profile_success_;
}

ACE_INLINE
TAO_Profile *
STUB_Object::set_base_profiles (TAO_MProfile *mprofiles)
{
  ACE_MT (ACE_GUARD_RETURN (ACE_Lock,
                            guard,
                            *this->profile_lock_ptr_,
                            0));

  // first reset things so we start from scratch!
  reset_forward ();
  base_profiles_.set (mprofiles);
  reset_base ();
  return profile_in_use_;

}

ACE_INLINE
void
STUB_Object::add_forward_profiles (TAO_MProfile *mprofiles)
{
  // we assume that the profile_in_use_ is being
  // forwarded!  Grab the lock so things don't change.
  ACE_MT (ACE_GUARD (ACE_Lock,
                     guard,
                     *this->profile_lock_ptr_));

  // forwarded profile points to the new IOR (profiles)
  profile_in_use_->forward_to (mprofiles);

  TAO_MProfile *now_pfiles = forward_profiles_ ? forward_profiles_ : &base_profiles_;

  // new profile list points back to the list which was forwarded.
  mprofiles->forward_from (now_pfiles);

  forward_profiles_ = mprofiles;

  // make sure we start at the beginning of mprofiles
  forward_profiles_->rewind ();

}