From 0d867b8b615add6e1a5aaa300c5a39b87614d906 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 1 Jul 2013 16:04:34 +0100 Subject: generating output xml --- rotord/rotord.cpp | 72 ++++++++++++++++++++++--------------------------------- 1 file changed, 29 insertions(+), 43 deletions(-) (limited to 'rotord/rotord.cpp') diff --git a/rotord/rotord.cpp b/rotord/rotord.cpp index 7b7285b..6ece98a 100755 --- a/rotord/rotord.cpp +++ b/rotord/rotord.cpp @@ -96,7 +96,6 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS logger.information(request.clientAddress().toString()+" "+request.getMethod()); - string content=""; HTTPResponse::HTTPStatus status=HTTPResponse::HTTP_BAD_REQUEST; //by default std::string body; @@ -104,6 +103,13 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS os<\n"; + //XML.addTag("sID"); + XML.addValue("sID",sID); status=HTTPResponse::HTTP_OK; } - if (request.getMethod()=="PUT") { //undocumented manual thread name + if (request.getMethod()=="PUT") { //unofficial manual thread name if (body.size()) { string sID=body; cerr << "Rotor: starting thread "<< sID << endl; manager.start(new Rotor::Render_context(sID)); - content=""+sID+"\n"; + XML.addValue("sID",sID); status=HTTPResponse::HTTP_OK; } } @@ -140,34 +147,11 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS //this is c++11 specific but works for (auto& task: manager.taskList()) { //c++11 - content+=""+task->name()+" \n"; + XML.addValue("sID",task->name()); } 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::string stylesfile = "styles.xml"; - Poco::File f=Poco::File(stylesfile); - if (f.exists()) { - Poco::FileInputStream file(stylesfile); - //while (!file.eof()) { - // file >> content; - //} - Poco::StreamCopier::copyToString(file, content); - status=HTTPResponse::HTTP_OK; - } - else { - content="Rotor: internal error: styles not found\n"; - } - - } - else { - content="Rotor: bad request\n"; - } - } else if (command[0]=="exit") { exit(0); } @@ -178,15 +162,15 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS //valid session command found=true; if (command.size()==1) { - //just invoking sID - if (request.getMethod()=="DELETE") { - task->cancel(); - content="1\n"; - status=HTTPResponse::HTTP_OK; - } - else { - content="Rotor: render context invoked with no command\n"; - } + //just invoking sID + if (request.getMethod()=="DELETE") { + task->cancel(); + XML.addValue("status","1"); + status=HTTPResponse::HTTP_OK; + } + 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 @@ -201,23 +185,25 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS } sc.push_back(body); - Rotor::Command_response response=((Poco::AutoPtr)task)->session_command(sc); - - content=response.description; - status=response.status; + //Rotor::Command_response response=((Poco::AutoPtr)task)->session_command(sc); + ((Poco::AutoPtr)task)->session_command(sc,XML,status); + //content=response.description; + //status=response.status; } } } if (!found) { status=HTTPResponse::HTTP_NOT_FOUND; - content="Rotor: render context not found\n"; + XML.addValue("error","Render context not found"); } } } else { - content="Rotor: empty request"; + XML.addValue("error","Emoty request"); } + string content; + XML.copyXmlToString(content); return new RenderContextHandler(content, status); } -- cgit v1.2.3