mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
SDK: Add ctors to adopt existing DDS API objects
This commit is contained in:
parent
ac8cd19915
commit
5ab328b01f
|
@ -59,7 +59,6 @@ struct DDSSession::Impl
|
||||||
explicit Impl(DDSEnvironment env)
|
explicit Impl(DDSEnvironment env)
|
||||||
: fEnv(std::move(env))
|
: fEnv(std::move(env))
|
||||||
, fRMSPlugin(DDSRMSPlugin::localhost)
|
, fRMSPlugin(DDSRMSPlugin::localhost)
|
||||||
, fDDSService()
|
|
||||||
, fDDSCustomCmd(fDDSService)
|
, fDDSCustomCmd(fDDSService)
|
||||||
, fId(to_string(fSession.create()))
|
, fId(to_string(fSession.create()))
|
||||||
, fStopOnDestruction(false)
|
, fStopOnDestruction(false)
|
||||||
|
@ -74,7 +73,6 @@ struct DDSSession::Impl
|
||||||
explicit Impl(Id existing, DDSEnvironment env)
|
explicit Impl(Id existing, DDSEnvironment env)
|
||||||
: fEnv(std::move(env))
|
: fEnv(std::move(env))
|
||||||
, fRMSPlugin(DDSRMSPlugin::localhost)
|
, fRMSPlugin(DDSRMSPlugin::localhost)
|
||||||
, fDDSService()
|
|
||||||
, fDDSCustomCmd(fDDSService)
|
, fDDSCustomCmd(fDDSService)
|
||||||
, fId(std::move(existing))
|
, fId(std::move(existing))
|
||||||
, fStopOnDestruction(false)
|
, fStopOnDestruction(false)
|
||||||
|
@ -90,6 +88,20 @@ struct DDSSession::Impl
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
explicit Impl(dds::tools_api::CSession nativeSession, DDSEnv env)
|
||||||
|
: fEnv(std::move(env))
|
||||||
|
, fRMSPlugin(DDSRMSPlugin::localhost)
|
||||||
|
, fSession(std::move(nativeSession))
|
||||||
|
, fDDSCustomCmd(fDDSService)
|
||||||
|
, fId(to_string(fSession.getSessionID()))
|
||||||
|
, fStopOnDestruction(false)
|
||||||
|
{
|
||||||
|
// Sanity check
|
||||||
|
if (!fSession.IsRunning()) {
|
||||||
|
throw std::runtime_error("Given CSession must be running");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
~Impl()
|
~Impl()
|
||||||
{
|
{
|
||||||
if (fStopOnDestruction) {
|
if (fStopOnDestruction) {
|
||||||
|
@ -118,11 +130,15 @@ struct DDSSession::Impl
|
||||||
};
|
};
|
||||||
|
|
||||||
DDSSession::DDSSession(DDSEnvironment env)
|
DDSSession::DDSSession(DDSEnvironment env)
|
||||||
: fImpl(std::make_shared<Impl>(env))
|
: fImpl(std::make_shared<Impl>(std::move(env)))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DDSSession::DDSSession(Id existing, DDSEnvironment env)
|
DDSSession::DDSSession(Id existing, DDSEnvironment env)
|
||||||
: fImpl(std::make_shared<Impl>(std::move(existing), env))
|
: fImpl(std::make_shared<Impl>(std::move(existing), std::move(env)))
|
||||||
|
{}
|
||||||
|
|
||||||
|
DDSSession::DDSSession(dds::tools_api::CSession nativeSession, DDSEnv env)
|
||||||
|
: fImpl(std::make_shared<Impl>(std::move(nativeSession), std::move(env)))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
auto DDSSession::GetEnv() const -> DDSEnvironment { return fImpl->fEnv; }
|
auto DDSSession::GetEnv() const -> DDSEnvironment { return fImpl->fEnv; }
|
||||||
|
|
|
@ -57,6 +57,11 @@ class DDSSession
|
||||||
explicit DDSSession(DDSEnvironment env = DDSEnvironment());
|
explicit DDSSession(DDSEnvironment env = DDSEnvironment());
|
||||||
explicit DDSSession(Id existing, DDSEnvironment env = DDSEnvironment());
|
explicit DDSSession(Id existing, DDSEnvironment env = DDSEnvironment());
|
||||||
|
|
||||||
|
/// @brief Construct with already existing native DDS API objects
|
||||||
|
/// @param nativeSession Existing and initialized CSession (either via create() or attach())
|
||||||
|
/// @param env Optional DDSEnv
|
||||||
|
explicit DDSSession(dds::tools_api::CSession nativeSession, DDSEnv env = {});
|
||||||
|
|
||||||
auto GetEnv() const -> DDSEnvironment;
|
auto GetEnv() const -> DDSEnvironment;
|
||||||
auto GetId() const -> Id;
|
auto GetId() const -> Id;
|
||||||
auto GetRMSPlugin() const -> DDSRMSPlugin;
|
auto GetRMSPlugin() const -> DDSRMSPlugin;
|
||||||
|
@ -92,6 +97,7 @@ class DDSSession
|
||||||
void SendCommand(const std::string&);
|
void SendCommand(const std::string&);
|
||||||
|
|
||||||
friend auto operator<<(std::ostream& os, const DDSSession& session) -> std::ostream&;
|
friend auto operator<<(std::ostream& os, const DDSSession& session) -> std::ostream&;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Impl;
|
struct Impl;
|
||||||
std::shared_ptr<Impl> fImpl;
|
std::shared_ptr<Impl> fImpl;
|
||||||
|
|
|
@ -34,6 +34,11 @@ struct DDSTopology::Impl
|
||||||
, fTopo(fTopoFile.string())
|
, fTopo(fTopoFile.string())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
explicit Impl(dds::topology_api::CTopology nativeTopology, DDSEnvironment env)
|
||||||
|
: fEnv(std::move(env))
|
||||||
|
, fTopo(std::move(nativeTopology))
|
||||||
|
{}
|
||||||
|
|
||||||
DDSEnvironment fEnv;
|
DDSEnvironment fEnv;
|
||||||
Path fTopoFile;
|
Path fTopoFile;
|
||||||
dds::topology_api::CTopology fTopo;
|
dds::topology_api::CTopology fTopo;
|
||||||
|
@ -43,6 +48,10 @@ DDSTopology::DDSTopology(Path topoFile, DDSEnvironment env)
|
||||||
: fImpl(std::make_shared<Impl>(std::move(topoFile), std::move(env)))
|
: fImpl(std::make_shared<Impl>(std::move(topoFile), std::move(env)))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
DDSTopology::DDSTopology(dds::topology_api::CTopology nativeTopology, DDSEnv env)
|
||||||
|
: fImpl(std::make_shared<Impl>(std::move(nativeTopology), std::move(env)))
|
||||||
|
{}
|
||||||
|
|
||||||
auto DDSTopology::GetEnv() const -> DDSEnvironment { return fImpl->fEnv; }
|
auto DDSTopology::GetEnv() const -> DDSEnvironment { return fImpl->fEnv; }
|
||||||
|
|
||||||
auto DDSTopology::GetTopoFile() const -> Path
|
auto DDSTopology::GetTopoFile() const -> Path
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#define FAIR_MQ_SDK_DDSTOPOLOGY_H
|
#define FAIR_MQ_SDK_DDSTOPOLOGY_H
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <fairmq/sdk/DDSInfo.h>
|
||||||
#include <fairmq/sdk/DDSEnvironment.h>
|
#include <fairmq/sdk/DDSEnvironment.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -34,6 +35,11 @@ class DDSTopology
|
||||||
/// @param env DDS environment
|
/// @param env DDS environment
|
||||||
explicit DDSTopology(Path topoFile, DDSEnvironment env = DDSEnvironment());
|
explicit DDSTopology(Path topoFile, DDSEnvironment env = DDSEnvironment());
|
||||||
|
|
||||||
|
/// @brief Construct with already existing native DDS API objects
|
||||||
|
/// @param nativeTopology Existing and initialized CTopology
|
||||||
|
/// @param env Optional DDSEnv
|
||||||
|
explicit DDSTopology(dds::topology_api::CTopology nativeTopology, DDSEnv env = {});
|
||||||
|
|
||||||
/// @brief Get associated DDS environment
|
/// @brief Get associated DDS environment
|
||||||
auto GetEnv() const -> DDSEnvironment;
|
auto GetEnv() const -> DDSEnvironment;
|
||||||
|
|
||||||
|
|
|
@ -8,16 +8,16 @@
|
||||||
|
|
||||||
#include "Topology.h"
|
#include "Topology.h"
|
||||||
|
|
||||||
#include <fairlogger/Logger.h>
|
#include <DDS/Tools.h>
|
||||||
|
#include <DDS/Topology.h>
|
||||||
#include <boost/algorithm/string/split.hpp>
|
#include <boost/algorithm/string/split.hpp>
|
||||||
#include <boost/algorithm/string/trim.hpp>
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
|
#include <condition_variable>
|
||||||
#include <utility>
|
#include <fairlogger/Logger.h>
|
||||||
#include <thread>
|
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <condition_variable>
|
#include <thread>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace fair {
|
namespace fair {
|
||||||
namespace mq {
|
namespace mq {
|
||||||
|
@ -104,6 +104,12 @@ Topology::Topology(DDSTopology topo, DDSSession session)
|
||||||
fExecutionThread = std::thread(&Topology::WaitForState, this);
|
fExecutionThread = std::thread(&Topology::WaitForState, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Topology::Topology(dds::topology_api::CTopology nativeTopo,
|
||||||
|
dds::tools_api::CSession nativeSession,
|
||||||
|
DDSEnv env)
|
||||||
|
: Topology(DDSTopo(std::move(nativeTopo), env), DDSSession(std::move(nativeSession), env))
|
||||||
|
{}
|
||||||
|
|
||||||
auto Topology::ChangeState(TopologyTransition transition, ChangeStateCallback cb, Duration timeout) -> void
|
auto Topology::ChangeState(TopologyTransition transition, ChangeStateCallback cb, Duration timeout) -> void
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
|
|
@ -87,9 +87,18 @@ class Topology
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// @brief (Re)Construct a FairMQ topology from an existing DDS topology
|
/// @brief (Re)Construct a FairMQ topology from an existing DDS topology
|
||||||
/// @param topo Initialized DDS CTopology
|
/// @param topo DDSTopology
|
||||||
|
/// @param session DDSSession
|
||||||
explicit Topology(DDSTopology topo, DDSSession session = DDSSession());
|
explicit Topology(DDSTopology topo, DDSSession session = DDSSession());
|
||||||
|
|
||||||
|
/// @brief (Re)Construct a FairMQ topology based on already existing native DDS API objects
|
||||||
|
/// @param nativeTopo Existing CTopology
|
||||||
|
/// @param nativeSession Existing and initialized CSession (either via create() or attach())
|
||||||
|
/// @param env Optional DDSEnv (needed primarily for unit testing)
|
||||||
|
explicit Topology(dds::topology_api::CTopology nativeTopo,
|
||||||
|
dds::tools_api::CSession nativeSession,
|
||||||
|
DDSEnv env = {});
|
||||||
|
|
||||||
explicit Topology(const Topology&) = delete;
|
explicit Topology(const Topology&) = delete;
|
||||||
Topology& operator=(const Topology&) = delete;
|
Topology& operator=(const Topology&) = delete;
|
||||||
explicit Topology(Topology&&) = delete;
|
explicit Topology(Topology&&) = delete;
|
||||||
|
|
|
@ -295,6 +295,7 @@ if(BUILD_SDK)
|
||||||
SDK
|
SDK
|
||||||
Tools
|
Tools
|
||||||
DDS::dds_topology_lib
|
DDS::dds_topology_lib
|
||||||
|
DDS::dds_tools_lib
|
||||||
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
|
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
${CMAKE_CURRENT_BINARY_DIR}
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
TIMEOUT 15
|
TIMEOUT 15
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "TopologyFixture.h"
|
#include "TopologyFixture.h"
|
||||||
|
|
||||||
#include <DDS/Topology.h>
|
#include <DDS/Topology.h>
|
||||||
|
#include <DDS/Tools.h>
|
||||||
#include <fairmq/sdk/Topology.h>
|
#include <fairmq/sdk/Topology.h>
|
||||||
#include <fairmq/Tools.h>
|
#include <fairmq/Tools.h>
|
||||||
|
|
||||||
|
@ -16,6 +17,18 @@ namespace {
|
||||||
|
|
||||||
using Topology = fair::mq::test::TopologyFixture;
|
using Topology = fair::mq::test::TopologyFixture;
|
||||||
|
|
||||||
|
TEST(Topology2, ConstructionWithNativeDdsApiObjects)
|
||||||
|
{
|
||||||
|
// This is only needed for this unit test
|
||||||
|
fair::mq::sdk::DDSEnv env(CMAKE_CURRENT_BINARY_DIR);
|
||||||
|
|
||||||
|
// Example usage:
|
||||||
|
dds::topology_api::CTopology nativeTopo(fair::mq::tools::ToString(SDK_TESTSUITE_SOURCE_DIR, "/test_topo.xml"));
|
||||||
|
dds::tools_api::CSession nativeSession;
|
||||||
|
nativeSession.create();
|
||||||
|
fair::mq::sdk::Topology topo(nativeTopo, nativeSession, env);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(Topology, Construction)
|
TEST_F(Topology, Construction)
|
||||||
{
|
{
|
||||||
fair::mq::sdk::Topology topo(mDDSTopo, mDDSSession);
|
fair::mq::sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user