Skip to content

Commit

Permalink
Change the controls of both logging and operational streams to be loc…
Browse files Browse the repository at this point in the history
…al static in functions
  • Loading branch information
VeithMetro committed Jan 15, 2025
1 parent 007ebe3 commit 61b7aac
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 52 deletions.
29 changes: 21 additions & 8 deletions Source/messaging/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,27 @@ namespace Thunder {

namespace Logging {

// Announce upfront all SYSLOG categories...
SYSLOG_ANNOUNCE(Crash);
SYSLOG_ANNOUNCE(Startup);
SYSLOG_ANNOUNCE(Shutdown);
SYSLOG_ANNOUNCE(Fatal);
SYSLOG_ANNOUNCE(Error);
SYSLOG_ANNOUNCE(ParsingError);
SYSLOG_ANNOUNCE(Notification);
// -----------------------------------------------------------------
// REGISTRATION
// -----------------------------------------------------------------

namespace {

static class Instantiation {
public:
Instantiation()
{
SYSLOG_ANNOUNCE(Crash)
SYSLOG_ANNOUNCE(Startup)
SYSLOG_ANNOUNCE(Shutdown)
SYSLOG_ANNOUNCE(Fatal)
SYSLOG_ANNOUNCE(Error)
SYSLOG_ANNOUNCE(ParsingError)
SYSLOG_ANNOUNCE(Notification)
}
} ControlsRegistration;

}

static const TCHAR* UnknownCallsign = {_T("NoTLSCallsign") };

Expand Down
31 changes: 12 additions & 19 deletions Source/messaging/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,39 +49,32 @@ namespace Logging {
IsEnabled();
}

static Control& Instance() {
static Control control(true);
return (control);
}

inline static bool IsEnabled() {
return (_control.IsEnabled());
return (Instance().IsEnabled());
}

inline static void Enable(const bool enable) {
_control.Enable(enable);
Instance().Enable(enable);
}

inline static const Core::Messaging::Metadata& Metadata() {
return (_control.Metadata());
return (Instance().Metadata());
}

private:
static Control _control;
};

} // namespace Logging
}

#ifdef __WINDOWS__

#define DEFINE_LOGGING_CATEGORY(CATEGORY) DEFINE_MESSAGING_CATEGORY(Thunder::Logging::BaseLoggingType<CATEGORY>, CATEGORY)

#else

#define DEFINE_LOGGING_CATEGORY(CATEGORY) \
DEFINE_MESSAGING_CATEGORY(Thunder::Logging::BaseLoggingType<CATEGORY>, CATEGORY) \
template<> \
EXTERNAL typename Thunder::Logging::BaseLoggingType<CATEGORY>::Control Thunder::Logging::BaseLoggingType<CATEGORY>::_control;

#endif
#define DEFINE_LOGGING_CATEGORY(CATEGORY) \
DEFINE_MESSAGING_CATEGORY(Thunder::Logging::BaseLoggingType<CATEGORY>, CATEGORY)

#define SYSLOG_ANNOUNCE(CATEGORY) template<> Thunder::Logging::BaseLoggingType<CATEGORY>::Control Thunder::Logging::BaseLoggingType<CATEGORY>::_control(true)
#define SYSLOG_ANNOUNCE(CATEGORY) \
Thunder::Logging::BaseLoggingType<CATEGORY>::Instance();

#define SYSLOG(CATEGORY, PARAMETERS) \
do { \
Expand Down
19 changes: 16 additions & 3 deletions Source/messaging/OperationalCategories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,22 @@ namespace Thunder {

namespace OperationalStream {

// Announce upfront all OperationalStream categories...
OPERATIONAL_STREAM_ANNOUNCE(StandardOut);
OPERATIONAL_STREAM_ANNOUNCE(StandardError);
// -----------------------------------------------------------------
// REGISTRATION
// -----------------------------------------------------------------

namespace {

static class Instantiation {
public:
Instantiation()
{
OPERATIONAL_STREAM_ANNOUNCE(StandardOut)
OPERATIONAL_STREAM_ANNOUNCE(StandardError)
}
} ControlsRegistration;

}

}
}
33 changes: 11 additions & 22 deletions Source/messaging/OperationalCategories.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,11 @@
#include "Module.h"
#include "Control.h"

#ifdef __WINDOWS__

#define DEFINE_OPERATIONAL_CATEGORY(CATEGORY) \
#define DEFINE_OPERATIONAL_CATEGORY(CATEGORY) \
DEFINE_MESSAGING_CATEGORY(Thunder::OperationalStream::BaseOperationalType<CATEGORY>, CATEGORY)

#else

#define DEFINE_OPERATIONAL_CATEGORY(CATEGORY) \
DEFINE_MESSAGING_CATEGORY(Thunder::OperationalStream::BaseOperationalType<CATEGORY>, CATEGORY) \
template<> \
EXTERNAL typename Thunder::OperationalStream::BaseOperationalType<CATEGORY>::Control \
Thunder::OperationalStream::BaseOperationalType<CATEGORY>::_control;

#endif

#define OPERATIONAL_STREAM_ANNOUNCE(CATEGORY) \
template<> Thunder::OperationalStream::BaseOperationalType<CATEGORY>::Control \
Thunder::OperationalStream::BaseOperationalType<CATEGORY>::_control(true)
#define OPERATIONAL_STREAM_ANNOUNCE(CATEGORY) \
Thunder::OperationalStream::BaseOperationalType<CATEGORY>::Instance();

namespace Thunder {

Expand All @@ -64,20 +51,22 @@ namespace OperationalStream {
IsEnabled();
}

static Control& Instance() {
static Control control(true);
return (control);
}

inline static bool IsEnabled() {
return (_control.IsEnabled());
return (Instance().IsEnabled());
}

inline static void Enable(const bool enable) {
_control.Enable(enable);
Instance().Enable(enable);
}

inline static const Core::Messaging::Metadata& Metadata() {
return (_control.Metadata());
return (Instance().Metadata());
}

private:
static Control _control;
};

DEFINE_OPERATIONAL_CATEGORY(StandardOut)
Expand Down

0 comments on commit 61b7aac

Please sign in to comment.