summaryrefslogtreecommitdiff
path: root/NT/src/graph.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2014-01-24 17:00:22 +0000
committerTim Redfern <tim@eclectronics.org>2014-01-24 17:00:22 +0000
commit1f2bc21fd5ee9bff4fce190d7bb0ee4462e76e87 (patch)
treee42440db80a363c503e1e0b552631adbb194c245 /NT/src/graph.cpp
parent913bb43738c7d7391cd990ff1fc3f261afdf78ee (diff)
logging in nodes and text_render proof of concept
Diffstat (limited to 'NT/src/graph.cpp')
-rw-r--r--NT/src/graph.cpp29
1 files changed, 12 insertions, 17 deletions
diff --git a/NT/src/graph.cpp b/NT/src/graph.cpp
index e671238..50db271 100644
--- a/NT/src/graph.cpp
+++ b/NT/src/graph.cpp
@@ -19,6 +19,7 @@ bool Graph::check_audio(string audio,string path){
return false;
}
bool Graph::load_file(std::string filename,std::string media_path){
+ Logger& logger = Logger::get(id);
Poco::File f=Poco::File(filename);
if (f.exists()) {
Poco::FileInputStream fis(filename);
@@ -27,7 +28,7 @@ bool Graph::load_file(std::string filename,std::string media_path){
Poco::StreamCopier::copyToString(countingIstr, str);
return parse_json(str,media_path);
}
- cerr<<"Rotor: graph "<<filename<<" not found"<<endl;
+ logger.error("Graph "+filename+" not found");
return false;
}
Node* Graph::find_node(const string &type){
@@ -36,20 +37,24 @@ Node* Graph::find_node(const string &type){
}
return nullptr;
};
+Node* Graph::get_node(const std::string &id){
+ if (nodes.find(id)!=nodes.end()) return nodes[id];
+ return nullptr;
+}
bool Graph::parse_json(string &data,string &media_path){
+ Logger& logger = Logger::get(id);
Json::Value root; // will contain the root value after parsing.
Json::Reader reader;
bool parsing_successful = reader.parse( data, root );
if ( !parsing_successful )
{
- std::cout << "Failed to parse configuration\n"
- << reader.getFormattedErrorMessages();
+ logger.error("Failed to parse configuration: "+reader.getFormattedErrorMessages());
return false;
}
//The json validates, now we should attempt to retain nodes which haven't changed
//for now just clear the existing graph
clear();
- Node_factory factory;
+ Node_factory factory(id);
check_audio(root["audio"].asString(),media_path);
init(root["id"].asString());
Json::Value jnodes = root["nodes"];
@@ -58,24 +63,14 @@ bool Graph::parse_json(string &data,string &media_path){
Node* node=factory.create(jnodes[i]);
if (node) {
if (nodes.find(node_id)==nodes.end()){
- cerr << "Rotor: creating node '"<<node_id<<"': '"<<jnodes[i]["type"].asString()<< "'" << endl;
- //kind of have to do the links from outside thus
- //how do deal with variable arrays?
- //
- //on our left.. an array of pointers to variables..
- //some of which contain arrays of pointers to variables
- //
- //on our right.. an unordered map of nodes to be linked to
- //
- //node.create_links(nodes)
- //will allow the nodes to be passed into each member of a variable array
+ logger.information("Creating node '"+node_id+"'': '"+jnodes[i]["type"].asString()+"'");
node->create_connections(nodes);
nodes[node_id]=node;
}
- else cerr << "ERROR: duplicate node '"<<node_id<<"' "<< endl;
+ else logger.error("ERROR: duplicate node '"+node_id+"' ");
}
else {
- cerr << "ERROR: graph loader cannot find node '" <<jnodes[i]["type"].asString()<< "'" << endl;
+ logger.error("ERROR: graph loader cannot find node '"+jnodes[i]["type"].asString()+"'");
return false;
}
}