// pretty print (y) or compact print (default)
bool indent = request.RequestVariables.get("i") == "y";
+ bool timestamp = request.RequestVariables.get("t") == "y";
SGPropertyNode_ptr node = fgGetNode( string("/") + propertyPath );
if( false == node.valid() ) {
}
- response.Content = JSON::toJsonString( indent, node, depth );
+ response.Content = JSON::toJsonString( indent, node, depth, timestamp ? fgGetDouble("/sim/time/elapsed-sec") : -1.0 );
return true;
#include "PropertyChangeObserver.hxx"
#include "jsonprops.hxx"
#include <simgear/debug/logstream.hxx>
+#include <Main/fg_props.hxx>
#include <3rdparty/cjson/cJSON.h>
string newValue;
if (_propertyChangeObserver->isChangedValue(node)) {
SG_LOG(SG_NETWORK, SG_DEBUG, "httpd: new Value for " << node->getPath(true) << " '" << node->getStringValue() << "' #" << id);
- writer.writeText( JSON::toJsonString( false, node, 0 ) );
+ writer.writeText( JSON::toJsonString( false, node, 0, fgGetDouble("/sim/time/elapsed-sec") ) );
}
}
}
}
}
-cJSON * JSON::toJson(SGPropertyNode_ptr n, int depth)
+cJSON * JSON::toJson(SGPropertyNode_ptr n, int depth, double timestamp )
{
cJSON * json = cJSON_CreateObject();
cJSON_AddItemToObject(json, "path", cJSON_CreateString(n->getPath(true).c_str()));
cJSON_AddItemToObject(json, "value", cJSON_CreateString(n->getStringValue()));
cJSON_AddItemToObject(json, "type", cJSON_CreateString(getPropertyTypeString(n->getType())));
cJSON_AddItemToObject(json, "index", cJSON_CreateNumber(n->getIndex()));
+ if( timestamp >= 0.0 )
+ cJSON_AddItemToObject(json, "ts", cJSON_CreateNumber(timestamp));
+
if (depth > 0 && n->nChildren() > 0) {
cJSON * jsonArray = cJSON_CreateArray();
for (int i = 0; i < n->nChildren(); i++)
- cJSON_AddItemToArray(jsonArray, toJson(n->getChild(i), depth - 1));
+ cJSON_AddItemToArray(jsonArray, toJson(n->getChild(i), depth - 1, timestamp ));
cJSON_AddItemToObject(json, "children", jsonArray);
}
return json;
}
}
-string JSON::toJsonString(bool indent, SGPropertyNode_ptr n, int depth)
+string JSON::toJsonString(bool indent, SGPropertyNode_ptr n, int depth, double timestamp )
{
- cJSON * json = toJson( n, depth );
+ cJSON * json = toJson( n, depth, timestamp );
char * jsonString = indent ? cJSON_Print( json ) : cJSON_PrintUnformatted( json );
string reply(jsonString);
free( jsonString );
namespace http {
class JSON {
public:
- static cJSON * toJson(SGPropertyNode_ptr n, int depth);
- static std::string toJsonString(bool indent, SGPropertyNode_ptr n, int depth);
+ static cJSON * toJson(SGPropertyNode_ptr n, int depth, double timestamp = -1.0 );
+ static std::string toJsonString(bool indent, SGPropertyNode_ptr n, int depth, double timestamp = -1.0 );
static void toProp(cJSON * json, SGPropertyNode_ptr base);
};