#pragma once
#include <ableton/discovery/PeerGateways.hpp>
namespace ableton
{
namespace discovery
{
template <typename NodeState, typename GatewayFactory, typename IoContext>
class Service
{
public:
using ServicePeerGateways = PeerGateways<NodeState, GatewayFactory, IoContext>;
Service(NodeState state,
util::Injected<GatewayFactory> factory,
util::Injected<IoContext> io)
: mEnabled(false)
, mGateways(
std::chrono::seconds(5), std::move(state), std::move(factory), std::move(io))
{
}
void enable(const bool bEnable)
{
mEnabled = bEnable;
mGateways.enable(bEnable);
}
bool isEnabled() const { return mEnabled; }
template <typename Handler>
void withGateways(Handler handler)
{
mGateways.withGateways(std::move(handler));
}
void updateNodeState(const NodeState& state) { mGateways.updateNodeState(state); }
void repairGateway(const IpAddress& gatewayAddr)
{
mGateways.repairGateway(gatewayAddr);
}
private:
bool mEnabled;
ServicePeerGateways mGateways;
};
} }