From 24484509d57f0da9ab87367724ffe1adef21281e Mon Sep 17 00:00:00 2001 From: nxtumUbun Date: Tue, 24 Sep 2024 00:43:55 -0700 Subject: [PATCH 1/8] expose all proxies --- Source/com/Administrator.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Source/com/Administrator.h b/Source/com/Administrator.h index a378c6244..4155aa929 100644 --- a/Source/com/Administrator.h +++ b/Source/com/Administrator.h @@ -150,14 +150,22 @@ namespace RPC { bool Allocations(const uint32_t id, Proxies& proxies) const { bool found = false; if (id == 0) { + ChannelMap::const_iterator index(_channelProxyMap.begin()); + while ((index != _channelProxyMap.end())) { + const auto &temp = index -> second; + for(auto proxy : temp) { + proxies.push_back(proxy); + } + index++; + } + for(auto proxy : _danglingProxies) { + proxies.push_back(proxy); + } found = true; - proxies = _danglingProxies; } else { ChannelMap::const_iterator index(_channelProxyMap.begin()); - while ((found == false) && (index != _channelProxyMap.end())) { - if (index->first != id) { index++; } @@ -169,6 +177,7 @@ namespace RPC { } return (found); } + template void Announce() { From fe6da735ff78dff71e1ff387d58c6a8adb66cc29 Mon Sep 17 00:00:00 2001 From: nxtumUbun Date: Tue, 24 Sep 2024 00:48:21 -0700 Subject: [PATCH 2/8] formatting --- Source/com/Administrator.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/com/Administrator.h b/Source/com/Administrator.h index 4155aa929..8cdd5ad4a 100644 --- a/Source/com/Administrator.h +++ b/Source/com/Administrator.h @@ -151,14 +151,14 @@ namespace RPC { bool found = false; if (id == 0) { ChannelMap::const_iterator index(_channelProxyMap.begin()); - while ((index != _channelProxyMap.end())) { + while (index != _channelProxyMap.end()) { const auto &temp = index -> second; - for(auto proxy : temp) { + for (auto proxy : temp) { proxies.push_back(proxy); } index++; } - for(auto proxy : _danglingProxies) { + for (auto proxy : _danglingProxies) { proxies.push_back(proxy); } found = true; From 627a3c646200df5c476e935cf6158191c2dfb680 Mon Sep 17 00:00:00 2001 From: nxtumUbun Date: Tue, 24 Sep 2024 01:43:19 -0700 Subject: [PATCH 3/8] replace pushback with insert --- Source/com/Administrator.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Source/com/Administrator.h b/Source/com/Administrator.h index 8cdd5ad4a..c7803380e 100644 --- a/Source/com/Administrator.h +++ b/Source/com/Administrator.h @@ -153,14 +153,10 @@ namespace RPC { ChannelMap::const_iterator index(_channelProxyMap.begin()); while (index != _channelProxyMap.end()) { const auto &temp = index -> second; - for (auto proxy : temp) { - proxies.push_back(proxy); - } + proxies.insert(proxies.begin(), temp.begin(), temp.end()); index++; } - for (auto proxy : _danglingProxies) { - proxies.push_back(proxy); - } + proxies.insert(proxies.begin(), _danglingProxies.begin(), _danglingProxies.end()); found = true; } else { From 066f82a80d7297e194a75ca99a7f90fd55513423 Mon Sep 17 00:00:00 2001 From: nxtumUbun Date: Tue, 24 Sep 2024 01:45:07 -0700 Subject: [PATCH 4/8] use .end() --- Source/com/Administrator.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/com/Administrator.h b/Source/com/Administrator.h index c7803380e..686f01ee1 100644 --- a/Source/com/Administrator.h +++ b/Source/com/Administrator.h @@ -153,10 +153,10 @@ namespace RPC { ChannelMap::const_iterator index(_channelProxyMap.begin()); while (index != _channelProxyMap.end()) { const auto &temp = index -> second; - proxies.insert(proxies.begin(), temp.begin(), temp.end()); + proxies.insert(proxies.end(), temp.begin(), temp.end()); index++; } - proxies.insert(proxies.begin(), _danglingProxies.begin(), _danglingProxies.end()); + proxies.insert(proxies.end(), _danglingProxies.begin(), _danglingProxies.end()); found = true; } else { From 3717b0340de7633aa39d922a0e0a60d7a7b5eb15 Mon Sep 17 00:00:00 2001 From: nxtum <94901881+nxtum@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:55:01 +0200 Subject: [PATCH 5/8] keep arrow tight --- Source/com/Administrator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/com/Administrator.h b/Source/com/Administrator.h index 686f01ee1..30317db4c 100644 --- a/Source/com/Administrator.h +++ b/Source/com/Administrator.h @@ -152,7 +152,7 @@ namespace RPC { if (id == 0) { ChannelMap::const_iterator index(_channelProxyMap.begin()); while (index != _channelProxyMap.end()) { - const auto &temp = index -> second; + const auto &temp = index->second; proxies.insert(proxies.end(), temp.begin(), temp.end()); index++; } From 8e7d041d2df3edaf7bbf5a650e199d4182d77100 Mon Sep 17 00:00:00 2001 From: nxtumUbun Date: Thu, 26 Sep 2024 03:27:46 -0700 Subject: [PATCH 6/8] return pod of data --- Source/Thunder/Controller.cpp | 13 +++++---- Source/Thunder/PluginHost.cpp | 8 +++--- Source/com/Administrator.cpp | 50 +++++++++++++++++++++++++++++++++++ Source/com/Administrator.h | 36 +++++++------------------ 4 files changed, 70 insertions(+), 37 deletions(-) diff --git a/Source/Thunder/Controller.cpp b/Source/Thunder/Controller.cpp index e41ba97d7..3f90e499f 100644 --- a/Source/Thunder/Controller.cpp +++ b/Source/Thunder/Controller.cpp @@ -1220,7 +1220,7 @@ namespace Plugin { { Core::hresult result = Core::ERROR_UNKNOWN_KEY; - RPC::Administrator::Proxies collection; + RPC::Administrator::ProxyDataVector collection; // Search for the Dangling proxies if (RPC::Administrator::Instance().Allocations(linkId, collection) == true) { @@ -1229,13 +1229,12 @@ namespace Plugin { std::list< IMetadata::Data::Proxy> elements; - for (const ProxyStub::UnknownProxy* proxy : collection) { + for (const auto &proxy : collection) { IMetadata::Data::Proxy data; - data.Instance = proxy->Implementation(); - data.Interface = proxy->InterfaceId(); - data.Count = proxy->ReferenceCount(); - data.Name = proxy->Name(); - + data.Instance = proxy.Instance; + data.Interface = proxy.Interface; + data.Count = proxy.Count; + data.Name = proxy.Name; elements.emplace_back(std::move(data)); } diff --git a/Source/Thunder/PluginHost.cpp b/Source/Thunder/PluginHost.cpp index 307589c5e..6b356ea14 100644 --- a/Source/Thunder/PluginHost.cpp +++ b/Source/Thunder/PluginHost.cpp @@ -712,13 +712,13 @@ POP_WARNING() printf("Link: %s\n", index.Current().Remote.Value().c_str()); printf("------------------------------------------------------------\n"); - RPC::Administrator::Proxies proxies; + RPC::Administrator::ProxyDataVector proxies; RPC::Administrator::Instance().Allocations(index.Current().ID.Value(), proxies); - for (const ProxyStub::UnknownProxy* proxy : proxies) { - Core::instance_id instanceId = proxy->Implementation(); - printf("[%s] InstanceId: 0x%" PRIx64 ", RefCount: %d, InterfaceId %d [0x%X]\n", proxy->Name().c_str(), static_cast(instanceId), proxy->ReferenceCount(), proxy->InterfaceId(), proxy->InterfaceId()); + for (const auto &proxy: proxies) { + Core::instance_id instanceId = proxy.Instance; + printf("[%s] InstanceId: 0x%" PRIx64 ", RefCount: %d, InterfaceId %d [0x%X]\n", proxy.Name.c_str(), static_cast(instanceId), proxy.Count, proxy.Interface, proxy.Interface); } printf("\n"); } diff --git a/Source/com/Administrator.cpp b/Source/com/Administrator.cpp index 8ef34abcc..2fd1386cf 100644 --- a/Source/com/Administrator.cpp +++ b/Source/com/Administrator.cpp @@ -59,6 +59,56 @@ namespace RPC { return (systemAdministrator); } + bool Administrator::Allocations(const uint32_t id, ProxyDataVector& proxies) const { + bool found = false; + + if (id == 0) { + ChannelMap::const_iterator index(_channelProxyMap.begin()); + while (index != _channelProxyMap.end() && (found == false)) { + const auto &temp = index->second; + for (const auto &proxy : temp) { + ProxyData UnknownProxyData; + UnknownProxyData.Name = proxy->Name(); + UnknownProxyData.Instance = proxy->Implementation(); + UnknownProxyData.Interface = proxy->InterfaceId(); + UnknownProxyData.Count = proxy->ReferenceCount(); + proxies.push_back(UnknownProxyData); + } + index++; + } + for (const auto& proxy: _danglingProxies) { + ProxyData UnknownProxyData; + UnknownProxyData.Name = proxy->Name(); + UnknownProxyData.Instance = proxy->Implementation(); + UnknownProxyData.Interface = proxy->InterfaceId(); + UnknownProxyData.Count = proxy->ReferenceCount(); + proxies.push_back(UnknownProxyData); + } + found = true; + } + else { + ChannelMap::const_iterator index(_channelProxyMap.begin()); + while ((found == false) && (index != _channelProxyMap.end())) { + if (index->first != id) { + index++; + } + else { + found = true; + const auto &temp = index->second; + for (const auto &proxy : temp) { + ProxyData UnknownProxyData; + UnknownProxyData.Name = proxy->Name(); + UnknownProxyData.Instance = proxy->Implementation(); + UnknownProxyData.Interface = proxy->InterfaceId(); + UnknownProxyData.Count = proxy->ReferenceCount(); + proxies.push_back(UnknownProxyData); + } + } + } + } + return (found); + } + void Administrator::AddRef(const Core::ProxyType& channel, void* impl, const uint32_t interfaceId) { // stub are loaded before any action is taken and destructed if the process closes down, so no need to lock.. diff --git a/Source/com/Administrator.h b/Source/com/Administrator.h index 30317db4c..3e2602fb2 100644 --- a/Source/com/Administrator.h +++ b/Source/com/Administrator.h @@ -124,7 +124,15 @@ namespace RPC { }; public: + struct ProxyData { + uint32_t Interface; + string Name; + Core::instance_id Instance; + uint32_t Count; + }; + using Proxies = std::vector; + using ProxyDataVector = std::vector; using ChannelMap = std::unordered_map; using ReferenceMap = std::unordered_map >; using Stubs = std::unordered_map; @@ -147,32 +155,8 @@ namespace RPC { void DelegatedReleases(const bool enabled) { _delegatedReleases = enabled; } - bool Allocations(const uint32_t id, Proxies& proxies) const { - bool found = false; - if (id == 0) { - ChannelMap::const_iterator index(_channelProxyMap.begin()); - while (index != _channelProxyMap.end()) { - const auto &temp = index->second; - proxies.insert(proxies.end(), temp.begin(), temp.end()); - index++; - } - proxies.insert(proxies.end(), _danglingProxies.begin(), _danglingProxies.end()); - found = true; - } - else { - ChannelMap::const_iterator index(_channelProxyMap.begin()); - while ((found == false) && (index != _channelProxyMap.end())) { - if (index->first != id) { - index++; - } - else { - found = true; - proxies = index->second; - } - } - } - return (found); - } + + bool Allocations(const uint32_t id, ProxyDataVector& proxies) const; template void Announce() From e257885eca08343ecdff10b03b30a87663dce45a Mon Sep 17 00:00:00 2001 From: nxtumUbun Date: Mon, 30 Sep 2024 02:28:15 -0700 Subject: [PATCH 7/8] use visitor way --- Source/Thunder/Controller.cpp | 33 ++++++++++------------- Source/Thunder/PluginHost.cpp | 12 ++++----- Source/com/Administrator.cpp | 50 ----------------------------------- Source/com/Administrator.h | 28 ++++++++++++++++++-- 4 files changed, 45 insertions(+), 78 deletions(-) diff --git a/Source/Thunder/Controller.cpp b/Source/Thunder/Controller.cpp index 3f90e499f..f0683b703 100644 --- a/Source/Thunder/Controller.cpp +++ b/Source/Thunder/Controller.cpp @@ -1220,30 +1220,25 @@ namespace Plugin { { Core::hresult result = Core::ERROR_UNKNOWN_KEY; - RPC::Administrator::ProxyDataVector collection; - - // Search for the Dangling proxies - if (RPC::Administrator::Instance().Allocations(linkId, collection) == true) { - - using Iterator = IMetadata::Data::IProxiesIterator; - - std::list< IMetadata::Data::Proxy> elements; - - for (const auto &proxy : collection) { + std::vector collection; + bool proxySearch = RPC::Administrator::Instance().Allocations(linkId, [&collection](const std::vector& proxies) { + for (const auto& proxy : proxies) { IMetadata::Data::Proxy data; - data.Instance = proxy.Instance; - data.Interface = proxy.Interface; - data.Count = proxy.Count; - data.Name = proxy.Name; - elements.emplace_back(std::move(data)); - } + data.Count = proxy->ReferenceCount(); + data.Instance = proxy->Implementation(); + data.Interface = proxy->InterfaceId(); + data.Name = proxy->Name(); + collection.emplace_back(std::move(data)); + } + }); + + if (proxySearch == true) { + using Iterator = IMetadata::Data::IProxiesIterator; - outProxies = Core::ServiceType>::Create(std::move(elements)); + outProxies = Core::ServiceType>::Create(std::move(collection)); ASSERT(outProxies != nullptr); - result = Core::ERROR_NONE; } - return (result); } diff --git a/Source/Thunder/PluginHost.cpp b/Source/Thunder/PluginHost.cpp index 6b356ea14..be22a0b7a 100644 --- a/Source/Thunder/PluginHost.cpp +++ b/Source/Thunder/PluginHost.cpp @@ -712,15 +712,13 @@ POP_WARNING() printf("Link: %s\n", index.Current().Remote.Value().c_str()); printf("------------------------------------------------------------\n"); - RPC::Administrator::ProxyDataVector proxies; - - RPC::Administrator::Instance().Allocations(index.Current().ID.Value(), proxies); - - for (const auto &proxy: proxies) { - Core::instance_id instanceId = proxy.Instance; - printf("[%s] InstanceId: 0x%" PRIx64 ", RefCount: %d, InterfaceId %d [0x%X]\n", proxy.Name.c_str(), static_cast(instanceId), proxy.Count, proxy.Interface, proxy.Interface); + RPC::Administrator::Instance().Allocations(index.Current().ID.Value(), [](const std::vector& proxies) { + for (const auto& proxy: proxies) { + Core::instance_id instanceId = proxy->Implementation(); + printf("[%s] InstanceId: 0x%" PRIx64 ", RefCount: %d, InterfaceId %d [0x%X]\n", proxy->Name().c_str(), static_cast(instanceId), proxy->ReferenceCount(), proxy->InterfaceId(), proxy->InterfaceId()); } printf("\n"); + }); } } break; diff --git a/Source/com/Administrator.cpp b/Source/com/Administrator.cpp index 2fd1386cf..8ef34abcc 100644 --- a/Source/com/Administrator.cpp +++ b/Source/com/Administrator.cpp @@ -59,56 +59,6 @@ namespace RPC { return (systemAdministrator); } - bool Administrator::Allocations(const uint32_t id, ProxyDataVector& proxies) const { - bool found = false; - - if (id == 0) { - ChannelMap::const_iterator index(_channelProxyMap.begin()); - while (index != _channelProxyMap.end() && (found == false)) { - const auto &temp = index->second; - for (const auto &proxy : temp) { - ProxyData UnknownProxyData; - UnknownProxyData.Name = proxy->Name(); - UnknownProxyData.Instance = proxy->Implementation(); - UnknownProxyData.Interface = proxy->InterfaceId(); - UnknownProxyData.Count = proxy->ReferenceCount(); - proxies.push_back(UnknownProxyData); - } - index++; - } - for (const auto& proxy: _danglingProxies) { - ProxyData UnknownProxyData; - UnknownProxyData.Name = proxy->Name(); - UnknownProxyData.Instance = proxy->Implementation(); - UnknownProxyData.Interface = proxy->InterfaceId(); - UnknownProxyData.Count = proxy->ReferenceCount(); - proxies.push_back(UnknownProxyData); - } - found = true; - } - else { - ChannelMap::const_iterator index(_channelProxyMap.begin()); - while ((found == false) && (index != _channelProxyMap.end())) { - if (index->first != id) { - index++; - } - else { - found = true; - const auto &temp = index->second; - for (const auto &proxy : temp) { - ProxyData UnknownProxyData; - UnknownProxyData.Name = proxy->Name(); - UnknownProxyData.Instance = proxy->Implementation(); - UnknownProxyData.Interface = proxy->InterfaceId(); - UnknownProxyData.Count = proxy->ReferenceCount(); - proxies.push_back(UnknownProxyData); - } - } - } - } - return (found); - } - void Administrator::AddRef(const Core::ProxyType& channel, void* impl, const uint32_t interfaceId) { // stub are loaded before any action is taken and destructed if the process closes down, so no need to lock.. diff --git a/Source/com/Administrator.h b/Source/com/Administrator.h index 3e2602fb2..f93352ec7 100644 --- a/Source/com/Administrator.h +++ b/Source/com/Administrator.h @@ -132,7 +132,6 @@ namespace RPC { }; using Proxies = std::vector; - using ProxyDataVector = std::vector; using ChannelMap = std::unordered_map; using ReferenceMap = std::unordered_map >; using Stubs = std::unordered_map; @@ -156,7 +155,32 @@ namespace RPC { _delegatedReleases = enabled; } - bool Allocations(const uint32_t id, ProxyDataVector& proxies) const; + template + bool Allocations(const uint32_t id, ACTION&& action) const { + bool found = false; + _adminLock.Lock(); + if (id == 0) { + for (const auto& proxy : _channelProxyMap) { + action(proxy.second); + } + action(_danglingProxies); + found = true; + } + else { + ChannelMap::const_iterator index(_channelProxyMap.begin()); + while ((found == false) && (index != _channelProxyMap.end())) { + if (index->first != id) { + index++; + } + else { + found = true; + action(index->second); + } + } + } + _adminLock.Unlock(); + return found; + } template void Announce() From ade0382f76d6430450e0b09dbd4211bfb4b84672 Mon Sep 17 00:00:00 2001 From: nxtumUbun Date: Mon, 30 Sep 2024 03:40:44 -0700 Subject: [PATCH 8/8] remove unwanted struct --- Source/com/Administrator.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Source/com/Administrator.h b/Source/com/Administrator.h index f93352ec7..95b5eeea0 100644 --- a/Source/com/Administrator.h +++ b/Source/com/Administrator.h @@ -124,13 +124,6 @@ namespace RPC { }; public: - struct ProxyData { - uint32_t Interface; - string Name; - Core::instance_id Instance; - uint32_t Count; - }; - using Proxies = std::vector; using ChannelMap = std::unordered_map; using ReferenceMap = std::unordered_map >;