Skip to content

Commit

Permalink
Fixed messages and tested applications.
Browse files Browse the repository at this point in the history
  • Loading branch information
aregtech committed Jan 1, 2024
1 parent af6520d commit 4af7417
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 11 deletions.
6 changes: 6 additions & 0 deletions framework/areg/trace/NETrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,12 @@ namespace NETrace
**/
AREG_API void logMessage(const RemoteMessage& message);

/**
* \brief Log generated custom message locally bypassing priority settings of a scope.
* \param logMessage The structure that contains information to log a message.
**/
AREG_API void logAnyMessageLocal(const NETrace::sLogMessage& logMessage);

/**
* \brief Creates a message for logging service to register scopes with message priority.
* \param source The ID of the source that generated the message.
Expand Down
7 changes: 6 additions & 1 deletion framework/areg/trace/private/NETrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ NETrace::sLogMessage::sLogMessage(NETrace::eLogMessageType msgType, unsigned int
, logModuleLen { 0 }
, logModule { '\0' }
{
uint32_t len = NEMemory::memCopy(logMessage, NETrace::LOG_MESSAGE_IZE - 1, message, msgLen);
uint32_t len = message != nullptr ? NEMemory::memCopy(logMessage, NETrace::LOG_MESSAGE_IZE - 1, message, msgLen) : 0u;
logMessage[len] = String::EmptyChar;
}

Expand Down Expand Up @@ -352,6 +352,11 @@ AREG_API_IMPL RemoteMessage NETrace::messageRegisterScopes(const ITEM_ID & sourc
return msgScope;
}

AREG_API void NETrace::logAnyMessageLocal(const NETrace::sLogMessage& logMessage)
{
return TraceManager::logMessage(logMessage);
}

AREG_API_IMPL RemoteMessage NETrace::messageUpdateScopes(const ITEM_ID& source, const ITEM_ID& target, const NETrace::ScopeNames& scopeNames)
{
RemoteMessage msgScope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void LoggerMessageProcessor::notifyConnectedInstances(const ITEM_ID& target /*=
const ServiceCommunicatonBase::MapInstances& instances = mLoggerService.getInstances();
ASSERT((target == NEService::COOKIE_ANY) || (instances.contains(target) && isLogObserver(instances.getAt(target).ciSource)));

if (msgInstances.initMessage(NERemoteService::getMessageQueryInstances().rbHeader) != nullptr)
if (msgInstances.initMessage(NERemoteService::getMessageNotifyInstances().rbHeader) != nullptr)
{
uint32_t count{ 0 };
uint32_t pos = msgInstances.getPosition();
Expand Down
36 changes: 32 additions & 4 deletions framework/logger/service/private/LoggerServerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,23 @@ LoggerServerService::LoggerServerService( void )
{
}

void LoggerServerService::addInstance(const ITEM_ID & cookie, const NEService::sServiceConnectedInstance& instance)
void LoggerServerService::addInstance(const ITEM_ID& cookie, const NEService::sServiceConnectedInstance& instance)
{
Lock lock(mLock);

ServiceCommunicatonBase::addInstance(cookie, instance);
if (LoggerMessageProcessor::isLogSource(instance.ciSource))
{
NETrace::sLogMessage logMsgHello(NETrace::eLogMessageType::LogMessageText, 0, NETrace::eLogPriority::PrioAny, nullptr, 0);
String::formatString( logMsgHello.logMessage
, NETrace::LOG_MESSAGE_IZE
, "CONNECTED the %u-bit instance [ %s ] with cookie [ %llu ] and location [ %s ]"
, static_cast<uint32_t>(instance.ciBitness)
, instance.ciInstance.getString()
, instance.ciCookie
, instance.ciLocation.getString());
NETrace::logAnyMessageLocal(logMsgHello);

mLoggerProcessor.notifyConnectedInstances(NEService::COOKIE_ANY);
}
else if (LoggerMessageProcessor::isLogObserver(instance.ciSource))
Expand All @@ -65,6 +75,16 @@ void LoggerServerService::removeInstance(const ITEM_ID & cookie)

if (exists && LoggerMessageProcessor::isLogSource(instance.ciSource))
{
NETrace::sLogMessage logMsgBye(NETrace::eLogMessageType::LogMessageText, 0, NETrace::eLogPriority::PrioAny, nullptr, 0);
String::formatString(logMsgBye.logMessage
, NETrace::LOG_MESSAGE_IZE
, "DISCONNECTED the %u-bit instance [ %s ] with cookie [ %llu ] and location [ %s ]"
, static_cast<uint32_t>(instance.ciBitness)
, instance.ciInstance.getString()
, instance.ciCookie
, instance.ciLocation.getString());
NETrace::logAnyMessageLocal(logMsgBye);

mLoggerProcessor.notifyConnectedInstances(NEService::COOKIE_ANY);
}
else if (LoggerMessageProcessor::isLogObserver(instance.ciSource))
Expand All @@ -76,8 +96,15 @@ void LoggerServerService::removeInstance(const ITEM_ID & cookie)
void LoggerServerService::removeAllInstances(void)
{
Lock lock(mLock);
ServiceCommunicatonBase::removeAllInstances();
mLoggerProcessor.notifyConnectedInstances(NEService::COOKIE_ANY);
if (mInstanceMap.getSize() != 0)
{
NETrace::sLogMessage logMsgClose(NETrace::eLogMessageType::LogMessageText, 0, NETrace::eLogPriority::PrioAny, nullptr, 0);
String::formatString(logMsgClose.logMessage, NETrace::LOG_MESSAGE_IZE, "Disconnecting and removing [ %u ] instances.", mInstanceMap.getSize());
NETrace::logAnyMessageLocal(logMsgClose);
ServiceCommunicatonBase::removeAllInstances();
mLoggerProcessor.notifyConnectedInstances(NEService::COOKIE_ANY);
}

mObservers.clear();
}

Expand Down Expand Up @@ -153,13 +180,14 @@ void LoggerServerService::onServiceMessageReceived(const RemoteMessage &msgRecei
case NEService::eFuncIdRange::SystemServiceDisconnect:
break;

case NEService::eFuncIdRange::SystemServiceNotifyInstances:

case NEService::eFuncIdRange::RequestRegisterService: // fall through
case NEService::eFuncIdRange::RequestServiceProviderVersion: // fall through
case NEService::eFuncIdRange::ResponseServiceProviderVersion: // fall through
case NEService::eFuncIdRange::RequestServiceProviderConnection: // fall through
case NEService::eFuncIdRange::ResponseServiceProviderConnection:// fall through
case NEService::eFuncIdRange::SystemServiceNotifyConnection: // fall through
case NEService::eFuncIdRange::SystemServiceNotifyInstances: // fall through
case NEService::eFuncIdRange::SystemServiceRequestRegister: // fall through
case NEService::eFuncIdRange::SystemServiceNotifyRegister: // fall through
default:
Expand Down
6 changes: 3 additions & 3 deletions framework/observer/lib/private/LoggerClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ void LoggerClient::processReceivedMessage(const RemoteMessage& msgReceived, Sock
mMessageProcessor.notifyServiceConnection(msgReceived);
break;

case NEService::eFuncIdRange::SystemServiceQueryInstances:
case NEService::eFuncIdRange::SystemServiceNotifyInstances:
mMessageProcessor.notifyConnectedClients(msgReceived);
break;

case NEService::eFuncIdRange::ServiceLogQueryScopes:
mMessageProcessor.notifyLogScopes(msgReceived);
case NEService::eFuncIdRange::ServiceLogRegisterScopes:
mMessageProcessor.notifyLogRegisterScopes(msgReceived);
break;

case NEService::eFuncIdRange::ServiceLogMessage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void ObserverMessageProcessor::notifyConnectedClients(const RemoteMessage& msgRe
}
}

void ObserverMessageProcessor::notifyLogScopes(const RemoteMessage& msgReceived)
void ObserverMessageProcessor::notifyLogRegisterScopes(const RemoteMessage& msgReceived)
{
if (IS_VALID(mLoggerClient.mCallbacks->evtLogScopes))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ObserverMessageProcessor
* \param msgReceived The buffer with data of scope names, scope IDs and the message priority.
* This contains the information of all scopes.
**/
void notifyLogScopes(const RemoteMessage& msgReceived);
void notifyLogRegisterScopes(const RemoteMessage& msgReceived);

/**
* \brief Triggered to notify to log a message.
Expand Down

0 comments on commit 4af7417

Please sign in to comment.