From 7e3657d7783b7a6cdb48719d17ec3ac381dd8ae7 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 17 Jul 2013 14:55:08 +0100 Subject: logging http responses --- rotord/rendercontext.cpp | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'rotord/rendercontext.cpp') diff --git a/rotord/rendercontext.cpp b/rotord/rendercontext.cpp index 776e842..7362d64 100644 --- a/rotord/rendercontext.cpp +++ b/rotord/rendercontext.cpp @@ -50,6 +50,7 @@ void Render_context::add_queue(int item) { mutex.unlock(); } void Render_context::session_command(const std::vector& command,xmlIO& XML,HTTPResponse::HTTPStatus& status){ + Logger& logger = Logger::get("Rotor"); status=HTTPResponse::HTTP_BAD_REQUEST; //error by default if (command[2]=="resolution") { if (command[0]=="PUT") { @@ -60,10 +61,12 @@ void Render_context::session_command(const std::vector& command,xml int w=ofToInt(t1[0]); int h=ofToInt(t1[1]); if (graph.set_resolution(w,h)){ + logger.information("resolution set to "+t1[0]+"x"+t1[1]); XML.addValue("status","resolution set to "+t1[0]+"x"+t1[1]); status=HTTPResponse::HTTP_OK; } else { + logger.error("ERROR: invalid resolution request: "+t1[0]+"x"+t1[1]); XML.addValue("error","invalid resolution request: "+t1[0]+"x"+t1[1]); } } @@ -84,15 +87,18 @@ void Render_context::session_command(const std::vector& command,xml //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read?? add_queue(ANALYSE_AUDIO); status=HTTPResponse::HTTP_OK; + logger.information("Starting audio analysis: "+command[3]); XML.addValue("status","Starting audio analysis: "+command[3]); } else { status=HTTPResponse::HTTP_NOT_FOUND; + logger.error("ERROR: audio file "+command[3]+" not found"); XML.addValue("error",command[3]+" not found"); } } else { + logger.error("ERROR: Session busy"); XML.addValue("error","Session busy"); } } @@ -114,16 +120,19 @@ void Render_context::session_command(const std::vector& command,xml XML.addValue("audio",audio_thumb->print()); } else { + logger.error("ERROR: audio thumbnail requested but no audio loaded"); XML.addValue("error","No audio loaded"); } } if (command[0]=="DELETE") { if (state==IDLE) { audio_filename=""; + logger.information("Audio deleted"); XML.addValue("status","Audio deleted"); status=HTTPResponse::HTTP_OK; } else { + logger.error("ERROR: Session busy"); XML.addValue("error","Session busy"); } } @@ -133,9 +142,11 @@ void Render_context::session_command(const std::vector& command,xml if (graph.loaded) { status=HTTPResponse::HTTP_OK; //XML.addValue("patchbay",graph.toString()); + logger.information("Requested graph"); XML.loadFromBuffer(graph.toString()); } else { + logger.error("ERROR: graph not loaded: check XML"); XML.addValue("error","graph not loaded: check XML"); } } @@ -146,10 +157,12 @@ void Render_context::session_command(const std::vector& command,xml if (state==IDLE) { //eventually not like this if (graph.load(command[3])) { status=HTTPResponse::HTTP_OK; + logger.information("Loaded graph from http PUT body"); XML.addValue("status","Loaded graph from PUT body"); if (audio_loaded) { add_queue(ANALYSE_AUDIO); status=HTTPResponse::HTTP_OK; + logger.information("Starting audio analysis for graph: "+command[3]); XML.addValue("status","Starting audio analysis for graph: "+command[3]); } } @@ -169,16 +182,19 @@ void Render_context::session_command(const std::vector& command,xml if (audio_loaded) { add_queue(ANALYSE_AUDIO); status=HTTPResponse::HTTP_OK; + logger.information("Starting audio analysis for graph: "+command[3]); XML.addValue("status","Starting audio analysis for graph: "+command[3]); } } else { status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; //~/sources/poco-1.4.6-all/Net/include/Poco/Net/HTTPResponse.h + logger.error("ERROR: graph not loaded: check XML"); XML.addValue("error","graph not loaded: check XML"); } } else { status=HTTPResponse::HTTP_NOT_FOUND; + logger.error("ERROR: "+command[3]+" not found"); XML.addValue("error",command[3]+" not found"); } } @@ -188,6 +204,7 @@ void Render_context::session_command(const std::vector& command,xml if (command[0]=="DELETE") { //for now graph=Graph(); + logger.information("graph deleted"); XML.addValue("status","graph deleted"); status=HTTPResponse::HTTP_OK; } @@ -203,10 +220,12 @@ void Render_context::session_command(const std::vector& command,xml string signal_xml; if (graph.signal_render(signal_xml,framerate)){ status=HTTPResponse::HTTP_OK; - XML.addValue("signal",signal_xml); //this doesn't work + logger.information("rendering signal to xml"); + XML.addValue("signal",signal_xml); //this doesn't work >> pseudo xml } else { status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; + logger.error("ERROR: could not render output signal"); XML.addValue("error","could not render output signal"); } //else { @@ -216,6 +235,7 @@ void Render_context::session_command(const std::vector& command,xml } else { status=HTTPResponse::HTTP_SERVICE_UNAVAILABLE; + logger.error("ERROR: context busy"); XML.addValue("error","Context busy"); } } @@ -232,25 +252,30 @@ void Render_context::session_command(const std::vector& command,xml //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read?? //DUMMY RESPONSE status=HTTPResponse::HTTP_OK; + logger.information("Succesfully loaded "+command[4]+" into video node "+command[3]); XML.addValue("status","Succesfully loaded "+command[4]+" into video node "+command[3]); } else { status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; + logger.error("ERROR: could not load "+command[4]+" into video node "+command[3]); XML.addValue("error","could not load "+command[4]+" into video node "+command[3]); } } else { status=HTTPResponse::HTTP_NOT_FOUND; - XML.addValue("error",command[4]+" not found"); + logger.error("ERROR: "+command[4]+" not found"); + XML.addValue("error",command[4]+" not found"); } } else { status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Session busy"); XML.addValue("error","Session busy"); } } else { status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Bad request"); XML.addValue("error","Bad request"); } } @@ -263,6 +288,7 @@ void Render_context::session_command(const std::vector& command,xml XML.addValue("progress",ofToString(progress)); } else { + logger.error("ERROR: Render progress requested but not rendering"); XML.addValue("error","Not rendering"); } } @@ -275,28 +301,32 @@ void Render_context::session_command(const std::vector& command,xml } add_queue(RENDER); status=HTTPResponse::HTTP_OK; - XML.addValue("status","Starting render: "+command[3]); + logger.information("Starting render: "+command[3]); + XML.addValue("status","Starting render: "+command[3]); } else { status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: Session busy"); XML.addValue("error","Session busy"); } } else { status=HTTPResponse::HTTP_BAD_REQUEST; + logger.error("ERROR: No output file specified"); XML.addValue("error","No output file specified"); } } if (command[0]=="DELETE") { status=HTTPResponse::HTTP_OK; + logger.error("ERROR: Not implemented"); XML.addValue("status","DUMMY RESPONSE: cancelling render"); } } } bool Render_context::load_audio(const string &filename,vector processors){ - - cerr<<"Rotor: starting audio analysis"<init(channels,bits,samples,rate) ){ - cerr<<"Plugin failed to initialse"<print_summary(); } - cerr<<"Rotor: finished audio analysis"<