summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Redfern <tim@herge.(none)>2013-07-09 16:34:23 +0100
committerTim Redfern <tim@herge.(none)>2013-07-09 16:34:23 +0100
commit06c6f158088ce9132375cfe7f5c27f7c200b44dc (patch)
treefa1f90f9a3d5eab842638a6b009f817f10f481b6
parent1f7aeab37ebe41d57972f429fc0884d2de7eab4d (diff)
load graph from body
-rw-r--r--rotord/graph.cpp17
-rw-r--r--rotord/rendercontext.cpp42
-rwxr-xr-xrotord/rotor.h4
-rwxr-xr-xrotord/rotord.cpp17
4 files changed, 53 insertions, 27 deletions
diff --git a/rotord/graph.cpp b/rotord/graph.cpp
index e3b0669..74fadb8 100644
--- a/rotord/graph.cpp
+++ b/rotord/graph.cpp
@@ -55,11 +55,22 @@ bool Graph::set_resolution(int w,int h){
}
else return false;
}
-bool Graph::load(string &filename){
+bool Graph::load(string data){
+ if (xml.loadFromBuffer(data)){
+ return parseXml();
+ }
+ return false;
+}
+bool Graph::loadFile(string &filename){
loaded=false;
printf("loading graph: %s\n",filename.c_str());
if(xml.loadFile(filename) ){
- init(xml.getAttribute("patchbay","ID","",0),xml.getValue("patchbay","",0));
+ return parseXml();
+ }
+ else return false;
+}
+bool Graph::parseXml(){
+ init(xml.getAttribute("patchbay","ID","",0),xml.getValue("patchbay","",0));
if(xml.pushTag("patchbay")) {
int n1=xml.getNumTags("node");
for (int i1=0;i1<n1;i1++){
@@ -136,6 +147,4 @@ bool Graph::load(string &filename){
}
loaded=true;
return true;
- }
- else return false;
} \ No newline at end of file
diff --git a/rotord/rendercontext.cpp b/rotord/rendercontext.cpp
index 1e0fe1e..1da5725 100644
--- a/rotord/rendercontext.cpp
+++ b/rotord/rendercontext.cpp
@@ -144,28 +144,34 @@ void Render_context::session_command(const std::vector<std::string>& command,xml
//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
+ if (graph.load(command[3])) {
+ status=HTTPResponse::HTTP_OK;
+ XML.addValue("status","Loaded graph from PUT body");
+ }
+ else {
+ string graph_filename=graph_dir+command[3];
+ Poco::File f=Poco::File(graph_filename);
+ if (f.exists()) {
+ if (graph.loadFile(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_INTERNAL_SERVER_ERROR; //~/sources/poco-1.4.6-all/Net/include/Poco/Net/HTTPResponse.h
- XML.addValue("error","graph not loaded: check XML");
+ status=HTTPResponse::HTTP_NOT_FOUND;
+ XML.addValue("error",command[3]+" not found");
}
}
- else {
- status=HTTPResponse::HTTP_NOT_FOUND;
- XML.addValue("error",command[3]+" not found");
- }
}
}
}
diff --git a/rotord/rotor.h b/rotord/rotor.h
index 63ac886..8e6e9b7 100755
--- a/rotord/rotor.h
+++ b/rotord/rotor.h
@@ -1192,7 +1192,9 @@ namespace Rotor {
bool signal_render(string &signal_xml,const float framerate);
bool video_render(const string &output_filename,const string &audio_filename,const float framerate,float& progress);
int load(Poco::UUID uid);
- bool load(string &graph_filename);
+ bool load(string data);
+ bool loadFile(string &filename);
+ bool parseXml();
bool set_resolution(int w,int h);
UUID save(); //save to DB, returns UUID of saved graph
bool loaded;
diff --git a/rotord/rotord.cpp b/rotord/rotord.cpp
index 8790d39..77725ff 100755
--- a/rotord/rotord.cpp
+++ b/rotord/rotord.cpp
@@ -61,10 +61,19 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
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));
- XML.addValue("sID",sID);
- status=HTTPResponse::HTTP_OK;
+ bool found=false;
+ for (auto& task: manager.taskList()) {
+ if(task->name()==sID) {
+ XML.addValue("error","Render context /"+sID+"/ exists already");
+ found=true;
+ }
+ }
+ if (!found){
+ cerr << "Rotor: starting thread "<< sID << endl;
+ manager.start(new Rotor::Render_context(sID));
+ XML.addValue("sID",sID);
+ status=HTTPResponse::HTTP_OK;
+ }
}
}
}