Skip to content

Commit

Permalink
[Messaging] Adding a functionality to the MessageControl plugin to ha…
Browse files Browse the repository at this point in the history
…ndle redirected standard out and error (#255)

* Adding factories for the two new message types (std out and error)

* Changing the factories to match the new message type

* Changing the factory name in the constructor

* Changing the Output methods to use Format() method from ConsoleStandardOut class

* Adding a test printfs

* Cleaning the testing prints

* Adding operational streams to JSON::Convert and optimizing it to have less conditions
  • Loading branch information
VeithMetro authored Oct 3, 2023
1 parent fbe046e commit 999211b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
2 changes: 2 additions & 0 deletions MessageControl/MessageControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ namespace WPEFramework {
, _tracingFactory()
, _loggingFactory()
, _warningReportingFactory()
, _operationalStreamFactory()
{
_client.AddInstance(0);
_client.AddFactory(Core::Messaging::Metadata::type::TRACING, &_tracingFactory);
_client.AddFactory(Core::Messaging::Metadata::type::LOGGING, &_loggingFactory);
_client.AddFactory(Core::Messaging::Metadata::type::REPORTING, &_warningReportingFactory);
_client.AddFactory(Core::Messaging::Metadata::type::OPERATIONAL_STREAM, &_operationalStreamFactory);
}

const string MessageControl::Initialize(PluginHost::IShell* service)
Expand Down
1 change: 1 addition & 0 deletions MessageControl/MessageControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ namespace Plugin {
Messaging::TraceFactoryType<Core::Messaging::IStore::Tracing, Messaging::TextMessage> _tracingFactory;
Messaging::TraceFactoryType<Core::Messaging::IStore::Logging, Messaging::TextMessage> _loggingFactory;
Messaging::TraceFactoryType<Core::Messaging::IStore::WarningReporting, Messaging::TextMessage> _warningReportingFactory;
Messaging::TraceFactoryType<Core::Messaging::IStore::OperationalStream, Messaging::TextMessage> _operationalStreamFactory;
Cleanups _cleaning;
};

Expand Down
40 changes: 10 additions & 30 deletions MessageControl/MessageOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ namespace Publishers {

void ConsoleOutput::Message(const Core::Messaging::MessageInfo& metadata, const string& text) /* override */
{
std::cout << _convertor.Convert(metadata, text);
Messaging::ConsoleStandardOut::Instance().Format(_convertor.Convert(metadata, text).c_str());
}

void SyslogOutput::Message(const Core::Messaging::MessageInfo& metadata, const string& text) /* override */
{
#ifndef __WINDOWS__
syslog(LOG_NOTICE, _T("%s"), _convertor.Convert(metadata, text).c_str());
#else
printf(_T("%s"), _convertor.Convert(metadata, text).c_str());
Messaging::ConsoleStandardOut::Instance().Format(_convertor.Convert(metadata, text).c_str());
#endif
}

Expand All @@ -69,17 +69,17 @@ namespace Publishers {
data.Module = metadata.Module();
}

const Core::Time now(metadata.TimeStamp());
if ((AsNumber(options) & AsNumber(ExtraOutputOptions::INCLUDINGDATE)) != 0) {
data.Time = now.ToRFC1123(true);
}
else {
data.Time = now.ToTimeOnly(true);
}

if (metadata.Type() == Core::Messaging::Metadata::type::TRACING) {
ASSERT(dynamic_cast<const Core::Messaging::IStore::Tracing*>(&metadata) != nullptr);
const Core::Messaging::IStore::Tracing& trace = static_cast<const Core::Messaging::IStore::Tracing&>(metadata);
const Core::Time now(trace.TimeStamp());

if ((AsNumber(options) & AsNumber(ExtraOutputOptions::INCLUDINGDATE)) != 0) {
data.Time = now.ToRFC1123(true);
}
else {
data.Time = now.ToTimeOnly(true);
}

if ((AsNumber(options) & AsNumber(ExtraOutputOptions::FILENAME)) != 0) {
data.FileName = trace.FileName();
Expand All @@ -93,29 +93,9 @@ namespace Publishers {
data.ClassName = trace.ClassName();
}
}
else if (metadata.Type() == Core::Messaging::Metadata::type::LOGGING) {
ASSERT(dynamic_cast<const Core::Messaging::IStore::Logging*>(&metadata) != nullptr);
const Core::Messaging::IStore::Logging& log = static_cast<const Core::Messaging::IStore::Logging&>(metadata);
const Core::Time now(log.TimeStamp());

if ((AsNumber(options) & AsNumber(ExtraOutputOptions::INCLUDINGDATE)) != 0) {
data.Time = now.ToRFC1123(true);
}
else {
data.Time = now.ToTimeOnly(true);
}
}
else if (metadata.Type() == Core::Messaging::Metadata::type::REPORTING) {
ASSERT(dynamic_cast<const Core::Messaging::IStore::WarningReporting*>(&metadata) != nullptr);
const Core::Messaging::IStore::WarningReporting& report = static_cast<const Core::Messaging::IStore::WarningReporting&>(metadata);
const Core::Time now(report.TimeStamp());

if ((AsNumber(options) & AsNumber(ExtraOutputOptions::INCLUDINGDATE)) != 0) {
data.Time = now.ToRFC1123(true);
}
else {
data.Time = now.ToTimeOnly(true);
}

if ((AsNumber(options) & AsNumber(ExtraOutputOptions::CALLSIGN)) != 0) {
data.Callsign = report.Callsign();
Expand Down

0 comments on commit 999211b

Please sign in to comment.