Skip to content

Commit 60bcb04

Browse files
committed
Slight optimization and scope modification
1 parent 010d554 commit 60bcb04

File tree

4 files changed

+51
-42
lines changed

4 files changed

+51
-42
lines changed

framework/areg/logging/LogScope.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ class AREG_API LogScope
154154
// Member variables
155155
//////////////////////////////////////////////////////////////////////////////
156156
private:
157-
/**
158-
* \brief The name of log scope. It cannot be changed
159-
**/
160-
const String mScopeName;
161157
/**
162158
* \brief The ID of log scope. It cannot be changed
163159
**/
@@ -166,6 +162,14 @@ class AREG_API LogScope
166162
* \brief The log message priority of the scope.
167163
**/
168164
unsigned int mScopePrio;
165+
/**
166+
* \brief The name of log scope. It cannot be changed
167+
**/
168+
const String mScopeName;
169+
/**
170+
* \brief The log scope is active or not.
171+
**/
172+
const bool mIsRegistered;
169173

170174
//////////////////////////////////////////////////////////////////////////////
171175
// Hidden methods
@@ -209,9 +213,9 @@ namespace std
209213

210214
inline IEOutStream & operator << ( IEOutStream & stream, const LogScope & output )
211215
{
212-
stream << output.mScopeName;
213216
stream << output.mScopeId;
214217
stream << output.mScopePrio;
218+
stream << output.mScopeName;
215219

216220
return stream;
217221
}

framework/areg/logging/private/LogScope.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,28 @@
3030
#if AREG_LOGS
3131

3232
LogScope::LogScope( const char * scopeName, NELogging::eLogPriority priority /*= NELogging::PrioNotset*/ )
33-
: mScopeName ( scopeName != nullptr ? scopeName : "" )
34-
, mScopeId ( NELogging::makeScopeId(mScopeName.getString()) )
33+
: mScopeId ( NELogging::makeScopeId(scopeName) )
3534
, mScopePrio ( priority )
35+
, mScopeName ( scopeName != nullptr ? scopeName : "" )
36+
, mIsRegistered ( true )
3637
{
3738
LogManager::registerLogScope( self() );
3839
}
3940

4041
LogScope::LogScope(const IEInStream & stream)
41-
: mScopeName (stream)
42-
, mScopeId (stream.read32Bits())
43-
, mScopePrio (stream.read32Bits())
42+
: mScopeId ( stream.read32Bits() )
43+
, mScopePrio ( stream.read32Bits() )
44+
, mScopeName ( stream )
45+
, mIsRegistered ( false )
4446
{
4547
}
4648

4749
LogScope::~LogScope( void )
4850
{
49-
LogManager::unregisterLogScope( self() );
51+
if (mIsRegistered)
52+
{
53+
LogManager::unregisterLogScope(self());
54+
}
5055
}
5156

5257
void LogScope::setPriority(const char* newPrio)
@@ -62,16 +67,18 @@ void LogScope::setPriority(const String& newPrio)
6267
#else // AREG_LOGS
6368

6469
LogScope::LogScope(const char* /*scopeName*/, NELogging::eLogPriority /*priority*/ /*= NELogging::PrioNotset*/)
65-
: mScopeName ()
66-
, mScopeId ( 0 )
70+
: mScopeId ( 0 )
6771
, mScopePrio ( static_cast<unsigned int>(NELogging::eLogPriority::PrioInvalid) )
72+
, mScopeName ( )
73+
, mIsRegistered (false)
6874
{
6975
}
7076

7177
LogScope::LogScope(const IEInStream& /*stream*/ )
72-
: mScopeName ()
73-
, mScopeId ( 0 )
78+
: mScopeId ( 0 )
7479
, mScopePrio ( static_cast<unsigned int>(NELogging::eLogPriority::PrioInvalid) )
80+
, mScopeName ( )
81+
, mIsRegistered (false)
7582
{
7683
}
7784

