summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Notify/Topology_Object.cpp
blob: f7be8f65e2c37d4ad45a306211a414d90cf9d9f8 (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
// $Id$

#include "Topology_Object.h"

#if ! defined (__ACE_INLINE__)
#include "Topology_Object.inl"
#endif /* __ACE_INLINE__ */

// question: is there a race_conditon with self_changed and children_changed?
// answer: toplogy_changed and/or children_changed must be set after the change is
// made, and before the call to child_change.
// self_changed and children_changed must be cleared before this object and its
// children have been saved in Topology_Object::save_persistent ().
// If these rules are followed, the only risk is a (harmless) extra save.

namespace TAO_Notify
{
  Topology_Savable::~Topology_Savable (void)
  {
  }

  void
  Topology_Savable::reconnect (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
  {
  }

  Topology_Object::Topology_Object ()
    : TAO_Notify_Object ()
      , Topology_Savable ()
      , self_changed_ (false)
      , children_changed_ (false)
      , topology_parent_ (0)
  {
  }

  Topology_Object::~Topology_Object ()
  {
  }

  void
  Topology_Object::initialize (Topology_Parent* topology_parent ACE_ENV_ARG_DECL_NOT_USED)
  {
  	ACE_ASSERT (topology_parent != 0 && this->topology_parent_ == 0);
    this->topology_parent_ = topology_parent;
    TAO_Notify_Object::initialize (topology_parent);
  }

  Topology_Parent *
  Topology_Object::topology_parent () const
  {
    return this->topology_parent_;
  }


  Topology_Object *
  Topology_Object::load_child (const ACE_CString & /*type*/,
    CORBA::Long /* id */,
    const NVPList& /* attrs */
    ACE_ENV_ARG_DECL_NOT_USED)
  {
    return 0;
  }

  bool
  Topology_Object::is_persistent () const
  {
    bool result = false;
    if (this->qos_properties_.event_reliability().is_valid ())
      {
        result = CosNotification::Persistent == this->qos_properties_.event_reliability().value ();
      }
    else if (this->topology_parent () != 0)
      {
        result = this->topology_parent ()->is_persistent ();
      }
    return result;
  }

  bool
  Topology_Object::self_change (ACE_ENV_SINGLE_ARG_DECL)
  {
    this->self_changed_ = true;
    return send_change (ACE_ENV_SINGLE_ARG_PARAMETER);
  }

  bool
  Topology_Object::send_change (ACE_ENV_SINGLE_ARG_DECL)
  {
    bool saving = false;
    if (is_persistent ())
    {
      while (this->self_changed_ || this->children_changed_)
      {
        saving = this->change_to_parent (ACE_ENV_SINGLE_ARG_PARAMETER);
        ACE_CHECK_RETURN (false);
        if (!saving)
        {
          this->self_changed_ = false;
          this->children_changed_ = false;
        }
      }
    }
    else
    {
      this->self_changed_ = false;
      this->children_changed_ = false;
    }
    return saving;
  }

  bool
  Topology_Object::change_to_parent (ACE_ENV_SINGLE_ARG_DECL)
  {
    bool result = false;
    Topology_Parent * parent = this->topology_parent();
    if (parent != 0)
    {
      result = parent->child_change(ACE_ENV_SINGLE_ARG_PARAMETER);
    }
    return result;
  }

  void
  Topology_Object::get_id_path (TAO_Notify::IdVec & id_path) const
  {
    if (this->topology_parent() != 0)
    {
      this->topology_parent()->get_id_path (id_path);
    }
    id_path.push_back (this->get_id ());
  }

  TAO_Notify_Object::ID
  Topology_Object::get_id () const
  {
    // If this assert triggers then implement the
    // get_id method in the actual class
    // derived from Topology_Object
    // or else figure out why this method was called
    // on an object that doesn't have an id.
    ACE_ASSERT (false);
    // if it is called in a release build, provide 'em a value
    return -1;
  }
} // namespace TAO_Notify