From: Torsten Dreyer Date: Mon, 17 Mar 2014 15:22:42 +0000 (+0100) Subject: httpd: better handling of first-time notifications X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1867ccb4a8484b9bc856c88629e09e25bcc35d42;p=flightgear.git httpd: better handling of first-time notifications ensure new listeners get notified on first update loop also cleanup the PropertyChangeObserver on reset --- diff --git a/src/Network/http/PropertyChangeObserver.cxx b/src/Network/http/PropertyChangeObserver.cxx index 6594c2d0a..6bb555c62 100644 --- a/src/Network/http/PropertyChangeObserver.cxx +++ b/src/Network/http/PropertyChangeObserver.cxx @@ -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; } } diff --git a/src/Network/http/PropertyChangeObserver.hxx b/src/Network/http/PropertyChangeObserver.hxx index a81571583..f431d3154 100644 --- a/src/Network/http/PropertyChangeObserver.hxx +++ b/src/Network/http/PropertyChangeObserver.hxx @@ -51,6 +51,8 @@ public: void check(); void uncheck(); + void clear() { _entries.clear(); } + private: typedef std::vector Entries_t; Entries_t _entries; diff --git a/src/Network/http/httpd.cxx b/src/Network/http/httpd.cxx index c85b7d43a..5733768a1 100644 --- a/src/Network/http/httpd.cxx +++ b/src/Network/http/httpd.cxx @@ -161,6 +161,7 @@ void MongooseHttpd::unbind() { mg_destroy_server(&_server); _uriHandlers.clear(); + _propertyChangeObserver.clear(); } void MongooseHttpd::shutdown()