Skip to content

Commit

Permalink
Merge branch 'rdkcentral:master' into development/windows-system-headers
Browse files Browse the repository at this point in the history
  • Loading branch information
VeithMetro authored Oct 3, 2023
2 parents 48ef9a8 + ce43523 commit b51d2ea
Show file tree
Hide file tree
Showing 18 changed files with 1,366 additions and 497 deletions.
11 changes: 11 additions & 0 deletions Source/WPEFramework/PluginHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace PluginHost {
#ifndef __WINDOWS__
case 'b':
_background = true;
Core::SystemInfo::SetEnvironment(_T("THUNDER_BACKGROUND"), _T("true"));
break;
#endif
case 'h':
Expand Down Expand Up @@ -595,6 +596,16 @@ POP_WARNING()
fprintf(stdout, "Could not enable messaging/tracing functionality!\n");
}
}

// Redirect the standard error to the messaging engine and the MessageControl plugin
// And if Thunder is running in the background, do the same for standard output
Messaging::ConsoleStandardError::Instance().Open();
if (_background == true) {
// Line-buffering on text streams can still lead to messages not being displayed even if they end with a new line (only \n)
// So we disable buffering for stdout (line-buffered by default), as we do it in ProcessBuffer() before outputting the message anyway
::setvbuf(stdout, NULL, _IONBF, 0);
Messaging::ConsoleStandardOut::Instance().Open();
}

