Skip to content

Commit

Permalink
254 log observer console application (#293)
Browse files Browse the repository at this point in the history
* Added the log observer console application
  • Loading branch information
aregtech authored Jan 7, 2024
1 parent 2a594a8 commit cabaac4
Show file tree
Hide file tree
Showing 72 changed files with 2,915 additions and 565 deletions.
15 changes: 15 additions & 0 deletions areg-sdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,13 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "observerapi", "framework\observerapi.vcxproj", "{B29F438E-904C-4929-903C-F4673182A417}"
ProjectSection(ProjectDependencies) = postProject
{2DF8165C-EDE2-4F76-8D2C-2FFE82CB6CE5} = {2DF8165C-EDE2-4F76-8D2C-2FFE82CB6CE5}
{FBC5BEAE-01B9-4943-A5CB-0D3DE2067EB3} = {FBC5BEAE-01B9-4943-A5CB-0D3DE2067EB3}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "logobserver", "framework\logobserver.vcxproj", "{6941F2A7-F0C7-4293-8646-AF68A7E35183}"
ProjectSection(ProjectDependencies) = postProject
{2DF8165C-EDE2-4F76-8D2C-2FFE82CB6CE5} = {2DF8165C-EDE2-4F76-8D2C-2FFE82CB6CE5}
{B29F438E-904C-4929-903C-F4673182A417} = {B29F438E-904C-4929-903C-F4673182A417}
EndProjectSection
EndProject
Global
Expand Down Expand Up @@ -1196,6 +1203,14 @@ Global
{B29F438E-904C-4929-903C-F4673182A417}.Release|Win32.Build.0 = Release|Win32
{B29F438E-904C-4929-903C-F4673182A417}.Release|x64.ActiveCfg = Release|x64
{B29F438E-904C-4929-903C-F4673182A417}.Release|x64.Build.0 = Release|x64
{6941F2A7-F0C7-4293-8646-AF68A7E35183}.Debug|Win32.ActiveCfg = Debug|Win32
{6941F2A7-F0C7-4293-8646-AF68A7E35183}.Debug|Win32.Build.0 = Debug|Win32
{6941F2A7-F0C7-4293-8646-AF68A7E35183}.Debug|x64.ActiveCfg = Debug|x64
{6941F2A7-F0C7-4293-8646-AF68A7E35183}.Debug|x64.Build.0 = Debug|x64
{6941F2A7-F0C7-4293-8646-AF68A7E35183}.Release|Win32.ActiveCfg = Release|Win32
{6941F2A7-F0C7-4293-8646-AF68A7E35183}.Release|Win32.Build.0 = Release|Win32
{6941F2A7-F0C7-4293-8646-AF68A7E35183}.Release|x64.ActiveCfg = Release|x64
{6941F2A7-F0C7-4293-8646-AF68A7E35183}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
20 changes: 14 additions & 6 deletions framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ set_target_properties(areg PROPERTIES CXX_STANDARD ${AREG_CXX_STANDARD} CXX_STAN
# build areg extended static library
addStaticLib(areg-extend "${extend_SRC}")

# build mcrouter executable
addExecutable(mcrouter "${mcrouter_SRC}")

# build logger executable
addExecutable(logger "${logger_SRC}")

# build observer API library
if (AREG_OBSERVER_LIB MATCHES "shared")
# in case of Windows add DEF file.
Expand Down Expand Up @@ -83,6 +77,20 @@ else(AREG_OBSERVER_LIB MATCHES "shared")

endif(AREG_OBSERVER_LIB MATCHES "shared")

# build mcrouter executable
addExecutable(mcrouter "${mcrouter_SRC}")

# build logger executable
addExecutable(logger "${logger_SRC}")

# build log observer console application
addExecutableEx(logobserver "${logobserver_SRC}" observerapi)
if (AREG_OBSERVER_LIB MATCHES "shared")
target_compile_definitions(logobserver PRIVATE IMP_OBSERVER_DLL)
else(AREG_OBSERVER_LIB MATCHES "shared")
target_compile_definitions(observerapi PRIVATE IMP_OBSERVER_LIB)
endif(AREG_OBSERVER_LIB MATCHES "shared")

# copying log and router init files to 'bin/config'
file(MAKE_DIRECTORY ${AREG_OUTPUT_BIN}/config)
file(COPY ${AREG_BASE}/areg/resources/areg.init DESTINATION ${AREG_OUTPUT_BIN}/config)
Expand Down
6 changes: 4 additions & 2 deletions framework/areg-extend.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<ClCompile Include="extend\console\private\OptionParser.cpp" />
<ClCompile Include="extend\console\private\win32\ConsoleWin32.cpp" />
<ClCompile Include="extend\console\private\SystemServiceConsole.cpp" />
<ClCompile Include="extend\service\private\DataRateHelper.cpp" />
<ClCompile Include="extend\service\private\NESystemService.cpp" />
<ClCompile Include="extend\service\private\SystemServiceBase.cpp" />
<ClCompile Include="extend\service\private\IEServiceConnectionHandler.cpp" />
Expand All @@ -61,13 +62,14 @@
<ItemGroup>
<ClInclude Include="extend\console\Console.hpp" />
<ClInclude Include="extend\console\OptionParser.hpp" />
<ClInclude Include="extend\service\DataRateHelper.hpp" />
<ClInclude Include="extend\service\NESystemService.hpp" />
<ClInclude Include="extend\console\SystemServiceConsole.hpp" />
<ClInclude Include="extend\service\SystemServiceBase.hpp" />
<ClInclude Include="extend\service\IEServiceConnectionHandler.hpp" />
<ClInclude Include="extend\service\ServerConnection.hpp" />
<ClInclude Include="extend\service\ServerReceiveThread.hpp" />
<ClInclude Include="extend\service\ServerSendThread.hpp" />
<ClInclude Include="extend\service\private\ServerReceiveThread.hpp" />
<ClInclude Include="extend\service\private\ServerSendThread.hpp" />
<ClInclude Include="extend\service\ServiceCommunicatonBase.hpp" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions framework/areg-extend.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ClCompile Include="extend\service\private\SystemServiceBase.cpp" />
<ClCompile Include="extend\service\private\NESystemService.cpp" />
<ClCompile Include="extend\console\private\SystemServiceConsole.cpp" />
<ClCompile Include="extend\service\private\DataRateHelper.cpp" />
</ItemGroup>
<ItemGroup>
<Text Include="extend\console\private\CMakeLists.txt" />
Expand All @@ -25,12 +26,13 @@
<ClInclude Include="extend\console\OptionParser.hpp" />
<ClInclude Include="extend\service\IEServiceConnectionHandler.hpp" />
<ClInclude Include="extend\service\ServerConnection.hpp" />
<ClInclude Include="extend\service\ServerReceiveThread.hpp" />
<ClInclude Include="extend\service\ServerSendThread.hpp" />
<ClInclude Include="extend\service\private\ServerReceiveThread.hpp" />
<ClInclude Include="extend\service\private\ServerSendThread.hpp" />
<ClInclude Include="extend\service\ServiceCommunicatonBase.hpp" />
<ClInclude Include="extend\service\NESystemService.hpp" />
<ClInclude Include="extend\service\SystemServiceBase.hpp" />
<ClInclude Include="extend\console\SystemServiceConsole.hpp" />
<ClInclude Include="extend\service\DataRateHelper.hpp" />
</ItemGroup>
<ItemGroup>
<None Include="extend\Readme.md" />
Expand Down
4 changes: 3 additions & 1 deletion framework/areg/base/GESwitches.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@
#endif // WIN32

// By default, no AREG extended features.
#ifndef AREG_EXTENDED
#if !defined(AREG_EXTENDED) && !defined(AREG_EXTEND)
#pragma message("The AREG_EXTENDED is not defined, setting default value 0")
#define AREG_EXTENDED 0
#elif defined(AREG_EXTEND) && !defined(AREG_EXTENDED)
#define AREG_EXTENDED AREG_EXTEND
#endif // AREG_EXTENDED

// By default, compile with logs
Expand Down
50 changes: 48 additions & 2 deletions framework/areg/base/NEString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,21 +688,27 @@ namespace NEString
* \brief Returns true if a give string starts with specified phrase.
* \param strString The string to check the phrase.
* \param phrase The phrase to check.
* \param ch The character to check.
* \param caseSensitive If false, it with check ignoring upper / lower case. Otherwise, checks exact match.
* \return Returns true if the string starts with given phrase.
**/
template<typename CharType>
bool stringStartsWith(const CharType * strString, const CharType * phrase, bool caseSensitive = true);
template<typename CharType>
bool stringStartsWith(const CharType * strString, const CharType ch, bool caseSensitive = true);

/**
* \brief Returns true if a give string ends with specified phrase.
* \param strString The string to check the phrase.
* \param phrase The phrase to check.
* \param ch The character to check.
* \param caseSensitive If false, it with check ignoring upper / lower case. Otherwise, checks exact match.
* \return Returns true if the string ends with given phrase.
**/
template<typename CharType>
bool stringEndsWith(const CharType * strString, const CharType * phrase, bool caseSensitive = true);
template<typename CharType>
bool stringEndsWith(const CharType * strString, const CharType ch, bool caseSensitive = true);

/**
* \brief Returns printable string of given buffer. The buffer should be possible to modify.
Expand Down Expand Up @@ -1252,7 +1258,7 @@ NEString::CharPos NEString::findFirst( const CharType * strPhrase
template<typename CharType>
bool NEString::stringStartsWith(const CharType * strString, const CharType * phrase, bool caseSensitive /*= true*/)
{
bool result = false;
bool result{ false };
if ((isEmpty<CharType>(strString) == false) && (isEmpty<CharType>(phrase) == false))
{
result = true;
Expand All @@ -1279,10 +1285,29 @@ bool NEString::stringStartsWith(const CharType * strString, const CharType * phr
return result;
}

template<typename CharType>
bool NEString::stringStartsWith(const CharType* strString, const CharType ch, bool caseSensitive)
{
bool result{ false };
if (isEmpty<CharType>(strString) == false)
{
if (caseSensitive)
{
result = *strString == ch;
}
else
{
result = NEString::makeAsciiLower<CharType>(*strString) == NEString::makeAsciiLower<CharType>(ch);
}
}

return result;
}

template<typename CharType>
bool NEString::stringEndsWith(const CharType * strString, const CharType * phrase, bool caseSensitive /*= true*/)
{
bool result = false;
bool result{ false };
if ((isEmpty<CharType>(strString) == false) && (isEmpty<CharType>(phrase) == false))
{
int lenString = NEString::getStringLength<CharType>(strString);
Expand All @@ -1299,6 +1324,27 @@ bool NEString::stringEndsWith(const CharType * strString, const CharType * phras
return result;
}

template<typename CharType>
bool NEString::stringEndsWith(const CharType* strString, const CharType ch, bool caseSensitive /*= true*/)
{
bool result{ false };
if (isEmpty<CharType>(strString) == false)
{
int len = NEString::getStringLength<CharType>(strString);
ASSERT(len != 0);
if (caseSensitive)
{
result = strString[len - 1] == ch;
}
else
{
result = NEString::makeAsciiLower<CharType>(strString[len - 1]) == NEString::makeAsciiLower<CharType>(ch);
}
}

return result;
}

template<typename CharType>
NEString::CharCount NEString::removeChar(const CharType chRemove, CharType* strSource, NEString::CharCount count /*= NEString::COUNT_ALL*/, bool removeAll /*= true*/)
{
Expand Down
6 changes: 5 additions & 1 deletion framework/areg/base/TEArrayList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,12 @@ inline TEArrayList<VALUE>::TEArrayList( const std::vector<VALUE> & src )
template<typename VALUE>
inline TEArrayList<VALUE>::TEArrayList(const VALUE* list, uint32_t count)
: Constless<std::vector<VALUE>>( )
, mValueList( list, list != nullptr ? count : 0)
, mValueList( list != nullptr ? count : 0)
{
for (uint32_t i = 0; i < count; ++i)
{
mValueList.at(i) = list[i];
}
}

template<typename VALUE>
Expand Down
6 changes: 4 additions & 2 deletions framework/areg/component/NEService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,8 @@ namespace NEService
NEService::eInstanceBitness ciBitness { NEService::eInstanceBitness::BitnessUnknown };
//!< The cookie of the connected instance.
ITEM_ID ciCookie { NEService::COOKIE_UNKNOWN };
//!< The connection timestamp
TIME64 ciTimestamp { 0 };
//!< The name of the application
String ciInstance { "" };
//!< The optional file location
Expand Down Expand Up @@ -1311,7 +1313,7 @@ inline NEService::eDataStateType NEService::ProxyData::getParamState( unsigned i
**/
inline IEOutStream& operator << (IEOutStream& stream, const NEService::sServiceConnectedInstance & output)
{
stream << output.ciSource << output.ciBitness << output.ciCookie << output.ciInstance << output.ciLocation;
stream << output.ciSource << output.ciBitness << output.ciCookie << output.ciTimestamp << output.ciInstance << output.ciLocation;
return stream;
}

Expand All @@ -1322,7 +1324,7 @@ inline IEOutStream& operator << (IEOutStream& stream, const NEService::sServiceC
**/
inline const IEInStream& operator >> (const IEInStream& stream, NEService::sServiceConnectedInstance & input)
{
stream >> input.ciSource >> input.ciBitness >> input.ciCookie >> input.ciInstance >> input.ciLocation;
stream >> input.ciSource >> input.ciBitness >> input.ciCookie >> input.ciTimestamp >> input.ciInstance >> input.ciLocation;
return stream;
}

Expand Down
12 changes: 12 additions & 0 deletions framework/areg/ipc/NERemoteService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ namespace NERemoteService
, ServiceLogger = 2 //!< Message logging service.
};

/**
* \brief Indicates the connect or disconnect of the remote instance.
**/
enum eRemoteConnection : uint32_t
{
/* Remote instance is disconnected. */
RemoteDisconnected = 0
/* Remote instance is connected. */
, RemoteConnected = 1
};

/**
* \brief NERemoteService::DEFAULT_REMOTE_SERVICE_ENABLED
* Message router enable / disable default flag. If true, by default it is enabled.
Expand Down Expand Up @@ -272,5 +283,6 @@ namespace NERemoteService
//////////////////////////////////////////////////////////////////////////
IMPLEMENT_STREAMABLE(NERemoteService::eRemoteServices);
IMPLEMENT_STREAMABLE(NERemoteService::eConnectionTypes);
IMPLEMENT_STREAMABLE(NERemoteService::eRemoteConnection);

#endif // AREG_IPC_NEREMOTESERVICE_HPP
42 changes: 41 additions & 1 deletion framework/areg/ipc/ServiceClientConnectionBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "areg/ipc/ClientConnection.hpp"
#include "areg/ipc/private/ClientReceiveThread.hpp"
#include "areg/ipc/private/ClientSendThread.hpp"
#include "areg/ipc/NERemoteService.hpp"
#include "areg/component/Channel.hpp"
#include "areg/component/Timer.hpp"
#include "areg/base/SynchObjects.hpp"
Expand Down Expand Up @@ -119,6 +118,18 @@ class AREG_API ServiceClientConnectionBase : public IEServiceConnectionProvi
**/
inline uint32_t queryBytesReceived( void );

/**
* \brief Enable or disable the data rate calculation.
* \param enable If true, the data rate calculation is enabled.
* Otherwise, it is disabled.
**/
inline void enableCalculateDataRate(bool enable);

/**
* \brief Returns enable or disable the data rate calculation flag.
**/
inline bool isCalculateDataRateEnabled(void) const;

/**
* \brief Returns true if the connection status is either connecting or connected.
**/
Expand Down Expand Up @@ -149,6 +160,18 @@ class AREG_API ServiceClientConnectionBase : public IEServiceConnectionProvi
//////////////////////////////////////////////////////////////////////////
protected:

/************************************************************************/
// ServiceClientConnectionBase interface overrides
/************************************************************************/

/**
* \brief Triggered when get service notifies the client the connection
* status like connection accepted, disconnected or rejected.
* Override the method if need custom connection reaction.
* \param msgReceived The message sent by service to the client.
**/
virtual void serviceConnectionEvent(const RemoteMessage& msgReceived);

/************************************************************************/
// IEServiceConnectionProvider interface overrides
/************************************************************************/
Expand Down Expand Up @@ -280,6 +303,12 @@ class AREG_API ServiceClientConnectionBase : public IEServiceConnectionProvi
**/
virtual void onServiceMessageSend(const RemoteMessage& msgSend) override;

/**
* \brief Called when need to inform the channel connection.
* \param cookie The channel connection cookie.
**/
virtual void onChannelConnected(const ITEM_ID & cookie) override;

//////////////////////////////////////////////////////////////////////////
// Protected operations and attributes
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -459,6 +488,17 @@ inline uint32_t ServiceClientConnectionBase::queryBytesReceived( void )
return mThreadReceive.extractDataReceive();
}

inline void ServiceClientConnectionBase::enableCalculateDataRate(bool enable)
{
mThreadReceive.setEnableCalculateData(enable);
mThreadSend.setEnableCalculateData(enable);
}

inline bool ServiceClientConnectionBase::isCalculateDataRateEnabled(void) const
{
return mThreadReceive.isCalculateDataEnabled() && mThreadSend.isCalculateDataEnabled();
}

inline bool ServiceClientConnectionBase::isConnectState( void ) const
{
return (static_cast<uint16_t>(mConnectionState) & static_cast<uint16_t>(ServiceClientConnectionBase::eConnectionState::ConnectState));
Expand Down
6 changes: 6 additions & 0 deletions framework/areg/ipc/ServiceEventConsumerBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ class AREG_API IEServiceEventConsumerBase
**/
virtual void onServiceMessageSend(const RemoteMessage& msgSend) = 0;

/**
* \brief Called when need to inform the channel connection.
* \param cookie The channel connection cookie.
**/
virtual void onChannelConnected(const ITEM_ID & cookie) = 0;

//////////////////////////////////////////////////////////////////////////
// Forbidden calls
//////////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 6 additions & 1 deletion framework/areg/ipc/private/ClientReceiveThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ClientReceiveThread::ClientReceiveThread(IERemoteMessageHandler& remoteService,
, mRemoteService ( remoteService )
, mConnection ( connection )
, mBytesReceive ( 0 )
, mSaveDataReceive ( false )
{
}

Expand Down Expand Up @@ -58,7 +59,11 @@ bool ClientReceiveThread::runDispatcher(void)
}
else
{
mBytesReceive += static_cast<uint32_t>(sizeReceive);
if (mSaveDataReceive)
{
mBytesReceive += static_cast<uint32_t>(sizeReceive);
}

mRemoteService.processReceivedMessage( msgReceived, mConnection.getSocket( ) );
}

Expand Down
Loading

0 comments on commit cabaac4

Please sign in to comment.