mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 01:45:38 +08:00
refs #467 Mechanism for processes to notify each other of which log patterns they are subscribed to.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "voice_channel.h"
|
||||
#include "network.h"
|
||||
#include "simulator.h"
|
||||
#include "context_application.h"
|
||||
#include <QThread>
|
||||
|
||||
namespace BlackCore
|
||||
@@ -19,6 +20,8 @@ namespace BlackCore
|
||||
qRegisterMetaType<BlackCore::INetwork::ConnectionStatus>();
|
||||
qRegisterMetaType<BlackCore::CWebReaderFlags::WebReaderFlag>();
|
||||
qRegisterMetaType<BlackCore::CWebReaderFlags::WebReader>();
|
||||
qDBusRegisterMetaType<BlackCore::CLogSubscriptionHash>();
|
||||
qDBusRegisterMetaType<BlackCore::CLogSubscriptionPair>();
|
||||
}
|
||||
|
||||
bool isCurrentThreadObjectThread(QObject *toBeTested)
|
||||
|
||||
@@ -48,6 +48,22 @@ namespace BlackCore
|
||||
{
|
||||
this->logMessage(message, {});
|
||||
});
|
||||
connect(CLogHandler::instance(), &CLogHandler::subscriptionAdded, this, [this](const CLogPattern &pattern)
|
||||
{
|
||||
this->addLogSubscription({}, pattern);
|
||||
});
|
||||
connect(CLogHandler::instance(), &CLogHandler::subscriptionRemoved, this, [this](const CLogPattern &pattern)
|
||||
{
|
||||
this->removeLogSubscription({}, pattern);
|
||||
});
|
||||
connect(this, &IContextApplication::logSubscriptionAdded, this, [this](const CIdentifier &subscriber, const CLogPattern &pattern)
|
||||
{
|
||||
this->m_logSubscriptions[subscriber].push_back(pattern);
|
||||
});
|
||||
connect(this, &IContextApplication::logSubscriptionRemoved, this, [this](const CIdentifier &subscriber, const CLogPattern &pattern)
|
||||
{
|
||||
this->m_logSubscriptions[subscriber].removeAll(pattern);
|
||||
});
|
||||
|
||||
connect(CSettingsCache::instance(), &CSettingsCache::valuesChangedByLocal, [this](const CVariantMap &settings)
|
||||
{
|
||||
@@ -122,3 +138,18 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
QDBusArgument &operator <<(QDBusArgument &arg, const BlackCore::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::CLogSubscriptionHash &hash)
|
||||
{
|
||||
QList<CLogSubscriptionPair> listOfPairs;
|
||||
arg >> listOfPairs;
|
||||
for (const auto &pair : listOfPairs) { hash.insert(pair.first, pair.second); }
|
||||
return arg;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "blackmisc/audio/voiceroomlist.h"
|
||||
#include "blackmisc/identifierlist.h"
|
||||
#include "blackmisc/variantmap.h"
|
||||
#include "blackmisc/logpattern.h"
|
||||
#include <QObject>
|
||||
#include <QReadWriteLock>
|
||||
|
||||
@@ -36,6 +37,12 @@ namespace BlackCore
|
||||
{
|
||||
class CInputManager;
|
||||
|
||||
//! 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>>;
|
||||
|
||||
//! Application context interface
|
||||
class BLACKCORE_EXPORT IContextApplication : public CContext
|
||||
{
|
||||
@@ -78,6 +85,14 @@ namespace BlackCore
|
||||
//! \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::CVariantMap &settings, const BlackMisc::CIdentifier &origin);
|
||||
@@ -93,12 +108,30 @@ namespace BlackCore
|
||||
//! Work around for audio context, #382
|
||||
void fakedSetComVoiceRoom(const BlackMisc::Audio::CVoiceRoomList &requestedRooms);
|
||||
|
||||
protected:
|
||||
//! Tracks which processes are subscribed to which patterns of log messages.
|
||||
CLogSubscriptionHash m_logSubscriptions;
|
||||
|
||||
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::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.
|
||||
@@ -154,4 +187,13 @@ namespace BlackCore
|
||||
};
|
||||
}
|
||||
|
||||
//! DBus marshalling for CLogSubscriptionHash, needed because QtDBus can't marshal a QHash with CIdentifier keys.
|
||||
QDBusArgument &operator <<(QDBusArgument &arg, const BlackCore::CLogSubscriptionHash &);
|
||||
|
||||
//! DBus unmarshalling for CLogSubscriptionHash, needed because QtDBus can't marshal a QHash with CIdentifier keys.
|
||||
const QDBusArgument &operator >>(const QDBusArgument &arg, BlackCore::CLogSubscriptionHash &);
|
||||
|
||||
Q_DECLARE_METATYPE(BlackCore::CLogSubscriptionHash)
|
||||
Q_DECLARE_METATYPE(BlackCore::CLogSubscriptionPair)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -41,6 +41,29 @@ namespace BlackCore
|
||||
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 CVariantMap &settings, const CIdentifier &origin)
|
||||
{
|
||||
// Intentionally don't check for round trip here
|
||||
|
||||
@@ -32,6 +32,18 @@ namespace BlackCore
|
||||
//! \copydoc IContextApplication::logMessage
|
||||
virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin) override;
|
||||
|
||||
//! \copydoc IContextApplication::addLogSubscription
|
||||
virtual void addLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override;
|
||||
|
||||
//! \copydoc IContextApplication::removeLogSubscription
|
||||
virtual void removeLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override;
|
||||
|
||||
//! \copydoc IContextApplication::getAllLogSubscriptions
|
||||
virtual CLogSubscriptionHash getAllLogSubscriptions() const;
|
||||
|
||||
//! \copydoc IContextApplication::synchronizeLogSubscriptions
|
||||
virtual void synchronizeLogSubscriptions();
|
||||
|
||||
//! \copydoc IContextApplication::changeSettings
|
||||
virtual void changeSettings(const BlackMisc::CVariantMap &settings, const BlackMisc::CIdentifier &origin) override;
|
||||
|
||||
|
||||
@@ -43,6 +43,12 @@ namespace BlackCore
|
||||
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::CVariantMap, BlackMisc::CIdentifier)));
|
||||
Q_ASSERT(s);
|
||||
@@ -62,6 +68,28 @@ namespace BlackCore
|
||||
this->m_dBusInterface->callDBus(QLatin1Literal("logMessage"), message, origin);
|
||||
}
|
||||
|
||||
void CContextApplicationProxy::addLogSubscription(const CIdentifier &subscriber, const CLogPattern &pattern)
|
||||
{
|
||||
this->m_dBusInterface->callDBus(QLatin1Literal("addLogSubscription"), subscriber, pattern);
|
||||
}
|
||||
|
||||
void CContextApplicationProxy::removeLogSubscription(const CIdentifier &subscriber, const CLogPattern &pattern)
|
||||
{
|
||||
this->m_dBusInterface->callDBus(QLatin1Literal("removeLogSubscription"), subscriber, pattern);
|
||||
}
|
||||
|
||||
CLogSubscriptionHash CContextApplicationProxy::getAllLogSubscriptions() const
|
||||
{
|
||||
return this->m_dBusInterface->callDBusRet<CLogSubscriptionHash>(QLatin1Literal("getAllLogSubscriptions"));
|
||||
}
|
||||
|
||||
void CContextApplicationProxy::synchronizeLogSubscriptions()
|
||||
{
|
||||
// note this proxy method does not call synchronizeLogSubscriptions in core
|
||||
m_logSubscriptions = getAllLogSubscriptions();
|
||||
for (const auto &pattern : CLogHandler::instance()->getAllSubscriptions()) { this->addLogSubscription({}, pattern); }
|
||||
}
|
||||
|
||||
void CContextApplicationProxy::changeSettings(const CVariantMap &settings, const CIdentifier &origin)
|
||||
{
|
||||
this->m_dBusInterface->callDBus(QLatin1Literal("changeSettings"), settings, origin);
|
||||
|
||||
@@ -28,6 +28,18 @@ namespace BlackCore
|
||||
//! \copydoc IContextApplication::logMessage
|
||||
virtual void logMessage(const BlackMisc::CStatusMessage &message, const BlackMisc::CIdentifier &origin) override;
|
||||
|
||||
//! \copydoc IContextApplication::addLogSubscription
|
||||
virtual void addLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override;
|
||||
|
||||
//! \copydoc IContextApplication::removeLogSubscription
|
||||
virtual void removeLogSubscription(const BlackMisc::CIdentifier &subscriber, const BlackMisc::CLogPattern &pattern) override;
|
||||
|
||||
//! \copydoc IContextApplication::getAllLogSubscriptions
|
||||
virtual CLogSubscriptionHash getAllLogSubscriptions() const;
|
||||
|
||||
//! \copydoc IContextApplication::synchronizeLogSubscriptions
|
||||
virtual void synchronizeLogSubscriptions();
|
||||
|
||||
//! \copydoc IContextApplication::changeSettings
|
||||
virtual void changeSettings(const BlackMisc::CVariantMap &settings, const BlackMisc::CIdentifier &origin) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user