~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to TAO/orbsvcs/orbsvcs/FaultTolerance/FT_IOGR_Property.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "FT_IOGR_Property.h"
2
 
 
3
 
#include "tao/MProfile.h"
4
 
#include "tao/Profile.h"
5
 
#include "tao/Stub.h"
6
 
#include "tao/ORB_Core.h"
7
 
#include "tao/Tagged_Components.h"
8
 
 
9
 
#include "ace/Auto_Ptr.h"
10
 
#include "tao/debug.h"
11
 
 
12
 
 
13
 
ACE_RCSID (FaultTolerance,
14
 
           TAO_FT_IOGR_Property,
15
 
           "FT_IOGR_Property.cpp,v 1.18 2003/12/22 01:44:38 wilson_d Exp")
16
 
 
17
 
#if !defined (__ACE_INLINE__)
18
 
# include "FT_IOGR_Property.inl"
19
 
#endif /* ! __ACE_INLINE__ */
20
 
 
21
 
 
22
 
CORBA::Boolean
23
 
TAO_FT_IOGR_Property::set_property (
24
 
    CORBA::Object_ptr &ior
25
 
    ACE_ENV_ARG_DECL_NOT_USED /*ACE_ENV_SINGLE_ARG_PARAMETER*/)
26
 
  ACE_THROW_SPEC ((CORBA::SystemException,
27
 
                   TAO_IOP::Invalid_IOR))
28
 
{
29
 
  // We need to apply the property for every profile in the IOR
30
 
 
31
 
  // Make profiles from the sent <ior>
32
 
  TAO_MProfile &tmp_pfiles =
33
 
    ior->_stubobj ()->base_profiles ();
34
 
 
35
 
  // Get the profile count.
36
 
  CORBA::ULong count =
37
 
    ior->_stubobj ()->base_profiles ().profile_count ();
38
 
 
39
 
  // Make the output CDR stream
40
 
  TAO_OutputCDR cdr;
41
 
  CORBA::Boolean retval = 0;
42
 
  retval =
43
 
    cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER);
44
 
 
45
 
  IOP::TaggedComponent tagged_components;
46
 
  tagged_components.tag = IOP::TAG_FT_GROUP;
47
 
 
48
 
  // Encode the property in to the tagged_components
49
 
  retval = retval &&
50
 
    this->encode_properties (cdr,
51
 
                             tagged_components);
52
 
 
53
 
  if (retval == 0)
54
 
    return retval;
55
 
 
56
 
  const IOP::TaggedComponent &tmp_tc = tagged_components;
57
 
 
58
 
  // Go through every profile and set the TaggedComponent field
59
 
  for (CORBA::ULong i = 0; i < count ; i++)
60
 
    {
61
 
      // Get the tagged components in the profile
62
 
      TAO_Tagged_Components &tag_comp =
63
 
        tmp_pfiles.get_profile (i)->tagged_components ();
64
 
 
65
 
      // Finally set the <tagged_component> in the
66
 
      // <TAO_Tagged_Component>
67
 
      tag_comp.set_component (tmp_tc);
68
 
    }
69
 
 
70
 
  // Success
71
 
  return 1;
72
 
 
73
 
}
74
 
 
75
 
 
76
 
CORBA::Boolean
77
 
TAO_FT_IOGR_Property::is_primary_set (
78
 
    CORBA::Object_ptr ior
79
 
    ACE_ENV_ARG_DECL_NOT_USED /*ACE_ENV_SINGLE_ARG_PARAMETER*/)
80
 
      ACE_THROW_SPEC ((
81
 
        CORBA::SystemException
82
 
      ))
83
 
{
84
 
  if (this->get_primary_profile (ior) != 0)
85
 
    return 1;
86
 
 
87
 
  return 0;
88
 
}
89
 
 
90
 
 
91
 
CORBA::Object_ptr
92
 
TAO_FT_IOGR_Property::get_primary (
93
 
    CORBA::Object_ptr ior
94
 
    ACE_ENV_ARG_DECL)
95
 
      ACE_THROW_SPEC ((
96
 
        CORBA::SystemException,
97
 
        TAO_IOP::NotFound
98
 
      ))
99
 
