#include "rotord.h" RenderContextHandler::RenderContextHandler(const std::string _content,const HTTPServerResponse::HTTPStatus _status){ content=_content; status=_status; } void RenderContextHandler::handleRequest(HTTPServerRequest& request,HTTPServerResponse& response) { response.setChunkedTransferEncoding(true); response.setContentType("text/html"); response.setStatus(status); std::ostream& ostr = response.send(); ostr << "\n"; ostr << content; } HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPServerRequest& request){ Logger& logger = Logger::get("Rotor"); Poco::URI theuri=Poco::URI(request.getURI()); std::vector command; theuri.getPathSegments(command); logger.information(request.clientAddress().toString()+" "+request.getMethod()); HTTPResponse::HTTPStatus status=HTTPResponse::HTTP_BAD_REQUEST; //by default std::string body; std::ostringstream os; os< >::iterator it; //it=manager.taskList().begin(); //for (it=manager.taskList().begin();it !=manager.taskList().end();++it) { //content+=""+(*it)->name()+"\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()) { //c++11 XML.addValue("sID",task->name()); } status=HTTPResponse::HTTP_OK; } } else if (command[0]=="exit") { exit(0); } else { bool found=false; for (auto& task: manager.taskList()) { //c++11 if(task->name()==command[0]) { //valid session command found=true; XML.addAttribute("rotor","context",task->name(),0); XML.pushTag("rotor"); if (command.size()==1) { //just invoking sID if (request.getMethod()=="DELETE") { task->cancel(); status=HTTPResponse::HTTP_OK; XML.addValue("status","context deleted successfully"); } else { XML.addValue("error","Render context invoked with no command"); } } else { //session modifier command- to be passed to render context //some commands need to return error codes //ie where the audio file isn't found //on the other hand, some commands need to know state of the renderer? vector sc; //method,id,command1,{command2,}{body} sc.push_back(request.getMethod()); for (auto& i: command){ sc.push_back(i); } sc.push_back(body); ((Poco::AutoPtr)task)->session_command(sc,XML,status); } } } if (!found) { status=HTTPResponse::HTTP_NOT_FOUND; XML.pushTag("rotor"); XML.addValue("error","Render context not found"); } } } else { XML.addValue("error","Emoty request"); } string content; XML.copyXmlToString(content); return new RenderContextHandler(content, status); } RotorServer::RotorServer(): _helpRequested(false) { } RotorServer::~RotorServer() { } void RotorServer::initialize(Application& self){ loadConfiguration(); ServerApplication::initialize(self); } void RotorServer::uninitialize(){ ServerApplication::uninitialize(); } void RotorServer::defineOptions(OptionSet& options) { ServerApplication::defineOptions(options); options.addOption( Option("help", "h", "display argument help information") .required(false) .repeatable(false) .callback(OptionCallback(this, &RotorServer::handleHelp) ) ); } void RotorServer::handleHelp(const std::string& name, const std::string& value){ HelpFormatter helpFormatter(options()); helpFormatter.setCommand(commandName()); helpFormatter.setUsage("OPTIONS"); helpFormatter.setHeader( "Rotor"); helpFormatter.format(std::cout); stopOptionsProcessing(); _helpRequested = true; } int RotorServer::main(const std::vector& args){ if (!_helpRequested) { unsigned short port; xmlIO xml; if(xml.loadFile("settings.xml") ){ port=xml.getAttribute("Rotor","port",9000,0); } else cerr<<"Rotord: settings.xml not found, using defaults"<