From a5a55692c864ab7b91c00b03013a7a58f690ff27 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 10 Jun 2021 21:47:47 +0200 Subject: [PATCH] Tests: PityTest - cleanup model/node/persp and eliminate forward decls --- test/pitytest11/src/PityModel.cc | 87 +------------------------- test/pitytest11/src/PityModel.hh | 19 ------ test/pitytest11/src/PityNode.cc | 6 -- test/pitytest11/src/PityNode.hh | 4 -- test/pitytest11/src/PityPerspective.cc | 5 +- test/pitytest11/src/PityPerspective.hh | 6 +- 6 files changed, 8 insertions(+), 119 deletions(-) diff --git a/test/pitytest11/src/PityModel.cc b/test/pitytest11/src/PityModel.cc index e6ddaf8..8855a77 100644 --- a/test/pitytest11/src/PityModel.cc +++ b/test/pitytest11/src/PityModel.cc @@ -1,9 +1,6 @@ #include "PityModel.hh" -//#include "PityUnit.hh" -#include "iostream" -#include "../../../src/std_utils.hh" +#include "PityNode.hh" #include -#include #include namespace pEp { @@ -22,96 +19,14 @@ namespace pEp { return _name; } -// void PityModel::setName(std::string name) -// { -// _name = name; -// } - std::vector> PityModel::nodes() const { return _nodes; } - // PityUnit* PityModel::unitOfNodeNr(int nr) const - // { - // return nodes().at(nr)->unit().get(); - // } - PityNode* PityModel::nodeNr(int nr) const { return nodes().at(nr).get(); } - - - // void PityModel::sendMsg(const std::string nodename, const std::string& msg) const - // { - // pEpLogClass("Address: " + nodename + " msg: " + msg); - // bool found = false; - // for (auto n : _nodes) { - // if (n->getName() == nodename) { - // found = true; - // Utils::dir_ensure(n->inboxDir()); - // std::stringstream filename; - // // collision detect - // do { - // filename << n->inboxDir() << Utils::random_string(97, 122, 16) << ".pitymsg"; - // } while (Utils::path_exists(filename.str())); - // std::ofstream msgfile = Utils::file_create(filename.str()); - // msgfile << msg; - // } - // } - // if (!found) { - // throw std::runtime_error("no such nodename: " + nodename); - // } - // } - // - // bool PityModel::hasMsg() const{ - // bool ret = false; - // pEpLogClass("called"); - // Utils::dir_ensure(own_node->inboxDir()); - // auto msg_filenames = Utils::dir_list_files(own_node->inboxDir()); - // ret = msg_filenames.size() > 0; - // return ret; - // } - // - // // Non-blocking - // // throws underflow_error if inbox empty - // std::string PityModel::pollMsg() const - // { - // pEpLogClass("called"); - // std::string ret; - // Utils::dir_ensure(own_node->inboxDir()); - // auto msg_filenames = Utils::dir_list_files(own_node->inboxDir()); - // if (!msg_filenames.empty()) { - // std::string msg_filename = msg_filenames.at(0); - // std::string msg_path = own_node->inboxDir() + "/" + msg_filename; - // pEpLogClass("Reading file: " + msg_filename); - // ret = Utils::file_read(msg_path); - // Utils::path_delete(msg_path); - // } else { - // throw std::underflow_error("inbox empty: " + own_node->inboxDir()); - // } - // - // return ret; - // } - // - // std::string PityModel::receiveMsg(int timeout_msec) const - // { - // pEpLogClass("called"); - // std::string ret; - // bool retry = false; - // do { - // try { - // ret = pollMsg(); - // retry = false; - // } catch (const std::underflow_error&) { - // pEpLogClass("polling again in [ms]: " + std::to_string(timeout_msec) + "..."); - // Utils::sleep_millis(timeout_msec); - // retry = true; - // } - // } while (retry); - // return ret; - // } - } // namespace PityTest11 } // namespace pEp diff --git a/test/pitytest11/src/PityModel.hh b/test/pitytest11/src/PityModel.hh index 07929b7..aa38dfc 100644 --- a/test/pitytest11/src/PityModel.hh +++ b/test/pitytest11/src/PityModel.hh @@ -6,17 +6,12 @@ #include "../../../src/pEpLog.hh" #include "PityNode.hh" -#include "PityUnit.hh" #include #include // The Model currently is as follows: // The Model creates the TestTree using PityUnits. // When creating the model you specify how many nodes you want -// The Model has a PityUnit rootUnit. -// The Model then creates a list of PityNodes, each containing a PityUnit connected to the rootUnit -// The PityNode, when run will modify the model to represent the perspective of the respective node nr. -// The perspective currently is complete by specifying a node, since there is a 1-1 node/ident relationship currently // // ATTENTION - TODO: // Currently there is a strict 1-1 relationship of nodes and identities. @@ -38,22 +33,8 @@ namespace pEp { // Getters std::string getName() const; std::vector> nodes() const; -// PityUnit& unit(); -// PityUnit* unitOfNodeNr(int nr) const; PityNode* nodeNr(int nr) const; - // Setter - void setName(std::string name); - - // Perspective - PityNode* own_node = nullptr; - - //Transport -// bool hasMsg() const; -// void sendMsg(const std::string nodename, const std::string& msg) const; -// std::string pollMsg() const; -// std::string receiveMsg(int timeout_msec = 100) const; - //internal logging static bool debug_log_enabled; Adapter::pEpLog::pEpLogger logger_debug{ "PityModel", debug_log_enabled }; diff --git a/test/pitytest11/src/PityNode.cc b/test/pitytest11/src/PityNode.cc index 1a29dae..62dfb2b 100644 --- a/test/pitytest11/src/PityNode.cc +++ b/test/pitytest11/src/PityNode.cc @@ -1,13 +1,7 @@ -#include "PityModel.hh" #include "PityNode.hh" -#include "PityUnit.hh" -#include "PityPerspective.hh" -#include "iostream" #include -#include #include - namespace pEp { namespace PityTest11 { bool PityNode::debug_log_enabled = false; diff --git a/test/pitytest11/src/PityNode.hh b/test/pitytest11/src/PityNode.hh index ef5db16..1d099fb 100644 --- a/test/pitytest11/src/PityNode.hh +++ b/test/pitytest11/src/PityNode.hh @@ -5,13 +5,9 @@ #define PITYTEST_PITYNODE_HH #include "../../../src/pEpLog.hh" -#include "PityUnit.hh" -#include "PityModel.hh" -#include "PityPerspective.hh" namespace pEp { namespace PityTest11 { - class PityModel; class PityNode { public: // Constructors diff --git a/test/pitytest11/src/PityPerspective.cc b/test/pitytest11/src/PityPerspective.cc index 8ee6821..fc2ff4c 100644 --- a/test/pitytest11/src/PityPerspective.cc +++ b/test/pitytest11/src/PityPerspective.cc @@ -1,14 +1,13 @@ #include "PityPerspective.hh" +#include "PityModel.hh" namespace pEp { namespace PityTest11 { bool PityPerspective::debug_log_enabled = false; - PityPerspective::PityPerspective() + PityPerspective::PityPerspective(PityModel& model) : model{ model } { pEpLogClass("called"); - - } } // namespace PityTest11 } // namespace pEp diff --git a/test/pitytest11/src/PityPerspective.hh b/test/pitytest11/src/PityPerspective.hh index 02ae469..2e4f445 100644 --- a/test/pitytest11/src/PityPerspective.hh +++ b/test/pitytest11/src/PityPerspective.hh @@ -5,13 +5,17 @@ #define PITYTEST_PITYPERSPECTIVE_HH #include "../../../src/pEpLog.hh" +#include "PityModel.hh" namespace pEp { namespace PityTest11 { class PityPerspective { public: // Constructors - PityPerspective(); + PityPerspective(PityModel& model); + + // Lets grant access to the whole model too + PityModel& model; // Perspective std::string name;