SDK: Add ctors to adopt existing DDS API objects

This commit is contained in:
Dennis Klein
2019-07-25 10:40:31 +02:00
parent ac8cd19915
commit 5ab328b01f
8 changed files with 77 additions and 11 deletions

View File

@@ -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; }