Skip to content

Commit

Permalink
[FIXES] After testing on windows :-)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwielders committed Nov 10, 2024
1 parent 9c1c896 commit bf3c1a2
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 103 deletions.
5 changes: 4 additions & 1 deletion Source/Thunder/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,13 +1221,16 @@ namespace Plugin {
Core::hresult result = Core::ERROR_UNKNOWN_KEY;

std::vector<IMetadata::Data::Proxy> collection;
bool proxySearch = RPC::Administrator::Instance().Allocations(linkId.IsSet() ? linkId.Value() : EMPTY_STRING, [&collection](const std::vector<ProxyStub::UnknownProxy*>& proxies) {
bool proxySearch = RPC::Administrator::Instance().Allocations(linkId.IsSet() ? linkId.Value() : EMPTY_STRING, [&collection, &linkId](const string& origin, const std::vector<ProxyStub::UnknownProxy*>& proxies) {
for (const auto& proxy : proxies) {
IMetadata::Data::Proxy data;
data.Count = proxy->ReferenceCount();
data.Instance = proxy->Implementation();
data.Interface = proxy->InterfaceId();
data.Name = proxy->Name();
if (linkId.IsSet() == false) {
data.Origin = Core::NumberType<uint32_t>(proxy->ChannelId()).Text() + '@' + origin;
}
collection.emplace_back(std::move(data));
}
});
Expand Down
30 changes: 12 additions & 18 deletions Source/Thunder/ExampleConfigWindows.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
"binding": "127.0.0.1",
"idletime": 60,
"ipv6": false,
"persistentpath": "C:/ThunderWin/artifacts/Persistent",
"volatilepath": "C:/ThunderWin/artifacts/temp",
"datapath": "C:/ThunderWin/artifacts/Debug/Plugins",
"systempath": "C:/ThunderWin/artifacts/Debug",
"proxystubpath": "C:/ThunderWin/artifacts/ProxyStubs/Debug",
"persistentpath": "D:/domotica/artifacts/Persistent",
"volatilepath": "D:/domotica//artifacts/temp",
"datapath": "D:/domotica/artifacts/Debug/Plugins",
"systempath": "D:/domotica/artifacts/Debug",
"proxystubpath": "D:/domotica/artifacts/ProxyStubs/Debug",
"communicator": "127.0.0.1:62000",
"redirect": "Service/Controller/UI",
"observe": {
"proxystubpath": "C:/ThunderWin/artifacts/dynamic/proxystubs",
"configpath": "C:/ThunderWin/artifacts/dynamic/config"
"proxystubpath": "D:/domotica/artifacts/dynamic/proxystubs",
"configpath": "D:/domotica/artifacts/dynamic/config"
},
"messaging": {
"port": 63000,
Expand Down Expand Up @@ -137,7 +137,7 @@
"callsign": "Butler",
"locator": "libButler.so",
"classname": "Butler",
"startmode": "Activated"
"startmode": "Deactivated"
},
{
"callsign": "ZigbeeControl",
Expand All @@ -154,10 +154,10 @@
"callsign": "ZWaveControl",
"locator": "libZWaveControl.so",
"classname": "ZWaveControl",
"startmode": "Activated",
"startmode": "Deactivated",
"configuration": {
"port": "\\\\.\\COM4",
"key": "ba:09:87:65:43:21:de:ad:be:ef:12:34:56:78:90:ab"
"key": "ba:09:87:65:43:21:de:ad:be:ef:12:34:56:78:90:ab"
}
},
{
Expand Down Expand Up @@ -401,7 +401,7 @@
"sleep": "5",
"single": false,
"crash": true,
"leak": true,
"leak": true,
"root": {
"mode": "Local"
}
Expand Down Expand Up @@ -458,7 +458,7 @@
"callsign": "WebServer",
"locator": "libWebServer.so",
"classname": "WebServer",
"startmode": "Deactivated",
"startmode": "Activated",
"communicator": "127.0.0.1:2349",
"configuration": {
"port": 8080,
Expand Down Expand Up @@ -571,12 +571,6 @@
"classname": "MessageControl",
"startmode": "Activated"
},
{
"callsign": "TraceControl",
"locator": "libtracecontrol.so",
"classname": "TraceControl",
"startmode": "Deactivated"
},
{
"callsign": "RemoteControl",
"locator": "libremotecontrol.so",
Expand Down
2 changes: 1 addition & 1 deletion Source/Thunder/PluginHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ POP_WARNING()
printf("Link: %s\n", index.Current().Remote.Value().c_str());
printf("------------------------------------------------------------\n");

RPC::Administrator::Instance().Allocations(index.Current().Name.Value(), [](const std::vector<ProxyStub::UnknownProxy*>& proxies) {
RPC::Administrator::Instance().Allocations(index.Current().Name.Value(), [](const string& origin, const std::vector<ProxyStub::UnknownProxy*>& 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<uint64_t>(instanceId), proxy->ReferenceCount(), proxy->InterfaceId(), proxy->InterfaceId());
Expand Down
10 changes: 5 additions & 5 deletions Source/Thunder/PluginServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,11 @@ namespace PluginHost {
ExternalAccess& operator=(const ExternalAccess&) = delete;

ExternalAccess(
const string& sourceName,
const Core::NodeId& sourceNode,
const string& proxyStubPath,
const Core::ProxyType<RPC::InvokeServer>& handler)
: RPC::Communicator(sourceName, sourceNode, proxyStubPath, Core::ProxyType<Core::IIPCServer>(handler))
const Core::ProxyType<RPC::InvokeServer>& handler,
const string& sourceName)
: RPC::Communicator(sourceNode, proxyStubPath, Core::ProxyType<Core::IIPCServer>(handler), sourceName.c_str())
, _plugin(nullptr) {
}
~ExternalAccess() override = default;
Expand Down Expand Up @@ -823,7 +823,7 @@ namespace PluginHost {
, _lastId(0)
, _metadata(plugin.MaxRequests.Value())
, _library()
, _external('/' + Callsign(), PluginNodeId(server, plugin), server.ProxyStubPath(), handler)
, _external(PluginNodeId(server, plugin), server.ProxyStubPath(), handler, '/' + Callsign())
, _administrator(administrator)
, _composit(*this)
, _jobs(administrator)
Expand Down Expand Up @@ -2209,7 +2209,7 @@ namespace PluginHost {
const uint8_t hardKillCheckWaitTime,
const bool delegatedReleases,
const Core::ProxyType<RPC::InvokeServer>& handler)
: RPC::Communicator(_T("/"), node, ProxyStubPathCreator(proxyStubPath, observableProxyStubPath), Core::ProxyType<Core::IIPCServer>(handler))
: RPC::Communicator(node, ProxyStubPathCreator(proxyStubPath, observableProxyStubPath), Core::ProxyType<Core::IIPCServer>(handler), _T("/"))
, _parent(parent)
, _persistentPath(persistentPath)
, _systemPath(systemPath)
Expand Down
48 changes: 29 additions & 19 deletions Source/com/Administrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@

#include "Administrator.h"
#include "IUnknown.h"
#include "Communicator.h"

namespace Thunder {
namespace RPC {

/* static */ const string Administrator::DanglingId("/Dangling");

Administrator::Administrator()
: _adminLock()
, _stubs()
Expand Down Expand Up @@ -122,17 +125,17 @@ namespace RPC {
ChannelMap::iterator index(_channelProxyMap.find(proxy.Id()));

if (index != _channelProxyMap.end()) {
Proxies::iterator entry(index->second.begin());
while ((entry != index->second.end()) && ((*entry) != &proxy)) {
Proxies::iterator entry(index->second.second.begin());
while ((entry != index->second.second.end()) && ((*entry) != &proxy)) {
entry++;
}

ASSERT(entry != index->second.end());
ASSERT(entry != index->second.second.end());

if (entry != index->second.end()) {
index->second.erase(entry);
if (entry != index->second.second.end()) {
index->second.second.erase(entry);
removed = true;
if (index->second.size() == 0) {
if (index->second.second.size() == 0) {
_channelProxyMap.erase(index);
}
}
Expand Down Expand Up @@ -228,11 +231,11 @@ namespace RPC {
ChannelMap::iterator index(_channelProxyMap.find(channel->Id()));

if (index != _channelProxyMap.end()) {
Proxies::iterator entry(index->second.begin());
while ((entry != index->second.end()) && (((*entry)->InterfaceId() != id) || ((*entry)->Implementation() != impl))) {
Proxies::iterator entry(index->second.second.begin());
while ((entry != index->second.second.end()) && (((*entry)->InterfaceId() != id) || ((*entry)->Implementation() != impl))) {
entry++;
}
if (entry != index->second.end()) {
if (entry != index->second.second.end()) {
interface = (*entry)->QueryInterface(id);
if (interface != nullptr) {
result = (*entry);
Expand Down Expand Up @@ -261,11 +264,11 @@ namespace RPC {
ChannelMap::iterator index(_channelProxyMap.find(channelId));

if (index != _channelProxyMap.end()) {
Proxies::iterator entry(index->second.begin());
while ((entry != index->second.end()) && (((*entry)->InterfaceId() != id) || ((*entry)->Implementation() != impl))) {
Proxies::iterator entry(index->second.second.begin());
while ((entry != index->second.second.end()) && (((*entry)->InterfaceId() != id) || ((*entry)->Implementation() != impl))) {
entry++;
}
if (entry != index->second.end()) {
if (entry != index->second.second.end()) {
interface = (*entry)->Acquire(outbound, id);

// The implementation could be found, but the current implemented proxy is not
Expand All @@ -287,7 +290,18 @@ namespace RPC {
ASSERT(result != nullptr);

// Register it as it is remotely registered :-)
_channelProxyMap[channelId].push_back(result);
ChannelMap::iterator channelIndex(_channelProxyMap.find(channelId));

if (channelIndex != _channelProxyMap.end()) {
channelIndex->second.second.push_back(result);
}
else {
Proxies baseList;
baseList.emplace_back(result);
_channelProxyMap.emplace(std::piecewise_construct,
std::forward_as_tuple(channelId),
std::forward_as_tuple(std::pair<string, Proxies>(channel->Origin(), baseList)));
}

// This will increment the reference count to 2 (one in the ChannelProxyMap and one in the QueryInterface ).
interface = result->QueryInterface(id);
Expand Down Expand Up @@ -398,10 +412,6 @@ namespace RPC {
return(index != _stubs.end() ? index->second->Convert(rawImplementation) : nullptr);
}

bool Administrator::IsRequestedLink(const ProxyStub::UnknownProxy* proxy, const string& id) const {
return (proxy->LinkId() == id);
}

void Administrator::DeleteChannel(const Core::ProxyType<Core::IPCChannel>& channel, Proxies& pendingProxies)
{
_adminLock.Lock();
Expand Down Expand Up @@ -435,7 +445,7 @@ namespace RPC {
ChannelMap::iterator index(_channelProxyMap.find(channelId));

if (index != _channelProxyMap.end()) {
for (auto entry : index->second) {
for (auto entry : index->second.second) {
entry->Invalidate();
_danglingProxies.emplace_back(entry);

Expand All @@ -448,7 +458,7 @@ namespace RPC {
// the pendingProxies. The receiver of pendingProxies has to take
// care of releasing the last reference we, as administration layer
// hold upon this..
pendingProxies = std::move(index->second);
pendingProxies = std::move(index->second.second);
_channelProxyMap.erase(index);
}

Expand Down
19 changes: 10 additions & 9 deletions Source/com/Administrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ namespace RPC {
};

public:
static const string DanglingId;

using Proxies = std::vector<ProxyStub::UnknownProxy*>;
using ChannelMap = std::unordered_map<uint32_t, Proxies>;
using ChannelMap = std::unordered_map<uint32_t, std::pair<string, Proxies > >;
using ReferenceMap = std::unordered_map<uint32_t, std::list< RecoverySet > >;
using Stubs = std::unordered_map<uint32_t, ProxyStub::UnknownStub*>;
using Factories = std::unordered_map<uint32_t, IMetadata*>;
Expand Down Expand Up @@ -154,26 +156,26 @@ namespace RPC {
_adminLock.Lock();
if (linkId.empty() == true) {
for (const auto& proxy : _channelProxyMap) {
action(proxy.second);
action(proxy.second.first, proxy.second.second);
}
action(_danglingProxies);
action(DanglingId, _danglingProxies);
found = true;
}
else if (linkId == _T("/Dangling")) {
action(_danglingProxies);
else if (linkId == DanglingId) {
action(DanglingId, _danglingProxies);
found = true;
}
else {
ChannelMap::const_iterator index(_channelProxyMap.begin());
while ((found == false) && (index != _channelProxyMap.end())) {
ASSERT(index->second.size() != 0);
ASSERT(index->second.second.size() != 0);

if (IsRequestedLink(index->second[0], linkId) == true) {
if (index->second.first != linkId) {
index++;
}
else {
found = true;
action(index->second);
action(index->second.first, index->second.second);
}
}
}
Expand Down Expand Up @@ -311,7 +313,6 @@ POP_WARNING()
// ----------------------------------------------------------------------------------------------------
// Methods for the Stub Environment
// ----------------------------------------------------------------------------------------------------
bool IsRequestedLink(const ProxyStub::UnknownProxy* proxy, const string& id) const;
Core::IUnknown* Convert(void* rawImplementation, const uint32_t id);
const Core::IUnknown* Convert(void* rawImplementation, const uint32_t id) const;
void RegisterUnknown(const Core::ProxyType<Core::IPCChannel>& channel, Core::IUnknown* source, const uint32_t id);
Expand Down
16 changes: 8 additions & 8 deletions Source/com/Communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ namespace RPC {
uint8_t Communicator::_hardKillCheckWaitTime = 4;

PUSH_WARNING(DISABLE_WARNING_THIS_IN_MEMBER_INITIALIZER_LIST)
Communicator::Communicator(const string& source, const Core::NodeId& node, const string& proxyStubPath)
: _source(source)
Communicator::Communicator(const Core::NodeId& node, const string& proxyStubPath, const TCHAR* sourceName)
: _source(sourceName == nullptr ? _T("UnknownServer") : sourceName)
, _connectionMap(*this)
, _ipcServer(node, _connectionMap, proxyStubPath) {
if (proxyStubPath.empty() == false) {
Expand All @@ -375,11 +375,11 @@ namespace RPC {
}

Communicator::Communicator(
const string& source,
const Core::NodeId& node,
const Core::NodeId& node,
const string& proxyStubPath,
const Core::ProxyType<Core::IIPCServer>& handler)
: _source(source)
const Core::ProxyType<Core::IIPCServer>& handler,
const TCHAR* sourceName)
: _source(sourceName == nullptr ? _T("UnknownServer") : sourceName)
, _connectionMap(*this)
, _ipcServer(node, _connectionMap, proxyStubPath, handler) {
if (proxyStubPath.empty() == false) {
Expand Down Expand Up @@ -419,7 +419,7 @@ namespace RPC {
PUSH_WARNING(DISABLE_WARNING_THIS_IN_MEMBER_INITIALIZER_LIST)
CommunicatorClient::CommunicatorClient(
const Core::NodeId& remoteNode)
: Core::IPCChannelClientType<Core::Void, false, true>(remoteNode, CommunicationBufferSize)
: BaseClass(remoteNode, CommunicationBufferSize)
, _announceMessage()
, _announceEvent(false, true)
, _connectionId(~0)
Expand All @@ -435,7 +435,7 @@ namespace RPC {
CommunicatorClient::CommunicatorClient(
const Core::NodeId& remoteNode,
const Core::ProxyType<Core::IIPCServer>& handler)
: Core::IPCChannelClientType<Core::Void, false, true>(remoteNode, CommunicationBufferSize)
: BaseClass(remoteNode, CommunicationBufferSize)
, _announceMessage()
, _announceEvent(false, true)
, _connectionId(~0)
Expand Down
Loading

0 comments on commit bf3c1a2

Please sign in to comment.