mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-16 01:51:45 +00:00
(WIP) SDK: Implement Topology::ChangeState
This commit is contained in:
committed by
Dennis Klein
parent
499ffcd300
commit
18dc536f3d
@@ -9,25 +9,45 @@
|
||||
#ifndef FAIR_MQ_SDK_TOPOLOGY_H
|
||||
#define FAIR_MQ_SDK_TOPOLOGY_H
|
||||
|
||||
#include <fairmq/sdk/DDSInfo.h>
|
||||
#include <fairmq/sdk/DDSSession.h>
|
||||
#include <fairmq/sdk/DDSTopology.h>
|
||||
#include <fairmq/States.h>
|
||||
#include <fairmq/Tools.h>
|
||||
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace dds {
|
||||
namespace topology_api {
|
||||
|
||||
class CTopology;
|
||||
|
||||
} // namespace topology_api
|
||||
} // namespace dds
|
||||
|
||||
namespace fair {
|
||||
namespace mq {
|
||||
|
||||
enum class AsyncOpResult {
|
||||
Ok,
|
||||
Timeout,
|
||||
Error,
|
||||
Aborted
|
||||
};
|
||||
auto operator<<(std::ostream& os, AsyncOpResult v) -> std::ostream&;
|
||||
|
||||
namespace sdk {
|
||||
|
||||
using DeviceState = fair::mq::State;
|
||||
using DeviceTransition = fair::mq::Transition;
|
||||
|
||||
struct DeviceStatus
|
||||
{
|
||||
bool initialized;
|
||||
DeviceState state;
|
||||
};
|
||||
|
||||
using TopologyState = std::unordered_map<uint64_t, DeviceStatus>;
|
||||
using TopologyTransition = fair::mq::Transition;
|
||||
|
||||
/**
|
||||
* @class Topology Topology.h <fairmq/sdk/Topology.h>
|
||||
* @brief Represents a FairMQ topology
|
||||
@@ -35,16 +55,46 @@ namespace sdk {
|
||||
class Topology
|
||||
{
|
||||
public:
|
||||
/// @brief (Re)Construct a FairMQ topology from an existing DDS topology
|
||||
/// @param topo Initialized DDS CTopology
|
||||
explicit Topology(DDSTopology topo, DDSSession session = DDSSession());
|
||||
~Topology();
|
||||
|
||||
/// @brief Construct a FairMQ topology from an existing DDS session via the dds::topology_api
|
||||
/// @param topo An initialized CTopology object
|
||||
explicit Topology(dds::topology_api::CTopology topo);
|
||||
struct ChangeStateResult {
|
||||
AsyncOpResult rc;
|
||||
TopologyState state;
|
||||
friend auto operator<<(std::ostream& os, ChangeStateResult v) -> std::ostream&;
|
||||
};
|
||||
using ChangeStateCallback = std::function<void(ChangeStateResult)>;
|
||||
|
||||
/// @brief Initiate state transition on all FairMQ devices in this topology
|
||||
/// @param t FairMQ device state machine transition
|
||||
/// @param cb Completion callback
|
||||
auto ChangeState(TopologyTransition t, ChangeStateCallback cb, const std::chrono::milliseconds& timeout = std::chrono::milliseconds(0)) -> void;
|
||||
|
||||
static const std::unordered_map<DeviceTransition, DeviceState, tools::HashEnum<DeviceTransition>> fkExpectedState;
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
std::shared_ptr<Impl> fImpl;
|
||||
DDSSession fDDSSession;
|
||||
DDSTopology fDDSTopo;
|
||||
TopologyState fTopologyState;
|
||||
bool fStateChangeOngoing;
|
||||
DeviceState fTargetState;
|
||||
std::mutex fMtx;
|
||||
std::mutex fExecutionMtx;
|
||||
std::condition_variable fCV;
|
||||
std::condition_variable fExecutionCV;
|
||||
std::thread fExecutionThread;
|
||||
ChangeStateCallback fChangeStateCallback;
|
||||
std::chrono::milliseconds fStateChangeTimeout;
|
||||
bool fShutdown;
|
||||
|
||||
void WaitForState();
|
||||
void AddNewStateEntry(uint64_t senderId, const std::string& state);
|
||||
};
|
||||
|
||||
using Topo = Topology;
|
||||
|
||||
} // namespace sdk
|
||||
} // namespace mq
|
||||
} // namespace fair
|
||||
|
Reference in New Issue
Block a user