summaryrefslogtreecommitdiff
path: root/rotord
diff options
context:
space:
mode:
authorTim Redfern <tim@herge.(none)>2013-02-26 18:21:12 +0000
committerTim Redfern <tim@herge.(none)>2013-02-26 18:21:12 +0000
commit77c22b76a19793f36377ca10d7137522720548e4 (patch)
treeb85570be6af37b8de5b574078c50a2fb8e734c4a /rotord
parentc0758ba28eb13c198551e3a18d37d8582e76e02d (diff)
thread messaging
Diffstat (limited to 'rotord')
-rwxr-xr-xrotord/rotor.h73
-rwxr-xr-xrotord/rotord.cpp17
-rwxr-xr-xrotord/rotord.h1
3 files changed, 66 insertions, 25 deletions
diff --git a/rotord/rotor.h b/rotord/rotor.h
index ac4532a..4a0c540 100755
--- a/rotord/rotor.h
+++ b/rotord/rotor.h
@@ -48,11 +48,11 @@ bool Same_frame(float time1, float time2);
2 main questions
authentication - how
authentication to renderer or just session?
-files - where
+files - where
generated images & movies where?
-nb where a signal enters a channel comp input - it is duplicated
-
+nb where a signal enters a channel comp input - it is duplicated
+
next - Poco create thread
1st - create thread and return id - create method to kill it
@@ -60,12 +60,27 @@ next - Poco create thread
sql stuff
+messaging - http factory includes a poco notication center
+when it creates the rotor session it registers it
+session messages are posted thus and consumed
+
*/
#include <unordered_map>
+#include <deque>
#include "Poco/UUID.h"
#include "Poco/UUIDGenerator.h"
+#include "Poco/Notification.h"
+#include "Poco/NotificationCenter.h"
+#include "Poco/Observer.h"
+#include "Poco/ThreadPool.h"
+#include "Poco/Thread.h"
+#include "Poco/Runnable.h"
+#include "Poco/Mutex.h"
+#include "Poco/Random.h"
+#include "Poco/AutoPtr.h"
+#include <iostream>
using Poco::UUID;
using Poco::UUIDGenerator;
@@ -76,9 +91,10 @@ using Poco::UUIDGenerator;
#define ROTOR_RENDERING 3
namespace Rotor {
+
//forward declaration
class Node;
-
+
class Render_status{
public:
int id;
@@ -89,36 +105,51 @@ namespace Rotor {
int num_performances;
int num_clips;
};
- class Render_context: public Poco::Task{ //Poco task object
- //manages a 'patchbay'
- //high level interfaces for the wizard
- //and low level interface onto the graph
+ class Render_context: public Poco::Task { //Poco task object
+ //manages a 'patchbay'
+ //high level interfaces for the wizard
+ //and low level interface onto the graph
public:
Render_context(const std::string& name): Task(name) {
};
void runTask() {
- while (!isCancelled()) sleep(1);
+ while (!isCancelled()) {
+ mutex.lock();
+ if (work_queue.size()){
+ std::string out=name()+": "+work_queue[0]+"\n";
+ printf(out.c_str());
+ work_queue.pop_front();
+ }
+ mutex.unlock();
+ sleep(100);
+ }
printf("Rotor: stopping thread\n");
-
+ }
+ void add_queue(std::string item) {
+ mutex.lock();
+ work_queue.push_back(item);
+ mutex.unlock();
}
Render_status get_status();
- void cancel(); //interrupt locking process
- int make_preview(int nodeID, float time); //starts a frame preview - returns status code - how to retrieve?
+ void cancel(); //interrupt locking process
+ int make_preview(int nodeID, float time); //starts a frame preview - returns status code - how to retrieve?
int load_graph(Poco::UUID uid);
- UUID save_graph(); //returns UUID of saved graph
+ UUID save_graph(); //returns UUID of saved graph
int load_audio(string filename);
Render_requirements get_requirements();
- int load_video(int num,string filename); //can be performance or clip
-
+ int load_video(int num,string filename); //can be performance or clip
+
private:
int status;
- float progress; //for a locking process: audio analysis or rendering
-
- };
+ float progress; //for a locking process: audio analysis or rendering
+ std::deque<std::string> work_queue;
+
+ Poco::Mutex mutex; //access to notification queue
+ };
class Input{
public:
Node* connection;
-
+
};
class Image_input: public Input{
public:
@@ -155,7 +186,7 @@ namespace Rotor {
Image* get_output(float time){ //sample implementation
gather_inputs(time);
//do something with the inputs
-
+
//and then
return ((Image_node*)image_inputs[0].connection)->image;
}
@@ -175,4 +206,4 @@ namespace Rotor {
/*
coding style
Types begin with a capital, use underscore as a seperator
-*/ \ No newline at end of file
+*/
diff --git a/rotord/rotord.cpp b/rotord/rotord.cpp
index fc74801..6ea61df 100755
--- a/rotord/rotord.cpp
+++ b/rotord/rotord.cpp
@@ -188,12 +188,21 @@ HTTPRequestHandler* RotorRequestHandlerFactory::createRequestHandler(const HTTPS
}
}
else {
- if (command[0]=="audio") {
+ //in a way the rest of this stuff happens inside the thread
+ //its not elegant to decipher the message just to assemble another message to decipher elsewhere!
+ //pass a message object with the command type and contents selected?
+ //every action will have a seperate work function in the render_context
+ //some of these functions have to return data immediately- maybe a queue isn't the ideal model
+ if (command[1]=="audio") {
if (request.getMethod()=="PUT") {
//get audio file location and initiate analysis
- stringstream str;
- str << request.stream();
- //content << str;
+ std::string s;
+ std::ostringstream os;
+ os<<request.stream().rdbuf();
+ s=os.str();
+ //pass message to task
+ ((Poco::AutoPtr<Rotor::Render_context>)task)->add_queue(s);
+ content="<status>1</status>\n";
}
}
diff --git a/rotord/rotord.h b/rotord/rotord.h
index 99e588a..e645e29 100755
--- a/rotord/rotord.h
+++ b/rotord/rotord.h
@@ -12,6 +12,7 @@
#include "Poco/Exception.h"
#include "Poco/ThreadPool.h"
#include "Poco/Task.h"
+#include "Poco/NotificationCenter.h"
#include "Poco/TaskManager.h"
#include "Poco/Util/ServerApplication.h"
#include "Poco/Util/Option.h"