SDK: Allow passing path to Set/GetProperties

This commit is contained in:
Alexey Rybalchenko 2020-01-24 15:43:16 +01:00 committed by Dennis Klein
parent 50dacbcdde
commit 92af823135
2 changed files with 21 additions and 20 deletions

View File

@ -524,6 +524,7 @@ class BasicTopology : public AsioBase<Executor, Allocator>
public: public:
template<typename CompletionToken> template<typename CompletionToken>
auto AsyncGetProperties(DevicePropertyQuery const& query, auto AsyncGetProperties(DevicePropertyQuery const& query,
const std::string& path,
Duration timeout, Duration timeout,
CompletionToken&& token) CompletionToken&& token)
{ {
@ -536,7 +537,7 @@ class BasicTopology : public AsioBase<Executor, Allocator>
std::piecewise_construct, std::piecewise_construct,
std::forward_as_tuple(id), std::forward_as_tuple(id),
std::forward_as_tuple(id, std::forward_as_tuple(id,
fStateData.size(), fDDSTopo.GetTasks(path).size(),
timeout, timeout,
fMtx, fMtx,
AsioBase<Executor, Allocator>::GetExecutor(), AsioBase<Executor, Allocator>::GetExecutor(),
@ -544,7 +545,7 @@ class BasicTopology : public AsioBase<Executor, Allocator>
std::move(handler))); std::move(handler)));
cmd::Cmds const cmds(cmd::make<cmd::GetProperties>(id, query)); cmd::Cmds const cmds(cmd::make<cmd::GetProperties>(id, query));
fDDSSession.SendCommand(cmds.Serialize()); fDDSSession.SendCommand(cmds.Serialize(), path);
}, },
token); token);
} }
@ -552,21 +553,20 @@ class BasicTopology : public AsioBase<Executor, Allocator>
template<typename CompletionToken> template<typename CompletionToken>
auto AsyncGetProperties(DevicePropertyQuery const& query, CompletionToken&& token) auto AsyncGetProperties(DevicePropertyQuery const& query, CompletionToken&& token)
{ {
return AsyncGetProperties(query, Duration(0), std::move(token)); return AsyncGetProperties(query, "", Duration(0), std::move(token));
} }
auto GetProperties(DevicePropertyQuery const& query, Duration timeout = Duration(0)) auto GetProperties(DevicePropertyQuery const& query, const std::string& path = "", Duration timeout = Duration(0))
-> std::pair<std::error_code, GetPropertiesResult> -> std::pair<std::error_code, GetPropertiesResult>
{ {
tools::SharedSemaphore blocker; tools::SharedSemaphore blocker;
std::error_code ec; std::error_code ec;
GetPropertiesResult result; GetPropertiesResult result;
AsyncGetProperties( AsyncGetProperties(query, path, timeout, [&, blocker](std::error_code _ec, GetPropertiesResult _result) mutable {
query, timeout, [&, blocker](std::error_code _ec, GetPropertiesResult _result) mutable { ec = _ec;
ec = _ec; result = _result;
result = _result; blocker.Signal();
blocker.Signal(); });
});
blocker.Wait(); blocker.Wait();
return {ec, result}; return {ec, result};
} }
@ -663,6 +663,7 @@ class BasicTopology : public AsioBase<Executor, Allocator>
public: public:
template<typename CompletionToken> template<typename CompletionToken>
auto AsyncSetProperties(const DeviceProperties& props, auto AsyncSetProperties(const DeviceProperties& props,
const std::string& path,
Duration timeout, Duration timeout,
CompletionToken&& token) CompletionToken&& token)
{ {
@ -675,7 +676,7 @@ class BasicTopology : public AsioBase<Executor, Allocator>
std::piecewise_construct, std::piecewise_construct,
std::forward_as_tuple(id), std::forward_as_tuple(id),
std::forward_as_tuple(id, std::forward_as_tuple(id,
fStateData.size(), fDDSTopo.GetTasks(path).size(),
timeout, timeout,
fMtx, fMtx,
AsioBase<Executor, Allocator>::GetExecutor(), AsioBase<Executor, Allocator>::GetExecutor(),
@ -683,7 +684,7 @@ class BasicTopology : public AsioBase<Executor, Allocator>
std::move(handler))); std::move(handler)));
cmd::Cmds const cmds(cmd::make<cmd::SetProperties>(id, props)); cmd::Cmds const cmds(cmd::make<cmd::SetProperties>(id, props));
fDDSSession.SendCommand(cmds.Serialize()); fDDSSession.SendCommand(cmds.Serialize(), path);
}, },
token); token);
} }
@ -691,21 +692,20 @@ class BasicTopology : public AsioBase<Executor, Allocator>
template<typename CompletionToken> template<typename CompletionToken>
auto AsyncSetProperties(DeviceProperties const & properties, CompletionToken&& token) auto AsyncSetProperties(DeviceProperties const & properties, CompletionToken&& token)
{ {
return AsyncSetProperties(properties, Duration(0), std::move(token)); return AsyncSetProperties(properties, "", Duration(0), std::move(token));
} }
auto SetProperties(DeviceProperties const& properties, Duration timeout = Duration(0)) auto SetProperties(DeviceProperties const& properties, const std::string& path = "", Duration timeout = Duration(0))
-> std::pair<std::error_code, FailedDevices> -> std::pair<std::error_code, FailedDevices>
{ {
tools::SharedSemaphore blocker; tools::SharedSemaphore blocker;
std::error_code ec; std::error_code ec;
FailedDevices failed; FailedDevices failed;
AsyncSetProperties( AsyncSetProperties(properties, path, timeout, [&, blocker](std::error_code _ec, FailedDevices _failed) mutable {
properties, timeout, [&, blocker](std::error_code _ec, FailedDevices _failed) mutable { ec = _ec;
ec = _ec; failed = _failed;
failed = _failed; blocker.Signal();
blocker.Signal(); });
});
blocker.Wait(); blocker.Wait();
return {ec, failed}; return {ec, failed};
} }

View File

@ -304,6 +304,7 @@ TEST_F(Topology, AsyncSetPropertiesTimeout)
ASSERT_EQ(topo.ChangeState(TopologyTransition::InitDevice).first, std::error_code()); ASSERT_EQ(topo.ChangeState(TopologyTransition::InitDevice).first, std::error_code());
topo.AsyncSetProperties({{"key1", "val1"}}, topo.AsyncSetProperties({{"key1", "val1"}},
"",
std::chrono::milliseconds(1), std::chrono::milliseconds(1),
[=](std::error_code ec, sdk::FailedDevices) mutable { [=](std::error_code ec, sdk::FailedDevices) mutable {
LOG(info) << ec; LOG(info) << ec;