From 1f2bc21fd5ee9bff4fce190d7bb0ee4462e76e87 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 24 Jan 2014 17:00:22 +0000 Subject: logging in nodes and text_render proof of concept --- NT/src/rotor.h | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'NT/src/rotor.h') diff --git a/NT/src/rotor.h b/NT/src/rotor.h index 5023a95..4a9eb70 100644 --- a/NT/src/rotor.h +++ b/NT/src/rotor.h @@ -7,6 +7,8 @@ ROTORD rewrite TJR-Jan-2014 NB when plugging in to framework - convert all cerr messages to logged + +What next? */ #define ENABLE_TYPENAME(A) template<> struct TypeName { static const char *Get() { return #A; }}; @@ -119,14 +121,15 @@ namespace Rotor { virtual void init(Json::Value s)=0; virtual bool connect(Node* target)=0; virtual std::string get_type()=0; - virtual void create_connection(std::unordered_map &nodes)=0; + virtual bool create_connection(std::unordered_map &nodes)=0; bool is_connected(){ if (connection) return true; return false; } std::string get_connection_id(); - std::string name; + std::string get_name(); protected: + std::string name; Node* connection; bool connectable; std::string input; @@ -144,16 +147,13 @@ namespace Rotor { name=s["name"].asString(); input=s["input"].asString(); } - void create_connection(std::unordered_map &nodes){ + bool create_connection(std::unordered_map &nodes){ for (auto node:nodes){ if (node.first==input){ - if (connect(node.second)) { - if (connection) std::cerr<<"connected '"<::Get()<<"' input to '"<<(dynamic_cast*>(connection))->get_type()<<"' "<::Get()<<"'' input to '"< &nodes){ + bool create_connection(std::unordered_map &nodes){ + bool success=true; //for (auto v:values){ //weirdly does not work even though it seems to! maybe it returns a copy of of the object? // v.create_connection(nodes); //} - for (uint32_t i=0;i &nodes){ - for (auto var:vars) var.second->create_connection(nodes); + Logger& logger = Logger::get(log_id); + for (auto var:vars) { + if (var.second->create_connection(nodes)) { + logger.information("Connected input '"+var.second->get_name()+"' of node '"+id+"' to node "+var.second->get_connection_id()); + } + } } protected: std::unordered_map vars; @@ -281,6 +290,7 @@ namespace Rotor { std::string description; std::string title; std::string ui_type; + std::string log_id; }; template class Node_type : public Node { public: @@ -288,10 +298,12 @@ namespace Rotor { void init(Json::Value settings){ if (!settings["vars"].empty()){ for ( uint32_t i = 0; i < settings["vars"].size(); ++i ) { + if (!settings["id"].empty()) settings["vars"][i]["log_id"]=settings["log_id"].asString(); vars[settings["vars"][i]["name"].asString()]->init(settings["vars"][i]); } } if (!settings["id"].empty()) id=settings["id"].asString(); + if (!settings["log_id"].empty()) log_id=settings["log_id"].asString(); } std::string get_output_type(){return TypeName::Get();}; template Variable_type* create_inlet(std::string name){ -- cgit v1.2.3