diff options
| author | Tim Redfern <tim@herge.(none)> | 2013-03-07 14:16:55 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@herge.(none)> | 2013-03-07 14:16:55 +0000 |
| commit | a2d174346667f2e81a7612aecb78da746081d490 (patch) | |
| tree | 13c0f0e10a1df1f36c5b04e72a445c9d75886f46 /rotord/rotor.cpp | |
| parent | c8b7dd8fadea12792a9e93881dfd5eca461b42e1 (diff) | |
building REST API
Diffstat (limited to 'rotord/rotor.cpp')
| -rw-r--r-- | rotord/rotor.cpp | 32 |
1 files changed, 29 insertions, 3 deletions
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<std::string>& 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<std::string>& } if (command[0]=="GET") { if (state==ANALYSING_AUDIO) { + response.status=HTTPResponse::HTTP_OK; response.description="<status context='"+command[1]+"'>Rotor: analysing audio</status>\n"; char c[20]; sprintf(c,"%02f",audio_analyser.get_progress()); @@ -103,6 +105,7 @@ Command_response Render_context::session_command(const std::vector<std::string>& //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="<status context='"+command[1]+"'>Rotor: audio ready</status>\n"; response.description+="<beats>"; for (auto& i: audio_analyser.beats) { //is actually giving no data? @@ -114,8 +117,23 @@ Command_response Render_context::session_command(const std::vector<std::string>& state=IDLE; } } + if (command[0]=="DELETE") { + //for now + audio_filename=""; + response.description="<status>1</status>\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="<status>Rotor: graph not loaded</status>\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<std::string>& if (f.exists()) { string graph_filename=command[3]; if (load_graph(graph_filename)) { - response.description="<status context='"+command[1]+"'>Rotor: loaded graph "+command[3]+"</status>\n"; + response.status=HTTPResponse::HTTP_OK; + //response.description="<status context='"+command[1]+"'>Rotor: loaded graph "+command[3]+"</status>\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<std::string>& } } } + if (command[0]=="DELETE") { + //for now + graph=Graph(); + response.description="<status>1</status>\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<std::string>& } string signal_xml; if (graph.signal_render(framerate,signal_xml)){ + response.status=HTTPResponse::HTTP_OK; response.description=signal_xml; } else { |