framework/aregextend/db/private/LogSqliteDatabase.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -677,14 +677,7 @@ bool LogSqliteDatabase::logInstanceDisconnected(const ITEM_ID& cookie, const Dat
677677

678678
bool LogSqliteDatabase::logScopeActivate(const NELogging::sScopeInfo & scope, const ITEM_ID& cookie, const DateTime& timestamp)
679679
{
680-
char sql[SQL_LEN];
681-
String::formatString( sql, SQL_LEN, _fmtScopes.data()
682-
, static_cast<uint32_t>(scope.scopeId)
683-
, static_cast<uint64_t>(cookie)
684-
, static_cast<uint32_t>(scope.scopePrio)
685-
, scope.scopeName.getString()
686-
, static_cast<uint64_t>(timestamp.getTime()));
687-
return mDatabase.execute(sql);
680+
return logScopeActivate(scope.scopeName, scope.scopeId, scope.scopePrio, cookie, timestamp);
688681
}
689682

690683
uint32_t LogSqliteDatabase::logScopesActivate(const NELogging::ScopeNames& scopes, const ITEM_ID& cookie, const DateTime& timestamp)

framework/areglogger/client/private/ObserverMessageProcessor.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ void ObserverMessageProcessor::notifyLogRegisterScopes(const RemoteMessage& msgR
8787
sLogScope& entry{ scopes[i] };
8888
entry.lsId = scope.getScopeId();
8989
entry.lsPrio = scope.getPriority();
90-
NEString::copyString(entry.lsName, static_cast<NEString::CharCount>(LENGTH_SCOPE), scope.getScopeName().getString(), scope.getScopeName().getLength());
91-
90+
NEMemory::memCopy(entry.lsName, LENGTH_SCOPE, scope.getScopeName().getString(), scope.getScopeName().getLength() + 1);
9291
mLoggerClient.mLogDatabase.logScopeActivate(scope.getScopeName(), scope.getScopeId(), scope.getPriority(), cookie, now);
9392
}
9493

@@ -138,7 +137,7 @@ void ObserverMessageProcessor::notifyLogUpdateScopes(const RemoteMessage& msgRec
138137
sLogScope& entry{ scopes[i] };
139138
entry.lsId = scope.getScopeId();
140139
entry.lsPrio = scope.getPriority();
141-
NEString::copyString(entry.lsName, static_cast<NEString::CharCount>(LENGTH_SCOPE), scope.getScopeName().getString(), scope.getScopeName().getLength());
140+
NEMemory::memCopy(entry.lsName, LENGTH_SCOPE, scope.getScopeName().getString(), scope.getScopeName().getLength() + 1);
142141
mLoggerClient.mLogDatabase.logScopeActivate(scope.getScopeName(), scope.getScopeId(), scope.getPriority(), cookie, now);
143142
}
144143

@@ -197,8 +196,8 @@ void ObserverMessageProcessor::notifyLogMessage(const RemoteMessage& msgReceived
197196
msgLog.msgScopeId = static_cast<unsigned int>(msgRemote->logScopeId);
198197

199198
NEMemory::memCopy(msgLog.msgLogText, LENGTH_MESSAGE , msgRemote->logMessage , msgRemote->logMessageLen + 1);
200-
NEMemory::memCopy(msgLog.msgThread, LENGTH_NAME , msgRemote->logThread , msgRemote->logThreadLen + 1);
201-
NEMemory::memCopy(msgLog.msgModule, LENGTH_NAME , msgRemote->logModule , msgRemote->logModuleLen + 1);
199+
NEMemory::memCopy(msgLog.msgThread, LENGTH_NAME , msgRemote->logThread , msgRemote->logThreadLen + 1);
200+
NEMemory::memCopy(msgLog.msgModule, LENGTH_NAME , msgRemote->logModule , msgRemote->logModuleLen + 1);
202201
}
203202
else if (mLoggerClient.mCallbacks->evtLogMessageEx != nullptr)
204203
{
@@ -227,18 +226,31 @@ void ObserverMessageProcessor::_clientsConnected(const RemoteMessage& msgReceive
227226
FuncInstancesConnect callback{ nullptr };
228227
sLogInstance* listInstances{ nullptr };
229228
int size{ static_cast<int>(listConnected.getSize()) };
229+
if (size == 0)
230+
return;
230231

231232
do
232233
{
233234
Lock lock(mLoggerClient.mLock);
234-
if (LogObserverBase::_theLogObserver == nullptr)
235+
DateTime now(DateTime::getNow());
236+
237+
if (LogObserverBase::_theLogObserver != nullptr)
235238
{
236-
callback = mLoggerClient.mCallbacks != nullptr ? mLoggerClient.mCallbacks->evtInstConnected : nullptr;
237-
}
239+
for (int i = 0; i < size; ++i)
240+
{
241+
const NEService::sServiceConnectedInstance& client{ listConnected[static_cast<uint32_t>(i)] };
242+
auto added = mLoggerClient.mInstances.addIfUnique(client.ciCookie, client, false);
243+
if (added.second)
244+
{
245+
mLoggerClient.mLogDatabase.logInstanceConnected(client, now);
246+
}
247+
}
238248

239-
if (size > 0)
249+
mLoggerClient.mLogDatabase.commit(true);
250+
}
251+
else
240252
{
241-
DateTime now(DateTime::getNow());
253+
callback = mLoggerClient.mCallbacks != nullptr ? mLoggerClient.mCallbacks->evtInstConnected : nullptr;
242254
listInstances = new sLogInstance[size];
243255

244256
for (int i = 0; i < size; ++i)
@@ -257,20 +269,13 @@ void ObserverMessageProcessor::_clientsConnected(const RemoteMessage& msgReceive
257269
inst.liBitness = static_cast<uint32_t>(client.ciBitness);
258270
inst.liCookie = client.ciCookie;
259271
inst.liTimestamp = client.ciTimestamp;
260-
NEString::copyString(inst.liName
261-
, static_cast<NEString::CharCount>(LENGTH_NAME)
262-
, client.ciInstance.c_str()
263-
, static_cast<NEString::CharCount>(client.ciInstance.length()));
264-
NEString::copyString(inst.liLocation
265-
, static_cast<NEString::CharCount>(LENGTH_LOCATION)
266-
, client.ciLocation.c_str()
267-
, static_cast<NEString::CharCount>(client.ciLocation.length()));
272+
NEMemory::memCopy(inst.liName , LENGTH_NAME , client.ciInstance.c_str(), static_cast<int>(client.ciInstance.length()) + 1);
273+
NEMemory::memCopy(inst.liLocation, LENGTH_LOCATION, client.ciLocation.c_str(), static_cast<int>(client.ciLocation.length()) + 1);
268274
}
269275
}
270276

271277
mLoggerClient.mLogDatabase.commit(true);
272278
}
273-
274279
} while (false);
275280

276281
if (LogObserverBase::_theLogObserver != nullptr)

0 commit comments

Comments
 (0)