From 2abcafea32611988168f119bd7687dca5278dd9b Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 21 Aug 2013 17:00:28 +0100 Subject: json nodelist --- install_dependencies_linux.sh | 2 +- rotord/Makefile | 4 +-- rotord/src/rotor.h | 70 +++++++++++++++++++++++++++++++++++++++++++ rotord/src/rotord.cpp | 37 ++++++++++++----------- rotord/src/rotord.h | 2 ++ 5 files changed, 95 insertions(+), 20 deletions(-) diff --git a/install_dependencies_linux.sh b/install_dependencies_linux.sh index afa8d54..1724027 100755 --- a/install_dependencies_linux.sh +++ b/install_dependencies_linux.sh @@ -54,7 +54,7 @@ sudo apt-get install libnoise0 libnoise-dev sudo apt-get install libopencv-dev libopencv-core-dev libopencv-highgui-dev - +sudo apt-get install libjsoncpp0 libjsoncpp-dev cd .. rm -r deps \ No newline at end of file diff --git a/rotord/Makefile b/rotord/Makefile index 8fea700..2842cf1 100644 --- a/rotord/Makefile +++ b/rotord/Makefile @@ -3,13 +3,13 @@ #http://docs.gstreamer.com/display/GstSDK/Installing+on+Linux #MY_CFLAGS = -fpermissive -std=c++11 -Wno-error -I /opt/gstreamer-sdk/include/gstreamer-0.10/ -I /opt/gstreamer-sdk/include/glib-2.0 -I /opt/gstreamer-sdk/lib/glib-2.0/include -I /opt/gstreamer-sdk/include/libxml2 $(shell pkg-config gstreamer-0.10 gstreamer-video-0.10 gstreamer-base-0.10 --cflags) -MY_CFLAGS = -fpermissive -std=c++11 -I /usr/include/opencv -I /usr/include/cairo +MY_CFLAGS = -fpermissive -std=c++11 -I /usr/include/opencv -I /usr/include/cairo -I /usr/include/jsoncpp #-Wno-error $(shell pkg-config gstreamer-0.10 gstreamer-video-0.10 gstreamer-base-0.10 --cflags) # -I ../ffmpeg # The linker options.libgstaasinklibgstaasink.so -MY_LIBS = -lcairo -lopencv_core -lopencv_video -lopencv_imgproc -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation -lvamp-hostsdk -lsndfile -L /usr/local/lib -lswscale -lavcodec -lavformat -lavfilter -lavdevice -lavutil -lstdc++ -lm +MY_LIBS = -ljsoncpp -lcairo -lopencv_core -lopencv_video -lopencv_imgproc -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation -lvamp-hostsdk -lsndfile -L /usr/local/lib -lswscale -lavcodec -lavformat -lavfilter -lavdevice -lavutil -lstdc++ -lm #-lopencv_highgui #MY_LIBS = -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation -lvamp-hostsdk -lsndfile -L /usr/local/lib -lswscale -lavcodec -lavformat -lavfilter -lavdevice -lavutil $(shell pkg-config gstreamer-0.10 gstreamer-video-0.10 gstreamer-base-0.10 --libs) # -lgstreamer-0.10 -lgstreamer-video-0.10 -lgstreamer-base-0.10 -lglib-2.0 -lgstapp-0.10 diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h index 069e908..9427d83 100755 --- a/rotord/src/rotor.h +++ b/rotord/src/rotor.h @@ -10,6 +10,8 @@ #include #include +#include + #include "Poco/Net/HTTPResponse.h" #include "Poco/Logger.h" #include "Poco/Path.h" @@ -955,6 +957,74 @@ namespace Rotor { } } } + void list_nodes(Json::Value &JSON){ + JSON["nodeslist"]=Json::arrayValue; + for (auto& type: type_map) { + if (type.second->description!="") { //blank description = internal/ testing node + Json::Value node; + node["type"]=type.first; + node["title"]=type.second->title; + node["inputs"]=type.second->duplicate_inputs?"expandable":"fixed"; + if (dynamic_cast (type.second)!=nullptr) node["output"]="signal"; + if (dynamic_cast (type.second)!=nullptr) node["output"]="image"; + node["description"]=type.second->description; + if (type.second->inputs.size()){ + node["signal_inputs"]=Json::arrayValue; + for (auto& input: type.second->inputs) { + Json::Value signal_input; + signal_input["title"]=input->title; + signal_input["description"]=input->description; + node["signal_inputs"].append(signal_input); + } + } + if (dynamic_cast (type.second)!=nullptr) { + if ((dynamic_cast(type.second))->inputs.size()){ + node["image_inputs"]=Json::arrayValue; + for (auto& input: (dynamic_cast(type.second))->image_inputs) { + Json::Value image_input; + image_input["title"]=input->title; + image_input["description"]=input->description; + node["image_inputs"].append(image_input); + } + } + } + if (type.second->parameters.size()){ + node["parameters"]=Json::arrayValue; + for (auto& param: type.second->parameters) { + Json::Value parameter; + parameter["name"]=param.first; + parameter["type"]=param.second->type; + parameter["title"]=param.second->title; + parameter["description"]=param.second->description; + parameter["value"]=param.second->value; + parameter["min"]=param.second->min; + parameter["max"]=param.second->max; + node["parameters"].append(parameter); + } + } + if (type.second->attributes.size()){ + node["attributes"]=Json::arrayValue; + for (auto& attr: type.second->attributes) { + Json::Value attribute; + attribute["name"]=attr.first; + attribute["title"]=attr.second->title; + attribute["description"]=attr.second->description; + attribute["value"]=attr.second->value; + if (attr.second->vals.size()){ //document attribute enumeration + attribute["type"]="enum"; + attribute["attribute"]=Json::arrayValue; + for (auto val: attr.second->vals){ + attribute["attribute"].append(val); + } + } + else attribute["type"]="string"; + node["attributes"].append(attribute); + } + } + JSON["nodeslist"].append(node); + } + } + } private: unordered_map type_map; }; diff --git a/rotord/src/rotord.cpp b/rotord/src/rotord.cpp index 600462c..928e07e 100755 --- a/rotord/src/rotord.cpp +++ b/rotord/src/rotord.cpp @@ -16,7 +16,6 @@ void RenderContextHandler::handleRequest(HTTPServerRequest& request,HTTPServerRe std::ostream& ostr = response.send(); - ostr << "\n"; //this is the mysterious extra header ostr << content; } @@ -101,23 +100,25 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS } } else if (command[0]=="listnodes") { - XML.pushTag("rotor"); - if (request.getMethod()=="GET") { - Node_factory factory; - factory.list_nodes(XML); - status=HTTPResponse::HTTP_OK; - } if (command.size()>1){ if (command[1]=="json") { - string content="{\ - title: 'Lights Down @Rotor'',\ - audio: 'filename'',\ - id:,\ - type: 'patchBay',\ - nodeDefinitions: []\ - }"; - - return new RenderContextHandler(content, status); + Json::Value root; + Json::StyledWriter writer; + //root["title"]="Lights Down @Rotor"; + //root["audio"]="filename"; + root["nodeslist"]=Json::arrayValue; + Node_factory factory; + factory.list_nodes(root); + string content = writer.write(root); + return new RenderContextHandler(content, status); + } + } + else { + XML.pushTag("rotor"); + if (request.getMethod()=="GET") { + Node_factory factory; + factory.list_nodes(XML); + status=HTTPResponse::HTTP_OK; } } } @@ -227,9 +228,11 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS logger.error("ERROR: Empty request"); XML.addValue("error","Empty request"); } + string header="\n"; string content; XML.copyXmlToString(content); - return new RenderContextHandler(content, status); + header+=content; + return new RenderContextHandler(header, status); } diff --git a/rotord/src/rotord.h b/rotord/src/rotord.h index ea065c0..25ff3e3 100755 --- a/rotord/src/rotord.h +++ b/rotord/src/rotord.h @@ -36,6 +36,8 @@ #include "Poco/PatternFormatter.h" #include "Poco/AutoPtr.h" + + using Poco::Net::ServerSocket; using Poco::Net::HTTPResponse; using Poco::Net::HTTPRequestHandler; -- cgit v1.2.3