mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 08:41:16 +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)
|
||||
: fEnv(std::move(env))
|
||||
, fRMSPlugin(DDSRMSPlugin::localhost)
|
||||
, fDDSService()
|
||||
, fDDSCustomCmd(fDDSService)
|
||||
, fId(to_string(fSession.create()))
|
||||
, fStopOnDestruction(false)
|
||||
|
@ -74,7 +73,6 @@ struct DDSSession::Impl
|
|||
explicit Impl(Id existing, DDSEnvironment env)
|
||||
: fEnv(std::move(env))
|
||||
, fRMSPlugin(DDSRMSPlugin::localhost)
|
||||
, fDDSService()
|
||||
, fDDSCustomCmd(fDDSService)
|
||||
, fId(std::move(existing))
|
||||
, 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()
|
||||
{
|
||||
if (fStopOnDestruction) {
|
||||
|
@ -118,11 +130,15 @@ struct DDSSession::Impl
|
|||
};
|
||||
|
||||
DDSSession::DDSSession(DDSEnvironment env)
|
||||
: fImpl(std::make_shared<Impl>(env))
|
||||
: fImpl(std::make_shared<Impl>(std::move(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; }
|
||||
|
|
|
@ -57,6 +57,11 @@ class DDSSession
|
|||
explicit DDSSession(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 GetId() const -> Id;
|
||||
auto GetRMSPlugin() const -> DDSRMSPlugin;
|
||||
|
@ -92,6 +97,7 @@ class DDSSession
|
|||
void SendCommand(const std::string&);
|
||||
|
||||
friend auto operator<<(std::ostream& os, const DDSSession& session) -> std::ostream&;
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
std::shared_ptr<Impl> fImpl;
|
||||
|
|
|
@ -34,6 +34,11 @@ struct DDSTopology::Impl
|
|||
, fTopo(fTopoFile.string())
|
||||
{}
|
||||
|
||||
explicit Impl(dds::topology_api::CTopology nativeTopology, DDSEnvironment env)
|
||||
: fEnv(std::move(env))
|
||||
, fTopo(std::move(nativeTopology))
|
||||
{}
|
||||
|
||||
DDSEnvironment fEnv;
|
||||
Path fTopoFile;
|
||||
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)))
|
||||
{}
|
||||
|
||||
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::GetTopoFile() const -> Path
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#define FAIR_MQ_SDK_DDSTOPOLOGY_H
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <fairmq/sdk/DDSInfo.h>
|
||||
#include <fairmq/sdk/DDSEnvironment.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
@ -34,6 +35,11 @@ class DDSTopology
|
|||
/// @param env DDS environment
|
||||
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
|
||||
auto GetEnv() const -> DDSEnvironment;
|
||||
|
||||
|
|
|
@ -8,16 +8,16 @@
|
|||
|
||||
#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/trim.hpp>
|
||||
|
||||
#include <utility>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <fairlogger/Logger.h>
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
|
||||
namespace fair {
|
||||
namespace mq {
|
||||
|
@ -104,6 +104,12 @@ Topology::Topology(DDSTopology topo, DDSSession session)
|
|||
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
|
||||
{
|
||||
{
|
||||
|
|
|
@ -87,9 +87,18 @@ class Topology
|
|||
{
|
||||
public:
|
||||
/// @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());
|
||||
|
||||
/// @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;
|
||||
Topology& operator=(const Topology&) = delete;
|
||||
explicit Topology(Topology&&) = delete;
|
||||
|
|
|
@ -295,6 +295,7 @@ if(BUILD_SDK)
|
|||
SDK
|
||||
Tools
|
||||
DDS::dds_topology_lib
|
||||
DDS::dds_tools_lib
|
||||
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
TIMEOUT 15
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "TopologyFixture.h"
|
||||
|
||||
#include <DDS/Topology.h>
|
||||
#include <DDS/Tools.h>
|
||||
#include <fairmq/sdk/Topology.h>
|
||||
#include <fairmq/Tools.h>
|
||||
|
||||
|
@ -16,6 +17,18 @@ namespace {
|
|||
|
||||
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)
|
||||
{
|
||||
fair::mq::sdk::Topology topo(mDDSTopo, mDDSSession);
|
||||
|
|
Loading…
Reference in New Issue
Block a user