- Rename `DataViewerCollectionImpl` to `DataViewerCollection`
- Updated Locks to make them C++11 compatible.
This commit is contained in:
Родитель
789d8c034c
Коммит
7af1bf51de
|
@ -24,7 +24,7 @@
|
|||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\api\LogManager.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\api\LogManagerFactory.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\api\LogManagerImpl.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\api\DataViewerCollectionImpl.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\api\DataViewerCollection.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\api\LogManagerProvider.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\api\LogSessionData.cpp" />
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\backoff\IBackoff.cpp" />
|
||||
|
@ -68,7 +68,7 @@
|
|||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\api\Logger.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\api\LogManagerFactory.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\api\LogManagerImpl.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\api\DataViewerCollectionImpl.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\api\DataViewerCollection.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\backoff\Backoff_ExponentialWithJitter.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\backoff\IBackoff.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\bond\All.hpp" />
|
||||
|
|
|
@ -204,7 +204,7 @@
|
|||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\system\JsonFormatter.cpp">
|
||||
<Filter>system</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\api\DataViewerCollectionImpl.cpp" >
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\api\DataViewerCollection.cpp">
|
||||
<Filter>api</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
|
@ -569,12 +569,12 @@
|
|||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\system\JsonFormatter.hpp">
|
||||
<Filter>system</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\api\DataViewerCollectionImpl.hpp">
|
||||
<Filter>api</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\IDataViewerCollection.hpp">
|
||||
<Filter>include\public</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\lib\api\DataViewerCollection.hpp">
|
||||
<Filter>api</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="$(MSBuildThisFileDirectory)..\..\lib\include\public\Version.hpp.template">
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
#ifdef _MSC_VER
|
||||
// evntprov.h(838) : warning C4459 : declaration of 'Version' hides global declaration
|
||||
#pragma warning( disable : 4459 )
|
||||
#endif
|
||||
|
||||
#include "DataViewerCollection.hpp"
|
||||
#include <mutex>
|
||||
|
||||
namespace ARIASDK_NS_BEGIN {
|
||||
|
||||
MATSDK_LOG_INST_COMPONENT_CLASS(DataViewerCollection, "EventsSDK.DataViewerCollection", "Microsoft Telemetry Client - DataViewerCollection class");
|
||||
|
||||
void DataViewerCollection::DispatchDataViewerEvent(const std::vector<std::uint8_t>& packetData) noexcept
|
||||
{
|
||||
if (IsViewerEnabled() == false)
|
||||
return;
|
||||
|
||||
LOCKGUARD(m_dataViewerMapLock);
|
||||
auto dataViewerIterator = m_dataViewerCollection.cbegin();
|
||||
while (dataViewerIterator != m_dataViewerCollection.cend())
|
||||
{
|
||||
//ToDo: Send data asynchronously to individual viewers
|
||||
dataViewerIterator->second->RecieveData(packetData);
|
||||
}
|
||||
};
|
||||
|
||||
void DataViewerCollection::RegisterViewer(const std::shared_ptr<IDataViewer>& dataViewer)
|
||||
{
|
||||
|
||||
if (dataViewer == nullptr)
|
||||
{
|
||||
throw std::invalid_argument("nullptr passed for data viewer");
|
||||
}
|
||||
|
||||
LOCKGUARD(m_dataViewerMapLock);
|
||||
if (m_dataViewerCollection.find(dataViewer->GetName()) != m_dataViewerCollection.end())
|
||||
{
|
||||
throw std::invalid_argument(std::string { "Viewer: '%s' is already registered", dataViewer->GetName() });
|
||||
}
|
||||
|
||||
m_dataViewerCollection.emplace(dataViewer->GetName(), std::move(dataViewer));
|
||||
}
|
||||
|
||||
void DataViewerCollection::UnregisterViewer(const char* viewerName)
|
||||
{
|
||||
if (viewerName == nullptr)
|
||||
{
|
||||
throw std::invalid_argument("nullptr passed for viewer name");
|
||||
}
|
||||
|
||||
LOCKGUARD(m_dataViewerMapLock);
|
||||
if (m_dataViewerCollection.find(viewerName) == m_dataViewerCollection.end())
|
||||
{
|
||||
throw std::invalid_argument(std::string { "Viewer: '%s' is not currently registered", viewerName });
|
||||
}
|
||||
|
||||
m_dataViewerCollection.erase(viewerName);
|
||||
}
|
||||
|
||||
void DataViewerCollection::UnregisterAllViewers()
|
||||
{
|
||||
LOCKGUARD(m_dataViewerMapLock);
|
||||
m_dataViewerCollection.clear();
|
||||
}
|
||||
|
||||
bool DataViewerCollection::IsViewerEnabled(const char* viewerName)
|
||||
{
|
||||
if (viewerName == nullptr)
|
||||
{
|
||||
throw std::invalid_argument("nullptr passed for viewer name");
|
||||
}
|
||||
|
||||
LOCKGUARD(m_dataViewerMapLock);
|
||||
return m_dataViewerCollection.find(viewerName) != m_dataViewerCollection.end();
|
||||
}
|
||||
|
||||
bool DataViewerCollection::IsViewerEnabled() noexcept
|
||||
{
|
||||
LOCKGUARD(m_dataViewerMapLock);
|
||||
return m_dataViewerCollection.empty() == false;
|
||||
}
|
||||
} ARIASDK_NS_END
|
|
@ -6,12 +6,12 @@
|
|||
#include "pal/DebugTrace.hpp"
|
||||
#include "public/ctmacros.hpp"
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
|
||||
namespace ARIASDK_NS_BEGIN {
|
||||
|
||||
class DataViewerCollectionImpl : public IDataViewerCollection
|
||||
class DataViewerCollection : public IDataViewerCollection
|
||||
{
|
||||
public:
|
||||
virtual void DispatchDataViewerEvent(const std::vector<std::uint8_t>& packetData) noexcept override;
|
||||
|
@ -26,13 +26,13 @@ namespace ARIASDK_NS_BEGIN {
|
|||
|
||||
virtual bool IsViewerEnabled() noexcept override;
|
||||
|
||||
protected:
|
||||
std::map<const char*, std::shared_ptr<IDataViewer>> m_dataViewerCollection;
|
||||
|
||||
private:
|
||||
MATSDK_LOG_DECL_COMPONENT_CLASS();
|
||||
|
||||
mutable std::shared_mutex m_dataViewerMapLock;
|
||||
mutable std::recursive_mutex m_dataViewerMapLock;
|
||||
|
||||
protected:
|
||||
std::map<const char*, std::shared_ptr<IDataViewer>> m_dataViewerCollection;
|
||||
};
|
||||
|
||||
} ARIASDK_NS_END
|
|
@ -1,94 +0,0 @@
|
|||
#ifdef _MSC_VER
|
||||
// evntprov.h(838) : warning C4459 : declaration of 'Version' hides global declaration
|
||||
#pragma warning( disable : 4459 )
|
||||
#endif
|
||||
|
||||
#include "DataViewerCollectionImpl.hpp"
|
||||
#include <mutex>
|
||||
|
||||
namespace ARIASDK_NS_BEGIN {
|
||||
|
||||
MATSDK_LOG_INST_COMPONENT_CLASS(DataViewerCollectionImpl, "EventsSDK.DataViewerCollection", "Microsoft Telemetry Client - DataViewerCollection class");
|
||||
|
||||
void DataViewerCollectionImpl::DispatchDataViewerEvent(const std::vector<std::uint8_t>& packetData) noexcept
|
||||
{
|
||||
if (IsViewerEnabled() == false)
|
||||
return;
|
||||
|
||||
LOG_DEBUG("LOCKGUARD locking at %s:%d", __FILE__, __LINE__);
|
||||
std::shared_lock<std::shared_mutex> lock(m_dataViewerMapLock);
|
||||
|
||||
auto dataViewerIterator = m_dataViewerCollection.cbegin();
|
||||
while (dataViewerIterator != m_dataViewerCollection.cend())
|
||||
{
|
||||
//ToDo: Send data asynchronously to individual viewers
|
||||
dataViewerIterator->second->RecieveData(packetData);
|
||||
}
|
||||
};
|
||||
|
||||
void DataViewerCollectionImpl::RegisterViewer(const std::shared_ptr<IDataViewer>& dataViewer)
|
||||
{
|
||||
LOG_DEBUG("LOCKGUARD locking at %s:%d", __FILE__, __LINE__);
|
||||
std::unique_lock<std::shared_mutex> lock(m_dataViewerMapLock);
|
||||
|
||||
if (dataViewer == nullptr)
|
||||
{
|
||||
throw std::invalid_argument("nullptr passed for data viewer");
|
||||
}
|
||||
|
||||
if (m_dataViewerCollection.find(dataViewer->GetName()) == m_dataViewerCollection.end())
|
||||
{
|
||||
m_dataViewerCollection.emplace(dataViewer->GetName(), std::move(dataViewer));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::invalid_argument(std::string { "Viewer: '%s' is already registered", dataViewer->GetName() });
|
||||
}
|
||||
}
|
||||
|
||||
void DataViewerCollectionImpl::UnregisterViewer(const char* viewerName)
|
||||
{
|
||||
LOG_DEBUG("LOCKGUARD locking at %s:%d", __FILE__, __LINE__);
|
||||
std::unique_lock<std::shared_mutex> lock(m_dataViewerMapLock);
|
||||
|
||||
if (viewerName == nullptr)
|
||||
{
|
||||
throw std::invalid_argument("nullptr passed for viewer name");
|
||||
}
|
||||
|
||||
if (m_dataViewerCollection.find(viewerName) == m_dataViewerCollection.end())
|
||||
{
|
||||
throw std::invalid_argument(std::string { "Viewer: '%s' is not currently registered", viewerName });
|
||||
}
|
||||
|
||||
m_dataViewerCollection.erase(viewerName);
|
||||
}
|
||||
|
||||
void DataViewerCollectionImpl::UnregisterAllViewers()
|
||||
{
|
||||
LOG_DEBUG("LOCKGUARD locking at %s:%d", __FILE__, __LINE__);
|
||||
std::unique_lock<std::shared_mutex> lock(m_dataViewerMapLock);
|
||||
m_dataViewerCollection.clear();
|
||||
}
|
||||
|
||||
bool DataViewerCollectionImpl::IsViewerEnabled(const char* viewerName)
|
||||
{
|
||||
LOG_DEBUG("LOCKGUARD locking at %s:%d", __FILE__, __LINE__);
|
||||
std::shared_lock<std::shared_mutex> lock(m_dataViewerMapLock);
|
||||
|
||||
if (viewerName == nullptr)
|
||||
{
|
||||
throw std::invalid_argument("nullptr passed for viewer name");
|
||||
}
|
||||
|
||||
return m_dataViewerCollection.find(viewerName) != m_dataViewerCollection.end();
|
||||
}
|
||||
|
||||
bool DataViewerCollectionImpl::IsViewerEnabled() noexcept
|
||||
{
|
||||
LOG_DEBUG("LOCKGUARD locking at %s:%d", __FILE__, __LINE__);
|
||||
std::shared_lock<std::shared_mutex> lock(m_dataViewerMapLock);
|
||||
|
||||
return m_dataViewerCollection.empty() == false;
|
||||
}
|
||||
} ARIASDK_NS_END
|
|
@ -14,7 +14,7 @@
|
|||
#include "TransmitProfiles.hpp"
|
||||
#include "EventProperty.hpp"
|
||||
#include "http/HttpClientFactory.hpp"
|
||||
#include "api/DataViewerCollectionImpl.hpp"
|
||||
#include "api/DataViewerCollection.hpp"
|
||||
|
||||
#ifdef HAVE_MAT_UTC
|
||||
#if defined __has_include
|
||||
|
@ -170,14 +170,12 @@ namespace ARIASDK_NS_BEGIN
|
|||
m_context.SetCommonField(SESSION_ID_LEGACY, PAL::generateUuidString());
|
||||
|
||||
LOG_TRACE("Setting up the Data Viewer Collection implementation...");
|
||||
m_dataViewerCollection = std::make_unique<DataViewerCollectionImpl>();
|
||||
m_dataViewerCollection = std::unique_ptr<DataViewerCollection>(new DataViewerCollection());
|
||||
|
||||
#ifdef HAVE_MAT_DEFAULTDATAVIEWER
|
||||
if (dataViewer != nullptr)
|
||||
{
|
||||
m_dataViewerCollection->RegisterViewer(dataViewer);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MAT_UTC
|
||||
// UTC is not active
|
||||
|
@ -286,6 +284,7 @@ namespace ARIASDK_NS_BEGIN
|
|||
|
||||
m_ownHttpClient.reset();
|
||||
m_httpClient = nullptr;
|
||||
m_dataViewerCollection = nullptr;
|
||||
|
||||
// Reset the contents of m_eventFilterRegulator, but keep the object
|
||||
m_eventFilterRegulator.Reset();
|
||||
|
|
|
@ -16,7 +16,7 @@ public:
|
|||
|
||||
void RecieveData(const std::vector<std::uint8_t>& packetData) noexcept override
|
||||
{
|
||||
localPacketData.assign(packetData.cbegin(), packetData.cend() );
|
||||
localPacketData = packetData;
|
||||
}
|
||||
|
||||
const char* const GetName() const noexcept override
|
||||
|
@ -28,15 +28,15 @@ public:
|
|||
const char* m_name;
|
||||
};
|
||||
|
||||
class TestDataViewerCollectionImpl : public DataViewerCollectionImpl
|
||||
class TestDataViewerCollectionImpl : public DataViewerCollection
|
||||
{
|
||||
public:
|
||||
|
||||
using DataViewerCollectionImpl::DispatchDataViewerEvent;
|
||||
using DataViewerCollectionImpl::RegisterViewer;
|
||||
using DataViewerCollectionImpl::UnregisterViewer;
|
||||
using DataViewerCollectionImpl::UnregisterAllViewers;
|
||||
using DataViewerCollectionImpl::IsViewerEnabled;
|
||||
using DataViewerCollection::DispatchDataViewerEvent;
|
||||
using DataViewerCollection::RegisterViewer;
|
||||
using DataViewerCollection::UnregisterViewer;
|
||||
using DataViewerCollection::UnregisterAllViewers;
|
||||
using DataViewerCollection::IsViewerEnabled;
|
||||
|
||||
std::map<const char*, std::shared_ptr<IDataViewer>>& GetCollection()
|
||||
{
|
|
@ -417,7 +417,7 @@
|
|||
<ClCompile Include="ClockSkewManagerTests.cpp" />
|
||||
<ClCompile Include="DebugEventSourceTests.cpp" />
|
||||
<ClCompile Include="EventPropertiesStorageTests.cpp" />
|
||||
<ClCompile Include="DataViewerCollectionImplTests.cpp" />
|
||||
<ClCompile Include="DataViewerCollectionTests.cpp" />
|
||||
<ClCompile Include="LogManagerImplTests.cpp" />
|
||||
<ClCompile Include="LogSessionDataTests.cpp" />
|
||||
<ClCompile Include="MemoryStorageTests.cpp" />
|
||||
|
|
|
@ -39,8 +39,8 @@
|
|||
<ClCompile Include="DebugEventSourceTests.cpp" />
|
||||
<ClCompile Include="ClockSkewManagerTests.cpp" />
|
||||
<ClCompile Include="LogSessionDataTests.cpp" />
|
||||
<ClCompile Include="DataViewerCollectionImplTests.cpp" />
|
||||
<ClCompile Include="LogManagerImplTests.cpp" />
|
||||
<ClCompile Include="DataViewerCollectionTests.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="$(ProjectDir)..\common\MockIHttpClient.hpp">
|
||||
|
|
Загрузка…
Ссылка в новой задаче