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:
@@ -24,6 +24,7 @@
|
||||
#include "pixmap.h"
|
||||
#include "iconlist.h"
|
||||
#include "identifierlist.h"
|
||||
#include "logpattern.h"
|
||||
#include <QtNetwork/QHostInfo>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QSysInfo>
|
||||
@@ -83,6 +84,7 @@ void BlackMisc::registerMetadata()
|
||||
CIconList::registerMetadata();
|
||||
CLogCategory::registerMetadata();
|
||||
CLogCategoryList::registerMetadata();
|
||||
CLogPattern::registerMetadata();
|
||||
CPixmap::registerMetadata();
|
||||
CIdentifier::registerMetadata();
|
||||
CIdentifierList::registerMetadata();
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace BlackMisc
|
||||
auto it = std::find_if(m_patternHandlers.begin(), m_patternHandlers.end(), finder);
|
||||
if (it == m_patternHandlers.end())
|
||||
{
|
||||
auto *handler = new CLogPatternHandler(this);
|
||||
auto *handler = new CLogPatternHandler(this, pattern);
|
||||
topologicallySortedInsert(m_patternHandlers, PatternPair(pattern, handler), comparator);
|
||||
return handler;
|
||||
}
|
||||
@@ -149,8 +149,21 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
CLogPatternHandler::CLogPatternHandler(CLogHandler *parent) :
|
||||
QObject(parent), m_parent(parent)
|
||||
QList<CLogPattern> CLogHandler::getAllSubscriptions() const
|
||||
{
|
||||
QList<CLogPattern> result;
|
||||
for (const auto &pair : m_patternHandlers)
|
||||
{
|
||||
if (pair.second->isSignalConnected(QMetaMethod::fromSignal(&CLogPatternHandler::messageLogged)))
|
||||
{
|
||||
result.push_back(pair.first);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
CLogPatternHandler::CLogPatternHandler(CLogHandler *parent, const CLogPattern &pattern) :
|
||||
QObject(parent), m_parent(parent), m_pattern(pattern)
|
||||
{
|
||||
connect(&m_subscriptionUpdateTimer, &QTimer::timeout, this, &CLogPatternHandler::updateSubscription);
|
||||
m_subscriptionUpdateTimer.start(1);
|
||||
@@ -163,7 +176,20 @@ namespace BlackMisc
|
||||
m_subscriptionNeedsUpdate = false;
|
||||
bool isSubscribed = isSignalConnected(QMetaMethod::fromSignal(&CLogPatternHandler::messageLogged));
|
||||
|
||||
if (m_inheritFallThrough && ! isSubscribed)
|
||||
if (isSubscribed != m_isSubscribed)
|
||||
{
|
||||
m_isSubscribed = isSubscribed;
|
||||
if (m_isSubscribed)
|
||||
{
|
||||
emit m_parent->subscriptionAdded(m_pattern);
|
||||
}
|
||||
else
|
||||
{
|
||||
emit m_parent->subscriptionRemoved(m_pattern);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_inheritFallThrough && ! m_isSubscribed)
|
||||
{
|
||||
m_parent->removePatternHandler(this);
|
||||
}
|
||||
|
||||
@@ -63,6 +63,9 @@ namespace BlackMisc
|
||||
return handlerForPattern(CLogPattern::exactMatch(CLogCategory::validation()).withSeverityAtOrAbove(CStatusMessage::SeverityWarning));
|
||||
}
|
||||
|
||||
//! Returns all log patterns for which there are currently subscribed log pattern handlers.
|
||||
QList<CLogPattern> getAllSubscriptions() const;
|
||||
|
||||
signals:
|
||||
//! Emitted when a message is logged in this process.
|
||||
void localMessageLogged(const BlackMisc::CStatusMessage &message);
|
||||
@@ -70,6 +73,12 @@ namespace BlackMisc
|
||||
//! Emitted when a log message is relayed from a different process.
|
||||
void remoteMessageLogged(const BlackMisc::CStatusMessage &message);
|
||||
|
||||
//! Emitted when an object subscribes to a pattern of log messages.
|
||||
void subscriptionAdded(const BlackMisc::CLogPattern &pattern);
|
||||
|
||||
//! Emitted when an object unsubscribes from a pattern of log messages.
|
||||
void subscriptionRemoved(const BlackMisc::CLogPattern &pattern);
|
||||
|
||||
public slots:
|
||||
//! Called by our QtMessageHandler to log a message.
|
||||
void logLocalMessage(const BlackMisc::CStatusMessage &message);
|
||||
@@ -178,11 +187,13 @@ namespace BlackMisc
|
||||
|
||||
private:
|
||||
friend class CLogHandler;
|
||||
CLogPatternHandler(CLogHandler *parent);
|
||||
CLogPatternHandler(CLogHandler *parent, const CLogPattern &pattern);
|
||||
CLogHandler *m_parent = nullptr;
|
||||
CLogPattern m_pattern;
|
||||
bool m_inheritFallThrough = true;
|
||||
bool m_enableFallThrough = true;
|
||||
std::atomic<bool> m_subscriptionNeedsUpdate = false;
|
||||
bool m_isSubscribed = false;
|
||||
std::atomic<bool> m_subscriptionNeedsUpdate { false };
|
||||
QTimer m_subscriptionUpdateTimer;
|
||||
void updateSubscription();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user