summaryrefslogtreecommitdiff
path: root/rotord/rotord.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/rotord.cpp')
-rwxr-xr-xrotord/rotord.cpp73
1 files changed, 49 insertions, 24 deletions
diff --git a/rotord/rotord.cpp b/rotord/rotord.cpp
index fe860a6..74a9ae7 100755
--- a/rotord/rotord.cpp
+++ b/rotord/rotord.cpp
@@ -103,7 +103,7 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
app.logger().information(request.clientAddress().toString()+" "+request.getMethod());
string content="";
- HTTPResponse::HTTPStatus status=HTTPResponse::HTTP_OK;
+ HTTPResponse::HTTPStatus status=HTTPResponse::HTTP_BAD_REQUEST; //by default
/*
@@ -144,16 +144,20 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
if (command.size()) {
if (command[0]=="new") {
- 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";
+ if (request.getMethod()=="GET") {
+ 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
+ cerr << "Rotor: starting thread "<< sID << endl;
+ manager.start(new Rotor::Render_context(sID));
+ content="<sID>"+sID+"</sID>\n";
+ status=HTTPResponse::HTTP_OK;
+ }
}
else if (command[0]=="list") {
+ if (request.getMethod()=="GET") {
//std::list < Poco::AutoPtr < Poco::Task > >::iterator it;
//it=manager.taskList().begin();
//for (it=manager.taskList().begin();it !=manager.taskList().end();++it) {
@@ -164,26 +168,47 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
//solution: auto type range-based for-loop
//this is c++11 specific but works
- for (auto& task: manager.taskList()) //c++11
- {
- content+="<sID>"+task->name()+" </sID>\n";
- }
+ for (auto& task: manager.taskList()) { //c++11
+ content+="<sID>"+task->name()+" </sID>\n";
+ }
+ 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::vector<std::string> styles = {"style01.xml","style02.xml" }; //c++11 STL initialiser list
+ for (auto &style: styles) {
+ Poco::File f=Poco::File(style);
+ if (f.exists()) {
+ Poco::FileInputStream file(style);
+ string s="";
+ while (!file.eof()) {
+ content +=s;
+ file >> s;
+ content +=" ";
+ }
+ content +="\n";
+ }
}
- else {
- bool found=false;
- for (auto& task: manager.taskList()) //c++11
- {
+ status=HTTPResponse::HTTP_OK;
+ }
+ }
+ else {
+ bool found=false;
+ for (auto& task: manager.taskList()) { //c++11
if(task->name()==command[0]) {
- //valid session command
- found=true;
- if (command.size()==1) {
+ //valid session command
+ found=true;
+ if (command.size()==1) {
//just invoking sID
if (request.getMethod()=="DELETE") {
- task->cancel();
- content="<status>1</status>\n";
+ task->cancel();
+ content="<status>1</status>\n";
+ status=HTTPResponse::HTTP_OK;
}
else {
- status=HTTPResponse::HTTP_BAD_REQUEST;
content="<status>Rotor: render context invoked with no command</status>\n";
}
}
@@ -210,7 +235,7 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
}
}
- }
+ }
if (!found) {
status=HTTPResponse::HTTP_NOT_FOUND;
content="<status>Rotor: render context not found</status>\n";