summaryrefslogtreecommitdiff
path: root/rotord/rotord.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/rotord.cpp')
-rwxr-xr-xrotord/rotord.cpp72
1 files changed, 29 insertions, 43 deletions
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<<request.stream().rdbuf();
body=os.str();
+ xmlIO XML; //xml object handles the servers responses
+ XML.addTag("rotor");
+ XML.pushTag("rotor");
+
+ //can we create a tinyxml object here and pass a pointer to it to the render context?
+ //can tinyxml output to a string? is there any reason to use poco instead?
+
if (command.size()) {
if (command[0]=="new") {
if (request.getMethod()=="GET") {
@@ -114,15 +120,16 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
//seems to hang, to me
logger.information("Rotor: starting thread "+sID);
manager.start(new Rotor::Render_context(sID));
- content="<sID>"+sID+"</sID>\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>"+sID+"</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+="<sID>"+task->name()+" </sID>\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="<status>Rotor: internal error: styles not found</status>\n";
- }
-
- }
- else {
- content="<status>Rotor: bad request</status>\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="<status>1</status>\n";
- status=HTTPResponse::HTTP_OK;
- }
- else {
- content="<status>Rotor: render context invoked with no command</status>\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<Rotor::Render_context>)task)->session_command(sc);
-
- content=response.description;
- status=response.status;
+ //Rotor::Command_response response=((Poco::AutoPtr<Rotor::Render_context>)task)->session_command(sc);
+ ((Poco::AutoPtr<Rotor::Render_context>)task)->session_command(sc,XML,status);
+ //content=response.description;
+ //status=response.status;
}
}
}
if (!found) {
status=HTTPResponse::HTTP_NOT_FOUND;
- content="<status>Rotor: render context not found</status>\n";
+ XML.addValue("error","Render context not found");
}
}
}
else {
- content="<status>Rotor: empty request</status>";
+ XML.addValue("error","Emoty request");
}
+ string content;
+ XML.copyXmlToString(content);
return new RenderContextHandler(content, status);
}