refs #316 Changed blackmisc and blacksim to use CLogMessage to emit messages.

Also changed functions which always returned CStatusMessageList containing a single CStatusMessage,
to return CStatusMessage instead for simplicity.
This commit is contained in:
Mathew Sutcliffe
2014-09-25 21:24:11 +01:00
parent ed723c5e97
commit b16b02c3d6
10 changed files with 36 additions and 30 deletions

View File

@@ -1,4 +1,5 @@
#include "setaudio.h" #include "setaudio.h"
#include "logmessage.h"
using namespace BlackSound; using namespace BlackSound;
namespace BlackMisc namespace BlackMisc
@@ -160,11 +161,10 @@ namespace BlackMisc
/* /*
* Value * Value
*/ */
BlackMisc::CStatusMessageList CSettingsAudio::value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag) BlackMisc::CStatusMessage CSettingsAudio::value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag)
{ {
// TODO: This needs to be refactored to a smarter way to delegate commands // TODO: This needs to be refactored to a smarter way to delegate commands
changedFlag = false; changedFlag = false;
CStatusMessageList msgs;
if (path == CSettingsAudio::ValueNotificationFlag()) if (path == CSettingsAudio::ValueNotificationFlag())
{ {
if (command == CSettingUtilities::CmdSetTrue() || command == CSettingUtilities::CmdSetFalse()) if (command == CSettingUtilities::CmdSetTrue() || command == CSettingUtilities::CmdSetFalse())
@@ -173,10 +173,10 @@ namespace BlackMisc
char value = (command == CSettingUtilities::CmdSetTrue()) ? '1' : '0' ; char value = (command == CSettingUtilities::CmdSetTrue()) ? '1' : '0' ;
this->initNotificationFlags(); this->initNotificationFlags();
this->m_notificationFlags.replace(index, 1, value); this->m_notificationFlags.replace(index, 1, value);
return msgs; return {};
} }
} }
return CSettingUtilities::wrongPathMessages(path); return CLogMessage().error(CSettingUtilities::validationMessageCategory(), "wrong path: %1") << path;
} }
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -58,7 +58,7 @@ namespace BlackMisc
bool operator !=(const CSettingsAudio &other) const; bool operator !=(const CSettingsAudio &other) const;
//! \copydoc BlackCore::IContextSettings //! \copydoc BlackCore::IContextSettings
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const BlackMisc::CVariant &value, bool &changedFlag); virtual BlackMisc::CStatusMessage value(const QString &path, const QString &command, const BlackMisc::CVariant &value, bool &changedFlag);
//! \copydoc CValueObject::getValueHash //! \copydoc CValueObject::getValueHash
virtual uint getValueHash() const override; virtual uint getValueHash() const override;

View File

@@ -4,6 +4,7 @@
#include "blackmisc/statusmessagelist.h" #include "blackmisc/statusmessagelist.h"
#include "blackmisc/settingutilities.h" #include "blackmisc/settingutilities.h"
#include "blackmisc/variant.h" #include "blackmisc/variant.h"
#include "blackmisc/logmessage.h"
using namespace BlackMisc::Network; using namespace BlackMisc::Network;
@@ -156,11 +157,10 @@ namespace BlackMisc
/* /*
* Value * Value
*/ */
BlackMisc::CStatusMessageList CSettingsNetwork::value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag) BlackMisc::CStatusMessage CSettingsNetwork::value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag)
{ {
// TODO: This needs to be refactored to a smarter way to delegate commands // TODO: This needs to be refactored to a smarter way to delegate commands
changedFlag = false; changedFlag = false;
CStatusMessageList msgs;
if (path == CSettingsNetwork::ValueTrafficServers()) if (path == CSettingsNetwork::ValueTrafficServers())
{ {
const CServer server = value.value<CServer>(); const CServer server = value.value<CServer>();
@@ -183,8 +183,7 @@ namespace BlackMisc
changedFlag = this->m_trafficNetworkServers.contains(&CServer::getName, server.getName()); changedFlag = this->m_trafficNetworkServers.contains(&CServer::getName, server.getName());
this->m_trafficNetworkServers.removeIf(&CServer::getName, server.getName()); this->m_trafficNetworkServers.removeIf(&CServer::getName, server.getName());
} }
msgs.push_back(CStatusMessage::getInfoMessage("Set current server", CStatusMessage::TypeSettings)); return CLogMessage().info(CSettingUtilities::updateMessageCategory(), "Set current server");
return msgs;
} }
else if (path == CSettingsNetwork::ValueBookingServiceUrl()) else if (path == CSettingsNetwork::ValueBookingServiceUrl())
{ {
@@ -192,12 +191,11 @@ namespace BlackMisc
{ {
QString v = value.toString(); QString v = value.toString();
changedFlag = (v != this->m_bookingServiceUrl); changedFlag = (v != this->m_bookingServiceUrl);
msgs.push_back(CSettingUtilities::valueChangedMessage(changedFlag, "booking URL"));
this->m_bookingServiceUrl = v; this->m_bookingServiceUrl = v;
return msgs; return CLogMessage().info(CSettingUtilities::updateMessageCategory(), "booking URL%1 changed") << (changedFlag ? "" : " not");
} }
} }
return CSettingUtilities::wrongPathMessages(path); return CLogMessage().error(CSettingUtilities::validationMessageCategory(), "wrong path: %1") << path;
} }
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -94,7 +94,7 @@ namespace BlackMisc
bool operator !=(const CSettingsNetwork &other) const; bool operator !=(const CSettingsNetwork &other) const;
//! \copydoc BlackCore::IContextSettings //! \copydoc BlackCore::IContextSettings
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag); virtual BlackMisc::CStatusMessage value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag);
//! \copydoc CValueObject::getValueHash //! \copydoc CValueObject::getValueHash
virtual uint getValueHash() const override; virtual uint getValueHash() const override;

