]> git.mxchange.org Git - flightgear.git/commitdiff
httpd: better handling of first-time notifications
authorTorsten Dreyer <torsten@t3r.de>
Mon, 17 Mar 2014 15:22:42 +0000 (16:22 +0100)
committerTorsten Dreyer <torsten@t3r.de>
Mon, 17 Mar 2014 15:22:42 +0000 (16:22 +0100)
ensure new listeners get notified on first update loop
also cleanup the PropertyChangeObserver on reset

src/Network/http/PropertyChangeObserver.cxx
src/Network/http/PropertyChangeObserver.hxx
src/Network/http/httpd.cxx

index 6594c2d0aad38fa882627eaba687c3eb7c6da1f6..6bb555c623dc98fb6a1b1537f9574ec8b83f4169 100644 (file)
@@ -46,8 +46,12 @@ void PropertyChangeObserver::check()
       continue;
     }
 
-    (*it)->_changed = (*it)->_prevValue != (*it)->_node->getStringValue();
-    if ((*it)->_changed) (*it)->_prevValue = (*it)->_node->getStringValue();
+    if( false == (*it)->_changed ) {
+      (*it)->_changed = (*it)->_prevValue != (*it)->_node->getStringValue();
+      if ((*it)->_changed)
+        (*it)->_prevValue = (*it)->_node->getStringValue();
+
+    }
   }
 }
 
@@ -62,6 +66,10 @@ const SGPropertyNode_ptr PropertyChangeObserver::addObservation( const string pr
 {
   for (Entries_t::iterator it = _entries.begin(); it != _entries.end(); ++it) {
     if (propertyName == (*it)->_node->getPath(true) ) {
+      // if a new observer is added to a property, mark it as changed to ensure the observer
+      // gets notified on initial call. This also causes a notification for all other observers of this
+      // property.
+      (*it)->_changed = true;
       return (*it)->_node;
     }
   }
index a815715835ce079049cc7d17975d66a345e23ace..f431d3154a5534f62308740f5f88e679480c5267 100644 (file)
@@ -51,6 +51,8 @@ public:
   void check();
   void uncheck();
 
+  void clear() { _entries.clear(); }
+
 private:
   typedef std::vector<PropertyChangeObserverEntryRef> Entries_t;
   Entries_t _entries;
index c85b7d43a437a1f55789c36c4ae76a89e5794564..5733768a1555186fc8bee247e95c70f490380f8f 100644 (file)
@@ -161,6 +161,7 @@ void MongooseHttpd::unbind()
 {
   mg_destroy_server(&_server);
   _uriHandlers.clear();
+  _propertyChangeObserver.clear();
 }
 
 void MongooseHttpd::shutdown()