diff options
| author | Tim Redfern <tim@herge.(none)> | 2013-02-25 17:51:10 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@herge.(none)> | 2013-02-25 17:51:10 +0000 |
| commit | 58792f6cfd314499264183a5f63d8539e8b1e5e5 (patch) | |
| tree | 4e504f7a901a06a5d6929656d3791d8fbad6fd64 /rotord/rotord.cpp | |
| parent | d5193b058ca06db9bda772ccdf49a8c4976c7274 (diff) | |
threads stopping and starting
Diffstat (limited to 'rotord/rotord.cpp')
| -rwxr-xr-x | rotord/rotord.cpp | 106 |
1 files changed, 62 insertions, 44 deletions
diff --git a/rotord/rotord.cpp b/rotord/rotord.cpp index cb106d0..f9e1d21 100755 --- a/rotord/rotord.cpp +++ b/rotord/rotord.cpp @@ -35,7 +35,7 @@ RotorRequestHandler::RotorRequestHandler(const std::string& format): _format(for } void RotorRequestHandler::handleRequest(HTTPServerRequest& request,HTTPServerResponse& response) { - + Timestamp now; std::string dt(DateTimeFormatter::format(now, _format)); @@ -60,7 +60,7 @@ void AudioAnalyserHandler::handleRequest(HTTPServerRequest& request,HTTPServerRe response.setChunkedTransferEncoding(true); response.setContentType("text/html"); - + //string audioData=vampHost::runPlugin(); std::ostream& ostr = response.send(); @@ -81,13 +81,13 @@ RenderContextHandler::RenderContextHandler(const std::string _content,const HTTP void RenderContextHandler::handleRequest(HTTPServerRequest& request,HTTPServerResponse& response) { - response.setChunkedTransferEncoding(true); - response.setContentType("text/html"); + response.setChunkedTransferEncoding(true); + response.setContentType("text/html"); response.setStatus(status); - - std::ostream& ostr = response.send(); - - ostr << "<?xml version='1.0' encoding='ISO-8859-1'?>"; + + std::ostream& ostr = response.send(); + + ostr << "<?xml version='1.0' encoding='ISO-8859-1'?>\n"; ostr << content; } @@ -95,17 +95,17 @@ void RenderContextHandler::handleRequest(HTTPServerRequest& request,HTTPServerRe HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPServerRequest& request){ Application& app = Application::instance(); - + Poco::URI theuri=Poco::URI(request.getURI()); std::vector <std::string> command; theuri.getPathSegments(command); - + app.logger().information(request.clientAddress().toString()+" "+request.getMethod()); - + string content=""; HTTPResponse::HTTPStatus status=HTTPResponse::HTTP_OK; - - + + /* if (segments.size() == 0) { return new RotorRequestHandler(_format); @@ -113,7 +113,7 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS else if (segments[0]=="vamp"&&segments.size()>3) { // vamp/plugin/filter/filename // how do deal with error condition? - + //Settings(string _so="",string _filter="",string _id="",string _input=""); return new AudioAnalyserHandler(vampHost::Settings(segments[1],segments[2],segments[3])); //string audioData=runPlugin(string myname, string soname, string id, @@ -123,61 +123,79 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS } else if (segments[0]=="new") { // create a new render context - + return 0; } else { return 0; } */ - - + + //at this point we are within app - //making a new contexthandler? + //making a new contexthandler? //how will this have access to the thread that it refers to //how will messages be passed - //we need to do testing etc here and - + //we need to do testing etc here and + //what does the handler do? //it gets passed the response- gets to set response code - - + + if (command.size()) { if (command[0]=="new") { - string sID=idGen.create().toString(); + 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"; } else if (command[0]=="list") { - std::list < Poco::AutoPtr < Poco::Task > >::iterator it; - it=manager.taskList().begin(); - for (it=manager.taskList().begin();it !=manager.taskList().end();++it) { - content+="<sID>"+(*it)->name()+"</sID>\n"; - } + //std::list < Poco::AutoPtr < Poco::Task > >::iterator it; + //it=manager.taskList().begin(); + //for (it=manager.taskList().begin();it !=manager.taskList().end();++it) { + //content+="<sID>"+(*it)->name()+"</sID>\n"; + //} + + //massive problems making an iterator for the tasklist, the above crashes + //solution: auto type range-based for-loop + //this is c++11 specific but works + + for (auto& task: manager.taskList()) + { + content+="<sID>"+task->name()+" </sID>\n"; + } } else { - std::unordered_map<std::string,Rotor::Render_context>::iterator iter = context.find(command[0]); - if (iter!=context.end()) { - //successfully located context - if (command.size()==1) { - //just invoking sID - if (request.getMethod()=="DELETE") { - - } - } - else { - - } - } - else { + bool found=false; + for (auto& task: manager.taskList()) + { + if(task->name()==command[0]) { + found=true; + if (command.size()==1) { + //just invoking sID + if (request.getMethod()=="DELETE") { + task->cancel(); + content="<status>1</status>\n"; + } + else { + status=HTTPResponse::HTTP_BAD_REQUEST; + content="<status>Rotor: render context invoked with no command</status>\n"; + } + } + } + } + if (!found) { status=HTTPResponse::HTTP_NOT_FOUND; - content="<body>Rotor: render context not found</body>\n"; + content="<status>Rotor: render context not found</status>\n"; } } } else { - content="<body>Rotor: empty request</body>"; + content="<status>Rotor: empty request</status>"; } return new RenderContextHandler(content, status); } |