View File

@@ -26,6 +26,15 @@ namespace BlackMisc
public: public:
//! Log message category for anything related to settings
static QString getMessageCategory() { return "swift.settings"; }
//! Log message category for settings validation messages
static QString validationMessageCategory() { return "swift.settings.validation"; }
//! Log message category for settings update messages
static QString updateMessageCategory() { return "swift.settings.update"; }
//! Command validate //! Command validate
static const QString &CmdValidate() static const QString &CmdValidate()
{ {

View File

@@ -8,6 +8,7 @@
*/ */
#include "setsimulator.h" #include "setsimulator.h"
#include "blackmisc/logmessage.h"
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Settings; using namespace BlackMisc::Settings;
@@ -149,22 +150,20 @@ namespace BlackSim
/* /*
* Value * Value
*/ */
BlackMisc::CStatusMessageList CSettingsSimulator::value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag) BlackMisc::CStatusMessage CSettingsSimulator::value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag)
{ {
// TODO: This needs to be refactored to a smarter way to delegate commands // TODO: This needs to be refactored to a smarter way to delegate commands
changedFlag = false; changedFlag = false;
CStatusMessageList msgs;
if (path == CSettingsSimulator::ValueSelectedDriver()) if (path == CSettingsSimulator::ValueSelectedDriver())
{ {
if (command == CSettingUtilities::CmdAdd() || command == CSettingUtilities::CmdUpdate()) if (command == CSettingUtilities::CmdAdd() || command == CSettingUtilities::CmdUpdate())
{ {
CSimulatorInfo v = value.value<CSimulatorInfo>(); CSimulatorInfo v = value.value<CSimulatorInfo>();
changedFlag = (v != this->m_selectedPlugin); changedFlag = (v != this->m_selectedPlugin);
msgs.push_back(CSettingUtilities::valueChangedMessage(changedFlag, "selected driver"));
this->m_selectedPlugin = v; this->m_selectedPlugin = v;
return msgs; return CLogMessage().info(CSettingUtilities::updateMessageCategory(), "selected driver%1 changed") << (changedFlag ? "" : " not");
} }
return CSettingUtilities::wrongCommandMessages(command); return CLogMessage().error(CSettingUtilities::validationMessageCategory(), "wrong command: %1") << command;
} }
else if (path == CSettingsSimulator::ValueSyncTime()) else if (path == CSettingsSimulator::ValueSyncTime())
{ {
@@ -172,11 +171,10 @@ namespace BlackSim
{ {
bool v = value.value<bool>(); bool v = value.value<bool>();
changedFlag = (v != this->m_timeSync); changedFlag = (v != this->m_timeSync);
msgs.push_back(CSettingUtilities::valueChangedMessage(changedFlag, "time synchronization"));
this->m_timeSync = v; this->m_timeSync = v;
return msgs; return CLogMessage().info(CSettingUtilities::updateMessageCategory(), "time synchronization%1 changed") << (changedFlag ? "" : " not");
} }
return CSettingUtilities::wrongCommandMessages(command); return CLogMessage().error(CSettingUtilities::validationMessageCategory(), "wrong command: %1") << command;
} }
else if (path == CSettingsSimulator::ValueSyncTimeOffset()) else if (path == CSettingsSimulator::ValueSyncTimeOffset())
{ {
@@ -184,15 +182,14 @@ namespace BlackSim
{ {
CTime v = value.value<CTime>(); CTime v = value.value<CTime>();
changedFlag = (v != this->m_timeSyncOffset); changedFlag = (v != this->m_timeSyncOffset);
msgs.push_back(CSettingUtilities::valueChangedMessage(changedFlag, "time synchronization offset"));
this->m_timeSyncOffset = v; this->m_timeSyncOffset = v;
return msgs; return CLogMessage().info(CSettingUtilities::updateMessageCategory(), "time synchronization offset%1 changed") << (changedFlag ? "" : " not");
} }
return CSettingUtilities::wrongCommandMessages(command); return CLogMessage().error(CSettingUtilities::validationMessageCategory(), "wrong command: %1") << command;
} }
else else
{ {
return CSettingUtilities::wrongPathMessages(path); return CLogMessage().error(CSettingUtilities::validationMessageCategory(), "wrong path: %1") << path;
} }
} }
} // namespace } // namespace