{
100
 
 
101
 
  TAO_Profile *pfile =
102
 
    this->get_primary_profile (ior);
103
 
 
104
 
  if (pfile == 0)
105
 
    ACE_THROW_RETURN (TAO_IOP::NotFound (),
106
 
                      CORBA::Object::_nil ());
107
 
 
108
 
  // Search for the IOP::TAG_FT_PRIMARY in the tagged component of
109
 
  // the profile
110
 
 
111
 
  // Get the repository id
112
 
  CORBA::String_var id =
113
 
    CORBA::string_dup (ior->_stubobj ()->type_id.in ());
114
 
 
115
 
  TAO_ORB_Core *orb_core = TAO_ORB_Core_instance ();
116
 
 
117
 
  // Make a stub Object
118
 
  TAO_Stub *stub = 0;
119
 
 
120
 
  // Make a MProfile object for the primary profile alone. So, the
121
 
  // size is 1
122
 
  CORBA::ULong sz = 1;
123
 
  TAO_MProfile mpfile (sz);
124
 
  if (mpfile.add_profile (pfile) != -1)
125
 
    {
126
 
      ACE_NEW_THROW_EX (stub,
127
 
                        TAO_Stub (id._retn (),  // give the id string to stub
128
 
                                  mpfile,
129
 
                                  orb_core),
130
 
                        CORBA::NO_MEMORY ());
131
 
    }
132
 
 
133
 
  // Make the stub memory allocation exception safe for
134
 
  // the duration of this method.
135
 
  TAO_Stub_Auto_Ptr safe_stub (stub);
136
 
 
137
 
  // Create the CORBA level proxy
138
 
  CORBA::Object_ptr temp_obj = CORBA::Object::_nil ();
139
 
  ACE_NEW_THROW_EX (temp_obj,
140
 
                    CORBA::Object (safe_stub.get ()),
141
 
                    CORBA::NO_MEMORY ());
142
 
 
143
 
  CORBA::Object_var new_obj = temp_obj;
144
 
 
145
 
  ACE_CHECK_RETURN (CORBA::Object::_nil ());
146
 
 
147
 
  // Clean up in case of errors.
148
 
  if (CORBA::is_nil (new_obj.in ()))
149
 
    {
150
 
      ACE_THROW_RETURN (TAO_IOP::NotFound (),  // ** Changed from Invalid_IOR () **
151
 
                        CORBA::Object::_nil ());
152
 
    }
153
 
 
154
 
  // Release ownership of the pointers protected by the auto_ptrs since they
155
 
  // no longer need to be protected by this point.
156
 
  stub = safe_stub.release ();
157
 
 
158
 
  return new_obj._retn ();
159
 
 
160
 
}
161
 
 
162
 
 
163
 
CORBA::Boolean
164
 
TAO_FT_IOGR_Property::set_primary (
165
 
    CORBA::Object_ptr &ior1,
166
 
    CORBA::Object_ptr ior2
167
 
    ACE_ENV_ARG_DECL)
168
 
      ACE_THROW_SPEC ((
169
 
        CORBA::SystemException,
170
 
        TAO_IOP::NotFound,
171
 
        TAO_IOP::Duplicate
172
 
      ))
173
 
{
174
 
  // Check for primary in <ior2>
175
 
  IOP::TaggedComponent tagged_components;
176
 
  tagged_components.tag = IOP::TAG_FT_PRIMARY;
177
 
 
178
 
  TAO_MProfile &mprofile =
179
 
    ior2->_stubobj ()->base_profiles ();
180
 
 
181
 
  for (CORBA::ULong i = 0;
182
 
       i < mprofile.profile_count ();
183
 
       i++)
184
 
    {
185
 
      TAO_Tagged_Components &tag_comp =
186
 
        mprofile.get_profile (i)->tagged_components ();
187
 
 
188
 
      if (tag_comp.get_component (tagged_components) == 1)
189
 
        ACE_THROW_RETURN (TAO_IOP::Duplicate (),
190
 
                          0);
191
 
    }
192
 
 
193
 
  // Check whether ior1 exists in ior2
194
 
  CORBA::Long index = -1;
195
 
 
196
 
  // Even if it is a multi-profile (in case of multi-homed hosts we
197
 
  // could get a multiple IOR profile), we are going to make the first one
198
 
  // in that a primary
199
 
  TAO_Profile *prim_profile =
200
 
    ior1->_stubobj ()->base_profiles ().get_profile (0);
201
 
 
202
 
  CORBA::ULong count =
203
 
    ior2->_stubobj ()->base_profiles ().profile_count ();
204
 
 
205
 
 
206
 
  for (CORBA::ULong ctr = 0;
207
 
       ctr < count;
208
 
       ctr ++)
209
 
    {
210
 
      if (prim_profile->is_equivalent (
211
 
          ior2->_stubobj ()->base_profiles ().get_profile (ctr)) == 1)
212
 
        {
213
 
          // We know that <ior1> exists in <io2>
214
 
          // Take the index of that and break out of the loop
215
 
          index = ctr;
216
 
          break;
217
 
        }
218
 
    }
219
 
 
220
 
  // At the end of the loop check whether we have seen <ior1> in
221
 
  // <ior2>
222
 
  if (index == -1)
223
 
    ACE_THROW_RETURN (TAO_IOP::NotFound (),
224
 
                      0);
225
 
 
226
 
  CORBA::Boolean val = 1;
227
 
 
228
 
  TAO_OutputCDR cdr;
229
 
  cdr << ACE_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER);
