summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Redfern <tim@herge.(none)>2013-07-02 17:22:38 +0100
committerTim Redfern <tim@herge.(none)>2013-07-02 17:22:38 +0100
commit991099ad1f33d1ed6fd0423964f196b34b0c1669 (patch)
tree3831efb2aac6bd473766d277c3bb388343dca931
parent0d867b8b615add6e1a5aaa300c5a39b87614d906 (diff)
xml with root nodes
-rw-r--r--rotord/rendercontext.cpp216
-rwxr-xr-xrotord/rotor.h2
-rwxr-xr-xrotord/rotord.cpp6
3 files changed, 222 insertions, 2 deletions
diff --git a/rotord/rendercontext.cpp b/rotord/rendercontext.cpp
index 4be54f1..e31a161 100644
--- a/rotord/rendercontext.cpp
+++ b/rotord/rendercontext.cpp
@@ -49,7 +49,223 @@ void Render_context::add_queue(int item) {
mutex.unlock();
}
void Render_context::session_command(const std::vector<std::string>& command,xmlIO& XML,HTTPResponse::HTTPStatus& status){
+ status=HTTPResponse::HTTP_BAD_REQUEST; //error by default
+ if (command[2]=="resolution") {
+ if (command[0]=="PUT") {
+ if (command.size()>2) {
+ if (state==IDLE) {
+ Poco::StringTokenizer t1(command[3],",");
+ if (t1.count()>1){
+ int w=ofToInt(t1[0]);
+ int h=ofToInt(t1[1]);
+ if (graph.set_resolution(w,h)){
+ XML.addValue("status","resolution set to "+t1[0]+"x"+t1[1]);
+ status=HTTPResponse::HTTP_OK;
+ }
+ else {
+ XML.addValue("error","invalid resolution request: "+t1[0]+"x"+t1[1]);
+ }
+ }
+ }
+ else {
+ XML.addValue("error","session busy");
+ }
+ }
+ }
+ }
+ if (command[2]=="audio") {
+ if (command[0]=="PUT") { //get audio file location and initiate analysis
+ if (command.size()>2) {
+ if (state==IDLE) {
+ audio_filename=media_dir+command[3]; //for now, store session variables in memory //check file exists
+ Poco::File f=Poco::File(audio_filename);
+ if (f.exists()) {
+ //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read??
+ add_queue(ANALYSE_AUDIO);
+ status=HTTPResponse::HTTP_OK;
+ XML.addValue("status","Starting audio analysis: "+command[3]);
+ }
+ else {
+ status=HTTPResponse::HTTP_NOT_FOUND;
+ XML.addValue("error",command[3]+" not found");
+ }
+ }
+ else {
+ XML.addValue("error","session busy");
+ }
+ }
+ }
+ if (command[0]=="GET") {
+ if (state==ANALYSING_AUDIO) {
+ status=HTTPResponse::HTTP_OK;
+ XML.addValue("status","analysing audio");
+ char c[20];
+ sprintf(c,"%02f",progress);
+ XML.addValue("progress",string(c));
+ }
+ else if (audio_loaded) {
+ //not sure about this-- should this state be retained?
+ //can the data only be read once?
+ //for now
+ status=HTTPResponse::HTTP_OK;
+ XML.addValue("status","audio ready");
+ XML.addValue("audio",audio_thumb->print());
+ }
+ else {
+ XML.addValue("error","no audio loaded");
+ }
+ }
+ if (command[0]=="DELETE") {
+ //for now
+ audio_filename="";
+ XML.addValue("status","audio deleted");
+ status=HTTPResponse::HTTP_OK;
+ }
+ }
+ if (command[2]=="graph") {
+ if (command[0]=="GET") {
+ if (graph.loaded) {
+ status=HTTPResponse::HTTP_OK;
+ //XML.addValue("patchbay",graph.toString());
+ XML.loadFromBuffer(graph.toString());
+ }
+ else {
+ XML.addValue("error","graph not loaded: check XML");
+ }
+ }
+ if (command[0]=="PUT") { //get new graph from file
+ if (command.size()>2) {
+ //should interrupt whatever is happening?
+ //before begining to load from xml
+ if (state==IDLE) { //eventually not like this
+ string graph_filename=graph_dir+command[3];
+ Poco::File f=Poco::File(graph_filename);
+ if (f.exists()) {
+ if (graph.load(graph_filename)) {
+ status=HTTPResponse::HTTP_OK;
+ //XML.addValue("patchbay",graph.toString());
+ //XML.loadFromBuffer(graph.toString());
+ XML=graph.xml;
+ //the graph could actually contain an xml object and we could just print it here?
+ //or could our nodes even be subclassed from xml nodes?
+ //the graph or the audio could load first- have to analyse the audio with vamp after the graph is loaded
+ //for now the graph must load 1st
+ }
+ else {
+ status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR; //~/sources/poco-1.4.6-all/Net/include/Poco/Net/HTTPResponse.h
+ XML.addValue("error","graph not loaded: check XML");
+ }
+ }
+ else {
+ status=HTTPResponse::HTTP_NOT_FOUND;
+ XML.addValue("error",command[3]+" not found");
+ }
+ }
+ }
+ }
+ if (command[0]=="DELETE") {
+ //for now
+ graph=Graph();
+ XML.addValue("status","graph deleted");
+ status=HTTPResponse::HTTP_OK;
+ }
+ }
+ if (command[2]=="signal") {
+ if (command[0]=="GET") { //generate xml from 1st signal output
+ if (state==IDLE) {
+ //direct call for testing
+ float framerate=25.0f;
+ if (command.size()>2) {
+ framerate=ofToFloat(command[3]);
+ }
+ string signal_xml;
+ if (graph.signal_render(signal_xml,framerate)){
+ status=HTTPResponse::HTTP_OK;
+ XML.addValue("signal",signal_xml);
+ }
+ else {
+ status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR;
+ XML.addValue("error","could not render output signal");
+ }
+ }
+ else {
+ status=HTTPResponse::HTTP_NOT_FOUND;
+ XML.addValue("error","Signal output not found in graph");
+ }
+ }
+ else {
+ status=HTTPResponse::HTTP_SERVICE_UNAVAILABLE;
+ XML.addValue("error","Context busy");
+ }
+ }
+ if (command[2]=="video") {
+ if (command[0]=="PUT") { //get vide file location and initiate analysis
+ if (command.size()>4) { //there should be a filename + a destination node
+ if (state==IDLE) {
+ string video_filename=media_dir+command[4];
+ //check file exists
+ Poco::File f=Poco::File(video_filename);
+ if (f.exists()) {
+ if (load_video(command[3],video_filename)) {
+ //pass to worker thread ??if engine is ready?? ??what if engine has finished but results aren't read??
+ //DUMMY RESPONSE
+ status=HTTPResponse::HTTP_OK;
+ XML.addValue("status","succesfully loaded "+command[4]+" into video node "+command[3]);
+ }
+ else {
+ status=HTTPResponse::HTTP_INTERNAL_SERVER_ERROR;
+ XML.addValue("error","could not load "+command[4]+" into video node "+command[3]);
+ }
+ }
+ else {
+ status=HTTPResponse::HTTP_NOT_FOUND;
+ XML.addValue("error",command[4]+" not found");
+ }
+ }
+ else {
+ status=HTTPResponse::HTTP_BAD_REQUEST;
+ XML.addValue("error","Session busy");
+ }
+ }
+ else {
+ status=HTTPResponse::HTTP_BAD_REQUEST;
+ XML.addValue("error","Bad request");
+ }
+ }
+ }
+ if (command[2]=="render") {
+ if (command[0]=="GET") {
+ status=HTTPResponse::HTTP_OK;
+ XML.addValue("status","Rendering video");
+ XML.addValue("progress",ofToString(progress));
+ }
+ if (command[0]=="PUT") {
+ if (command.size()>2) {
+ if (state==IDLE) {
+ output_filename=output_dir+command[3];
+ if (command.size()>3) {
+// output_framerate=ofToFloat(command[4]);
+ }
+ add_queue(RENDER);
+ status=HTTPResponse::HTTP_OK;
+ XML.addValue("status","Starting render: "+command[3]);
+ }
+ else {
+ status=HTTPResponse::HTTP_BAD_REQUEST;
+ XML.addValue("error","Session busy");
+ }
+ }
+ else {
+ status=HTTPResponse::HTTP_BAD_REQUEST;
+ XML.addValue("error","No output file specified");
+ }
+ }
+ if (command[0]=="DELETE") {
+ status=HTTPResponse::HTTP_OK;
+ XML.addValue("status","DUMMY RESPONSE: cancelling render");
+ }
+ }
}
Command_response Render_context::session_command(const std::vector<std::string>& command){
//method,id,command1,{command2,}{body}
diff --git a/rotord/rotor.h b/rotord/rotor.h
index e2a26d9..4e22f1f 100755
--- a/rotord/rotor.h
+++ b/rotord/rotor.h
@@ -1358,9 +1358,9 @@ namespace Rotor {
bool loaded;
float duration;
const string toString();
+ xmlIO xml;
private:
Node_factory factory;
- xmlIO xml;
int outW,outH;
};
class Audio_thumbnailer: public Base_audio_processor {
diff --git a/rotord/rotord.cpp b/rotord/rotord.cpp
index 6ece98a..b46cebc 100755
--- a/rotord/rotord.cpp
+++ b/rotord/rotord.cpp
@@ -105,13 +105,13 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
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") {
+ XML.pushTag("rotor");
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.
@@ -135,6 +135,7 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
}
}
else if (command[0]=="list") {
+ XML.pushTag("rotor");
if (request.getMethod()=="GET") {
//std::list < Poco::AutoPtr < Poco::Task > >::iterator it;
//it=manager.taskList().begin();
@@ -161,6 +162,8 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
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") {
@@ -195,6 +198,7 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
}
if (!found) {
status=HTTPResponse::HTTP_NOT_FOUND;
+ XML.pushTag("rotor");
XML.addValue("error","Render context not found");
}
}