View File

@@ -81,7 +81,7 @@ namespace BlackSim
void initDefaultValues(); void initDefaultValues();
//! \copydoc BlackCore::IContextSettings //! \copydoc BlackCore::IContextSettings
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const BlackMisc::CVariant &value, bool &changedFlag); virtual BlackMisc::CStatusMessage value(const QString &path, const QString &command, const BlackMisc::CVariant &value, bool &changedFlag);
//! \copydoc CValueObject::getValueHash //! \copydoc CValueObject::getValueHash
virtual uint getValueHash() const override; virtual uint getValueHash() const override;

View File

@@ -11,6 +11,7 @@
#include "blacksim/simulatorinfo.h" #include "blacksim/simulatorinfo.h"
#include "blackmisc/project.h" #include "blackmisc/project.h"
#include "blackmisc/avairportlist.h" #include "blackmisc/avairportlist.h"
#include "blackmisc/logmessage.h"
#include <QTimer> #include <QTimer>
#include <QtConcurrent> #include <QtConcurrent>
@@ -550,8 +551,7 @@ namespace BlackSimPlugin
} }
m_syncDeferredCounter = 5; // allow some time to sync m_syncDeferredCounter = 5; // allow some time to sync
QString msg = QString("Synchronized time to UTC: %1").arg(myTime.toString()); CLogMessage().info(this, "Synchronized time to UTC: %1") << myTime.toString();
this->sendStatusMessage(CStatusMessage::getInfoMessage(msg, CStatusMessage::TypeSimulator));
} }
} }
} }

View File

@@ -11,6 +11,7 @@
#include "blacksim/simulatorinfo.h" #include "blacksim/simulatorinfo.h"
#include "blackmisc/project.h" #include "blackmisc/project.h"
#include "blackmisc/avairportlist.h" #include "blackmisc/avairportlist.h"
#include "blackmisc/logmessage.h"
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Aviation; using namespace BlackMisc::Aviation;
@@ -37,7 +38,7 @@ namespace BlackSimPlugin
.arg(event->szApplicationName) .arg(event->szApplicationName)
.arg(event->dwApplicationVersionMajor).arg(event->dwApplicationVersionMinor).arg(event->dwApplicationBuildMajor).arg(event->dwApplicationBuildMinor) .arg(event->dwApplicationVersionMajor).arg(event->dwApplicationVersionMinor).arg(event->dwApplicationBuildMajor).arg(event->dwApplicationBuildMinor)
.arg(event->dwSimConnectVersionMajor).arg(event->dwSimConnectVersionMinor).arg(event->dwSimConnectBuildMajor).arg(event->dwSimConnectBuildMinor); .arg(event->dwSimConnectVersionMajor).arg(event->dwSimConnectVersionMinor).arg(event->dwSimConnectBuildMajor).arg(event->dwSimConnectBuildMinor);
simulatorFsx->displayStatusMessage(CStatusMessage::getInfoMessage(CProject::systemNameAndVersion())); CLogMessage().info(CSimulatorFsx::getMessageCategory(), CProject::systemNameAndVersion());
break; break;
} }
case SIMCONNECT_RECV_ID_EXCEPTION: case SIMCONNECT_RECV_ID_EXCEPTION:

View File

@@ -6,6 +6,7 @@
#include "simulator_xplane.h" #include "simulator_xplane.h"
#include "xbus_service_proxy.h" #include "xbus_service_proxy.h"
#include "xbus_traffic_proxy.h" #include "xbus_traffic_proxy.h"
#include "blackmisc/logmessage.h"
#include <QDBusServiceWatcher> #include <QDBusServiceWatcher>
#include <QTimer> #include <QTimer>
@@ -254,7 +255,7 @@ namespace BlackSimPlugin
{ {
if (enable) if (enable)
{ {
emit displayStatusMessage(CStatusMessage::getWarningMessage("X-Plane already provides real time synchronization", CStatusMessage::TypeSimulator)); CLogMessage().warning(this, "X-Plane already provides real time synchronization");
} }
} }