230
 
  cdr << ACE_OutputCDR::from_boolean (val);
231
 
 
232
 
  // Get the length of the CDR stream
233
 
  CORBA::ULong length = ACE_static_cast (CORBA::ULong,
234
 
                                         cdr.total_length ());
235
 
 
236
 
  // Set the length
237
 
  tagged_components.component_data.length (length);
238
 
 
239
 
  // Get the pointer to the underlying buffer
240
 
  CORBA::Octet *buf =
241
 
    tagged_components.component_data.get_buffer ();
242
 
 
243
 
  for (const ACE_Message_Block *mb = cdr.begin ();
244
 
       mb != 0;
245
 
       mb = mb->cont ())
246
 
    {
247
 
      ACE_OS::memcpy (buf, mb->rd_ptr (), mb->length ());
248
 
      buf += mb->length ();
249
 
    }
250
 
 
251
 
  // Set the <tagged_component>
252
 
  TAO_Tagged_Components &tagg =
253
 
    ior2->_stubobj ()->base_profiles ().get_profile (index)->tagged_components ();
254
 
 
255
 
  tagg.set_component (tagged_components);
256
 
 
257
 
  return 1;
258
 
}
259
 
 
260
 
CORBA::Boolean
261
 
TAO_FT_IOGR_Property::encode_properties (
262
 
    TAO_OutputCDR &cdr,
263
 
    IOP::TaggedComponent &tagged_components)
264
 
{
265
 
  if (this->ft_group_tagged_component_ == 0)
266
 
    {
267
 
      if (TAO_debug_level > 2)
268
 
        ACE_ERROR_RETURN ((LM_ERROR,
269
 
                           "TAO-FT (%P|%t) - The group tagged component ",
270
 
                           "is null \n"),
271
 
                          0);
272
 
    }
273
 
 
274
 
  // the version info
275
 
  CORBA::Boolean status =
276
 
    cdr << this->ft_group_tagged_component_->component_version;
277
 
 
278
 
  // the domain id
279
 
  status = status &&
280
 
    cdr << this->ft_group_tagged_component_->group_domain_id.in ();
281
 
 
282
 
  // Object group id
283
 
  status = status &&
284
 
    cdr << this->ft_group_tagged_component_->object_group_id;
285
 
 
286
 
  // Object group reference version
287
 
  status = status &&
288
 
    cdr << this->ft_group_tagged_component_->object_group_ref_version;
289
 
 
290
 
  // Get the length of the CDR stream
291
 
  CORBA::ULong length = ACE_static_cast (CORBA::ULong,
292
 
                                         cdr.total_length ());
293
 
 
294
 
  // Set the length
295
 
  tagged_components.component_data.length (length);
296
 
 
297
 
  // Get the pointer to the underlying buffer
298
 
  CORBA::Octet *buf =
299
 
    tagged_components.component_data.get_buffer ();
300
 
 
301
 
  for (const ACE_Message_Block *i = cdr.begin ();
302
 
       i != 0;
303
 
       i = i->cont ())
304
 
    {
305
 
 
306
 
      ACE_OS::memcpy (buf, i->rd_ptr (), i->length ());
307
 
      buf += i->length ();
308
 
    }
309
 
 
310
 
 
311
 
  return status;
312
 
}
313
 
 
314
 
 
315
 
TAO_Profile *
316
 
TAO_FT_IOGR_Property::get_primary_profile (
317
 
    CORBA::Object_ptr ior)
318
 
