From e598cb4322671dad03b97d8de6d4fd1c1a9cc61d Mon Sep 17 00:00:00 2001 From: heck Date: Sun, 11 Jul 2021 01:42:20 +0200 Subject: [PATCH] Test: PityTest - PityPerspective group and peer handling --- src/PityPerspective.cc | 37 ++++++++++++++++++++++++++++++++++++- src/PityPerspective.hh | 23 +++++++++++++++++++---- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/PityPerspective.cc b/src/PityPerspective.cc index 404aa83..2a27ccf 100644 --- a/src/PityPerspective.cc +++ b/src/PityPerspective.cc @@ -5,9 +5,44 @@ namespace pEp { namespace PityTest11 { bool PityPerspective::debug_log_enabled = false; - PityPerspective::PityPerspective(const PityModel& model) : model{ model } + PityPerspective::PityPerspective(const PityModel& model) : model{ model }, peerNrAsCpt{ 0 } { pEpLogClass("called"); } + + TestIdent* PityPerspective::getPeer(const std::string& addr) + { + for (int i = 0; i < peers.size(); i++) { + if (peers.at(i).addr == addr) { + return &peers.at(i); + } + } + throw std::invalid_argument("getPeer(+" + addr + ") - not found"); + } + + void PityPerspective::setPeerNrAsCpt(int nr) + { + if (nr < peers.size()) { + peerNrAsCpt = nr; + } else { + throw std::invalid_argument("setPeerNrAsCpt(" + std::to_string(nr) + ") - out of range"); + } + } + + TestIdent& PityPerspective::getCpt() + { + return peers.at(peerNrAsCpt); + } + + Group* PityPerspective::getGroup(const std::string& addr) + { + for (int i = 0; i < groups.size(); i++) { + if (groups.at(i).addr == addr) { + return &groups.at(i); + } + } + throw std::invalid_argument("getGroup(" + addr + ") - not found"); + } + } // namespace PityTest11 } // namespace pEp diff --git a/src/PityPerspective.hh b/src/PityPerspective.hh index cd1db1f..70b09a3 100644 --- a/src/PityPerspective.hh +++ b/src/PityPerspective.hh @@ -7,9 +7,19 @@ #include "../../../src/pEpLog.hh" #include "../../framework/utils.hh" #include "PityModel.hh" +#include namespace pEp { namespace PityTest11 { + + // Group + struct Group { + std::string addr; + std::string moderator; + std::vector members; + + }; + class PityPerspective { public: // Constructors @@ -18,16 +28,20 @@ namespace pEp { // Lets grant access to the whole model too const PityModel& model; + TestIdent* getPeer(const std::string& addr); // Perspective std::string own_name; - std::string cpt_name; - std::vector peers; +// TestIdent* cpt = nullptr; + void setPeerNrAsCpt(int nr); + TestIdent& getCpt(); + std::vector peers; Test::Utils::pEpIdent own_ident; - Test::Utils::pEpIdent cpt_ident; +// Test::Utils::pEpIdent cpt_ident; // Groups - std::vector own_groups; + Group* getGroup(const std::string& addr); + std::vector groups; //Callbacks //internal logging @@ -35,6 +49,7 @@ namespace pEp { Adapter::pEpLog::pEpLogger logger_debug{ "PityNode", debug_log_enabled }; private: + int peerNrAsCpt; //internal logging Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger_debug; };