From a2d174346667f2e81a7612aecb78da746081d490 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 7 Mar 2013 14:16:55 +0000 Subject: building REST API --- rotord/rotor.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'rotord/rotor.cpp') diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index 4164baa..1094428 100644 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -68,7 +68,8 @@ bool Signal_output::render(const float duration, const float framerate,string &x Command_response Render_context::session_command(const std::vector& command){ //method,id,command1,{command2,}{body} //here we allow the controlling server to communicate with running tasks - Command_response response; + Command_response response; + response.status=HTTPResponse::HTTP_BAD_REQUEST; if (command[2]=="audio") { if (command[0]=="PUT") { //get audio file location and initiate analysis if (command.size()>2) { @@ -94,6 +95,7 @@ Command_response Render_context::session_command(const std::vector& } if (command[0]=="GET") { if (state==ANALYSING_AUDIO) { + response.status=HTTPResponse::HTTP_OK; response.description="Rotor: analysing audio\n"; char c[20]; sprintf(c,"%02f",audio_analyser.get_progress()); @@ -103,6 +105,7 @@ Command_response Render_context::session_command(const std::vector& //not sure about this-- should this state be retained? //can the data only be read once? //for now + response.status=HTTPResponse::HTTP_OK; response.description="Rotor: audio ready\n"; response.description+=""; for (auto& i: audio_analyser.beats) { //is actually giving no data? @@ -114,8 +117,23 @@ Command_response Render_context::session_command(const std::vector& state=IDLE; } } + if (command[0]=="DELETE") { + //for now + audio_filename=""; + response.description="1\n"; + response.status=HTTPResponse::HTTP_OK; + } } if (command[2]=="graph") { + if (command[0]=="GET") { + if (xml.bDocLoaded) { + response.status=HTTPResponse::HTTP_OK; + xml.copyXmlToString(response.description); + } + else { + response.description="Rotor: graph not loaded\n"; + } + } if (command[0]=="PUT") { //get new graph from file if (command.size()>2) { //should interrupt whatever is happening? @@ -125,10 +143,11 @@ Command_response Render_context::session_command(const std::vector& if (f.exists()) { string graph_filename=command[3]; if (load_graph(graph_filename)) { - response.description="Rotor: loaded graph "+command[3]+"\n"; + response.status=HTTPResponse::HTTP_OK; + //response.description="Rotor: loaded graph "+command[3]+"\n"; string xmlstring; xml.copyXmlToString(xmlstring); - response.description+=xmlstring; + response.description=xmlstring; //the graph could actually contain an xml object and we could just print it here? //or could our nodes even be subclassed from xml nodes? } @@ -144,6 +163,12 @@ Command_response Render_context::session_command(const std::vector& } } } + if (command[0]=="DELETE") { + //for now + graph=Graph(); + response.description="1\n"; + response.status=HTTPResponse::HTTP_OK; + } } if (command[2]=="signal") { if (command[0]=="GET") { //generate xml from 1st signal output @@ -155,6 +180,7 @@ Command_response Render_context::session_command(const std::vector& } string signal_xml; if (graph.signal_render(framerate,signal_xml)){ + response.status=HTTPResponse::HTTP_OK; response.description=signal_xml; } else { -- cgit v1.2.3