mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
Issue #15 Removed old log distribution code
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
#include "blackmisc/dbus.h"
|
||||
#include "blackmisc/dbusserver.h"
|
||||
#include "blackmisc/logcategory.h"
|
||||
#include "blackmisc/loghandler.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
@@ -53,32 +52,6 @@ namespace BlackCore
|
||||
if (mode == CCoreFacadeConfig::NotUsed) { return; }
|
||||
QPointer<IContextApplication> myself(this);
|
||||
|
||||
connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, this, [ = ](const CStatusMessage & message)
|
||||
{
|
||||
if (!myself) { return; }
|
||||
this->logMessage(message, {});
|
||||
});
|
||||
connect(CLogHandler::instance(), &CLogHandler::subscriptionAdded, this, [ = ](const CLogPattern & pattern)
|
||||
{
|
||||
if (!myself) { return; }
|
||||
this->addLogSubscription({}, pattern);
|
||||
});
|
||||
connect(CLogHandler::instance(), &CLogHandler::subscriptionRemoved, this, [ = ](const CLogPattern & pattern)
|
||||
{
|
||||
if (!myself) { return; }
|
||||
this->removeLogSubscription({}, pattern);
|
||||
});
|
||||
connect(this, &IContextApplication::logSubscriptionAdded, this, [ = ](const CIdentifier & subscriber, const CLogPattern & pattern)
|
||||
{
|
||||
if (!myself) { return; }
|
||||
m_logSubscriptions[subscriber].push_back(pattern);
|
||||
});
|
||||
connect(this, &IContextApplication::logSubscriptionRemoved, this, [ = ](const CIdentifier & subscriber, const CLogPattern & pattern)
|
||||
{
|
||||
if (!myself) { return; }
|
||||
m_logSubscriptions[subscriber].removeAll(pattern);
|
||||
});
|
||||
|
||||
connect(CSettingsCache::instance(), &CSettingsCache::valuesChangedByLocal, this, [ = ](const CValueCachePacket & settings)
|
||||
{
|
||||
if (!myself) { return; }
|
||||
@@ -122,17 +95,6 @@ namespace BlackCore
|
||||
sApp->getInputManager()->setForwarding(true);
|
||||
}
|
||||
|
||||
CIdentifierList IContextApplication::subscribersOf(const CStatusMessage &message) const
|
||||
{
|
||||
CIdentifierList result;
|
||||
for (auto it = m_logSubscriptions.begin(); it != m_logSubscriptions.end(); ++it)
|
||||
{
|
||||
bool match = std::any_of(it->begin(), it->end(), [&message](const CLogPattern & pattern) { return pattern.match(message); });
|
||||
if (match) { result.push_back(it.key()); }
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void IContextApplication::changeSettings(const CValueCachePacket &settings, const CIdentifier &origin)
|
||||
{
|
||||
Q_UNUSED(settings);
|
||||
@@ -161,18 +123,3 @@ namespace BlackCore
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
QDBusArgument &operator <<(QDBusArgument &arg, const BlackCore::Context::CLogSubscriptionHash &hash)
|
||||
{
|
||||
QList<CLogSubscriptionPair> listOfPairs;
|
||||
for (auto it = hash.begin(); it != hash.end(); ++it) { listOfPairs.push_back({ it.key(), it.value() }); }
|
||||
return arg << listOfPairs;
|
||||
}
|
||||
|
||||
const QDBusArgument &operator >>(const QDBusArgument &arg, BlackCore::Context::CLogSubscriptionHash &hash)
|
||||
{
|
||||
QList<CLogSubscriptionPair> listOfPairs;
|
||||
arg >> listOfPairs;
|
||||
for (const auto &pair : as_const(listOfPairs)) { hash.insert(pair.first, pair.second); }
|
||||
return arg;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "blackmisc/dictionary.h"
|
||||
#include "blackmisc/identifier.h"
|
||||
#include "blackmisc/identifierlist.h"
|
||||
#include "blackmisc/logpattern.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/valuecache.h"
|
||||
|
||||
@@ -54,12 +53,6 @@ namespace BlackCore
|
||||
|
||||
namespace Context
|
||||
{
|
||||
//! Used by application context to track which processes are subscribed to which patterns of log message
|
||||
using CLogSubscriptionHash = QHash<BlackMisc::CIdentifier, QList<BlackMisc::CLogPattern>>;
|
||||
|
||||
//! Used when marshalling CLogSubscriptionHash, as a QHash with CIdentifier keys can't be marshalled
|
||||
using CLogSubscriptionPair = QPair<BlackMisc::CIdentifier, QList<BlackMisc::CLogPattern>>;
|
||||
|
||||
//! Value type for settings keys with descriptions
|
||||
using CSettingsDictionary = BlackMisc::CDictionary<QString, QString, QMap>;
|
||||
|
||||
@@ -97,18 +90,6 @@ namespace BlackCore
|
||||
//! A component changes
|
||||
void registrationChanged();
|
||||
|
||||
//! A log message was logged
|
||||
//! \note Used with CLogMessage, do not use directly
|
||||
void messageLogged(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin);
|
||||
|
||||
//! A process subscribed to a particular pattern of log messages
|
||||
//! \note Used with CLogMessage, do not use directly
|
||||
void logSubscriptionAdded(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern);
|
||||
|
||||
//! A process unsubscribed from a particular pattern of log messages
|
||||
//! \note Used with CLogMessage, do not use directly
|
||||
void logSubscriptionRemoved(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern);
|
||||
|
||||
//! One or more settings were changed
|
||||
//! \note Used for cache relay, do not use directly
|
||||
void settingsChanged(const BlackMisc::CValueCachePacket &settings, const BlackMisc::CIdentifier &origin);
|
||||
@@ -126,25 +107,6 @@ namespace BlackCore
|
||||
void requestDisplayOnConsole(const QString &message);
|
||||
|
||||
public slots:
|
||||
//! Log a log message
|
||||
//! \note Not pure because it can be called from the base class constructor.
|
||||
//! \note this is the function which relays CLogMessage via DBus
|
||||
virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin) { Q_UNUSED(message); Q_UNUSED(origin); }
|
||||
|
||||
//! Subscribe a process to a particular pattern of log messages
|
||||
//! \note This is the function which relays subscription changes via DBus
|
||||
virtual void addLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) = 0;
|
||||
|
||||
//! Unsubscribe a process from a particular pattern of log messages
|
||||
//! \note This is the function which relays subscription changes via DBus
|
||||
virtual void removeLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) = 0;
|
||||
|
||||
//! Returns hash identifying which processes are subscribed to which patterns of log message
|
||||
virtual BlackCore::Context::CLogSubscriptionHash getAllLogSubscriptions() const = 0;
|
||||
|
||||
//! Update log subscriptions hash from core
|
||||
virtual void synchronizeLogSubscriptions() = 0;
|
||||
|
||||
//! Ratify some settings changed by another process
|
||||
//! \note Not pure because it can be called from the base class constructor.
|
||||
//! \note This is the function which relays cache changes via DBus.
|
||||
@@ -216,24 +178,10 @@ namespace BlackCore
|
||||
|
||||
//! Constructor
|
||||
IContextApplication(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime);
|
||||
|
||||
//! Compute which process' subscriptions match a given log message.
|
||||
BlackMisc::CIdentifierList subscribersOf(const BlackMisc::CStatusMessage &message) const;
|
||||
|
||||
//! Tracks which processes are subscribed to which patterns of log messages.
|
||||
CLogSubscriptionHash m_logSubscriptions;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
//! DBus marshalling for CLogSubscriptionHash, needed because QtDBus can't marshal a QHash with CIdentifier keys.
|
||||
QDBusArgument &operator <<(QDBusArgument &arg, const BlackCore::Context::CLogSubscriptionHash &);
|
||||
|
||||
//! DBus unmarshalling for CLogSubscriptionHash, needed because QtDBus can't marshal a QHash with CIdentifier keys.
|
||||
const QDBusArgument &operator >>(const QDBusArgument &arg, BlackCore::Context::CLogSubscriptionHash &);
|
||||
|
||||
Q_DECLARE_METATYPE(BlackCore::Context::CLogSubscriptionHash)
|
||||
Q_DECLARE_METATYPE(BlackCore::Context::CLogSubscriptionPair)
|
||||
Q_DECLARE_METATYPE(BlackCore::Context::CSettingsDictionary)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -33,44 +33,6 @@ namespace BlackCore
|
||||
CContextApplicationEmpty(CCoreFacade *runtime) : IContextApplication(CCoreFacadeConfig::NotUsed, runtime) {}
|
||||
|
||||
public slots:
|
||||
//! \copydoc IContextApplication::logMessage
|
||||
virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin) override
|
||||
{
|
||||
Q_UNUSED(message);
|
||||
Q_UNUSED(origin);
|
||||
logEmptyContextWarning(Q_FUNC_INFO);
|
||||
}
|
||||
|
||||
//! \copydoc IContextApplication::addLogSubscription
|
||||
virtual void addLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override
|
||||
{
|
||||
Q_UNUSED(subscriber);
|
||||
Q_UNUSED(pattern);
|
||||
logEmptyContextWarning(Q_FUNC_INFO);
|
||||
}
|
||||
|
||||
//! \copydoc IContextApplication::removeLogSubscription
|
||||
virtual void removeLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override
|
||||
{
|
||||
Q_UNUSED(subscriber);
|
||||
Q_UNUSED(pattern);
|
||||
logEmptyContextWarning(Q_FUNC_INFO);
|
||||
|
||||
}
|
||||
|
||||
//! \copydoc IContextApplication::getAllLogSubscriptions
|
||||
virtual BlackCore::Context::CLogSubscriptionHash getAllLogSubscriptions() const override
|
||||
{
|
||||
logEmptyContextWarning(Q_FUNC_INFO);
|
||||
return CLogSubscriptionHash();
|
||||
}
|
||||
|
||||
//! \copydoc IContextApplication::synchronizeLogSubscriptions
|
||||
virtual void synchronizeLogSubscriptions() override
|
||||
{
|
||||
logEmptyContextWarning(Q_FUNC_INFO);
|
||||
}
|
||||
|
||||
//! \copydoc IContextApplication::changeSettings
|
||||
virtual void changeSettings(const BlackMisc::CValueCachePacket &settings, const BlackMisc::CIdentifier &origin) override
|
||||
{
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "blackcore/inputmanager.h"
|
||||
#include "blackmisc/dbusserver.h"
|
||||
#include "blackmisc/logcategory.h"
|
||||
#include "blackmisc/loghandler.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/simplecommandparser.h"
|
||||
@@ -39,41 +38,6 @@ namespace BlackCore
|
||||
return this;
|
||||
}
|
||||
|
||||
void CContextApplication::logMessage(const CStatusMessage &message, const CIdentifier &origin)
|
||||
{
|
||||
if (!origin.hasApplicationProcessId())
|
||||
{
|
||||
CLogHandler::instance()->logRemoteMessage(message);
|
||||
}
|
||||
if (subscribersOf(message).containsAnyNotIn(CIdentifierList({ origin, {} })))
|
||||
{
|
||||
emit this->messageLogged(message, origin);
|
||||
}
|
||||
}
|
||||
|
||||
void CContextApplication::addLogSubscription(const CIdentifier &subscriber, const CLogPattern &pattern)
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
emit this->logSubscriptionAdded(subscriber, pattern);
|
||||
}
|
||||
|
||||
void CContextApplication::removeLogSubscription(const CIdentifier &subscriber, const CLogPattern &pattern)
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
emit this->logSubscriptionRemoved(subscriber, pattern);
|
||||
}
|
||||
|
||||
CLogSubscriptionHash CContextApplication::getAllLogSubscriptions() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
return m_logSubscriptions;
|
||||
}
|
||||
|
||||
void CContextApplication::synchronizeLogSubscriptions()
|
||||
{
|
||||
// no-op: proxy implements this method by calling getAllLogSubscriptions
|
||||
}
|
||||
|
||||
void CContextApplication::changeSettings(const CValueCachePacket &settings, const CIdentifier &origin)
|
||||
{
|
||||
// Intentionally don't check for round trip here
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
namespace BlackMisc
|
||||
{
|
||||
class CDBusServer;
|
||||
class CLogPattern;
|
||||
}
|
||||
|
||||
namespace BlackCore
|
||||
@@ -49,11 +48,6 @@ namespace BlackCore
|
||||
public slots:
|
||||
//! @{
|
||||
//! \publicsection
|
||||
virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin) override;
|
||||
virtual void addLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override;
|
||||
virtual void removeLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override;
|
||||
virtual BlackCore::Context::CLogSubscriptionHash getAllLogSubscriptions() const override;
|
||||
virtual void synchronizeLogSubscriptions() override;
|
||||
virtual void changeSettings(const BlackMisc::CValueCachePacket &settings, const BlackMisc::CIdentifier &origin) override;
|
||||
virtual BlackMisc::CValueCachePacket getAllSettings() const override;
|
||||
virtual QStringList getUnsavedSettingsKeys() const override;
|
||||
|
||||
@@ -30,14 +30,6 @@ namespace BlackCore
|
||||
m_dBusInterface = new CGenericDBusInterface(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(), connection, this);
|
||||
this->relaySignals(serviceName, connection);
|
||||
|
||||
connect(this, &IContextApplication::messageLogged, this, [](const CStatusMessage & message, const CIdentifier & origin)
|
||||
{
|
||||
if (!origin.hasApplicationProcessId())
|
||||
{
|
||||
CLogHandler::instance()->logRemoteMessage(message);
|
||||
}
|
||||
});
|
||||
|
||||
connect(this, &CContextApplicationProxy::remoteHotkeyAction, this, &CContextApplicationProxy::processRemoteHotkeyActionCall);
|
||||
|
||||
m_pingTimer.setObjectName(serviceName + "::m_pingTimer");
|
||||
@@ -49,15 +41,6 @@ namespace BlackCore
|
||||
{
|
||||
// signals originating from impl side
|
||||
bool s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(),
|
||||
"messageLogged", this, SIGNAL(messageLogged(BlackMisc::CStatusMessage, BlackMisc::CIdentifier)));
|
||||
Q_ASSERT(s);
|
||||
s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(),
|
||||
"logSubscriptionAdded", this, SIGNAL(logSubscriptionAdded(BlackMisc::CIdentifier, BlackMisc::CLogPattern)));
|
||||
Q_ASSERT(s);
|
||||
s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(),
|
||||
"logSubscriptionRemoved", this, SIGNAL(logSubscriptionRemoved(BlackMisc::CIdentifier, BlackMisc::CLogPattern)));
|
||||
Q_ASSERT(s);
|
||||
s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(),
|
||||
"settingsChanged", this, SIGNAL(settingsChanged(BlackMisc::CValueCachePacket, BlackMisc::CIdentifier)));
|
||||
Q_ASSERT(s);
|
||||
s = connection.connect(serviceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(),
|
||||
@@ -75,36 +58,6 @@ namespace BlackCore
|
||||
this->relayBaseClassSignals(serviceName, connection, IContextApplication::ObjectPath(), IContextApplication::InterfaceName());
|
||||
}
|
||||
|
||||
void CContextApplicationProxy::logMessage(const CStatusMessage &message, const CIdentifier &origin)
|
||||
{
|
||||
if (subscribersOf(message).containsAnyNotIn(CIdentifierList({ origin, {} })))
|
||||
{
|
||||
m_dBusInterface->callDBus(QLatin1String("logMessage"), message, origin);
|
||||
}
|
||||
}
|
||||
|
||||
void CContextApplicationProxy::addLogSubscription(const CIdentifier &subscriber, const CLogPattern &pattern)
|
||||
{
|
||||
m_dBusInterface->callDBus(QLatin1String("addLogSubscription"), subscriber, pattern);
|
||||
}
|
||||
|
||||
void CContextApplicationProxy::removeLogSubscription(const CIdentifier &subscriber, const CLogPattern &pattern)
|
||||
{
|
||||
m_dBusInterface->callDBus(QLatin1String("removeLogSubscription"), subscriber, pattern);
|
||||
}
|
||||
|
||||
CLogSubscriptionHash CContextApplicationProxy::getAllLogSubscriptions() const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<CLogSubscriptionHash>(QLatin1String("getAllLogSubscriptions"));
|
||||
}
|
||||
|
||||
void CContextApplicationProxy::synchronizeLogSubscriptions()
|
||||
{
|
||||
// note this proxy method does not call synchronizeLogSubscriptions in core
|
||||
m_logSubscriptions = this->getAllLogSubscriptions();
|
||||
for (const auto &pattern : CLogHandler::instance()->getAllSubscriptions()) { this->addLogSubscription({}, pattern); }
|
||||
}
|
||||
|
||||
void CContextApplicationProxy::changeSettings(const CValueCachePacket &settings, const CIdentifier &origin)
|
||||
{
|
||||
m_dBusInterface->callDBus(QLatin1String("changeSettings"), settings, origin);
|
||||
|
||||
@@ -30,7 +30,6 @@ class QDBusConnection;
|
||||
namespace BlackMisc
|
||||
{
|
||||
class CGenericDBusInterface;
|
||||
class CLogPattern;
|
||||
}
|
||||
|
||||
namespace BlackCore
|
||||
@@ -52,11 +51,6 @@ namespace BlackCore
|
||||
public slots:
|
||||
//! @{
|
||||
//! \publicsection
|
||||
virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin) override;
|
||||
virtual void addLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override;
|
||||
virtual void removeLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override;
|
||||
virtual BlackCore::Context::CLogSubscriptionHash getAllLogSubscriptions() const override;
|
||||
virtual void synchronizeLogSubscriptions() override;
|
||||
virtual void changeSettings(const BlackMisc::CValueCachePacket &settings, const BlackMisc::CIdentifier &origin) override;
|
||||
virtual BlackMisc::CValueCachePacket getAllSettings() const override;
|
||||
virtual QStringList getUnsavedSettingsKeys() const override;
|
||||
|
||||
Reference in New Issue
Block a user