diff --git a/lib/api/LogManagerImpl.cpp b/lib/api/LogManagerImpl.cpp index 0e074795..7fc32e12 100644 --- a/lib/api/LogManagerImpl.cpp +++ b/lib/api/LogManagerImpl.cpp @@ -402,7 +402,7 @@ namespace MAT_NS_BEGIN m_httpClient = nullptr; m_taskDispatcher = nullptr; m_dataViewer = nullptr; - m_dataInspector = nullptr; + ClearDataInspectors(); m_filters.UnregisterAllFilters(); @@ -525,9 +525,9 @@ namespace MAT_NS_BEGIN m_context.SetCustomField(name, prop); { LOCKGUARD(m_dataInspectorGuard); - if (m_dataInspector) + for(const auto& dataInspector : m_dataInspectors) { - m_dataInspector->InspectSemanticContext(name, value, /*isGlobalContext: */ true, std::string{}); + dataInspector->InspectSemanticContext(name, value, /*isGlobalContext: */ true, std::string{}); } } return STATUS_SUCCESS; @@ -603,9 +603,9 @@ namespace MAT_NS_BEGIN m_context.SetCustomField(name, prop); { LOCKGUARD(m_dataInspectorGuard); - if (m_dataInspector) + for(const auto& dataInspector : m_dataInspectors) { - m_dataInspector->InspectSemanticContext(name, value, /*isGlobalContext: */ true, std::string{}); + dataInspector->InspectSemanticContext(name, value, /*isGlobalContext: */ true, std::string{}); } } return STATUS_SUCCESS; @@ -710,9 +710,9 @@ namespace MAT_NS_BEGIN { LOCKGUARD(m_dataInspectorGuard); - if (m_dataInspector) + for (const auto& dataInspector : m_dataInspectors) { - m_dataInspector->InspectRecord(*(event->source)); + dataInspector->InspectRecord(*(event->source)); } } GetSystem()->sendEvent(event); @@ -807,12 +807,53 @@ namespace MAT_NS_BEGIN void LogManagerImpl::SetDataInspector(const std::shared_ptr& dataInspector) { LOCKGUARD(m_dataInspectorGuard); - m_dataInspector = dataInspector; + if(dataInspector == nullptr) + { + LOG_WARN("Attempting to set nullptr as DataInspector"); + return; + } + + auto itDataInspector = std::find_if(m_dataInspectors.begin(), m_dataInspectors.end(), [&dataInspector](const std::shared_ptr& currentInspector) + { + return strcmp(dataInspector->GetName(), currentInspector->GetName()) == 0; + }); + + if (itDataInspector != m_dataInspectors.end()) + { + LOG_WARN("Replacing specified IDataInspector with passed in inspector"); + m_dataInspectors.erase(itDataInspector); + } + + m_dataInspectors.push_back(dataInspector); } - std::shared_ptr LogManagerImpl::GetDataInspector() noexcept + void LogManagerImpl::ClearDataInspectors() { - return m_dataInspector; + LOCKGUARD(m_dataInspectorGuard); + std::vector>{}.swap(m_dataInspectors); + } + + void LogManagerImpl::RemoveDataInspector(const std::string& name) + { + LOCKGUARD(m_dataInspectorGuard); + auto itDataInspector = std::find_if(m_dataInspectors.begin(), m_dataInspectors.end(), [&name](const std::shared_ptr& inspector){ + return strcmp(inspector->GetName(), name.c_str()) == 0; + }); + + if (itDataInspector != m_dataInspectors.end()) + { + m_dataInspectors.erase(itDataInspector); + } + } + + std::shared_ptr LogManagerImpl::GetDataInspector(const std::string& name) noexcept + { + LOCKGUARD(m_dataInspectorGuard); + auto it = std::find_if(m_dataInspectors.begin(), m_dataInspectors.end(), [&name](const std::shared_ptr& inspector){ + return strcmp(inspector->GetName(), name.c_str()) == 0; + }); + + return it != m_dataInspectors.end() ? *it : nullptr; } status_t LogManagerImpl::DeleteData() diff --git a/lib/api/LogManagerImpl.hpp b/lib/api/LogManagerImpl.hpp index e8ed5524..5926368a 100644 --- a/lib/api/LogManagerImpl.hpp +++ b/lib/api/LogManagerImpl.hpp @@ -297,8 +297,9 @@ namespace MAT_NS_BEGIN static size_t GetDeadLoggerCount(); virtual void SetDataInspector(const std::shared_ptr& dataInspector) override; - - virtual std::shared_ptr GetDataInspector() noexcept override; + virtual void ClearDataInspectors() override; + virtual void RemoveDataInspector(const std::string& name) override; + virtual std::shared_ptr GetDataInspector(const std::string& name) noexcept override; protected: std::unique_ptr& GetSystem(); @@ -337,7 +338,7 @@ namespace MAT_NS_BEGIN EventFilterCollection m_filters; std::vector> m_modules; DataViewerCollection m_dataViewerCollection; - std::shared_ptr m_dataInspector; + std::vector> m_dataInspectors; std::recursive_mutex m_dataInspectorGuard; }; diff --git a/lib/include/public/IDataInspector.hpp b/lib/include/public/IDataInspector.hpp index 06e5ce7a..b6842bda 100644 --- a/lib/include/public/IDataInspector.hpp +++ b/lib/include/public/IDataInspector.hpp @@ -64,6 +64,12 @@ namespace MAT_NS_BEGIN /// Whether this is a global/logmanager Context or local ILogger context /// (Optional) Tenant associated with the Context virtual void InspectSemanticContext(const std::string& contextName, GUID_t contextValue, bool isGlobalContext, const std::string& associatedTenant) noexcept = 0; + + /// + /// Returns unique name for current Data Inspector + /// + /// Name of Data Inspector + virtual const char* GetName() const noexcept { return ""; } }; } diff --git a/lib/include/public/ILogManager.hpp b/lib/include/public/ILogManager.hpp index 11c261b3..9d1c78dd 100644 --- a/lib/include/public/ILogManager.hpp +++ b/lib/include/public/ILogManager.hpp @@ -380,10 +380,28 @@ namespace MAT_NS_BEGIN virtual void SetDataInspector(const std::shared_ptr& dataInspector) = 0; /// - /// Get the current instance of IDataInspector + /// Clears all IDataInspectors /// - /// Current instance of IDataInspector if set, nullptr otherwise. - virtual std::shared_ptr GetDataInspector() noexcept = 0; + virtual void ClearDataInspectors() = 0; + + /// + /// Removes specified IDataInspector + /// + /// String name that identifies IDataInspector + virtual void RemoveDataInspector(const std::string& name) = 0; + + /// + /// Get the current instance of IDataInspector specified by the name + /// + /// String name that identifies IDataInspector + /// Selected instance of IDataInspector if available, nullptr otherwise. + virtual std::shared_ptr GetDataInspector(const std::string& name) noexcept = 0; + + /// + /// Get the current instance of IDataInspector specified by an empty string + /// + /// Selected instance of IDataInspector if available, nullptr otherwise. + virtual std::shared_ptr GetDataInspector() noexcept { return GetDataInspector(std::string{}); } }; } diff --git a/lib/include/public/NullObjects.hpp b/lib/include/public/NullObjects.hpp index 7d6be04c..dbad2b4f 100644 --- a/lib/include/public/NullObjects.hpp +++ b/lib/include/public/NullObjects.hpp @@ -370,7 +370,11 @@ namespace MAT_NS_BEGIN void SetDataInspector(const std::shared_ptr& /*dataInspector*/) override {} - std::shared_ptr GetDataInspector() noexcept override + void RemoveDataInspector(const std::string& /*name*/) override {} + + void ClearDataInspectors() override {} + + std::shared_ptr GetDataInspector(const std::string& /*name*/) noexcept override { return nullptr; }