{
319
 
  // Get the MProfile
320
 
  TAO_MProfile &mprofile =
321
 
    ior->_stubobj ()->base_profiles ();
322
 
 
323
 
  // Looking for a tagged component with a PRIMARY flag.
324
 
  IOP::TaggedComponent tagged_components;
325
 
  tagged_components.tag = IOP::TAG_FT_PRIMARY;
326
 
 
327
 
  for (CORBA::ULong i = 0;
328
 
       i < mprofile.profile_count ();
329
 
       i++)
330
 
    {
331
 
      // Get the Tagged Components
332
 
      const TAO_Tagged_Components &pfile_tagged =
333
 
        mprofile.get_profile (i)->tagged_components ();
334
 
 
335
 
      // Look for the primary
336
 
      if (pfile_tagged.get_component (tagged_components) == 1)
337
 
        {
338
 
          // If there is one return the pfile
339
 
          return mprofile.get_profile (i);
340
 
        }
341
 
    }
342
 
  return 0;
343
 
}
344
 
 
345
 
 
346
 
CORBA::Boolean
347
 
TAO_FT_IOGR_Property::get_tagged_component (
348
 
    const CORBA::Object_ptr iogr,
349
 
    FT::TagFTGroupTaggedComponent &fgtc
350
 
    ACE_ENV_ARG_DECL) const
351
 
  ACE_THROW_SPEC ((CORBA::SystemException))
352
 
{
353
 
  TAO_Stub *stub =
354
 
    iogr->_stubobj ();
355
 
 
356
 
  if (stub == 0)
357
 
    return 0;
358
 
 
359
 
  // Get the MProfile
360
 
  TAO_MProfile &mprofile =
361
 
    iogr->_stubobj ()->base_profiles ();
362
 
 
363
 
  // Looking for a tagged component with a TAG_FT_GROUP flag.
364
 
  IOP::TaggedComponent tc;
365
 
  tc.tag = IOP::TAG_FT_GROUP;
366
 
 
367
 
  for (CORBA::ULong i = 0;
368
 
       i < mprofile.profile_count ();
369
 
       i++)
370
 
    {
371
 
 
372
 
      // Get the Tagged Components
373
 
      const TAO_Tagged_Components &pfile_tagged =
374
 
        mprofile.get_profile (i)->tagged_components ();
375
 
 
376
 
      // Look for the primary
377
 
      if (pfile_tagged.get_component (tc) == 1)
378
 
        {
379
 
          TAO_InputCDR cdr (ACE_reinterpret_cast (
380
 
                                const char*,
381
 
                                tc.component_data.get_buffer ()
382
 
                                ),
383
 
                            tc.component_data.length ());
384
 
          CORBA::Boolean byte_order;
385
 
 
386
 
          if ((cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0)
387
 
            ACE_THROW_RETURN (CORBA::MARSHAL (),
388
 
                              0);
389
 
 
390
 
          cdr.reset_byte_order (ACE_static_cast (int,byte_order));
391
 
 
392
 
          if ((cdr >> fgtc) == 1)
393
 
            return 1;
394
 
          else
395
 
            ACE_THROW_RETURN (CORBA::MARSHAL (),
396
 
                              0);
397
 
        }
398
 
    }
399
 
 
400
 
  return 0;
401
 
}
402
 
 
403
 
CORBA::Boolean
404
 
TAO_FT_IOGR_Property::remove_primary_tag (
405
 
    CORBA::Object_ptr &iogr
406
 
    ACE_ENV_ARG_DECL_NOT_USED)
407
 
  ACE_THROW_SPEC ((CORBA::SystemException))
408
 
{
409
 
  // Get the MProfile
410
 
  TAO_MProfile &mprofile =
411
 
    iogr->_stubobj ()->base_profiles ();
412
 
 
413
 
  for (CORBA::ULong i = 0;
414
 
       i < mprofile.profile_count ();
415
 
       ++i)
416
 
    {
417
 
      TAO_Profile* profile = mprofile.get_profile (i);
418
 
 
419
 
      // Get the Tagged Components
420
 
      TAO_Tagged_Components &pfile_tagged =
421
 
        profile->tagged_components ();
422
 
 
423
 
      if (pfile_tagged.remove_component (IOP::TAG_FT_PRIMARY))
424
 
        {
425
 
          return 1;
426
 
        }
427
 
    }
428
 
  return 0;
429
 
}