summaryrefslogtreecommitdiff
path: root/TAO/tao/RTCORBA/RT_Transport_Descriptor.cpp
blob: 79c86d3d785267e67c215b522b80adc1ad436ead (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
// $Id$

#include "tao/RTCORBA/RT_Transport_Descriptor.h"
#include "ace/OS_Memory.h"

#if ! defined (__ACE_INLINE__)
#include "tao/RTCORBA/RT_Transport_Descriptor.inl"
#endif /* __ACE_INLINE__ */

ACE_RCSID(RTCORBA, TAO_RT_Transport_Descriptor, "$Id$")

#include "tao/RTCORBA/RT_Transport_Descriptor_Property.h"
#include "tao/Endpoint.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO_RT_Transport_Descriptor::~TAO_RT_Transport_Descriptor ()
{
  if (this->delete_properties_ == 1)
    {
      TAO_RT_Transport_Descriptor_Property *current =
        this->property_list_;

      while (current)
        {
          TAO_RT_Transport_Descriptor_Property *next =
            current->next_;

          delete current;

          current = next;
        }
    }
}

TAO_Transport_Descriptor_Interface *
TAO_RT_Transport_Descriptor::duplicate (void)
{
  // Get a copy of the underlying endpoint
  TAO_Endpoint *endpoint =
    this->endpoint_->duplicate ();
  if (endpoint == 0)
    return 0;

  TAO_RT_Transport_Descriptor *new_descriptor = 0;

  ACE_NEW_RETURN (new_descriptor,
                  TAO_RT_Transport_Descriptor (endpoint, 1),
                  0);

  // Copy the Properties.
  TAO_RT_Transport_Descriptor_Property *current_property =
    this->property_list_;

  TAO_RT_Transport_Descriptor_Property *current_new_property = 0;
  TAO_RT_Transport_Descriptor_Property *new_property = 0;

  while (current_property)
    {
      new_property =
        current_property->duplicate ();

      // Note that we cannot use <insert> because that will reverse the stack.
      if (new_descriptor->property_list_ == 0)
        new_descriptor->property_list_ = new_property;
      else
        current_new_property->next_ = new_property;

      current_new_property = new_property;
      current_property = current_property->next_;
    }

  return new_descriptor;
}

CORBA::Boolean
TAO_RT_Transport_Descriptor::is_equivalent (const TAO_Transport_Descriptor_Interface *other_prop)
{
  const TAO_RT_Transport_Descriptor *rhs =
    dynamic_cast<const TAO_RT_Transport_Descriptor*> (other_prop);

  if (rhs == 0)
    return false;

  // Check if endpoint is equivalent.
  if (this->endpoint_->is_equivalent (rhs->endpoint_) == 0)
    return false;

  // Check the property_list_.
  TAO_RT_Transport_Descriptor_Property *current =
    this->property_list_;

  TAO_RT_Transport_Descriptor_Property *rhs_current =
    rhs->property_list_;

  while (current || rhs_current)
    {
      if (rhs_current == 0 || current == 0)
        return false;

      if (current->is_equivalent (rhs_current) == 0)
        return false;

      current = current->next_;
      rhs_current = rhs_current->next_;
    }

  return true;
}

u_long
TAO_RT_Transport_Descriptor::hash (void) const
{
  return this->endpoint_->hash ();
}

TAO_END_VERSIONED_NAMESPACE_DECL