Added connection assertion and moved msgPrintControl to key

This commit is contained in:
2025-04-25 15:54:41 +02:00
parent c7936191d9
commit dd0610fd99
5 changed files with 72 additions and 21 deletions

View File

@@ -2,11 +2,13 @@
#include <unordered_map>
msgPrintControlKey::msgPrintControlKey(char *controller, int axisNo,
const char *functionName, int line) {
const char *functionName, int line,
size_t maxRepetitions) {
controller_ = controller;
axisNo_ = axisNo;
line_ = line;
functionName_ = functionName;
maxRepetitions_ = maxRepetitions;
}
void msgPrintControlKey::format(char *buffer, size_t bufferSize) {
@@ -16,10 +18,6 @@ void msgPrintControlKey::format(char *buffer, size_t bufferSize) {
// =============================================================================
msgPrintControl::msgPrintControl(size_t maxRepetitions) {
maxRepetitions_ = maxRepetitions;
}
bool msgPrintControl::shouldBePrinted(msgPrintControlKey &key, bool wantToPrint,
asynUser *pasynUser) {
@@ -34,12 +32,12 @@ bool msgPrintControl::shouldBePrinted(msgPrintControlKey &key, bool wantToPrint,
*/
if (map_.find(key) != map_.end()) {
size_t repetitions = map_[key];
if (repetitions < maxRepetitions_) {
if (repetitions < key.maxRepetitions_) {
// Number of allowed repetitions not exceeded -> Printing the
// message is ok.
map_[key] = repetitions + 1;
return true;
} else if (repetitions == maxRepetitions_) {
} else if (repetitions == key.maxRepetitions_) {
// Reached number of allowed repetitions -> Printing the message
// is ok, but further trys are rejected.
char formattedKey[100] = {0};
@@ -88,7 +86,8 @@ bool msgPrintControl::shouldBePrinted(msgPrintControlKey &key, bool wantToPrint,
bool msgPrintControl::shouldBePrinted(char *portName, int axisNo,
const char *functionName, int line,
bool wantToPrint, asynUser *pasynUser) {
bool wantToPrint, asynUser *pasynUser,
size_t maxRepetitions) {
msgPrintControlKey key =
msgPrintControlKey(portName, axisNo, functionName, __LINE__);
return shouldBePrinted(key, wantToPrint, pasynUser);