1
0
Fork 0

PropertyChangeWebsocket: fire change after subscribe

This commit is contained in:
Torsten Dreyer 2014-03-14 21:36:29 +01:00
parent 95d4c5898d
commit a830708252
4 changed files with 14 additions and 6 deletions

View file

@ -50,6 +50,14 @@ void PropertyChangeObserver::check()
if ((*it)->_changed) (*it)->_prevValue = (*it)->_node->getStringValue(); if ((*it)->_changed) (*it)->_prevValue = (*it)->_node->getStringValue();
} }
} }
void PropertyChangeObserver::uncheck()
{
for (Entries_t::iterator it = _entries.begin(); it != _entries.end(); ++it) {
(*it)->_changed = false;
}
}
const SGPropertyNode_ptr PropertyChangeObserver::addObservation( const string propertyName) const SGPropertyNode_ptr PropertyChangeObserver::addObservation( const string propertyName)
{ {
for (Entries_t::iterator it = _entries.begin(); it != _entries.end(); ++it) { for (Entries_t::iterator it = _entries.begin(); it != _entries.end(); ++it) {
@ -72,14 +80,12 @@ const SGPropertyNode_ptr PropertyChangeObserver::addObservation( const string pr
return empty; return empty;
} }
bool PropertyChangeObserver::getChangedValue(const SGPropertyNode_ptr node, string & out) bool PropertyChangeObserver::isChangedValue(const SGPropertyNode_ptr node)
{ {
for (Entries_t::iterator it = _entries.begin(); it != _entries.end(); ++it) { for (Entries_t::iterator it = _entries.begin(); it != _entries.end(); ++it) {
PropertyChangeObserverEntryRef entry = *it; PropertyChangeObserverEntryRef entry = *it;
if( entry->_node == node && entry->_changed ) { if( entry->_node == node && entry->_changed ) {
out = entry->_node->getStringValue();
entry->_changed = false;
return true; return true;
} }
} }

View file

@ -46,9 +46,10 @@ public:
virtual ~PropertyChangeObserver(); virtual ~PropertyChangeObserver();
const SGPropertyNode_ptr addObservation( const std::string propertyName); const SGPropertyNode_ptr addObservation( const std::string propertyName);
bool getChangedValue(const SGPropertyNode_ptr node, std::string & out); bool isChangedValue(const SGPropertyNode_ptr node);
void check(); void check();
void uncheck();
private: private:
typedef std::vector<PropertyChangeObserverEntryRef> Entries_t; typedef std::vector<PropertyChangeObserverEntryRef> Entries_t;

View file

@ -95,8 +95,8 @@ void PropertyChangeWebsocket::update(WebsocketWriter & writer)
SGPropertyNode_ptr node = *it; SGPropertyNode_ptr node = *it;
string newValue; string newValue;
if (_propertyChangeObserver->getChangedValue(node, newValue)) { if (_propertyChangeObserver->isChangedValue(node)) {
SG_LOG(SG_NETWORK, SG_ALERT, "httpd: new Value for " << node->getPath(true) << " '" << newValue << "' #" << id); SG_LOG(SG_NETWORK, SG_ALERT, "httpd: new Value for " << node->getPath(true) << " '" << node->getStringValue() << "' #" << id);
writer.writeText( JSON::toJsonString( false, node, 0 ) ); writer.writeText( JSON::toJsonString( false, node, 0 ) );
} }
} }

View file

@ -172,6 +172,7 @@ void MongooseHttpd::update(double dt)
_propertyChangeObserver.check(); _propertyChangeObserver.check();
mg_poll_server(_server, 0); mg_poll_server(_server, 0);
mg_iterate_over_connections(_server, &MongooseHttpd::staticIterateCallback); mg_iterate_over_connections(_server, &MongooseHttpd::staticIterateCallback);
_propertyChangeObserver.uncheck();
} }
class MongooseHTTPRequest: public HTTPRequest { class MongooseHTTPRequest: public HTTPRequest {