Skip to content

Commit

Permalink
Breaking diamond inheritance that started to crash on latest VC++ (C+…
Browse files Browse the repository at this point in the history
…+23)
  • Loading branch information
DecoyRS committed Dec 15, 2023
1 parent 059e117 commit 637dc95
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion rd-cpp/src/rd_framework_cpp/src/main/base/IRdReactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace rd
* \brief A non-root node in an object graph which can be synchronized with its remote copy over a network or
* a similar connection, and which allows to subscribe to its changes.
*/
class RD_FRAMEWORK_API IRdReactive : public virtual IRdBindable
class RD_FRAMEWORK_API IRdReactive
{
public:
/**
Expand Down
3 changes: 2 additions & 1 deletion rd-cpp/src/rd_framework_cpp/src/main/base/IWire.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace rd
{
class RdReactiveBase;
/**
* \brief Sends and receives serialized object data over a network or a similar connection.
*/
Expand Down Expand Up @@ -45,7 +46,7 @@ class RD_FRAMEWORK_API IWire
* \param lifetime lifetime of subscription.
* \param entity to be subscripted
*/
virtual void advise(Lifetime lifetime, IRdReactive const* entity) const = 0;
virtual void advise(Lifetime lifetime, RdReactiveBase const* entity) const = 0;
};
} // namespace rd
#if defined(_MSC_VER)
Expand Down
2 changes: 1 addition & 1 deletion rd-cpp/src/rd_framework_cpp/src/main/base/WireBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace rd
{
void WireBase::advise(Lifetime lifetime, const IRdReactive* entity) const
void WireBase::advise(Lifetime lifetime, const RdReactiveBase* entity) const
{
message_broker.advise_on(lifetime, entity);
}
Expand Down
2 changes: 1 addition & 1 deletion rd-cpp/src/rd_framework_cpp/src/main/base/WireBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RD_FRAMEWORK_API WireBase : public IWire
virtual ~WireBase() = default;
// endregion

void advise(Lifetime lifetime, IRdReactive const* entity) const override;
virtual void advise(Lifetime lifetime, RdReactiveBase const* entity) const override;
};
} // namespace rd

Expand Down
2 changes: 1 addition & 1 deletion rd-cpp/src/rd_framework_cpp/src/main/ext/ExtWire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ExtWire::ExtWire()
});
}

void ExtWire::advise(Lifetime lifetime, IRdReactive const* entity) const
void ExtWire::advise(Lifetime lifetime, RdReactiveBase const* entity) const
{
realWire->advise(lifetime, entity);
}
Expand Down
2 changes: 1 addition & 1 deletion rd-cpp/src/rd_framework_cpp/src/main/ext/ExtWire.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RD_FRAMEWORK_API ExtWire final : public IWire

mutable IWire const* realWire = nullptr;

void advise(Lifetime lifetime, IRdReactive const* entity) const override;
void advise(Lifetime lifetime, RdReactiveBase const* entity) const override;

void send(RdId const& id, std::function<void(Buffer& buffer)> writer) const override;
};
Expand Down
12 changes: 6 additions & 6 deletions rd-cpp/src/rd_framework_cpp/src/main/protocol/MessageBroker.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "protocol/MessageBroker.h"

#include "base/RdReactiveBase.h"
#include "spdlog/sinks/stdout_color_sinks.h"

namespace rd
Expand All @@ -13,7 +14,7 @@ static void execute(const IRdReactive* that, Buffer msg)
that->on_wire_received(std::move(msg));
}

void MessageBroker::invoke(const IRdReactive* that, Buffer msg, bool sync) const
void MessageBroker::invoke(const RdReactiveBase* that, Buffer msg, bool sync) const
{
if (sync)
{
Expand Down Expand Up @@ -51,7 +52,7 @@ void MessageBroker::dispatch(RdId id, Buffer message) const

{ // synchronized recursively
std::lock_guard<decltype(lock)> guard(lock);
IRdReactive const* s = subscriptions[id];
RdReactiveBase const* s = subscriptions[id];
if (s == nullptr)
{
auto it = broker.find(id);
Expand All @@ -64,7 +65,7 @@ void MessageBroker::dispatch(RdId id, Buffer message) const

auto action = [this, it, id]() mutable {
auto& current = it->second;
IRdReactive const* subscription = subscriptions[id];
RdReactiveBase const* subscription = subscriptions[id];

optional<Buffer> message;
{
Expand Down Expand Up @@ -127,7 +128,7 @@ void MessageBroker::dispatch(RdId id, Buffer message) const
// }
}

void MessageBroker::advise_on(Lifetime lifetime, IRdReactive const* entity) const
void MessageBroker::advise_on(Lifetime lifetime, RdReactiveBase const* entity) const
{
RD_ASSERT_MSG(!entity->get_id().isNull(), ("id is null for entities: " + std::string(typeid(*entity).name())))

Expand All @@ -138,8 +139,7 @@ void MessageBroker::advise_on(Lifetime lifetime, IRdReactive const* entity) cons
if (!lifetime->is_terminated())
{
auto key = entity->get_id();
IRdReactive const* value = entity;
subscriptions[key] = value;
subscriptions[key] = entity;
lifetime->add_action([this, key]() { subscriptions.erase(key); });
}
}
Expand Down
8 changes: 5 additions & 3 deletions rd-cpp/src/rd_framework_cpp/src/main/protocol/MessageBroker.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

namespace rd
{
class RdReactiveBase;

class RD_FRAMEWORK_API Mq
{
public:
Expand All @@ -42,14 +44,14 @@ class RD_FRAMEWORK_API MessageBroker final
{
private:
IScheduler* default_scheduler = nullptr;
mutable rd::unordered_map<RdId, IRdReactive const*> subscriptions;
mutable rd::unordered_map<RdId, RdReactiveBase const*> subscriptions;
mutable rd::unordered_map<RdId, Mq> broker;

mutable std::recursive_mutex lock;

static std::shared_ptr<spdlog::logger> logger;

void invoke(const IRdReactive* that, Buffer msg, bool sync = false) const;
void invoke(const RdReactiveBase* that, Buffer msg, bool sync = false) const;

public:
// region ctor/dtor
Expand All @@ -59,7 +61,7 @@ class RD_FRAMEWORK_API MessageBroker final

void dispatch(RdId id, Buffer message) const;

void advise_on(Lifetime lifetime, IRdReactive const* entity) const;
void advise_on(Lifetime lifetime, RdReactiveBase const* entity) const;
};
} // namespace rd
#if defined(_MSC_VER)
Expand Down
2 changes: 1 addition & 1 deletion rd-cpp/src/rd_framework_cpp/src/main/task/RdCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class RdCall : public virtual RdReactiveBase, public ISerializable
* \param request value to deliver
* \return result of remote invoking
*/
WiredRdTask<TRes, ResSer> sync(TReq const& request, std::chrono::milliseconds timeout = 200ms) const
WiredRdTask<TRes, ResSer> sync(TReq const& request, std::chrono::milliseconds timeout = std::chrono::milliseconds(200)) const
{
auto task = start_internal(request, true, &SynchronousScheduler::Instance());
auto time_at_start = std::chrono::system_clock::now();
Expand Down

0 comments on commit 637dc95

Please sign in to comment.