PropertyChangeWebsocket: fire change after subscribe
This commit is contained in:
parent
95d4c5898d
commit
a830708252
4 changed files with 14 additions and 6 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue