xFE+kg*rC_sn}}eaYVo*?J*YFZ>$;!oOJ{
z{QCgB-)1FF4i?imzkPZz{4Rvr{h7I>sgUu{%LsSK%b0JUml0-1RnN;GSP!(-+jpO%JopO`B((dnpK-(&yRaUJ6F;
zchnE_k$Wv1f4{oG;*T$8Vx5|ss!Wf01@yO_$nuNBLZ4Gvb)Vu6x9f7RD3t3{RPFna
z@~=**zWfUs8kYPPZCSL4e)B1xT|TXnSM+U>y|{O?8%m4vtzIr_BVKg5vCP}`*3dR}
z&a!{N#n>%>kU18z!$Q_q$meQ#RW3=oZ=knFmg=8&V&`qOUg~p1N&lWwnpHmPb9YW3
zw+z)kIP(xwOMAJX5{|A*v__uZdtvV;w2rOkgeCCc1i
z#a5Q%Amc3IgIa3+fBIm(x&OWTs_~Un|HxNN{coH$#m{POUDev^Dy>e{FMhe1Y5iiu
zZ
+
+#endif // _WINDOWS
+
+#endif // AREG_LOGGER_RESOUR_TARGETVER_HPP
diff --git a/framework/observer/lib/LogObserverApi.h b/framework/observer/lib/LogObserverApi.h
index 83a1d147f..895ff2825 100644
--- a/framework/observer/lib/LogObserverApi.h
+++ b/framework/observer/lib/LogObserverApi.h
@@ -16,6 +16,9 @@
*
************************************************************************/
+/************************************************************************
+ * Include files.
+ ************************************************************************/
#include "observer/lib/LogObserverSwitches.h"
/**
@@ -62,15 +65,17 @@
struct sLogInstance
{
/* The type of the message source application. Either client, test or simulation */
- unsigned int liSource;
+ uint32_t liSource;
/* The bitness of the application, should be either 32 or 64 */
- unsigned int liBitness;
+ uint32_t liBitness;
/* The cookie ID of the connected client. */
- unsigned long long liCookie;
+ ITEM_ID liCookie;
+ /* The connection timestamp */
+ TIME64 liTimestamp;
/* The name of the connected application */
- char liName[LENGTH_NAME];
+ char liName[LENGTH_NAME];
/* The name of the file location. */
- char liLocation[LENGTH_LOCATION];
+ char liLocation[LENGTH_LOCATION];
};
/**
@@ -115,11 +120,11 @@ enum eLogPriority
struct sLogScope
{
/* The ID of the scope. Can be 0 if unknown or if indicates to scope group. */
- unsigned int lsId;
+ uint32_t lsId;
/* The priority of the scope to log messages. These are values of eLogPriority. Can be set bitwise. */
- unsigned int lsPrio;
+ uint32_t lsPrio;
/* The name of the scope or scope group. The scope groups are ending with '*'. For example 'areg_base_*' */
- char lsName[LENGTH_SCOPE];
+ char lsName[LENGTH_SCOPE];
};
/**
@@ -128,36 +133,68 @@ struct sLogScope
struct sLogMessage
{
/* The type of the message: scope enter, scope exit or message text. */
- eLogType msgType;
+ eLogType msgType;
/* The priority of the message to log. */
- eLogPriority msgPriority;
+ eLogPriority msgPriority;
/* The ID of the message source. This value is indicated in the sLogInstance::liCookie */
- unsigned long long msgSource;
+ ITEM_ID msgSource;
/* The cookie ID of the message. This value is indicated in the sLogInstance::liCookie */
- unsigned long long msgCookie;
+ ITEM_ID msgCookie;
/* The ID of the process, running on the local machine. */
- unsigned long long msgModuleId;
+ ITEM_ID msgModuleId;
/* The ID of the thread where the log has been generated. */
- unsigned long long msgThreadId;
+ ITEM_ID msgThreadId;
/* The timestamp where the log was generated. */
- unsigned long long msgTimestamp;
+ TIME64 msgTimestamp;
/* The ID of the scope that generated message. Same as indicated in sLogScope::lsId. */
- unsigned int msgScopeId;
+ uint32_t msgScopeId;
/* The text of generated log message. */
- char msgLogText[LENGTH_MESSAGE];
+ char msgLogText[LENGTH_MESSAGE];
/* The name of the thread, if set, where the message was generated. */
- char msgThread[LENGTH_NAME];
+ char msgThread[LENGTH_NAME];
/* The name of the application that generated the message. Same as in sLogInstance::liName */
- char msgModule[LENGTH_NAME];
+ char msgModule[LENGTH_NAME];
+};
+
+/**
+ * \brief The states of the log observer.
+ **/
+enum eObserverStates
+{
+ /* The lob observer is uninitialized */
+ ObserverUninitialized = 0
+ /* The log observer is initialized, but disconnected / stopped. */
+ , ObserverDisconnected = 1
+ /* The log observer is connected and started. */
+ , ObserverConnected = 3
+ /* The log observer is connected, but paused, i.e. receives, but does not write or forward logs. */
+ , ObserverPaused = 7
};
+/**
+ * \brief The callback of the event triggered when initializing and configuring the observer.
+ * The callback indicates the IP address and port number of the logger service set
+ * in the configuration file.
+ * \param address The null-terminated string of the IP address of the logger service set in the configuration file.
+ * \param port The IP port number of the logger service set in the configuration file.
+ **/
+typedef void (*FuncObserverConfigured)(const char * /*address*/, uint16_t /*port*/);
+
/**
* \brief The callback of the event triggered when the observer connects or disconnects from the logger service.
* \param isConnected Flag, indicating whether observer is connected or disconnected.
* \param address The IP address of the logger service to connect or disconnect.
* \param port The IP port number of the logger service to connect or disconnect.
**/
-typedef void (*FuncServiceConnected)(bool /*isConnected*/, const char * /*address*/, unsigned short /*port*/);
+typedef void (*FuncServiceConnected)(bool /*isConnected*/, const char * /*address*/, uint16_t /*port*/);
+
+/**
+ * \brief The callback of the event trigger when starting or pausing the log observer.
+ * If the log observer is paused, on start it continues to write logs in the same file.
+ * If the log observer is stopped (disconnected is called), on start it creates new file.
+ * \param isStarted The flag indicating whether the lob observer is started or paused.
+ **/
+typedef void(*FuncObserverStarted)(bool /*isStarted*/);
/**
* \brief The callback of the event triggered when fails to send or receive message.
@@ -165,11 +202,18 @@ typedef void (*FuncServiceConnected)(bool /*isConnected*/, const char * /*addres
typedef void (*FuncMessagingFailed)();
/**
- * \brief The callback of the event triggered when receive the list of connected instances that log messages.
- * \param instances The pointer to the list of instances.
+ * \brief The callback of the event triggered when receive the list of connected instances that make logs.
+ * \param instances The pointer to the list of the connected instances.
* \param count The number of entries in the list.
**/
-typedef void (*FuncLogInstances)(sLogInstance* /*instances*/, unsigned int /*count*/);
+typedef void (*FuncInstancesConnect)(const sLogInstance* /*instances*/, uint32_t /*count*/);
+
+/**
+ * \brief The callback of the event triggered when receive the list of disconnected instances that make logs.
+ * \param instances The pointer to the list of IDs of the disconnected instances.
+ * \param count The number of entries in the list.
+ **/
+typedef void (*FuncInstancesDisconnect)(const ITEM_ID * /*instances*/, uint32_t /*count*/);
/**
* \brief The callback of the event triggered when receive the list of the scopes registered in an application.
@@ -177,7 +221,7 @@ typedef void (*FuncLogInstances)(sLogInstance* /*instances*/, unsigned int /*cou
* \param scopes The list of the scopes registered in the application. Each entry contains the ID of the scope, message priority and the full name.
* \param count The number of scope entries in the list.
**/
-typedef void (*FuncLogScopes)(unsigned long long /*cookie*/, sLogScope* /*scopes*/, unsigned int /*count*/);
+typedef void (*FuncLogScopes)(ITEM_ID /*cookie*/, const sLogScope* /*scopes*/, uint32_t /*count*/);
/**
* \brief The callback of the event triggered when receive message to log.
@@ -185,21 +229,37 @@ typedef void (*FuncLogScopes)(unsigned long long /*cookie*/, sLogScope* /*scopes
**/
typedef void (*FuncLogMessage)(const sLogMessage * /*logMessage*/);
+/**
+ * \brief The callback of the event triggered when receive remote message to log.
+ * The buffer indicates to the NETrace::sLogMessage structure.
+ * \param logBuffer The pointer to the NETrace::sLogMessage structure to log messages.
+ * \param size The size of the buffer with log message.
+ **/
+typedef void (*FuncLogMessageEx)(const unsigned char* /*logBuffer*/, uint32_t /*size*/);
+
/**
* \brief The structure of the callbacks / events to set when send or receive messages.
**/
struct sObserverEvents
{
+ /* The callback to the trigger when the observer is initialized and configured. */
+ FuncObserverConfigured evtObserverConfigured;
/* The callback to trigger when connect or disconnect logger service. */
FuncServiceConnected evtServiceConnected;
+ /* The callback to trigger when log observer is tarted or paused. */
+ FuncObserverStarted evtLoggingStarted;
/* The callback to trigger when fails to send or receive message. */
FuncMessagingFailed evtMessagingFailed;
- /* The callback to trigger when receive list of connected instances that log messages. */
- FuncLogInstances evtLogSources;
+ /* The callback to trigger when receive list of connected instances that make logs. */
+ FuncInstancesConnect evtInstConnected;
+ /* The callback to trigger when receive list of IDs of the disconnected instances that make logs. */
+ FuncInstancesDisconnect evtInstDisconnected;
/* The callback to trigger when receive list of registered scopes. */
FuncLogScopes evtLogScopes;
- /* The callback to trigger when receive a message to log. */
+ /* The callback to trigger when receive a message to log. If is set and not null, the 'evtLogMessageEx' callback is ignored. */
FuncLogMessage evtLogMessage;
+ /* The callback to trigger when receive remote message to log. To use, set the 'evtLogMessage' callback null. */
+ FuncLogMessageEx evtLogMessageEx;
};
/**
@@ -210,7 +270,7 @@ struct sObserverEvents
* If NULL, it uses the default location of the config file './config/areg.init'
* \returns Returns true, if succeeded to initialize internals. Otherwise, returns false.
**/
-OBSERVER_API bool logObserverInitialize(const sObserverEvents * callbacks, const char * configFilePath);
+OBSERVER_API bool logObserverInitialize(const sObserverEvents * callbacks, const char * configFilePath = 0);
/**
* \brief Call to release the log observer internals and release resources. This function should
@@ -231,7 +291,7 @@ OBSERVER_API void logObserverRelease();
* \note The 'ipAddress' and 'portNr' parameters should be either both valid or they are ignored and the default values
* indicated in the configuration file are used.
**/
-OBSERVER_API bool logObserverConnectLogger(const char* ipAddress, unsigned short portNr);
+OBSERVER_API bool logObserverConnectLogger(const char* ipAddress = 0, uint16_t portNr = 0);
/**
* \brief Call to trigger disconnect from logger service.
@@ -239,6 +299,19 @@ OBSERVER_API bool logObserverConnectLogger(const char* ipAddress, unsigned short
**/
OBSERVER_API void logObserverDisconnectLogger();
+/**
+ * \brief Call to start paused log observer. By default, when log observer is connected, it is in started state.
+ * When call logObserverStart(false) it pauses the log observer and no messages are logged.
+ * On start, the log observer resumes and continues writing logs.
+ * \param doPause The flag to set to indicate whether the log observer should pause or resume writing logs.
+ **/
+OBSERVER_API void logObserverPauseLogging(bool doPause);
+
+/**
+ * \brief Call to get the current state of the log observer.
+ **/
+OBSERVER_API eObserverStates logObserverCurrentState();
+
/**
* \brief Returns true if observer is initialized and the logger service connection is triggered.
* Otherwise, it returns false.
@@ -252,6 +325,12 @@ OBSERVER_API bool logObserverIsInitialized();
**/
OBSERVER_API bool logObserverIsConnected();
+/**
+ * \brief Returns true, if log observer is initialized, connected, receives and writes or forwards logs.
+ * In all other cases it returns false.
+ **/
+OBSERVER_API bool logObserverIsStarted();
+
/**
* \brief Returns the current IP address of the logger service to connect.
* Returns empty string, if not configured or the IP address is unknown
@@ -262,7 +341,7 @@ OBSERVER_API const char * logObserverLoggerAddress();
* \brief Returns the current IP port of the logger service to connect.
* Return 0 (invalid port), if not configured or the port number is unknown
**/
-OBSERVER_API unsigned short logObserverLoggerPort();
+OBSERVER_API uint16_t logObserverLoggerPort();
/**
* \brief Return true if logger TCP/IP connection is enabled in the configuration file.
@@ -273,11 +352,11 @@ OBSERVER_API bool logObserverConfigLoggerEnabled();
/**
* \brief On exit, the addrBuffer contains the IP address of the logger registered in the configuration file.
* \param addrBuffer Should be valid pointer of the buffer to write the IP address, the minimum size should be 16 bytes.
- * \param count The length of the buffer to write the IP address, inclusive the null-terminated character at the end.
+ * \param space The length of the buffer to write the IP address, inclusive the null-terminated character at the end.
* \return Returns true, if succeeds to write the address. Returns false, if the observer is not configured,
* or the address is not specified in the configuration, or the buffer is not big enough to write address.
**/
-OBSERVER_API bool logObserverConfigLoggerAddress(char * addrBuffer, int count);
+OBSERVER_API bool logObserverConfigLoggerAddress(char * addrBuffer, uint32_t space);
/**
* \brief Returns the configured IP port of the logger service to connect,
@@ -298,7 +377,7 @@ OBSERVER_API void logObserverRequestInstances();
* If the target is ID_IGNORE (or 0), it receives the list of scopes of all connected instances.
* Otherwise, should be indicated the valid cookie ID of the connected log instance.
**/
-OBSERVER_API void logObserverRequestScopes(unsigned long long target);
+OBSERVER_API void logObserverRequestScopes(ITEM_ID target);
/**
* \brief Call to update the priority of the logging message to receive.
@@ -310,7 +389,7 @@ OBSERVER_API void logObserverRequestScopes(unsigned long long target);
* In this case the ID of the scope can be 0.
* \param count The number of scope entries in the list.
**/
-OBSERVER_API void logObserverRequestChangeScopePrio(unsigned long long target, const sLogScope* scopes, unsigned int count);
+OBSERVER_API void logObserverRequestChangeScopePrio(ITEM_ID target, const sLogScope* scopes, uint32_t count);
/**
* \brief Call to save current configuration of the specified target. This is normally called when update the log priority of the instance,
@@ -319,7 +398,7 @@ OBSERVER_API void logObserverRequestChangeScopePrio(unsigned long long target, c
* If the target is ID_IGNORE (or 0), the request is sent to all connected instances.
* Otherwise, should be indicated the valid cookie ID of the connected log instance.
**/
-OBSERVER_API void logObserverRequestSaveConfig(unsigned long long target);
+OBSERVER_API void logObserverRequestSaveConfig(ITEM_ID target);
#endif // AREG_OBSERVER_LIB_LOGOBSERVERAPI_H
diff --git a/framework/observer/lib/LogObserverSwitches.h b/framework/observer/lib/LogObserverSwitches.h
index 35e0e8153..8ba60b7cf 100644
--- a/framework/observer/lib/LogObserverSwitches.h
+++ b/framework/observer/lib/LogObserverSwitches.h
@@ -125,7 +125,7 @@
#define OBSERVER_API_IMPL
#endif // WIN32
-#if !defined(IMP_AREG_DLL) && !defined(IMP_AREG_LIB)
+#if !defined(IMP_AREG_DLL) && !defined(IMP_AREG_LIB) && !defined(IMPORT_SHARED_SYMBOLS) && !defined(IMPORT_STATIC_SYMBOLS)
#pragma message ("WARNING: Neither IMP_AREG_DLL, nor IMP_AREG_LIB is defined. Make proper settings. By default setting IMP_AREG_DLL.")
#define IMP_AREG_DLL
#endif // !defined(IMP_AREG_DLL) && !defined(IMP_AREG_LIB)
diff --git a/framework/observer/lib/Makefile b/framework/observer/lib/Makefile
index 12146227b..629f216b2 100644
--- a/framework/observer/lib/Makefile
+++ b/framework/observer/lib/Makefile
@@ -1,7 +1,6 @@
observer_lib_PROJECT_NAME := observerapi
observer_lib_BASE := $(observer_BASE)/lib
-observer_lib_TARGET_PATH :=
observer_lib_OUTPUT_OBJ := $(AREG_OUTPUT_OBJ)/$(observer_lib_PROJECT_NAME)
observer_lib_SRC :=
@@ -13,14 +12,18 @@ observer_lib_CXXFLAGS := -I$(AREG_BASE) -D$(AREG_LIB_IMPORT) -fPIC
observer_lib_LDFLAGS := $(AREG_TOOL_FLAGS)
ifeq ($(AREG_OBSERVER_LIB), shared)
- observer_lib_CXXFLAGS += -DEXP_OBSERVER_DLL
+ OBSERVER_API_IMPORT := -DIMP_OBSERVER_DLL
+ observer_lib_CXXFLAGS += -DEXP_OBSERVER_DLL
+ OBSERVER_API_PATH := $(AREG_OUTPUT_BIN)
else
- observer_lib_CXXFLAGS += -DEXP_OBSERVER_LIB
+ OBSERVER_API_IMPORT := -DIMP_OBSERVER_LIB
+ observer_lib_CXXFLAGS += -DEXP_OBSERVER_LIB
+ OBSERVER_API_PATH := $(AREG_OUTPUT_LIB)
endif
-observer_lib_TARGET_PATH := $(AREG_OUTPUT_BIN)/$(AREG_LIB_PREFIX)$(observer_lib_PROJECT_NAME)$(AREG_OBSERVER_LIB_EXT)
+observer_lib_TARGET_BIN := $(OBSERVER_API_PATH)/$(AREG_LIB_PREFIX)$(observer_lib_PROJECT_NAME)$(AREG_OBSERVER_LIB_EXT)
-observerapi: $(observer_lib_TARGET_PATH)
+observerapi: $(observer_lib_TARGET_BIN)
# define one target for each source file
$(foreach cpp, $(observer_lib_SRC), $(eval $(call obj, $(cpp), $(observer_lib_OUTPUT_OBJ), observer_lib_OBJS, $(observer_lib_CXXFLAGS))))
@@ -28,7 +31,7 @@ $(foreach cpp, $(observer_lib_SRC), $(eval $(call obj, $(cpp), $(observer_lib_OU
DEPS = $(observer_lib_OBJS:%.o=%.d)
-include $(DEPS)
-$(observer_lib_TARGET_PATH): $(AREG_DEPEND) $(observer_lib_OBJS)
+$(observer_lib_TARGET_BIN): $(AREG_DEPEND) $(observer_lib_OBJS)
@echo "Linking $(observer_lib_PROJECT_NAME) $(AREG_OBSERVER_LIB) library ..."
@mkdir -p $(dir $@)
if [ "$(AREG_OBSERVER_LIB)" = "shared" ]; then \
diff --git a/framework/observer/lib/private/LogObserverApi.cpp b/framework/observer/lib/private/LogObserverApi.cpp
index 4659aba05..df0d73fc7 100644
--- a/framework/observer/lib/private/LogObserverApi.cpp
+++ b/framework/observer/lib/private/LogObserverApi.cpp
@@ -32,81 +32,148 @@ namespace
{
struct sLogObserverStruct
{
- Mutex losLock { false };
- bool losInitialized { false };
- sObserverEvents losEvents { };
+ Mutex losLock { false };
+ eObserverStates losState { eObserverStates::ObserverUninitialized };
+ sObserverEvents losEvents { };
};
sLogObserverStruct theObserver;
- void setCallbacks(const sObserverEvents* srcCallbacks, sObserverEvents & dstCallbacks)
+ void _setCallbacks(sObserverEvents & dstCallbacks, const sObserverEvents* srcCallbacks)
{
if (srcCallbacks != nullptr)
{
- dstCallbacks.evtServiceConnected = srcCallbacks->evtServiceConnected;
- dstCallbacks.evtMessagingFailed = srcCallbacks->evtMessagingFailed;
+ dstCallbacks.evtObserverConfigured = srcCallbacks->evtObserverConfigured;
+ dstCallbacks.evtServiceConnected = srcCallbacks->evtServiceConnected;
+ dstCallbacks.evtLoggingStarted = srcCallbacks->evtLoggingStarted;
+ dstCallbacks.evtMessagingFailed = srcCallbacks->evtMessagingFailed;
+ dstCallbacks.evtInstConnected = srcCallbacks->evtInstConnected;
+ dstCallbacks.evtInstDisconnected = srcCallbacks->evtInstDisconnected;
+ dstCallbacks.evtLogScopes = srcCallbacks->evtLogScopes;
+ dstCallbacks.evtLogMessage = srcCallbacks->evtLogMessage;
+ dstCallbacks.evtLogMessageEx = srcCallbacks->evtLogMessageEx;
}
else
{
- dstCallbacks.evtServiceConnected = nullptr;
- dstCallbacks.evtMessagingFailed = nullptr;
+ dstCallbacks.evtObserverConfigured = nullptr;
+ dstCallbacks.evtServiceConnected = nullptr;
+ dstCallbacks.evtLoggingStarted = nullptr;
+ dstCallbacks.evtMessagingFailed = nullptr;
+ dstCallbacks.evtInstConnected = nullptr;
+ dstCallbacks.evtInstDisconnected = nullptr;
+ dstCallbacks.evtLogScopes = nullptr;
+ dstCallbacks.evtLogMessage = nullptr;
+ dstCallbacks.evtLogMessageEx = nullptr;
}
}
+
+ inline bool _isInitialized(eObserverStates state)
+ {
+ return (state != eObserverStates::ObserverUninitialized);
+ }
+
+ inline bool _isDisconnected(eObserverStates state)
+ {
+ return (state == eObserverStates::ObserverDisconnected);
+ }
+
+ inline bool _isConnected(eObserverStates state)
+ {
+ return (state >= eObserverStates::ObserverConnected);
+ }
+
+ inline bool _isStarted(eObserverStates state)
+ {
+ return (state == eObserverStates::ObserverConnected);
+ }
}
OBSERVER_API_IMPL bool logObserverInitialize(const sObserverEvents * callbacks, const char* configFilePath /* = nullptr */)
{
Lock lock(theObserver.losLock);
- if (theObserver.losInitialized == false)
+ if (_isInitialized(theObserver.losState) == false)
{
- theObserver.losInitialized = true;
- setCallbacks(callbacks, theObserver.losEvents);
- Application::initApplication(true, false, false, true, false, configFilePath);
-
LoggerClient& client = LoggerClient::getInstance();
+ theObserver.losState = eObserverStates::ObserverDisconnected;
+ _setCallbacks(theObserver.losEvents, callbacks);
client.setCallbacks(&theObserver.losEvents);
+ Application::initApplication(true, false, false, true, false, configFilePath, static_cast(&client));
}
- return theObserver.losInitialized;
+ return _isInitialized(theObserver.losState);
}
-OBSERVER_API_IMPL bool logObserverConnectLogger(const char* ipAddress /*= nullptr*/, unsigned short portNr /* = 0 */)
+OBSERVER_API_IMPL bool logObserverConnectLogger(const char* ipAddress /*= nullptr*/, uint16_t portNr /* = 0 */)
{
- return LoggerClient::getInstance().startLoggerClient(ipAddress, portNr);
+ Lock lock(theObserver.losLock);
+
+ if (_isDisconnected(theObserver.losState))
+ {
+ if (LoggerClient::getInstance().startLoggerClient(ipAddress, portNr))
+ {
+ theObserver.losState = eObserverStates::ObserverConnected;
+ }
+ }
+
+ return _isConnected(theObserver.losState);
}
OBSERVER_API_IMPL void logObserverDisconnectLogger()
{
- LoggerClient::getInstance().stopLoggerClient();
+ Lock lock(theObserver.losLock);
+
+ if (_isConnected(theObserver.losState))
+ {
+ LoggerClient& client = LoggerClient::getInstance();
+ client.stopLoggerClient();
+ theObserver.losState = eObserverStates::ObserverDisconnected;
+ }
+}
+
+OBSERVER_API_IMPL void logObserverPauseLogging(bool doPause)
+{
+ Lock lock(theObserver.losLock);
+
+ if (_isConnected(theObserver.losState))
+ {
+ theObserver.losState = doPause ? eObserverStates::ObserverPaused : eObserverStates::ObserverConnected;
+ LoggerClient::getInstance().setPaused(doPause);
+ }
+}
+
+OBSERVER_API_IMPL eObserverStates logObserverCurrentState()
+{
+ Lock lock(theObserver.losLock);
+ return theObserver.losState;
}
OBSERVER_API_IMPL void logObserverRelease()
{
Lock lock(theObserver.losLock);
- if (theObserver.losInitialized)
+ if (_isInitialized(theObserver.losState))
{
LoggerClient& client = LoggerClient::getInstance();
client.setCallbacks(nullptr);
client.stopLoggerClient();
Application::releaseApplication();
- setCallbacks(nullptr, theObserver.losEvents);
- theObserver.losInitialized = false;
+ _setCallbacks(theObserver.losEvents, nullptr);
+ theObserver.losState = eObserverStates::ObserverUninitialized;
}
}
OBSERVER_API_IMPL bool logObserverIsInitialized()
{
Lock lock(theObserver.losLock);
- return theObserver.losInitialized;
+ return _isInitialized(theObserver.losState);
}
OBSERVER_API_IMPL bool logObserverIsConnected()
{
Lock lock(theObserver.losLock);
bool result{ false };
- if (theObserver.losInitialized)
+ if (_isInitialized(theObserver.losState))
{
LoggerClient& client = LoggerClient::getInstance();
result = client.isConnectedState();
@@ -115,11 +182,17 @@ OBSERVER_API_IMPL bool logObserverIsConnected()
return result;
}
+OBSERVER_API_IMPL bool logObserverIsStarted()
+{
+ Lock lock(theObserver.losLock);
+ return _isStarted(theObserver.losState);
+}
+
OBSERVER_API_IMPL const char* logObserverLoggerAddress()
{
Lock lock(theObserver.losLock);
const char * result{ nullptr };
- if (theObserver.losInitialized)
+ if (_isInitialized(theObserver.losState))
{
LoggerClient& client = LoggerClient::getInstance();
result = client.getAddress().getHostAddress().getString();
@@ -132,7 +205,7 @@ OBSERVER_API_IMPL unsigned short logObserverLoggerPort()
{
Lock lock(theObserver.losLock);
unsigned short result{ NESocket::InvalidPort };
- if (theObserver.losInitialized)
+ if (_isInitialized(theObserver.losState))
{
LoggerClient& client = LoggerClient::getInstance();
result = client.getAddress().getHostPort();
@@ -145,7 +218,7 @@ OBSERVER_API_IMPL bool logObserverConfigLoggerEnabled()
{
Lock lock(theObserver.losLock);
bool result{ false };
- if (theObserver.losInitialized)
+ if (_isInitialized(theObserver.losState))
{
LoggerClient& client = LoggerClient::getInstance();
result = client.isConfigLoggerConnectEnabled();
@@ -154,17 +227,17 @@ OBSERVER_API_IMPL bool logObserverConfigLoggerEnabled()
return result;
}
-OBSERVER_API_IMPL bool logObserverConfigLoggerAddress(char* addrBuffer, int count)
+OBSERVER_API_IMPL bool logObserverConfigLoggerAddress(char* addrBuffer, uint32_t space)
{
Lock lock(theObserver.losLock);
bool result{ false };
- if (theObserver.losInitialized)
+ if (_isInitialized(theObserver.losState))
{
LoggerClient& client = LoggerClient::getInstance();
String addr{ client.getConfigLoggerAddress() };
- if ((addrBuffer != nullptr) && (addr.getLength() > static_cast(count)))
+ if ((addrBuffer != nullptr) && (addr.getLength() > static_cast(space)))
{
- result = NEString::copyString(addrBuffer, count, addr.getString(), addr.getLength()) > 0;
+ result = NEString::copyString(addrBuffer, space, addr.getString(), addr.getLength()) > 0;
}
}
@@ -175,7 +248,7 @@ OBSERVER_API_IMPL unsigned short logObserverConfigLoggerPort()
{
Lock lock(theObserver.losLock);
uint16_t result{ NESocket::InvalidPort };
- if (theObserver.losInitialized)
+ if (_isInitialized(theObserver.losState))
{
LoggerClient& client = LoggerClient::getInstance();
result = client.getConfigLoggerPort();
@@ -187,25 +260,25 @@ OBSERVER_API_IMPL unsigned short logObserverConfigLoggerPort()
OBSERVER_API_IMPL void logObserverRequestInstances()
{
Lock lock(theObserver.losLock);
- if (theObserver.losInitialized)
+ if (_isInitialized(theObserver.losState))
{
LoggerClient::getInstance().requestConnectedInstances();
}
}
-OBSERVER_API_IMPL void logObserverRequestScopes(unsigned long long target /* = ID_IGNORED */)
+OBSERVER_API_IMPL void logObserverRequestScopes(ITEM_ID target /* = ID_IGNORED */)
{
Lock lock(theObserver.losLock);
- if (theObserver.losInitialized)
+ if (_isInitialized(theObserver.losState))
{
LoggerClient::getInstance().requestScopes(target);
}
}
-OBSERVER_API_IMPL void logObserverRequestChangeScopePrio(unsigned long long target, const sLogScope* scopes, unsigned int count)
+OBSERVER_API_IMPL void logObserverRequestChangeScopePrio(ITEM_ID target, const sLogScope* scopes, uint32_t count)
{
Lock lock(theObserver.losLock);
- if (theObserver.losInitialized && (target != ID_IGNORE))
+ if (_isInitialized(theObserver.losState) && (target != ID_IGNORE))
{
NETrace::ScopeNames scopeList(count);
for (uint32_t i = 0; i < count; ++i)
@@ -217,10 +290,10 @@ OBSERVER_API_IMPL void logObserverRequestChangeScopePrio(unsigned long long targ
}
}
-OBSERVER_API_IMPL void logObserverRequestSaveConfig(unsigned long long target /* = ID_IGNORED */)
+OBSERVER_API_IMPL void logObserverRequestSaveConfig(ITEM_ID target /* = ID_IGNORED */)
{
Lock lock(theObserver.losLock);
- if (theObserver.losInitialized)
+ if (_isInitialized(theObserver.losState))
{
LoggerClient::getInstance().requestSaveConfiguration(target);
}
diff --git a/framework/observer/lib/private/LoggerClient.cpp b/framework/observer/lib/private/LoggerClient.cpp
index 4bbdbaeb1..10ca1969e 100644
--- a/framework/observer/lib/private/LoggerClient.cpp
+++ b/framework/observer/lib/private/LoggerClient.cpp
@@ -14,10 +14,12 @@
* The logger service connection client.
************************************************************************/
+/************************************************************************
+ * Include files.
+ ************************************************************************/
#include "observer/lib/private/LoggerClient.hpp"
#include "areg/ipc/ConnectionConfiguration.hpp"
-#include "areg/trace/NETrace.hpp"
#include "observer/lib/LogObserverApi.h"
#define IS_VALID(callback) ((mCallbacks != nullptr) && ((callback) != nullptr))
@@ -37,24 +39,29 @@ LoggerClient::LoggerClient(void)
, static_cast(self())
, static_cast(self())
, ThreadPrefix)
+ , IEConfigurationListener ( )
, DispatcherThread ( ThreadName )
, IEServiceConnectionConsumer( )
, IERemoteMessageHandler ( )
, mCallbacks ( nullptr )
, mMessageProcessor ( self() )
+ , mIsPaused ( false )
{
}
bool LoggerClient::startLoggerClient(const String & address /*= String::EmptyString*/, uint16_t portNr /*= NESocket::InvalidPort*/)
{
- Lock lock(mLock);
if ((address.isEmpty() == false) && (portNr != NESocket::InvalidPort))
{
+ Lock lock(mLock);
+ mIsPaused = false;
applyServiceConnectionData(address, portNr);
}
else
{
+ Lock lock(mLock);
+ mIsPaused = false;
ConnectionConfiguration config(LoggerClient::ServiceType, LoggerClient::ConnectType);
if (config.isConfigured())
{
@@ -67,7 +74,12 @@ bool LoggerClient::startLoggerClient(const String & address /*= String::EmptyStr
void LoggerClient::stopLoggerClient(void)
{
- Lock lock(mLock);
+ do
+ {
+ Lock lock(mLock);
+ mIsPaused = false;
+ } while (false);
+
disconnectServiceHost();
}
@@ -77,6 +89,28 @@ void LoggerClient::setCallbacks(const sObserverEvents* callbacks)
mCallbacks = callbacks;
}
+void LoggerClient::setPaused(bool doPause)
+{
+ FuncObserverStarted evtStart{ nullptr };
+ bool isStarted{ false };
+
+ do
+ {
+ Lock lock(mLock);
+ mIsPaused = doPause;
+ if (mCallbacks != nullptr)
+ {
+ evtStart = isConnectionStarted() ? mCallbacks->evtLoggingStarted : nullptr;
+ isStarted = mIsPaused;
+ }
+ } while (false);
+
+ if (evtStart != nullptr)
+ {
+ evtStart(isStarted);
+ }
+}
+
const NESocket::SocketAddress& LoggerClient::getAddress(void) const
{
Lock lock(mLock);
@@ -125,6 +159,7 @@ void LoggerClient::requestConnectedInstances(void)
void LoggerClient::requestScopes(const ITEM_ID& target /*= NEService::COOKIE_ANY*/)
{
+ Lock lock(mLock);
if ((mChannel.getCookie() != NEService::COOKIE_UNKNOWN) && (target != NEService::COOKIE_UNKNOWN))
{
sendMessage(NETrace::messageQueryScopes(mChannel.getCookie(), target == NEService::COOKIE_ANY ? LoggerClient::TargetID : target));
@@ -133,6 +168,7 @@ void LoggerClient::requestScopes(const ITEM_ID& target /*= NEService::COOKIE_ANY
void LoggerClient::requestChangeScopePrio(const NETrace::ScopeNames & scopes, const ITEM_ID& target /*= NEService::COOKIE_ANY*/)
{
+ Lock lock(mLock);
if ((mChannel.getCookie() != NEService::COOKIE_UNKNOWN) && (target != NEService::COOKIE_UNKNOWN))
{
sendMessage(NETrace::messageUpdateScopes(mChannel.getCookie(), target == NEService::COOKIE_ANY ? LoggerClient::TargetID : target, scopes));
@@ -141,12 +177,60 @@ void LoggerClient::requestChangeScopePrio(const NETrace::ScopeNames & scopes, co
void LoggerClient::requestSaveConfiguration(const ITEM_ID& target /*= NEService::COOKIE_ANY*/)
{
+ Lock lock(mLock);
if ((mChannel.getCookie() != NEService::COOKIE_UNKNOWN) && (target != NEService::COOKIE_UNKNOWN))
{
sendMessage(NETrace::messageSaveConfiguration(mChannel.getCookie(), target == NEService::COOKIE_ANY ? LoggerClient::TargetID : target));
}
}
+void LoggerClient::prepareSaveConfiguration(ConfigManager& config)
+{
+}
+
+void LoggerClient::postSaveConfiguration(ConfigManager& config)
+{
+}
+
+void LoggerClient::prepareReadConfiguration(ConfigManager& config)
+{
+}
+
+void LoggerClient::postReadConfiguration(ConfigManager& config)
+{
+ FuncObserverConfigured evtConfig{ nullptr };
+ String address;
+ uint16_t port;
+
+ config.setLogEnabled(NETrace::eLogingTypes::LogTypeFile, true, true);
+ config.setLogEnabled(NETrace::eLogingTypes::LogTypeRemote, false, true);
+
+ do
+ {
+ Lock lock(mLock);
+ if (mCallbacks != nullptr)
+ {
+ evtConfig = mCallbacks->evtObserverConfigured;
+ address = config.getRemoteServiceAddress(LoggerClient::ServiceType, LoggerClient::ConnectType);
+ port = config.getRemoteServicePort(LoggerClient::ServiceType, LoggerClient::ConnectType);
+ }
+ } while (false);
+
+ if (evtConfig != nullptr)
+ {
+ evtConfig(address.getString(), port);
+ }
+}
+
+void LoggerClient::onSetupConfiguration(const NEPersistence::ListProperties& listReadonly, const NEPersistence::ListProperties& listWritable, ConfigManager& config)
+{
+}
+
+bool LoggerClient::postEvent(Event& eventElem)
+{
+ return EventDispatcher::postEvent(eventElem);
+}
+
void LoggerClient::readyForEvents(bool isReady)
{
if (isReady)
@@ -203,51 +287,123 @@ void LoggerClient::onServiceExit(void)
void LoggerClient::connectedRemoteServiceChannel(const Channel& channel)
{
- Lock lock(mLock);
- if (IS_VALID(mCallbacks->evtServiceConnected))
+ FuncServiceConnected evtConnect{ nullptr };
+ FuncObserverStarted evtStart{ nullptr };
+ String address;
+ uint16_t port{ NESocket::InvalidPort };
+ bool isStarted{ false };
+
+ do
+ {
+ Lock lock(mLock);
+ if (mCallbacks != nullptr)
+ {
+ evtConnect = mCallbacks->evtServiceConnected;
+ evtStart = mCallbacks->evtLoggingStarted;
+ const NESocket::SocketAddress& addr{ mClientConnection.getAddress() };
+ address = addr.getHostAddress();
+ port = addr.getHostPort();
+ isStarted = mIsPaused = false;
+ }
+ } while (false);
+
+ sendMessage(NETrace::messageQueryInstances(channel.getCookie(), LoggerClient::TargetID));
+ if (evtConnect != nullptr)
{
- const NESocket::SocketAddress& addr{ mClientConnection.getAddress() };
- mCallbacks->evtServiceConnected(true, addr.getHostAddress().getString(), addr.getHostPort());
+ evtConnect(true, address.getString(), port);
+ }
- sendMessage(NETrace::messageQueryInstances(channel.getCookie(), LoggerClient::TargetID));
+ if (evtStart != nullptr)
+ {
+ evtStart(isStarted);
}
}
void LoggerClient::disconnectedRemoteServiceChannel(const Channel& channel)
{
- Lock lock(mLock);
- if (IS_VALID(mCallbacks->evtServiceConnected))
+ FuncServiceConnected evtConnect{ nullptr };
+ FuncObserverStarted evtStart{ nullptr };
+ String address;
+ uint16_t port{ NESocket::InvalidPort };
+
+ do
+ {
+ Lock lock(mLock);
+ if (mCallbacks != nullptr)
+ {
+ evtConnect = mCallbacks->evtServiceConnected;
+ evtStart = mCallbacks->evtLoggingStarted;
+ const NESocket::SocketAddress& addr{ mClientConnection.getAddress() };
+ address = addr.getHostAddress();
+ port = addr.getHostPort();
+ }
+ } while (false);
+
+ if (evtStart != nullptr)
+ {
+ evtStart(false);
+ }
+
+ if (evtConnect != nullptr)
{
- const NESocket::SocketAddress& addr{ mClientConnection.getAddress() };
- mCallbacks->evtServiceConnected(false, addr.getHostAddress().getString(), addr.getHostPort());
+ evtConnect(false, address.getString(), port);
}
}
void LoggerClient::lostRemoteServiceChannel(const Channel& channel)
{
- Lock lock(mLock);
- if (IS_VALID(mCallbacks->evtServiceConnected))
+ FuncObserverStarted evtStart{ nullptr };
+
+ do
+ {
+ Lock lock(mLock);
+ if (mCallbacks != nullptr)
+ {
+ evtStart = mCallbacks->evtLoggingStarted;
+ }
+ } while (false);
+
+ if (evtStart != nullptr)
{
- const NESocket::SocketAddress& addr{ mClientConnection.getAddress() };
- mCallbacks->evtServiceConnected(false, addr.getHostAddress().getString(), addr.getHostPort());
+ evtStart(false);
}
}
void LoggerClient::failedSendMessage(const RemoteMessage& msgFailed, Socket& whichTarget)
{
- Lock lock(mLock);
- if (IS_VALID(mCallbacks->evtMessagingFailed))
+ FuncMessagingFailed evtFailed{ nullptr };
+ do
+ {
+ Lock lock(mLock);
+ if (mCallbacks != nullptr)
+ {
+ evtFailed = mCallbacks->evtMessagingFailed;
+ }
+ } while (false);
+
+
+ if (evtFailed)
{
- mCallbacks->evtMessagingFailed();
+ evtFailed();
}
}
void LoggerClient::failedReceiveMessage(Socket& whichSource)
{
- Lock lock(mLock);
- if (IS_VALID(mCallbacks->evtMessagingFailed))
+ FuncMessagingFailed evtFailed{ nullptr };
+ do
+ {
+ Lock lock(mLock);
+ if (mCallbacks != nullptr)
+ {
+ evtFailed = mCallbacks->evtMessagingFailed;
+ }
+ } while (false);
+
+
+ if (evtFailed)
{
- mCallbacks->evtMessagingFailed();
+ evtFailed();
}
}
@@ -275,7 +431,10 @@ void LoggerClient::processReceivedMessage(const RemoteMessage& msgReceived, Sock
break;
case NEService::eFuncIdRange::ServiceLogMessage:
- mMessageProcessor.notifyLogMessage(msgReceived);
+ if (mIsPaused == false)
+ {
+ mMessageProcessor.notifyLogMessage(msgReceived);
+ }
break;
default:
diff --git a/framework/observer/lib/private/LoggerClient.hpp b/framework/observer/lib/private/LoggerClient.hpp
index 9220ca6b5..226604021 100644
--- a/framework/observer/lib/private/LoggerClient.hpp
+++ b/framework/observer/lib/private/LoggerClient.hpp
@@ -25,10 +25,10 @@
#include "areg/ipc/ServiceClientConnectionBase.hpp"
#include "areg/ipc/IEServiceConnectionConsumer.hpp"
#include "areg/ipc/IERemoteMessageHandler.hpp"
+#include "areg/persist/IEConfigurationListener.hpp"
#include "areg/trace/NETrace.hpp"
-#include "areg/base/SynchObjects.hpp"
#include "observer/lib/private/ObserverMessageProcessor.hpp"
/************************************************************************
@@ -46,6 +46,7 @@ struct sObserverEvents;
* structure of callbacks to trigger when an event happens.
**/
class LoggerClient : public ServiceClientConnectionBase
+ , public IEConfigurationListener
, protected DispatcherThread
, protected IEServiceConnectionConsumer
, protected IERemoteMessageHandler
@@ -128,6 +129,13 @@ class LoggerClient : public ServiceClientConnectionBase
**/
void setCallbacks(const sObserverEvents * callbacks);
+ /**
+ * \brief Set paused flag true or false. If logger client is paused, it does not
+ * write logs in the file, but remain connected.
+ * \param doPause The paused flag to set.
+ **/
+ void setPaused(bool doPause);
+
/**
* \brief Returns the socket address (IP address and port number) to connect to the logger service.
* The connection might be not established yet.
@@ -190,10 +198,58 @@ class LoggerClient : public ServiceClientConnectionBase
// Overrides
//////////////////////////////////////////////////////////////////////////
protected:
+/************************************************************************/
+// IEConfigurationListener interface overrides
+/************************************************************************/
+
+ /**
+ * \brief Called by configuration manager before the configuration is saved in the file.
+ * \param config The instance of configuration manager.
+ **/
+ virtual void prepareSaveConfiguration(ConfigManager& config) override;
+
+ /**
+ * \brief Called by configuration manager after the configuration is saved in the file.
+ * \param config The instance of configuration manager.
+ **/
+ virtual void postSaveConfiguration(ConfigManager& config) override;
+
+ /**
+ * \brief Called by configuration manager before the configuration is loaded from the file.
+ * \param config The instance of configuration manager.
+ **/
+ virtual void prepareReadConfiguration(ConfigManager& config) override;
+
+ /**
+ * \brief Called by configuration manager when configuration is completed to load data from the file.
+ * \param config The instance of configuration manager.
+ **/
+ virtual void postReadConfiguration(ConfigManager& config) override;
+
+ /**
+ * \brief Called by configuration manager after setting read-only and writable properties.
+ * For example, when the default configuration is set.
+ * \param listReadonly The list of read-only properties to set in the configuration.
+ * \param listWritable The list of module / process specific properties to set in the configuration;
+ * \param config The instance of configuration manager.
+ **/
+ virtual void onSetupConfiguration(const NEPersistence::ListProperties& listReadonly, const NEPersistence::ListProperties& listWritable, ConfigManager& config) override;
+
/************************************************************************/
// DispatcherThread overrides
/************************************************************************/
+ /**
+ * \brief Posts event and delivers to its target.
+ * Since the Dispatcher Thread is a Base object for
+ * Worker and Component threads, it does nothing
+ * and only destroys event object without processing.
+ * Override this method or use Worker / Component thread.
+ * \param eventElem Event object to post
+ * \return In this class it always returns true.
+ **/
+ virtual bool postEvent(Event& eventElem) override;
+
/**
* \brief Call to enable or disable event dispatching threads to receive events.
* Override if need to make event dispatching preparation job.
@@ -298,6 +354,11 @@ class LoggerClient : public ServiceClientConnectionBase
**/
ObserverMessageProcessor mMessageProcessor;
+ /**
+ * \brief The flag, indicating whether the observer was paused or not.
+ **/
+ bool mIsPaused;
+
//////////////////////////////////////////////////////////////////////////
// Forbidden calls.
//////////////////////////////////////////////////////////////////////////
diff --git a/framework/observer/lib/private/ObserverMessageProcessor.cpp b/framework/observer/lib/private/ObserverMessageProcessor.cpp
index 555e17fc9..ea9b0fcb4 100644
--- a/framework/observer/lib/private/ObserverMessageProcessor.cpp
+++ b/framework/observer/lib/private/ObserverMessageProcessor.cpp
@@ -14,19 +14,18 @@
* The log observer message processor.
************************************************************************/
- /************************************************************************
- * Include files.
- ************************************************************************/
+/************************************************************************
+ * Include files.
+ ************************************************************************/
#include "observer/lib/private/ObserverMessageProcessor.hpp"
#include "areg/base/RemoteMessage.hpp"
-#include "areg/base/SynchObjects.hpp"
-#include "areg/base/TEArrayList.hpp"
#include "areg/component/NEService.hpp"
+#include "areg/ipc/NERemoteService.hpp"
#include "areg/trace/TraceScope.hpp"
-#include "observer/lib/private/LoggerClient.hpp"
#include "observer/lib/LogObserverApi.h"
+#include "observer/lib/private/LoggerClient.hpp"
#define IS_VALID(callback) ((mLoggerClient.mCallbacks != nullptr) && ((callback) != nullptr))
@@ -38,124 +37,187 @@ ObserverMessageProcessor::ObserverMessageProcessor(LoggerClient& loggerClient)
void ObserverMessageProcessor::notifyServiceConnection(const RemoteMessage& msgReceived)
{
- ITEM_ID cookie{ NEService::COOKIE_UNKNOWN };
- NEService::eServiceConnection connection{ NEService::eServiceConnection::ServiceConnectionUnknown };
- msgReceived >> cookie;
- msgReceived >> connection;
+ mLoggerClient.serviceConnectionEvent(msgReceived);
+}
+
+void ObserverMessageProcessor::notifyConnectedClients(const RemoteMessage& msgReceived)
+{
+ FuncInstancesConnect evtInstConnected{ nullptr };
+ FuncInstancesDisconnect evtInstDisconnected{ nullptr };
+
+ sLogInstance* listConnect{ nullptr };
+ ITEM_ID* listDisconnect{ nullptr };
+ NERemoteService::eRemoteConnection remConnect{ NERemoteService::eRemoteConnection::RemoteDisconnected };
+ uint32_t count{ 0 };
- switch (connection)
+ do
{
- case NEService::eServiceConnection::ServiceConnected:
- case NEService::eServiceConnection::ServicePending:
+ Lock lock(mLoggerClient.mLock);
+ if (mLoggerClient.mCallbacks != nullptr)
{
- if (msgReceived.getResult() == NEMemory::MESSAGE_SUCCESS)
+ msgReceived >> remConnect;
+ msgReceived >> count;
+
+ if (remConnect == NERemoteService::eRemoteConnection::RemoteConnected)
{
- ASSERT(cookie == msgReceived.getTarget());
- mLoggerClient.mClientConnection.setCookie(cookie);
- mLoggerClient.sendCommand(ServiceEventData::eServiceEventCommands::CMD_ServiceStarted);
+ evtInstConnected = mLoggerClient.mCallbacks->evtInstConnected;
+ listConnect = count != 0 ? new sLogInstance[count] : nullptr;
+ if (listConnect != nullptr)
+ {
+ for (uint32_t i = 0; i < count; ++i)
+ {
+ sLogInstance& inst{ listConnect[i] };
+ NEService::sServiceConnectedInstance instance{};
+ msgReceived >> instance;
+ inst.liSource = static_cast(instance.ciSource);
+ inst.liBitness = static_cast(instance.ciBitness);
+ inst.liCookie = instance.ciCookie;
+ inst.liTimestamp= instance.ciTimestamp;
+ NEString::copyString( inst.liName
+ , static_cast(LENGTH_NAME)
+ , instance.ciInstance.getString()
+ , static_cast(instance.ciInstance.getLength()));
+ NEString::copyString( inst.liLocation
+ , static_cast(LENGTH_LOCATION)
+ , instance.ciLocation.getString()
+ , static_cast(instance.ciLocation.getLength()));
+ }
+ }
+ else
+ {
+ count = 0;
+ }
}
else
{
- mLoggerClient.cancelConnection();
- mLoggerClient.sendCommand(ServiceEventData::eServiceEventCommands::CMD_ServiceLost);
+ evtInstDisconnected = mLoggerClient.mCallbacks->evtInstDisconnected;
+ listDisconnect = new ITEM_ID[count];
+ if (listDisconnect != nullptr)
+ {
+ for (uint32_t i = 0; i < count; ++i)
+ {
+ msgReceived >> listDisconnect[i];
+ }
+ }
+ else
+ {
+ count = 0;
+ }
}
}
- break;
+ } while (false);
- case NEService::eServiceConnection::ServiceRejected:
+ if (evtInstConnected != nullptr)
+ {
+ ASSERT(evtInstDisconnected == nullptr);
+ ASSERT(listDisconnect == nullptr);
+ evtInstConnected(static_cast(listConnect), count);
+ if (listConnect != nullptr)
{
- mLoggerClient.cancelConnection();
- mLoggerClient.sendCommand(ServiceEventData::eServiceEventCommands::CMD_ServiceStopped);
+ delete[] listConnect;
}
- break;
-
- default:
+ }
+ else if (evtInstDisconnected != nullptr)
+ {
+ ASSERT(evtInstConnected == nullptr);
+ ASSERT(listConnect == nullptr);
+ evtInstDisconnected(static_cast(listDisconnect), count);
+ if (listDisconnect != nullptr)
{
- mLoggerClient.cancelConnection();
- mLoggerClient.sendCommand(ServiceEventData::eServiceEventCommands::CMD_ServiceLost);
+ delete[] listDisconnect;
}
- break;
}
}
-void ObserverMessageProcessor::notifyConnectedClients(const RemoteMessage& msgReceived)
+void ObserverMessageProcessor::notifyLogRegisterScopes(const RemoteMessage& msgReceived)
{
- if (IS_VALID(mLoggerClient.mCallbacks->evtLogSources))
- {
- uint32_t count{ 0 };
- msgReceived >> count;
+ FuncLogScopes evtScopes{ nullptr };
+ ITEM_ID cookie{ msgReceived.getSource() };
+ sLogScope* scopes{ nullptr };
+ uint32_t count{ 0 };
- sLogInstance* list = new sLogInstance[count];
- if (list != nullptr)
+ do
+ {
+ Lock lock(mLoggerClient.mLock);
+ if (mLoggerClient.mCallbacks != nullptr)
{
- for (uint32_t i = 0; i < count; ++i)
+ evtScopes = mLoggerClient.mCallbacks->evtLogScopes;
+ msgReceived >> count;
+ scopes = count != 0 ? new sLogScope[count] : nullptr;
+ if (scopes != nullptr)
{
- NEService::sServiceConnectedInstance instance{};
- msgReceived >> instance;
- list[i].liSource = static_cast(instance.ciSource);
- list[i].liBitness = static_cast(instance.ciBitness);
- list[i].liCookie = instance.ciCookie;
- NEString::copyString( list[i].liName
- , static_cast(LENGTH_NAME)
- , instance.ciInstance.getString()
- , static_cast(instance.ciInstance.getLength()));
- NEString::copyString( list[i].liLocation
- , static_cast(LENGTH_LOCATION)
- , instance.ciLocation.getString()
- , static_cast(instance.ciLocation.getLength()));
+ for (uint32_t i = 0; i < count; ++i)
+ {
+ TraceScope scope(msgReceived);
+ scopes[i].lsId = scope.getScopeId();
+ scopes[i].lsPrio = scope.getPriority();
+ NEString::copyString(scopes[i].lsName, static_cast(LENGTH_SCOPE), scope.getScopeName().getString(), scope.getScopeName().getLength());
+ }
+ }
+ else
+ {
+ count = 0;
}
}
+ } while (false);
- mLoggerClient.mCallbacks->evtLogSources(list, list != nullptr ? count : 0);
- delete[] list;
+ if (evtScopes != nullptr)
+ {
+ evtScopes(cookie, scopes, count);
+ if (scopes != nullptr)
+ {
+ delete[] scopes;
+ }
}
}
-void ObserverMessageProcessor::notifyLogRegisterScopes(const RemoteMessage& msgReceived)
+void ObserverMessageProcessor::notifyLogMessage(const RemoteMessage& msgReceived)
{
- if (IS_VALID(mLoggerClient.mCallbacks->evtLogScopes))
+ FuncLogMessage evtMessage{ nullptr };
+ FuncLogMessageEx evtMessageEx{ nullptr };
+ sLogMessage msgLog{ };
+ const unsigned char* logBuffer{ nullptr };
+ unsigned int size{ 0 };
+
+ do
{
- ITEM_ID cookie{ msgReceived.getSource() };
- uint32_t count{ 0 };
- msgReceived >> count;
- sLogScope* scopes = new sLogScope[count];
- if (scopes != nullptr)
+ Lock lock(mLoggerClient.mLock);
+ if (mLoggerClient.mCallbacks != nullptr)
{
- for (uint32_t i = 0; i < count; ++i)
+ if (mLoggerClient.mCallbacks->evtLogMessage != nullptr)
{
- TraceScope scope(msgReceived);
- scopes[i].lsId = scope.getScopeId();
- scopes[i].lsPrio = scope.getPriority();
- NEString::copyString(scopes[i].lsName, static_cast(LENGTH_SCOPE), scope.getScopeName().getString(), scope.getScopeName().getLength());
+ evtMessage = mLoggerClient.mCallbacks->evtLogMessage;
+ const NETrace::sLogMessage* msgRemote = reinterpret_cast(msgReceived.getBuffer());
+ ASSERT(msgRemote != nullptr);
+
+ msgLog.msgType = static_cast(msgRemote->logMsgType);
+ msgLog.msgPriority = static_cast(msgRemote->logMessagePrio);
+ msgLog.msgSource = static_cast(msgRemote->logSource);
+ msgLog.msgCookie = static_cast(msgRemote->logCookie);
+ msgLog.msgModuleId = static_cast(msgRemote->logModuleId);
+ msgLog.msgThreadId = static_cast(msgRemote->logThreadId);
+ msgLog.msgTimestamp = static_cast(msgRemote->logTimestamp);
+ msgLog.msgScopeId = static_cast(msgRemote->logScopeId);
+
+ NEString::copyString(msgLog.msgLogText, LENGTH_MESSAGE, msgRemote->logMessage, msgRemote->logMessageLen);
+ NEString::copyString(msgLog.msgThread, LENGTH_NAME, msgRemote->logThread, msgRemote->logThreadLen);
+ NEString::copyString(msgLog.msgModule, LENGTH_NAME, msgRemote->logModule, msgRemote->logModuleLen);
+ }
+ else if (mLoggerClient.mCallbacks->evtLogMessageEx != nullptr)
+ {
+ evtMessageEx = mLoggerClient.mCallbacks->evtLogMessageEx;
+ logBuffer = msgReceived.getBuffer();
+ size = msgReceived.getSizeUsed();
}
}
+ } while (false);
- mLoggerClient.mCallbacks->evtLogScopes(cookie, scopes, scopes != nullptr ? count : 0u);
- delete[] scopes;
+ if (evtMessage != nullptr)
+ {
+ evtMessage(&msgLog);
}
-}
-
-void ObserverMessageProcessor::notifyLogMessage(const RemoteMessage& msgReceived)
-{
- if (IS_VALID(mLoggerClient.mCallbacks->evtLogMessage))
+ else if (evtMessageEx != nullptr)
{
- const NETrace::sLogMessage * msgRemote = reinterpret_cast(msgReceived.getBuffer());
- ASSERT(msgRemote != nullptr);
-
- sLogMessage msgLog{ };
- msgLog.msgType = static_cast(msgRemote->logMsgType);
- msgLog.msgPriority = static_cast(msgRemote->logMessagePrio);
- msgLog.msgSource = static_cast(msgRemote->logSource);
- msgLog.msgCookie = static_cast(msgRemote->logCookie);
- msgLog.msgModuleId = static_cast(msgRemote->logModuleId);
- msgLog.msgThreadId = static_cast(msgRemote->logThreadId);
- msgLog.msgTimestamp = static_cast(msgRemote->logTimestamp);
- msgLog.msgScopeId = static_cast(msgRemote->logScopeId);
-
- NEString::copyString(msgLog.msgLogText, LENGTH_MESSAGE, msgRemote->logMessage, msgRemote->logMessageLen);
- NEString::copyString(msgLog.msgThread, LENGTH_NAME, msgRemote->logThread, msgRemote->logThreadLen);
- NEString::copyString(msgLog.msgModule, LENGTH_NAME, msgRemote->logModule, msgRemote->logModuleLen);
-
- mLoggerClient.mCallbacks->evtLogMessage(&msgLog);
+ evtMessageEx(logBuffer, size);
}
}
diff --git a/msvc_setup.props b/msvc_setup.props
index 0c22c72b1..592906300 100644
--- a/msvc_setup.props
+++ b/msvc_setup.props
@@ -57,12 +57,12 @@
-
+ 1
-
+ 1