sync code

This commit is contained in:
Ned Wright
2024-09-17 10:53:09 +00:00
parent 3fe0b42fcd
commit 586150fe4f
143 changed files with 1886 additions and 380 deletions

View File

@@ -32,7 +32,14 @@ public:
}
operator const T *() const { return ptr; }
const T & operator*() const { dbgAssert(ptr != nullptr) << "Accessing a moved pointer"; return *ptr; }
const T &
operator*() const
{
dbgAssert(ptr != nullptr) << AlertInfo(AlertTeam::CORE, "buffer i/s") << "Accessing a moved pointer";
return *ptr;
}
const T * operator->() const { return ptr; }
private:

View File

@@ -36,6 +36,58 @@ class I_SignalHandler;
namespace Config { enum class Errors; }
std::ostream & operator<<(std::ostream &, const Config::Errors &);
enum class AlertTeam { CORE, WAAP, SDWAN, IOT };
class AlertInfo
{
public:
template <typename ... Args>
AlertInfo(AlertTeam _team, const std::string &func, const Args & ... args) : team(_team), functionality(func)
{
evalParams(args ...);
}
template <typename ... Args>
AlertInfo
operator()(const Args & ... args) const
{
AlertInfo res = *this;
res.evalParams(args ...);
return res;
}
AlertTeam getTeam() const { return team; }
const std::string & getFunctionality() const { return functionality; }
const std::string & getDescription() const { return description; }
std::size_t getId() const { return id; }
std::size_t getFamilyId() const { return family_id; }
private:
template <typename ... Args>
void
evalParams(const std::string &_description, const Args & ... args)
{
description = _description;
evalParams(args ...);
}
template <typename ... Args>
void
evalParams(const std::size_t &fam_id, const Args & ... args)
{
family_id = fam_id;
evalParams(args ...);
}
void evalParams();
AlertTeam team;
std::string functionality;
std::size_t id;
std::size_t family_id = 0;
std::string description;
};
class Debug
:
Singleton::Consume<I_TimeGet>,
@@ -93,6 +145,8 @@ public:
std::set<std::ostream *> streams;
};
class DebugAlert;
class DebugLockState
{
private:
@@ -208,6 +262,7 @@ private:
);
void isCommunicationFlag(const DebugFlags &flag);
void sendAlert(const AlertInfo &alert);
static DebugLevel lowest_global_level;
static I_TimeGet *time;
@@ -225,6 +280,34 @@ private:
std::set<std::shared_ptr<DebugStream>> current_active_streams;
};
class Debug::DebugAlert
{
class DebugAlertImpl
{
public:
DebugAlertImpl(Debug &_debug) : debug(_debug) {}
DebugStreamAggr &
operator<<(const AlertInfo &alert) __attribute__((warn_unused_result))
{
debug.sendAlert(alert);
return debug.getStreamAggr();
}
private:
Debug &debug;
};
public:
template <typename ... Args> DebugAlert(const Args & ... args) : debug(args...) {}
DebugAlertImpl getStreamAggr() __attribute__((warn_unused_result)) { return DebugAlertImpl(debug); }
private:
Debug debug;
};
#define USE_DEBUG_FLAG(x) extern const Debug::DebugFlags x
// This function extract the base name from a full path.
@@ -245,7 +328,7 @@ getBaseName(const char *iter, const char *base)
#define dbgAssert(cond) \
if (CP_LIKELY(cond)) { \
} else Debug(__FILENAME__, __FUNCTION__, __LINE__).getStreamAggr()
} else Debug::DebugAlert(__FILENAME__, __FUNCTION__, __LINE__).getStreamAggr()
// Macros to allow simple debug messaging
#define DBG_GENERIC(level, ...) \

View File

@@ -320,7 +320,7 @@ template <typename T, typename TErr>
const T &
Maybe<T, TErr>::unpack() const
{
dbgAssert(set) << "Maybe value is not set";
dbgAssert(set) << AlertInfo(AlertTeam::CORE, "maybe i/s") << "Maybe value is not set";
return val;
}
@@ -328,7 +328,7 @@ template <typename T, typename TErr>
T &&
Maybe<T, TErr>::unpackMove()
{
dbgAssert(set) << "No value to be moved";
dbgAssert(set) << AlertInfo(AlertTeam::CORE, "maybe i/s") << "No value to be moved";
return std::move(val);
}
@@ -336,7 +336,7 @@ template <typename T, typename TErr>
TErr
Maybe<T, TErr>::getErr() const
{
dbgAssert(!set) << "Maybe value is set";
dbgAssert(!set) << AlertInfo(AlertTeam::CORE, "maybe i/s") << "Maybe value is set";
return err.err;
}
@@ -344,7 +344,7 @@ template <typename T, typename TErr>
const Error<TErr> &
Maybe<T, TErr>::passErr() const
{
dbgAssert(!set) << "Maybe value is set";
dbgAssert(!set) << AlertInfo(AlertTeam::CORE, "maybe i/s") << "Maybe value is set";
return err;
}

View File

@@ -110,7 +110,9 @@ template <typename Key>
const Key &
Table<Key>::Impl::ExpList::getEarliest() const
{
dbgAssert(!list.empty()) << "Cannot access the earliest member of an empty list";
dbgAssert(!list.empty())
<< AlertInfo(AlertTeam::CORE, "table")
<< "Cannot access the earliest member of an empty list";
return list.back().getKey();
}