#ifdef __CORE_WARNING_REPORTING__
class GlobalConfig : public Core::JSON::Container {
Expand Down
5 changes: 5 additions & 0 deletions Source/WPEProcess/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
MODULE_NAME_DECLARATION(BUILD_REFERENCE)

namespace WPEFramework {
static string _background = _T("false");

namespace Process {

Expand Down Expand Up @@ -547,6 +548,10 @@ int main(int argc, char** argv)

Process::ConsoleOptions options(argc, argv);

if ((Core::SystemInfo::GetEnvironment(_T("THUNDER_BACKGROUND"), _background) == true) && (_background == "true")) {
::setvbuf(stdout, NULL, _IONBF, 0);
}

if ((options.RequestUsage() == true) || (options.Locator == nullptr) || (options.ClassName == nullptr) || (options.RemoteChannel == nullptr) || (options.Exchange == 0)) {
printf("Process [-h] \n");
printf(" -l <locator>\n");
Expand Down
1 change: 1 addition & 0 deletions Source/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ set(PUBLIC_HEADERS
SystemInfo.h
TextFragment.h
TextReader.h
TextStreamRedirectType.h
Thread.h
ThreadPool.h
Time.h
Expand Down
21 changes: 11 additions & 10 deletions Source/core/MessageStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ ENUM_CONVERSION_BEGIN(Core::Messaging::Metadata::type)
{ Core::Messaging::Metadata::type::TRACING, _TXT("Tracing") },
{ Core::Messaging::Metadata::type::LOGGING, _TXT("Logging") },
{ Core::Messaging::Metadata::type::REPORTING, _TXT("Reporting") },
{ Core::Messaging::Metadata::type::STANDARD_OUT, _TXT("StandardOut") },
{ Core::Messaging::Metadata::type::STANDARD_ERROR, _TXT("StandardError") },
{ Core::Messaging::Metadata::type::OPERATIONAL_STREAM, _TXT("OperationalStream") },
ENUM_CONVERSION_END(Core::Messaging::Metadata::type)

namespace {
Expand Down Expand Up @@ -119,11 +118,12 @@ namespace Core {

const char* MODULE_LOGGING = _T("SysLog");
const char* MODULE_REPORTING = _T("Reporting");
const char* MODULE_OPERATIONAL_STREAM = _T("Operational Stream");

uint16_t Metadata::Serialize(uint8_t buffer[], const uint16_t bufferSize) const
{
uint16_t length = static_cast<uint16_t>(sizeof(_type) + (_category.size() + 1));

if (_type == TRACING) {
length += static_cast<uint16_t>(_module.size() + 1);
}
Expand Down Expand Up @@ -159,7 +159,10 @@ namespace Core {
_type = frameReader.Number<type>();
_category = frameReader.NullTerminatedText();

length = (static_cast<uint16_t>(sizeof(_type) + (static_cast<uint16_t>(_category.size()) + 1)));

if (_type == TRACING) {
length += (static_cast<uint16_t>(_module.size()) + 1);
_module = frameReader.NullTerminatedText();
}
else if (_type == LOGGING) {
Expand All @@ -168,16 +171,14 @@ namespace Core {
else if (_type == REPORTING) {
_module = MODULE_REPORTING;
}
else {
ASSERT(_type != Metadata::type::INVALID);
}

if (_type == TRACING) {
length = std::min<uint16_t>(bufferSize, static_cast<uint16_t>(sizeof(_type) + (static_cast<uint16_t>(_category.size()) + 1) + (static_cast<uint16_t>(_module.size()) + 1)));
else if (_type == OPERATIONAL_STREAM) {
_module = MODULE_OPERATIONAL_STREAM;
}
else {
length = std::min<uint16_t>(bufferSize, static_cast<uint16_t>(sizeof(_type) + (static_cast<uint16_t>(_category.size()) + 1)));
ASSERT(_type != Metadata::type::INVALID);
}

length = std::min<uint16_t>(bufferSize, length);
}

return (length);
Expand Down
32 changes: 26 additions & 6 deletions Source/core/MessageStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace Core {

extern EXTERNAL const char* MODULE_LOGGING;
extern EXTERNAL const char* MODULE_REPORTING;
extern EXTERNAL const char* MODULE_OPERATIONAL_STREAM;

struct EXTERNAL IEvent {
virtual ~IEvent() = default;
Expand All @@ -44,12 +45,11 @@ namespace Core {
class EXTERNAL Metadata {
public:
enum type : uint8_t {
INVALID = 0,
TRACING = 1,
LOGGING = 2,
REPORTING = 3,
STANDARD_OUT = 4,
STANDARD_ERROR = 5
INVALID = 0,
TRACING = 1,
LOGGING = 2,
REPORTING = 3,
OPERATIONAL_STREAM = 4
};

// @stop
Expand Down Expand Up @@ -283,6 +283,26 @@ namespace Core {
string _callsign;
};

/**
* @brief Data-Carrier, extended information about the operational-stream-type message.
* No additional info for now, used for function overloading.
*/
class EXTERNAL OperationalStream : public MessageInfo {
public:
OperationalStream(const OperationalStream&) = default;
OperationalStream& operator=(const OperationalStream&) = default;

OperationalStream()
: MessageInfo()
{
}
OperationalStream(const MessageInfo& messageInfo)
: MessageInfo(messageInfo)
{
}
~OperationalStream() = default;
};

public:
virtual ~IStore() = default;
static IStore* Instance();
Expand Down
40 changes: 27 additions & 13 deletions Source/core/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,43 +158,57 @@ POP_WARNING()

static const TCHAR hex_chars[] = "0123456789abcdef";

void EXTERNAL ToHexString(const uint8_t object[], const uint32_t length, string& result)
void EXTERNAL ToHexString(const uint8_t object[], const uint32_t length, string& result, const TCHAR delimiter)
{
ASSERT(object != nullptr);

uint32_t index = static_cast<uint32_t>(result.length());
result.resize(index + (length * 2));
result.resize(index + (length * 2) + (delimiter == '\0' ? 0 : (length - 1)));

result[1] = hex_chars[object[0] & 0xF];

for (uint32_t i = 0, j = index; i < length; i++) {
if ((object[i] == '\\') && ((i + 3) < length) && (object[i + 1] == 'x')) {
result[j++] = object[i + 2];
result[j++] = object[i + 3];
i += 3;
} else {
result[j++] = hex_chars[object[i] >> 4];
result[j++] = hex_chars[object[i] & 0xF];
if ((delimiter != '\0') && (i > 0)) {
result[j++] = delimiter;
}
result[j++] = hex_chars[object[i] >> 4];
result[j++] = hex_chars[object[i] & 0xF];
}
}

uint32_t EXTERNAL FromHexString(const string& hexString, uint8_t* object, const uint32_t maxLength)
uint32_t EXTERNAL FromHexString(const string& hexString, uint8_t* object, const uint32_t maxLength, const TCHAR delimiter)
{
ASSERT(object != nullptr || maxLength == 0);
uint8_t highNibble;
uint8_t lowNibble;
uint32_t bufferIndex = 0, strIndex = 0;

// assume first character is 0 if length is odd.
if (hexString.length() % 2 == 1) {
if ((delimiter == '\0') && (hexString.length() % 2 == 1)) {
lowNibble = FromHexDigits(hexString[strIndex++]);
object[bufferIndex++] = lowNibble;
}

while ((bufferIndex < maxLength) && (strIndex < hexString.length())) {
highNibble = FromHexDigits(hexString[strIndex++]);
lowNibble = FromHexDigits(hexString[strIndex++]);
if (delimiter == '\0') {
highNibble = FromHexDigits(hexString[strIndex++]);
lowNibble = FromHexDigits(hexString[strIndex++]);
}
else {
uint8_t nibble = FromHexDigits(hexString[strIndex++]);
if (hexString[strIndex] == delimiter) {
highNibble = 0;
lowNibble = nibble;
++strIndex;
}
else {
highNibble = nibble;
lowNibble = FromHexDigits(hexString[strIndex++]);
if (hexString[strIndex] == delimiter) {
++strIndex;
}
}
}

object[bufferIndex++] = (highNibble << 4) + lowNibble;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/core/Serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ POP_WARNING()
//------------------------------------------------------------------------
// Serialize: binary buffer
//------------------------------------------------------------------------
void EXTERNAL ToHexString(const uint8_t object[], const uint32_t length, string& result);
uint32_t EXTERNAL FromHexString(const string& hexString, uint8_t* object, const uint32_t maxLength);
void EXTERNAL ToHexString(const uint8_t object[], const uint32_t length, string& result, const TCHAR delimiter = '\0');
uint32_t EXTERNAL FromHexString(const string& hexString, uint8_t* object, const uint32_t maxLength, const TCHAR delimiter = '\0');

//------------------------------------------------------------------------
// Serialize: Base64
Expand Down
Loading

0 comments on commit b51d2ea

Please sign in to comment.