Browse Source

Tests: PityTest - cleanup model/node/persp and eliminate forward decls

master
heck 1 year ago
parent
commit
d9ba519870
6 changed files with 8 additions and 119 deletions
  1. +1
    -86
      src/PityModel.cc
  2. +0
    -19
      src/PityModel.hh
  3. +0
    -6
      src/PityNode.cc
  4. +0
    -4
      src/PityNode.hh
  5. +2
    -3
      src/PityPerspective.cc
  6. +5
    -1
      src/PityPerspective.hh

+ 1
- 86
src/PityModel.cc View File

@ -1,9 +1,6 @@
#include "PityModel.hh"
//#include "PityUnit.hh"
#include "iostream"
#include "../../../src/std_utils.hh"
#include "PityNode.hh"
#include <random>
#include <fstream>
#include <memory>
namespace pEp {
@ -22,96 +19,14 @@ namespace pEp {
return _name;
}
// void PityModel::setName(std::string name)
// {
// _name = name;
// }
std::vector<std::shared_ptr<PityNode>> PityModel::nodes() const
{
return _nodes;
}
// PityUnit<PityModel>* 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

+ 0
- 19
src/PityModel.hh View File

@ -6,17 +6,12 @@
#include "../../../src/pEpLog.hh"
#include "PityNode.hh"
#include "PityUnit.hh"
#include <vector>
#include <memory>
// 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<std::shared_ptr<PityNode>> nodes() const;
// PityUnit<PityModel>& unit();
// PityUnit<PityModel>* 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 };


+ 0
- 6
src/PityNode.cc View File

@ -1,13 +1,7 @@
#include "PityModel.hh"
#include "PityNode.hh"
#include "PityUnit.hh"
#include "PityPerspective.hh"
#include "iostream"
#include <memory>
#include <functional>
#include <sstream>
namespace pEp {
namespace PityTest11 {
bool PityNode::debug_log_enabled = false;


+ 0
- 4
src/PityNode.hh View File

@ -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


+ 2
- 3
src/PityPerspective.cc View File

@ -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

+ 5
- 1
src/PityPerspective.hh View File

@ -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;


Loading…
Cancel
Save