Browse Source

Test: PityTest - Copy C'tor

master
heck 4 years ago
parent
commit
400989655b
  1. 47
      src/AbstractPityUnit.cc
  2. 17
      src/AbstractPityUnit.hh

47
src/AbstractPityUnit.cc

@ -23,10 +23,10 @@ namespace pEp {
// static // static
bool AbstractPityUnit::debug_log_enabled = false; bool AbstractPityUnit::debug_log_enabled = false;
// static // static
int AbstractPityUnit::procUnitsCount = 0; int AbstractPityUnit::_procUnitsCount = 0;
AbstractPityUnit::AbstractPityUnit(const std::string &name, ExecutionMode exec_mode) : AbstractPityUnit::AbstractPityUnit(const std::string &name, ExecutionMode exec_mode) :
PityTree<AbstractPityUnit>(*this, name), _exec_mode{ exec_mode }, procUnitNr{ 0 } PityTree<AbstractPityUnit>(*this, name), _exec_mode{ exec_mode }, _procUnitNr{ 0 }
{ {
_init(); _init();
} }
@ -36,12 +36,23 @@ namespace pEp {
const std::string &name, const std::string &name,
ExecutionMode exec_mode) : ExecutionMode exec_mode) :
PityTree<AbstractPityUnit>(*this, name, parent), PityTree<AbstractPityUnit>(*this, name, parent),
_exec_mode{ exec_mode }, procUnitNr{ 0 } _exec_mode{ exec_mode }, _procUnitNr{ 0 }
{ {
_init(); _init();
} }
void AbstractPityUnit::_init() { AbstractPityUnit::AbstractPityUnit(const AbstractPityUnit &rhs, AbstractPityUnit &self) :
PityTree<AbstractPityUnit>(rhs, self)
{
_procUnitNr = rhs._procUnitNr;
_exec_mode = rhs._exec_mode;
_transport = rhs._transport;
_transport_endpoints = rhs._transport_endpoints;
_init();
}
void AbstractPityUnit::_init()
{
_log_mutex = std::make_shared<fs_mutex>("log.mutex"); _log_mutex = std::make_shared<fs_mutex>("log.mutex");
_log_mutex->release(); _log_mutex->release();
} }
@ -123,18 +134,18 @@ namespace pEp {
{ {
if (!isRoot()) { if (!isRoot()) {
// Inherit // Inherit
procUnitNr = getParent()->procUnitNr; _procUnitNr = getParent()->_procUnitNr;
//Or update if procUnit //Or update if procUnit
if (_isProcessUnit()) { if (_isProcessUnit()) {
procUnitsCount++; _procUnitsCount++;
procUnitNr = procUnitsCount; _procUnitNr = _procUnitsCount;
} }
} else { } else {
procUnitNr = procUnitsCount; _procUnitNr = _procUnitsCount;
} }
// Recurse // Recurse
for (const auto &chld : getChildren()) { for (const auto &chld : getChildRefs()) {
chld.second._initProcUnitNrRecurse(); chld.second._initProcUnitNrRecurse();
} }
} }
@ -149,7 +160,7 @@ namespace pEp {
} }
// Recurse // Recurse
for (const auto &chld : getChildren()) { for (const auto &chld : getChildRefs()) {
chld.second._initTransportRecurse(); chld.second._initTransportRecurse();
} }
} }
@ -159,7 +170,7 @@ namespace pEp {
Utils::dir_recreate(processDir()); Utils::dir_recreate(processDir());
// Recurse // Recurse
for (const auto &child : getChildren()) { for (const auto &child : getChildRefs()) {
child.second._initDirsRecursive(); child.second._initDirsRecursive();
} }
} }
@ -186,8 +197,7 @@ namespace pEp {
_logRaw("\n\nTestTree"); _logRaw("\n\nTestTree");
_logRaw("--------"); _logRaw("--------");
_logRaw(to_string() + "\n"); _logRaw(to_string() + "\n");
_procUnitsCount = 0;
_initProcUnitNrRecurse(); _initProcUnitNrRecurse();
} }
@ -230,9 +240,9 @@ namespace pEp {
ret = builder.str(); ret = builder.str();
if (recursive) { if (recursive) {
if (!getChildren().empty()) { if (!getChildRefs().empty()) {
indent++; indent++;
for (const auto child : getChildren()) { for (const auto child : getChildRefs()) {
ret += child.second.to_string(true, indent); ret += child.second.to_string(true, indent);
} }
indent--; indent--;
@ -309,8 +319,8 @@ namespace pEp {
{ {
logH2(_status_string("STARTING")); logH2(_status_string("STARTING"));
_runSelf(); _runSelf();
if (!getChildren().empty()) { if (!getChildRefs().empty()) {
for (const auto child : getChildren()) { for (const auto child : getChildRefs()) {
child.second.run(false); child.second.run(false);
} }
} }
@ -427,7 +437,7 @@ namespace pEp {
Utils::Color AbstractPityUnit::_color() const Utils::Color AbstractPityUnit::_color() const
{ {
return _colForProcUnitNr(procUnitNr); return _colForProcUnitNr(_procUnitNr);
} }
void AbstractPityUnit::_logRaw(const std::string &msg) const void AbstractPityUnit::_logRaw(const std::string &msg) const
@ -438,5 +448,6 @@ namespace pEp {
_log_mutex->release(); _log_mutex->release();
} }
} // namespace PityTest11 } // namespace PityTest11
} // namespace pEp } // namespace pEp

17
src/AbstractPityUnit.hh

@ -31,12 +31,22 @@ namespace pEp {
INHERIT INHERIT
}; };
explicit AbstractPityUnit(const std::string& name, ExecutionMode exec_mode = ExecutionMode::FUNCTION); // RootNode
explicit AbstractPityUnit(
const std::string& name,
ExecutionMode exec_mode = ExecutionMode::FUNCTION);
// LeafNode
explicit AbstractPityUnit( explicit AbstractPityUnit(
AbstractPityUnit& parent, AbstractPityUnit& parent,
const std::string& name, const std::string& name,
ExecutionMode exec_mode = ExecutionMode::FUNCTION); ExecutionMode exec_mode = ExecutionMode::FUNCTION);
// Copy
explicit AbstractPityUnit(const AbstractPityUnit& rhs, AbstractPityUnit& self);
AbstractPityUnit* clone() override = 0;
// Read-Write // Read-Write
static void setGlobalRootDir(const std::string& dir); static void setGlobalRootDir(const std::string& dir);
static std::string getGlobalRootDir(); static std::string getGlobalRootDir();
@ -100,11 +110,12 @@ namespace pEp {
// Fields // Fields
// ------ // ------
static std::string _global_root_dir; static std::string _global_root_dir;
int procUnitNr; int _procUnitNr;
ExecutionMode _exec_mode; ExecutionMode _exec_mode;
static int procUnitsCount; // will be increased in every constructor static int _procUnitsCount; // will be increased in every constructor
// transport // transport
std::shared_ptr<PityTransport> _transport; //only ever read via transport() std::shared_ptr<PityTransport> _transport; //only ever read via transport()
// TODO move endpoints into PityTransport
Endpoints _transport_endpoints; // only ever access via transportEndpoints() Endpoints _transport_endpoints; // only ever access via transportEndpoints()
// fs-mutex to sync across processes // fs-mutex to sync across processes

Loading…
Cancel
Save