diff --git a/test/pitytest11/src/PityModel.cc b/test/pitytest11/src/PityModel.cc index c42867c..01d6b8f 100644 --- a/test/pitytest11/src/PityModel.cc +++ b/test/pitytest11/src/PityModel.cc @@ -6,13 +6,12 @@ namespace pEp { namespace PityTest11 { bool PityModel::debug_log_enabled = true; - PityModel::PityModel(const std::string& name, int nodesCount) : - _name{ name }, _nodes_count{ nodesCount }, _root_unit{ nullptr, name, nullptr, this } + PityModel::PityModel(const std::string& name, int nodeCount) : + _name{ name }, _root_unit{ nullptr, name, nullptr, this } { - - for (int i = 0; i < nodesCount; i++) { - _nodes.emplace_back(PityNode(*this, i)); -// _nodes.emplace_back(*this, i); + for (int i = 0; i < nodeCount; i++) { + auto tmp = std::make_shared(*this, i); + _nodes.emplace_back(tmp); } } @@ -21,7 +20,12 @@ namespace pEp { return _name; } - std::vector PityModel::getNodes() const + void PityModel::setName(std::string name) + { + _name = name; + } + + std::vector> PityModel::getNodes() const { return _nodes; } @@ -31,5 +35,10 @@ namespace pEp { return _root_unit; } + PityUnit* PityModel::getNodeUnit(int nr) const + { + return getNodes().at(nr)->getProcessUnit().get(); + } + } // namespace PityTest11 } // namespace pEp diff --git a/test/pitytest11/src/PityModel.hh b/test/pitytest11/src/PityModel.hh index 590fe63..887ed6a 100644 --- a/test/pitytest11/src/PityModel.hh +++ b/test/pitytest11/src/PityModel.hh @@ -7,26 +7,30 @@ #include "../../../src/pEpLog.hh" #include "PityNode.hh" #include "PityUnit.hh" +#include +#include namespace pEp { namespace PityTest11 { class PityModel { public: PityModel() = delete; - PityModel(const std::string& name, int nodesCount); + PityModel(const std::string& name, int nodeCount); std::string getName() const; - std::vector getNodes() const; + void setName(std::string name) ; + std::vector> getNodes() const; PityUnit& rootUnit(); + PityUnit* getNodeUnit(int nr) const; + PityNode* own_node = nullptr; //internal logging static bool debug_log_enabled; Adapter::pEpLog::pEpLogger logger_debug{ "PityModel", debug_log_enabled }; private: - const int _nodes_count; PityUnit _root_unit; - std::vector _nodes; - const std::string _name; + std::vector> _nodes; + std::string _name; //internal logging Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger_debug; diff --git a/test/pitytest11/src/PityNode.cc b/test/pitytest11/src/PityNode.cc index d9e0fb1..7586e1b 100644 --- a/test/pitytest11/src/PityNode.cc +++ b/test/pitytest11/src/PityNode.cc @@ -3,21 +3,36 @@ #include "PityUnit.hh" #include "iostream" #include +#include +#include + namespace pEp { namespace PityTest11 { bool PityNode::debug_log_enabled = false; - PityNode::PityNode(PityModel& model, int nodeNr) : - _model{ model }, _node_nr{ nodeNr }, _process_unit{ - std::make_shared>( - &(_model.rootUnit()), - getName(), - nullptr, - nullptr, - PityUnit::ExecutionMode::PROCESS_PARALLEL) - } + PityNode::PityNode(PityModel& model, int nodeNr) : _node_nr{ nodeNr } + { + logger_debug.set_instancename(getName()); + std::stringstream ss{}; + ss << this; + pEpLogClass(std::string("called with: " + std::to_string(_node_nr) + "AT: " +ss.str())); + + _process_unit = std::make_shared>( + &(model.rootUnit()), + getName(), + std::bind(&PityNode::_init,this, std::placeholders::_1), + &model, + PityUnit::ExecutionMode::PROCESS_PARALLEL); + + } + + void PityNode::_init(const PityUnit& unit) { + unit.log("INIT - " + getName()); + unit.getModel()->own_node = this; + unit.getModel()->setName("Copy for:" + getName()); + unit.log("INIT DONE"); } std::string PityNode::getName() const diff --git a/test/pitytest11/src/PityNode.hh b/test/pitytest11/src/PityNode.hh index f349cf3..d00fc1e 100644 --- a/test/pitytest11/src/PityNode.hh +++ b/test/pitytest11/src/PityNode.hh @@ -17,19 +17,17 @@ namespace pEp { explicit PityNode(PityModel& model, int nodeNr); std::string getName() const; std::string to_string() const; + const std::shared_ptr>& getProcessUnit() const; //internal logging static bool debug_log_enabled; Adapter::pEpLog::pEpLogger logger_debug{ "PityNode", debug_log_enabled }; + private: + void _init(const PityUnit& unit); const int _node_nr; - PityModel& _model; std::shared_ptr> _process_unit; - public: - const std::shared_ptr>& getProcessUnit() const; - - private: //internal logging Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger_debug; }; diff --git a/test/pitytest11/test/test_model.cc b/test/pitytest11/test/test_model.cc index 1708101..f52c757 100644 --- a/test/pitytest11/test/test_model.cc +++ b/test/pitytest11/test/test_model.cc @@ -6,30 +6,33 @@ #include #include #include +#include using namespace std; using namespace pEp::Adapter; using namespace pEp::PityTest11; -void test_node1(const PityUnit& unit) { +void test_node1(const PityUnit& unit) +{ + unit.log(unit.getModel()->getName()); + unit.log(unit.getModel()->own_node->); } int main(int argc, char* argv[]) { - pEpLog::log("FSDFSD"); PityModel::debug_log_enabled = false; - PityNode::debug_log_enabled = false; - PityModel model{ "test_Model", 3 }; + PityNode::debug_log_enabled = true; + PityModel model{ "test_model", 3 }; - for (PityNode n : model.getNodes()) { - pEpLog::log(n.to_string()); + for (auto n : model.getNodes()) { + pEpLog::log(n->getName()); } - auto node1_unit = model.getNodes().at(0).getProcessUnit(); - PityUnit node1_test1 = PityUnit{ node1_unit.get(), "test1", nullptr }; -// model.getPerspective(0); + PityUnit node1_test1 = PityUnit{ model.getNodeUnit(0), "test1", &test_node1 }; + PityUnit node2_test1 = PityUnit{ model.getNodeUnit(1), "test2", &test_node1 }; + PityUnit node3_test1 = PityUnit{ model.getNodeUnit(2), "test3", &test_node1 }; model.rootUnit().run(); // pEpLog::log(model.rootUnit().to_string());