00001 // $Id: Topology_Object.cpp 78925 2007-07-17 18:51:14Z zhangw $ 00002 00003 #include "orbsvcs/Notify/Topology_Object.h" 00004 00005 #if ! defined (__ACE_INLINE__) 00006 #include "orbsvcs/Notify/Topology_Object.inl" 00007 #endif /* __ACE_INLINE__ */ 00008 00009 // question: is there a race_conditon with self_changed and children_changed? 00010 // answer: toplogy_changed and/or children_changed must be set after the change is 00011 // made, and before the call to child_change. 00012 // self_changed and children_changed must be cleared before this object and its 00013 // children have been saved in Topology_Object::save_persistent (). 00014 // If these rules are followed, the only risk is a (harmless) extra save. 00015 00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00017 00018 namespace TAO_Notify 00019 { 00020 Topology_Savable::~Topology_Savable (void) 00021 { 00022 } 00023 00024 void 00025 Topology_Savable::reconnect (void) 00026 { 00027 } 00028 00029 Topology_Object::Topology_Object () 00030 : TAO_Notify_Object () 00031 , Topology_Savable () 00032 , self_changed_ (false) 00033 , children_changed_ (false) 00034 , topology_parent_ (0) 00035 { 00036 } 00037 00038 Topology_Object::~Topology_Object () 00039 { 00040 } 00041 00042 void 00043 Topology_Object::initialize (Topology_Parent* topology_parent) 00044 { 00045 ACE_ASSERT (topology_parent != 0 && this->topology_parent_ == 0); 00046 this->topology_parent_ = topology_parent; 00047 TAO_Notify_Object::initialize (topology_parent); 00048 } 00049 00050 Topology_Parent * 00051 Topology_Object::topology_parent () const 00052 { 00053 return this->topology_parent_; 00054 } 00055 00056 00057 Topology_Object * 00058 Topology_Object::load_child (const ACE_CString & /*type*/, 00059 CORBA::Long /* id */, 00060 const NVPList& /* attrs */) 00061 { 00062 return 0; 00063 } 00064 00065 bool 00066 Topology_Object::is_persistent () const 00067 { 00068 bool result = false; 00069 if (this->qos_properties_.event_reliability().is_valid ()) 00070 { 00071 result = CosNotification::Persistent == this->qos_properties_.event_reliability().value (); 00072 } 00073 else if (this->topology_parent () != 0) 00074 { 00075 result = this->topology_parent ()->is_persistent (); 00076 } 00077 return result; 00078 } 00079 00080 bool 00081 Topology_Object::self_change (void) 00082 { 00083 this->self_changed_ = true; 00084 return send_change (); 00085 } 00086 00087 bool 00088 Topology_Object::send_change (void) 00089 { 00090 bool saving = false; 00091 if (is_persistent ()) 00092 { 00093 while (this->self_changed_ || this->children_changed_) 00094 { 00095 saving = this->change_to_parent (); 00096 if (!saving) 00097 { 00098 this->self_changed_ = false; 00099 this->children_changed_ = false; 00100 } 00101 } 00102 } 00103 else 00104 { 00105 this->self_changed_ = false; 00106 this->children_changed_ = false; 00107 } 00108 return saving; 00109 } 00110 00111 bool 00112 Topology_Object::send_deletion_change (void) 00113 { 00114 bool saving = false; 00115 if (is_persistent ()) 00116 { 00117 saving = this->change_to_parent (); 00118 } 00119 this->self_changed_ = false; 00120 this->children_changed_ = false; 00121 return saving; 00122 } 00123 00124 bool 00125 Topology_Object::change_to_parent (void) 00126 { 00127 bool result = false; 00128 Topology_Parent * parent = this->topology_parent(); 00129 if (parent != 0) 00130 { 00131 result = parent->child_change(); 00132 } 00133 return result; 00134 } 00135 00136 void 00137 Topology_Object::get_id_path (TAO_Notify::IdVec & id_path) const 00138 { 00139 if (this->topology_parent() != 0) 00140 { 00141 this->topology_parent()->get_id_path (id_path); 00142 } 00143 id_path.push_back (this->get_id ()); 00144 } 00145 00146 TAO_Notify_Object::ID 00147 Topology_Object::get_id () const 00148 { 00149 // If this assert triggers then implement the 00150 // get_id method in the actual class 00151 // derived from Topology_Object 00152 // or else figure out why this method was called 00153 // on an object that doesn't have an id. 00154 ACE_ASSERT (false); 00155 // if it is called in a release build, provide 'em a value 00156 return -1; 00157 } 00158 00159 } // namespace TAO_Notify 00160 00161 TAO_END_VERSIONED_NAMESPACE_DECL