|
|
|
@ -14,33 +14,34 @@
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <exception>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
//using namespace pEp::Adapter::pEpLog;
|
|
|
|
|
|
|
|
|
|
namespace pEp {
|
|
|
|
|
namespace PityTest11 {
|
|
|
|
|
// static
|
|
|
|
|
template<class T>
|
|
|
|
|
std::string PityUnit<T>::_global_root_dir = "./pitytest_data/";
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
std::string PityUnit<T, P>::_global_root_dir = "./pitytest_data/";
|
|
|
|
|
// static
|
|
|
|
|
template<class T>
|
|
|
|
|
bool PityUnit<T>::debug_log_enabled = false;
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
bool PityUnit<T, P>::debug_log_enabled = false;
|
|
|
|
|
// static
|
|
|
|
|
template<class T>
|
|
|
|
|
int PityUnit<T>::procUnitsCount = 0;
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
int PityUnit<T, P>::procUnitsCount = 0;
|
|
|
|
|
|
|
|
|
|
// CONSTRUCTOR
|
|
|
|
|
template<class T>
|
|
|
|
|
PityUnit<T>::PityUnit(
|
|
|
|
|
PityUnit<T>* const parent,
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
PityUnit<T, P>::PityUnit(
|
|
|
|
|
PityUnit<>* const parent,
|
|
|
|
|
const std::string& name,
|
|
|
|
|
const std::function<void(const PityUnit&)> test_func,
|
|
|
|
|
const std::function<void(PityUnit&, T*, P*)> test_func,
|
|
|
|
|
T* model,
|
|
|
|
|
P* perspective,
|
|
|
|
|
ExecutionMode exec_mode) :
|
|
|
|
|
_parent{ parent },
|
|
|
|
|
_model{ model }, _name{ _normalizeName(name) }, _test_func{ test_func }, _exec_mode{
|
|
|
|
|
exec_mode
|
|
|
|
|
}
|
|
|
|
|
_model{ model }, _perspective{ perspective }, _name{ _normalizeName(name) },
|
|
|
|
|
_test_func{ test_func }, _exec_mode{ exec_mode }
|
|
|
|
|
{
|
|
|
|
|
logger_debug.set_instancename(getPath());
|
|
|
|
|
if (!_isRootUnit()) {
|
|
|
|
@ -49,6 +50,7 @@ namespace pEp {
|
|
|
|
|
procUnitNr = _parent->procUnitNr;
|
|
|
|
|
//Or update if procUnit
|
|
|
|
|
if (_isProcessUnit()) {
|
|
|
|
|
createTransport();
|
|
|
|
|
procUnitsCount++;
|
|
|
|
|
procUnitNr = procUnitsCount;
|
|
|
|
|
}
|
|
|
|
@ -57,14 +59,14 @@ namespace pEp {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
std::string PityUnit<T>::getName() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
std::string PityUnit<T, P>::getName() const
|
|
|
|
|
{
|
|
|
|
|
return _name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
std::string PityUnit<T>::getPath() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
std::string PityUnit<T, P>::getPath() const
|
|
|
|
|
{
|
|
|
|
|
std::string ret;
|
|
|
|
|
|
|
|
|
@ -81,8 +83,8 @@ namespace pEp {
|
|
|
|
|
// ProcessUnit - ".../<proc>"
|
|
|
|
|
// When Process as dir. parent - ".../<proc>/name"
|
|
|
|
|
// When no process as dir. parent - ".../<proc>/.../name"
|
|
|
|
|
template<class T>
|
|
|
|
|
std::string PityUnit<T>::getPathShort() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
std::string PityUnit<T, P>::getPathShort() const
|
|
|
|
|
{
|
|
|
|
|
std::string ret;
|
|
|
|
|
if (_isRootUnit()) {
|
|
|
|
@ -101,34 +103,18 @@ namespace pEp {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Inherited (if null see parent recursively)
|
|
|
|
|
template<class T>
|
|
|
|
|
T* PityUnit<T>::getModel() const
|
|
|
|
|
{
|
|
|
|
|
pEpLogClass("called");
|
|
|
|
|
T* ret = nullptr;
|
|
|
|
|
|
|
|
|
|
if (_model != nullptr) {
|
|
|
|
|
ret = _model;
|
|
|
|
|
} else {
|
|
|
|
|
if (!_isRootUnit()) {
|
|
|
|
|
ret = _parent->getModel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Every RootUnit has its own dir
|
|
|
|
|
template<class T>
|
|
|
|
|
std::string PityUnit<T>::_rootUnitDir() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
std::string PityUnit<T, P>::_rootUnitDir()
|
|
|
|
|
{
|
|
|
|
|
return getGlobalRootDir() + _rootUnit().getName() + "/";
|
|
|
|
|
return getGlobalRootDir() + _rootUnit()->getName() + "/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Every process has its own dir inside its rootUnitDir
|
|
|
|
|
// All other units inherit processDir from their Root/ProcessUnit
|
|
|
|
|
template<class T>
|
|
|
|
|
std::string PityUnit<T>::processDir() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
std::string PityUnit<T, P>::processDir()
|
|
|
|
|
{
|
|
|
|
|
if (_isRootUnit()) {
|
|
|
|
|
return _rootUnitDir();
|
|
|
|
@ -141,28 +127,44 @@ namespace pEp {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// template<class T>
|
|
|
|
|
// void PityUnit<T>::setExecutionMode(ExecutionMode mode)
|
|
|
|
|
// Every process has its own dir inside its rootUnitDir
|
|
|
|
|
// All other units inherit transportDir from their Root/ProcessUnit
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
std::string PityUnit<T, P>::transportDir()
|
|
|
|
|
{
|
|
|
|
|
if (_isRootUnit()) {
|
|
|
|
|
throw std::runtime_error("No transport dir");
|
|
|
|
|
} else {
|
|
|
|
|
if (_isProcessUnit()) {
|
|
|
|
|
return processDir() + "inbox/";
|
|
|
|
|
} else {
|
|
|
|
|
return _parent->transportDir();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// template<class T, class P>
|
|
|
|
|
// void PityUnit<T, P>::setExecutionMode(ExecutionMode mode)
|
|
|
|
|
// {
|
|
|
|
|
// _exec_mode = mode;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::setGlobalRootDir(const std::string& dir)
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::setGlobalRootDir(const std::string& dir)
|
|
|
|
|
{
|
|
|
|
|
PityUnit<T>::_global_root_dir = dir;
|
|
|
|
|
PityUnit<T, P>::_global_root_dir = dir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
|
template<class T>
|
|
|
|
|
std::string PityUnit<T>::getGlobalRootDir()
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
std::string PityUnit<T, P>::getGlobalRootDir()
|
|
|
|
|
{
|
|
|
|
|
return PityUnit::_global_root_dir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::run()
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::run()
|
|
|
|
|
{
|
|
|
|
|
pEpLogClass("called");
|
|
|
|
|
_log_mutex = std::make_shared<fs_mutex>("fds");
|
|
|
|
@ -174,10 +176,10 @@ namespace pEp {
|
|
|
|
|
|
|
|
|
|
// Execute in fork and wait here until process ends
|
|
|
|
|
if (_exec_mode == ExecutionMode::PROCESS_SEQUENTIAL) { // fork
|
|
|
|
|
_executeInFork(std::bind(&PityUnit<T>::_run, this), true);
|
|
|
|
|
_executeInFork(std::bind(&PityUnit<T, P>::_run, this), true);
|
|
|
|
|
// Execute in fork and go on, wait for process execution in the end
|
|
|
|
|
} else if (_exec_mode == ExecutionMode::PROCESS_PARALLEL) {
|
|
|
|
|
_executeInFork(std::bind(&PityUnit<T>::_run, this), false);
|
|
|
|
|
_executeInFork(std::bind(&PityUnit<T, P>::_run, this), false);
|
|
|
|
|
// Execute as normal funciton
|
|
|
|
|
} else if (_exec_mode == ExecutionMode::FUNCTION) {
|
|
|
|
|
_run();
|
|
|
|
@ -192,8 +194,8 @@ namespace pEp {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
std::string PityUnit<T>::to_string(bool recursive, int indent) const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
std::string PityUnit<T, P>::to_string(bool recursive, int indent)
|
|
|
|
|
{
|
|
|
|
|
std::string ret;
|
|
|
|
|
std::stringstream builder;
|
|
|
|
@ -210,7 +212,7 @@ namespace pEp {
|
|
|
|
|
if (recursive) {
|
|
|
|
|
if (!_children.empty()) {
|
|
|
|
|
indent++;
|
|
|
|
|
for (const std::pair<std::string, const PityUnit<T>&> child : _children) {
|
|
|
|
|
for (const std::pair<std::string, PityUnit<T, P>&> child : _children) {
|
|
|
|
|
ret += child.second.to_string(true, indent);
|
|
|
|
|
}
|
|
|
|
|
indent--;
|
|
|
|
@ -219,8 +221,8 @@ namespace pEp {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
std::string PityUnit<T>::to_string(const ExecutionMode& emode)
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
std::string PityUnit<T, P>::to_string(const ExecutionMode& emode)
|
|
|
|
|
{
|
|
|
|
|
switch (emode) {
|
|
|
|
|
case ExecutionMode::FUNCTION:
|
|
|
|
@ -240,8 +242,36 @@ namespace pEp {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::log(const std::string& msg) const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::recreateDirsRecursively()
|
|
|
|
|
{
|
|
|
|
|
Utils::dir_recreate(processDir());
|
|
|
|
|
if (!_children.empty()) {
|
|
|
|
|
for (const std::pair<std::string, PityUnit<T, P>&> child : _children) {
|
|
|
|
|
child.second.recreateDirsRecursively();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::registerAsTransportEndpoint()
|
|
|
|
|
{
|
|
|
|
|
transportEndpoints().insert({ getName(), transportDir() });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
Endpoints& PityUnit<T, P>::transportEndpoints()
|
|
|
|
|
{
|
|
|
|
|
if (_isRootUnit()) {
|
|
|
|
|
return _transport_endpoints;
|
|
|
|
|
} else {
|
|
|
|
|
return _rootUnit()->transportEndpoints();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::log(const std::string& msg) const
|
|
|
|
|
{
|
|
|
|
|
std::stringstream builder;
|
|
|
|
|
builder << "[";
|
|
|
|
@ -255,28 +285,28 @@ namespace pEp {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::logH1(const std::string& msg) const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::logH1(const std::string& msg) const
|
|
|
|
|
{
|
|
|
|
|
Adapter::pEpLog::logH1(msg, _termColor());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::logH2(const std::string& msg) const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::logH2(const std::string& msg) const
|
|
|
|
|
{
|
|
|
|
|
Adapter::pEpLog::logH2(msg, _termColor());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::logH3(const std::string& msg) const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::logH3(const std::string& msg) const
|
|
|
|
|
{
|
|
|
|
|
Adapter::pEpLog::logH3(msg, _termColor());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// PRIVATE ---------------------------------------------------------------------------------
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::_init() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::_init()
|
|
|
|
|
{
|
|
|
|
|
logH1("PityTest Starting...");
|
|
|
|
|
logRaw("RootUnit: " + getPathShort());
|
|
|
|
@ -292,20 +322,20 @@ namespace pEp {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::_run() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::_run()
|
|
|
|
|
{
|
|
|
|
|
logH2(_status_string("STARTING"));
|
|
|
|
|
_runSelf();
|
|
|
|
|
_runChildren();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::_runSelf() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::_runSelf()
|
|
|
|
|
{
|
|
|
|
|
if (_test_func != nullptr) {
|
|
|
|
|
try {
|
|
|
|
|
_test_func(*this);
|
|
|
|
|
_test_func(*this, _getModel(), _getPerspective());
|
|
|
|
|
logH3(_status_string("\033[1m\033[32mSUCCESS" + Utils::to_termcol(_termColor())));
|
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
|
logRaw("reason: " + std::string(e.what()));
|
|
|
|
@ -316,18 +346,18 @@ namespace pEp {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::_runChildren() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::_runChildren() const
|
|
|
|
|
{
|
|
|
|
|
if (!_children.empty()) {
|
|
|
|
|
for (const std::pair<std::string, PityUnit<T>&> child : _children) {
|
|
|
|
|
for (const std::pair<std::string, PityUnit<T, P>&> child : _children) {
|
|
|
|
|
child.second.run();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::_executeInFork(std::function<void(void)> func, bool wait_child) const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::_executeInFork(std::function<void(void)> func, bool wait_child) const
|
|
|
|
|
{
|
|
|
|
|
pid_t pid;
|
|
|
|
|
pid = fork();
|
|
|
|
@ -342,8 +372,8 @@ namespace pEp {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::_waitChildProcesses() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::_waitChildProcesses() const
|
|
|
|
|
{
|
|
|
|
|
int status;
|
|
|
|
|
pid_t pid;
|
|
|
|
@ -354,14 +384,14 @@ namespace pEp {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::_addChildUnit(PityUnit<T>& unit)
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::_addChildUnit(PityUnit<T, P>& unit)
|
|
|
|
|
{
|
|
|
|
|
_children.insert(std::pair<std::string, PityUnit<T>&>(unit.getName(), unit));
|
|
|
|
|
_children.insert(std::pair<std::string, PityUnit<T, P>&>(unit.getName(), unit));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
bool PityUnit<T>::_isProcessUnit() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
bool PityUnit<T, P>::_isProcessUnit() const
|
|
|
|
|
{
|
|
|
|
|
bool ret = false;
|
|
|
|
|
if (_exec_mode == ExecutionMode::PROCESS_SEQUENTIAL ||
|
|
|
|
@ -371,8 +401,8 @@ namespace pEp {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
bool PityUnit<T>::_isRootUnit() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
bool PityUnit<T, P>::_isRootUnit() const
|
|
|
|
|
{
|
|
|
|
|
if (_parent == nullptr) {
|
|
|
|
|
return true;
|
|
|
|
@ -381,23 +411,23 @@ namespace pEp {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
const PityUnit<T>& PityUnit<T>::_rootUnit() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
PityUnit<T, P>* PityUnit<T, P>::_rootUnit()
|
|
|
|
|
{
|
|
|
|
|
const PityUnit<T>* ret = nullptr;
|
|
|
|
|
// const PityUnit<T, P>* ret = nullptr;
|
|
|
|
|
if (!_isRootUnit()) {
|
|
|
|
|
ret = &(_parent->_rootUnit());
|
|
|
|
|
return _parent->_rootUnit();
|
|
|
|
|
} else {
|
|
|
|
|
ret = this;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
assert(ret != nullptr);
|
|
|
|
|
// assert(ret != nullptr);
|
|
|
|
|
// cant be null because for createChildUnit() you need to provide a TestUnit& and
|
|
|
|
|
// the only other way is using createRootUnit() which has parent == nullptr
|
|
|
|
|
return *ret;
|
|
|
|
|
// return *ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
const PityUnit<T>& PityUnit<T>::_parentingProcessUnit() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
const PityUnit<T, P>& PityUnit<T, P>::_parentingProcessUnit() const
|
|
|
|
|
{
|
|
|
|
|
if (_isRootUnit() || _isProcessUnit()) {
|
|
|
|
|
return *this;
|
|
|
|
@ -406,9 +436,68 @@ namespace pEp {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Inherited (if null see parent recursively)
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
T* PityUnit<T, P>::_getModel() const
|
|
|
|
|
{
|
|
|
|
|
pEpLogClass("called");
|
|
|
|
|
T* ret = nullptr;
|
|
|
|
|
|
|
|
|
|
if (_model != nullptr) {
|
|
|
|
|
ret = _model;
|
|
|
|
|
} else {
|
|
|
|
|
if (!_isRootUnit()) {
|
|
|
|
|
ret = _parent->_getModel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Inherited (if null see parent recursively)
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
P* PityUnit<T, P>::_getPerspective() const
|
|
|
|
|
{
|
|
|
|
|
pEpLogClass("called");
|
|
|
|
|
P* ret = nullptr;
|
|
|
|
|
|
|
|
|
|
if (_perspective != nullptr) {
|
|
|
|
|
ret = _perspective;
|
|
|
|
|
} else {
|
|
|
|
|
if (!_isRootUnit()) {
|
|
|
|
|
ret = _parent->_getPerspective();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Inherited (if null see parent recursively)
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::createTransport()
|
|
|
|
|
{
|
|
|
|
|
registerAsTransportEndpoint();
|
|
|
|
|
_transport = std::shared_ptr<PityTransport>(transportDir(), transportEndpoints());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Inherited (if null see parent recursively)
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
PityTransport* PityUnit<T, P>::transport() const
|
|
|
|
|
{
|
|
|
|
|
pEpLogClass("called");
|
|
|
|
|
PityTransport* ret = nullptr;
|
|
|
|
|
|
|
|
|
|
if (_transport.get() != nullptr) {
|
|
|
|
|
ret = _transport.get();
|
|
|
|
|
} else {
|
|
|
|
|
if (!_isRootUnit()) {
|
|
|
|
|
ret = _parent->transport();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// name is alphanumeric only (everything else will be replaced by an underscore)
|
|
|
|
|
template<class T>
|
|
|
|
|
std::string PityUnit<T>::_normalizeName(std::string name) const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
std::string PityUnit<T, P>::_normalizeName(std::string name) const
|
|
|
|
|
{
|
|
|
|
|
replace_if(
|
|
|
|
|
name.begin(),
|
|
|
|
@ -419,8 +508,8 @@ namespace pEp {
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
std::string PityUnit<T>::_status_string(const std::string& msg) const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
std::string PityUnit<T, P>::_status_string(const std::string& msg) const
|
|
|
|
|
{
|
|
|
|
|
std::string ret;
|
|
|
|
|
ret = "[ " + to_string(_exec_mode) + ":" + std::to_string(getpid()) + " ] [ " +
|
|
|
|
@ -429,8 +518,8 @@ namespace pEp {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
Utils::Color PityUnit<T>::_colForProcUnitNr(int procUnitNr) const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
Utils::Color PityUnit<T, P>::_colForProcUnitNr(int procUnitNr) const
|
|
|
|
|
{
|
|
|
|
|
int nrColors = 7;
|
|
|
|
|
switch (procUnitNr % nrColors) {
|
|
|
|
@ -453,32 +542,20 @@ namespace pEp {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
Utils::Color PityUnit<T>::_termColor() const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
Utils::Color PityUnit<T, P>::_termColor() const
|
|
|
|
|
{
|
|
|
|
|
return _colForProcUnitNr(procUnitNr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::logRaw(const std::string& msg) const
|
|
|
|
|
template<class T, class P>
|
|
|
|
|
void PityUnit<T, P>::logRaw(const std::string& msg) const
|
|
|
|
|
{
|
|
|
|
|
_log_mutex->aquire();
|
|
|
|
|
Adapter::pEpLog::log(msg, _termColor());
|
|
|
|
|
_log_mutex->release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
void PityUnit<T>::recreateDirsRecursively() const
|
|
|
|
|
{
|
|
|
|
|
Utils::dir_recreate(processDir());
|
|
|
|
|
if (!_children.empty()) {
|
|
|
|
|
for (const std::pair<std::string, PityUnit<T>&> child : _children) {
|
|
|
|
|
child.second.recreateDirsRecursively();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace PityTest11
|
|
|
|
|
} // namespace pEp
|
|
|
|
|
|
|
|
|
|