diff options
| -rwxr-xr-x | http | 2 | ||||
| -rw-r--r-- | rotord/rotor.cpp | 32 | ||||
| -rwxr-xr-x | rotord/rotord.cpp | 73 | ||||
| -rwxr-xr-x | rotord/rotord.h | 1 |
4 files changed, 80 insertions, 28 deletions
@@ -6,7 +6,7 @@ parser.add_argument("method",default="GET",nargs='?') parser.add_argument("path",default="/",nargs='?') parser.add_argument("body",default="body",nargs='?') args=parser.parse_args() -connection = httplib.HTTPConnection('54.228.219.55:80') +connection = httplib.HTTPConnection('127.0.0.1:9000') connection.request(args.method, args.path, args.body) print connection.getresponse().read() 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 { diff --git a/rotord/rotord.cpp b/rotord/rotord.cpp index fe860a6..74a9ae7 100755 --- a/rotord/rotord.cpp +++ b/rotord/rotord.cpp @@ -103,7 +103,7 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS app.logger().information(request.clientAddress().toString()+" "+request.getMethod()); string content=""; - HTTPResponse::HTTPStatus status=HTTPResponse::HTTP_OK; + HTTPResponse::HTTPStatus status=HTTPResponse::HTTP_BAD_REQUEST; //by default /* @@ -144,16 +144,20 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS if (command.size()) { if (command[0]=="new") { - string sID=idGen.createOne().toString(); //create() seems to cause problems - //Creates a new time-based UUID, using the MAC address of one of the system's ethernet adapters. - //Throws a SystemException if no MAC address can be obtained. - // - //seems to hang, to me - printf("Rotor: starting thread\n"); - manager.start(new Rotor::Render_context(sID)); - content="<sID>"+sID+"</sID>\n"; + if (request.getMethod()=="GET") { + string sID=idGen.createOne().toString(); //create() seems to cause problems + //Creates a new time-based UUID, using the MAC address of one of the system's ethernet adapters. + //Throws a SystemException if no MAC address can be obtained. + // + //seems to hang, to me + cerr << "Rotor: starting thread "<< sID << endl; + manager.start(new Rotor::Render_context(sID)); + content="<sID>"+sID+"</sID>\n"; + status=HTTPResponse::HTTP_OK; + } } else if (command[0]=="list") { + if (request.getMethod()=="GET") { //std::list < Poco::AutoPtr < Poco::Task > >::iterator it; //it=manager.taskList().begin(); //for (it=manager.taskList().begin();it !=manager.taskList().end();++it) { @@ -164,26 +168,47 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS //solution: auto type range-based for-loop //this is c++11 specific but works - for (auto& task: manager.taskList()) //c++11 - { - content+="<sID>"+task->name()+" </sID>\n"; - } + for (auto& task: manager.taskList()) { //c++11 + content+="<sID>"+task->name()+" </sID>\n"; + } + status=HTTPResponse::HTTP_OK; + } + } + else if (command[0]=="styles") { + //eventually retrieve from sql; + //a bit of weirdness here: prefer to just get whole file to a string. + if (request.getMethod()=="GET") { + std::vector<std::string> styles = {"style01.xml","style02.xml" }; //c++11 STL initialiser list + for (auto &style: styles) { + Poco::File f=Poco::File(style); + if (f.exists()) { + Poco::FileInputStream file(style); + string s=""; + while (!file.eof()) { + content +=s; + file >> s; + content +=" "; + } + content +="\n"; + } } - else { - bool found=false; - for (auto& task: manager.taskList()) //c++11 - { + status=HTTPResponse::HTTP_OK; + } + } + else { + bool found=false; + for (auto& task: manager.taskList()) { //c++11 if(task->name()==command[0]) { - //valid session command - found=true; - if (command.size()==1) { + //valid session command + found=true; + if (command.size()==1) { //just invoking sID if (request.getMethod()=="DELETE") { - task->cancel(); - content="<status>1</status>\n"; + task->cancel(); + content="<status>1</status>\n"; + status=HTTPResponse::HTTP_OK; } else { - status=HTTPResponse::HTTP_BAD_REQUEST; content="<status>Rotor: render context invoked with no command</status>\n"; } } @@ -210,7 +235,7 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS } } - } + } if (!found) { status=HTTPResponse::HTTP_NOT_FOUND; content="<status>Rotor: render context not found</status>\n"; diff --git a/rotord/rotord.h b/rotord/rotord.h index 2ea637d..f0f24ac 100755 --- a/rotord/rotord.h +++ b/rotord/rotord.h @@ -18,6 +18,7 @@ #include "Poco/Util/Option.h" #include "Poco/Util/OptionSet.h" #include "Poco/Util/HelpFormatter.h" +#include "Poco/FileStream.h" #include <iostream> #include <sstream> |
