diff options
| author | Comment <tim@gray.(none)> | 2013-02-24 19:24:40 +0000 |
|---|---|---|
| committer | Comment <tim@gray.(none)> | 2013-02-24 19:24:40 +0000 |
| commit | 9de16e3435b0e6fd14af991db278717387d676d3 (patch) | |
| tree | 54c906570bd936176a15d436137ccdc03052ad7e /rotord/rotord.cpp | |
| parent | 35f5f0938c82e9aa9f0c704b1d43dff3209ad567 (diff) | |
working threading
Diffstat (limited to 'rotord/rotord.cpp')
| -rwxr-xr-x | rotord/rotord.cpp | 108 |
1 files changed, 55 insertions, 53 deletions
diff --git a/rotord/rotord.cpp b/rotord/rotord.cpp index c9fbbf5..1843c9c 100755 --- a/rotord/rotord.cpp +++ b/rotord/rotord.cpp @@ -21,6 +21,8 @@ Output is: "segmentation" Done ./rotord: symbol lookup error: /usr/local/lib/vamp/qm-vamp-plugins.so: undefined symbol: clapack_dgetrf +http://www.codeproject.com/Articles/252827/Learning-Poco-A-simple-HTTP-server + next: load a movie and retreive frames save a movie @@ -50,8 +52,6 @@ void RotorRequestHandler::handleRequest(HTTPServerRequest& request,HTTPServerRes ostr << "</p></body></html>"; } -RotorRequestHandlerFactory::RotorRequestHandlerFactory(const std::string& format):_format(format){ -} AudioAnalyserHandler::AudioAnalyserHandler(const vampHost::Settings& _settings): settings(_settings){ } @@ -73,7 +73,9 @@ void AudioAnalyserHandler::handleRequest(HTTPServerRequest& request,HTTPServerRe ostr << "</p></body></html>"; } -RenderContextHandler::RenderContextHandler(const std::vector <std::string> _command): command(_command){ +RenderContextHandler::RenderContextHandler(const std::string _content,const HTTPServerResponse::HTTPStatus _status){ + content=_content; + status=_status; } @@ -81,47 +83,11 @@ void RenderContextHandler::handleRequest(HTTPServerRequest& request,HTTPServerRe response.setChunkedTransferEncoding(true); response.setContentType("text/html"); + response.setStatus(status); std::ostream& ostr = response.send(); - string content; - if (command.size()) { - if (command[0]=="new") { - Poco:UUID sID=idGen.create(); - context[sID]=new Rotor::Render_context(); - context[sID].run(); - content="<sID>"+sID.toString()+"</sID>"; - } - else { - Poco:UUID sID; - if (sID.tryParse(command[0]) { - iterator iter = context.find(sID); - if (iter!=context.end()) { - //successfully located context - if (command.size()==1) { - //just invoking sID - if (request.getMethod()=="DELETE") { - - } - } - else { - - } - } - else { - resp.setStatus(HTTPResponse::HTTP_NOT_FOUND); - content="<body>Rotor: render context not found</body>"; - } - } - else resp.setStatus(HTTPResponse::HTTP_BAD_REQUEST); - content="<body>Rotor: command not found</body>"; - } - } - else { - content="<body>Rotor: empty request</body>"; - } - - ostr << "<?xml version="1.0" encoding="ISO-8859-1"?>"; + ostr << "<?xml version='1.0' encoding='ISO-8859-1'?>"; ostr << content; } @@ -131,19 +97,14 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS Application& app = Application::instance(); Poco::URI theuri=Poco::URI(request.getURI()); - std::vector <std::string> segments; - theuri.getPathSegments(segments); + std::vector <std::string> command; + theuri.getPathSegments(command); - std::ostringstream ostr; - ostr << segments.size(); + app.logger().information(request.clientAddress().toString()+" "+request.getMethod()); - std::string out; - for (uint i=0;i<segments.size();i++) { - out+=segments[i]; - out+=" "; - } + string content=""; + HTTPResponse::HTTPStatus status=HTTPResponse::HTTP_OK; - app.logger().information(request.clientAddress().toString()+" "+request.getMethod()+": "+ostr.str()+" segments: "+out); /* if (segments.size() == 0) { @@ -169,13 +130,54 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS return 0; } */ - return new RenderContextHandler(segments); + //at this point we are within app //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 + + //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(); + context[sID]=Rotor::Render_context(); + pool.start(context[sID]); + content="<sID>"+sID+"</sID>\n"; + } + else if (command[0]=="list") { + for (std::unordered_map<std::string,Rotor::Render_context>::iterator it = context.begin(); it != context.end(); ++it) { + content+="<sID>"+it->first+"</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 { + status=HTTPResponse::HTTP_NOT_FOUND; + content="<body>Rotor: render context not found</body>\n"; + } + } + } + else { + content="<body>Rotor: empty request</body>"; + } + return new RenderContextHandler(content, status); } @@ -223,7 +225,7 @@ int RotorServer::main(const std::vector<std::string>& args){ unsigned short port = (unsigned short) config().getInt("port", 9980); std::string format(config().getString("format", DateTimeFormat::SORTABLE_FORMAT)); ServerSocket svs(port); - HTTPServer srv(new RotorRequestHandlerFactory(format),svs, new HTTPServerParams); + HTTPServer srv(new RotorRequestHandlerFactory(),svs, new HTTPServerParams); srv.start(); waitForTerminationRequest(); srv.stop(); |
