diff options
Diffstat (limited to 'rotord/src')
| -rw-r--r-- | rotord/src/graph.h | 1 | ||||
| -rw-r--r-- | rotord/src/rendercontext.cpp | 70 | ||||
| -rw-r--r-- | rotord/src/rendercontext.h | 3 |
3 files changed, 70 insertions, 4 deletions
diff --git a/rotord/src/graph.h b/rotord/src/graph.h index cbcc121..58861ac 100644 --- a/rotord/src/graph.h +++ b/rotord/src/graph.h @@ -34,6 +34,7 @@ namespace Rotor { delete n.second; } nodes.clear(); + loaded=false; } string uid; //every version of a graph has a UUID, no particular need to actually read its data(?) //?? is it faster than using strings?? diff --git a/rotord/src/rendercontext.cpp b/rotord/src/rendercontext.cpp index 62c60c0..d516cbd 100644 --- a/rotord/src/rendercontext.cpp +++ b/rotord/src/rendercontext.cpp @@ -48,6 +48,20 @@ void Render_context::runTask() { renders[cmd.uid].status=FAILED; } } + if(cmd.task==LOAD_GRAPH) { + state=LOADING_GRAPH; + if (graph_filename!="") { + if (!graph.loadFile(graph_filename,media_dir)){ + cerr<<"Rotor: failed to load graph from "<<graph_filename<<endl; + } + } + else if (graph_body!="") { + if (!graph.load(graph_body,media_dir)) { + cerr<<"Rotor: failed to load graph from body request"<<endl; + } + } + state=IDLE; + } sleep(100); } printf("Rotor: stopping thread\n"); @@ -166,8 +180,14 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H XML.loadFromBuffer(graph.graphToString()); } else { - logger.error("ERROR: graph not loaded: check XML"); - XML.addValue("error","graph not loaded: check XML"); + if (state==LOADING_GRAPH) { + logger.error("ERROR: graph still loading"); + XML.addValue("error","graph still loading"); + } + else { + logger.error("ERROR: graph not loaded"); + XML.addValue("error","graph not loaded"); + } } } if (command.method=="PUT") { //get new graph from file @@ -175,6 +195,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H //should interrupt whatever is happening? //before begining to load from xml if (state==IDLE) { //eventually not like this + /* if (Poco::File(graph_dir+command.body).exists()) { string graph_filename=graph_dir+command.body; if (graph.loadFile(graph_filename,media_dir)) { @@ -215,6 +236,47 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H logger.error("ERROR: graph unreadable"); XML.addValue("error","graph unreadable"); } + */ + + if (command.body!="") { + graph_filename=""; + graph_body=""; + if (Poco::File(graph_dir+command.body).exists()) { + graph_filename=graph_dir+command.body; + add_queue(Session_task(command.uid,LOAD_GRAPH)); + status=HTTPResponse::HTTP_OK; + logger.information("Loading graph from file: "+command.body); + XML.addValue("status","Loading graph from file: "+command.body); + //XML.addValue("render_id",command.uid); process ID? + } + else { + xmlIO xml; + bool readable=true; + if (!xml.loadFromBuffer(command.body)){ + Json::Value root; // will contains the root value after parsing. + Json::Reader reader; + if ( !reader.parse( command.body, root ) ) + { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Could not load graph"); + XML.addValue("error","Could not load graph"); + readable=false; + } + } + if (readable) { + graph_body=command.body; + add_queue(Session_task(command.uid,LOAD_GRAPH)); + status=HTTPResponse::HTTP_OK; + logger.information("Loading graph from body request"); + XML.addValue("status","Loading graph from body request"); + } + } + } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Empty request"); + XML.addValue("error","Empty request"); + } } else { logger.error("ERROR: Session busy"); @@ -308,7 +370,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H } if (command.commands[1]=="preview") { if (command.method=="GET") { - if(state!=RENDERING){ + if(state==IDLE){ //parse json to get preview spec, return XML? this is a mess string preview_node=command.commands[2]; Json::Value root; // will contains the root value after parsing. @@ -349,7 +411,7 @@ void Render_context::session_command(const Session_command& command,xmlIO& XML,H } if (command.commands[1]=="features") { if (command.method=="GET") { - if(state!=RENDERING){ + if(state==IDLE){ //parse json to get preview spec, return XML? this is a mess string features_node=command.commands[2]; if (graph.print_features(XML,features_node)) { diff --git a/rotord/src/rendercontext.h b/rotord/src/rendercontext.h index 16d007d..2c88510 100644 --- a/rotord/src/rendercontext.h +++ b/rotord/src/rendercontext.h @@ -71,6 +71,7 @@ namespace Rotor { } else cerr<<"Rotor: settings.xml not found, using defaults"<<endl; + output_filename=graph_filename=graph_body=""; }; ~Render_context(){delete audio_thumb;}; void runTask(); @@ -102,6 +103,8 @@ namespace Rotor { std::string graph_dir; std::string media_dir; std::string output_dir; + std::string graph_filename; + std::string graph_body; Audio_thumbnailer *audio_thumb; Graph graph; |
