15 #include "visiontransfer/deviceparameters.h"
16 #include "visiontransfer/internal/parametertransfer.h"
17 #include "visiontransfer/exceptions.h"
18 #include "visiontransfer/common.h"
20 using namespace visiontransfer;
21 using namespace visiontransfer::internal;
22 using namespace visiontransfer::param;
24 namespace visiontransfer {
28 class DeviceParameters::Pimpl {
31 Pimpl(
const char* address,
const char* service);
33 bool isConnected()
const;
36 void writeParameter(
const char*
id,
const T& value) {
37 paramTrans.writeParameterTransactionGuarded(
id, value);
40 int readIntParameter(
const char*
id);
41 double readDoubleParameter(
const char*
id);
42 bool readBoolParameter(
const char*
id);
44 void writeIntParameter(
const char*
id,
int value);
45 void writeDoubleParameter(
const char*
id,
double value);
46 void writeBoolParameter(
const char*
id,
bool value);
47 void writeBoolParameterUnguarded(
const char*
id,
bool value);
49 std::map<std::string, ParameterInfo> getAllParameters();
51 bool hasParameter(
const std::string& name)
const;
53 Parameter getParameter(
const std::string& name)
const;
57 Parameter pollParameter(
const std::string& name,
bool blockingCall);
59 void setParameterUpdateCallback(std::function<
void(
const std::string& uid)> callback,
bool threaded);
61 void transactionStartQueue();
62 void transactionCommitQueue(
int maxWaitMilliseconds);
64 void persistParameters(
const std::vector<std::string>& uids,
bool blocking=
true);
66 void setConnectionStateChangeCallback(std::function<
void(visiontransfer::ConnectionState)> callback);
69 std::map<std::string, ParameterInfo> serverSideEnumeration;
71 #ifndef DOXYGEN_SHOULD_SKIP_THIS
73 void setNamedParameterInternal(
const std::string& name, T value);
82 pimpl(new Pimpl(device)) {
87 pimpl(new Pimpl(address, service)) {
91 DeviceParameters::~DeviceParameters() {
96 return pimpl->isConnected();
99 int DeviceParameters::readIntParameter(
const char*
id) {
100 return pimpl->readIntParameter(
id);
103 double DeviceParameters::readDoubleParameter(
const char*
id) {
104 return pimpl->readDoubleParameter(
id);
107 bool DeviceParameters::readBoolParameter(
const char*
id) {
108 return pimpl->readBoolParameter(
id);
111 void DeviceParameters::writeIntParameter(
const char*
id,
int value) {
112 pimpl->writeIntParameter(
id, value);
115 void DeviceParameters::writeDoubleParameter(
const char*
id,
double value) {
116 pimpl->writeDoubleParameter(
id, value);
119 void DeviceParameters::writeBoolParameter(
const char*
id,
bool value) {
120 pimpl->writeBoolParameter(
id, value);
123 void DeviceParameters::writeBoolParameterUnguarded(
const char*
id,
bool value) {
124 pimpl->writeBoolParameterUnguarded(
id, value);
129 return pimpl->getAllParameters();
132 #ifndef DOXYGEN_SHOULD_SKIP_THIS
136 pimpl->writeParameter(name.c_str(), value);
140 pimpl->writeParameter(name.c_str(), value);
144 pimpl->writeParameter(name.c_str(), value);
149 pimpl->writeParameter(name.c_str(), value);
153 pimpl->writeParameter(name.c_str(), value);
157 pimpl->writeParameter(name.c_str(), value);
161 pimpl->writeParameter(name.c_str(), value);
165 pimpl->writeParameter(name.c_str(), value);
169 std::stringstream ss;
171 for (
const auto& v: tensorValues) {
175 pimpl->writeParameter(name.c_str(), ss.str());
180 return pimpl->readIntParameter(name.c_str());
184 return pimpl->readDoubleParameter(name.c_str());
188 return pimpl->readBoolParameter(name.c_str());
192 #if VISIONTRANSFER_CPLUSPLUS_VERSION >= 201103L
194 return pimpl->hasParameter(name);
198 return pimpl->getParameter(name);
202 return pimpl->getParameterSet();
206 return pimpl->pollParameter(name, blockingCall);
210 pimpl->setParameterUpdateCallback(callback, threaded);
213 DeviceParameters::TransactionLock::TransactionLock(DeviceParameters::Pimpl* pimpl)
215 pimpl->transactionStartQueue();
218 DeviceParameters::TransactionLock::~TransactionLock() {
219 pimpl->transactionCommitQueue(-1);
223 pimpl->transactionCommitQueue(waitMaxMilliseconds);
227 return std::make_unique<DeviceParameters::TransactionLock>(pimpl);
231 pimpl->persistParameters({uid}, blockingCall);
234 pimpl->persistParameters({uid}, blockingCall);
237 pimpl->persistParameters({param.
getUid()}, blockingCall);
240 pimpl->persistParameters(uids, blockingCall);
243 std::vector<std::string> uidvec;
244 for (
auto const& u: uids) uidvec.push_back(u);
245 pimpl->persistParameters(uidvec, blockingCall);
248 std::vector<std::string> uidvec;
249 for (
auto const& u: uids) uidvec.push_back(u);
250 pimpl->persistParameters(uidvec, blockingCall);
254 pimpl->setConnectionStateChangeCallback(callback);
261 DeviceParameters::Pimpl::Pimpl(
const char* address,
const char* service)
262 : paramTrans(address, service) {
265 DeviceParameters::Pimpl::Pimpl(
const DeviceInfo& device)
266 : paramTrans(device.getIpAddress().c_str(),
"7683") {
269 bool DeviceParameters::Pimpl::isConnected()
const {
270 return paramTrans.isConnected();
273 int DeviceParameters::Pimpl::readIntParameter(
const char*
id) {
274 return paramTrans.readIntParameter(
id);
277 double DeviceParameters::Pimpl::readDoubleParameter(
const char*
id) {
278 return paramTrans.readDoubleParameter(
id);
281 bool DeviceParameters::Pimpl::readBoolParameter(
const char*
id) {
282 return paramTrans.readBoolParameter(
id);
285 void DeviceParameters::Pimpl::writeIntParameter(
const char*
id,
int value) {
286 paramTrans.writeParameterTransactionGuarded(
id, value);
289 void DeviceParameters::Pimpl::writeDoubleParameter(
const char*
id,
double value) {
290 paramTrans.writeParameterTransactionGuarded(
id, value);
293 void DeviceParameters::Pimpl::writeBoolParameter(
const char*
id,
bool value) {
294 paramTrans.writeParameterTransactionGuarded(
id, value);
297 void DeviceParameters::Pimpl::writeBoolParameterUnguarded(
const char*
id,
bool value) {
298 paramTrans.writeParameterTransactionUnguarded(
id, value);
301 std::map<std::string, ParameterInfo> DeviceParameters::Pimpl::getAllParameters() {
302 serverSideEnumeration = paramTrans.getAllParameters();
303 return serverSideEnumeration;
306 bool DeviceParameters::Pimpl::hasParameter(
const std::string& name)
const {
307 return paramTrans.hasParameter(name);
310 Parameter DeviceParameters::Pimpl::getParameter(
const std::string& name)
const {
311 return paramTrans.getParameter(name);
314 Parameter DeviceParameters::Pimpl::pollParameter(
const std::string& name,
bool blockingCall) {
315 return paramTrans.pollParameter(name, blockingCall);
318 ParameterSet const& DeviceParameters::Pimpl::getParameterSet()
const {
319 return paramTrans.getParameterSet();
322 void DeviceParameters::Pimpl::setParameterUpdateCallback(std::function<
void(
const std::string& uid)> callback,
bool threaded) {
323 paramTrans.setParameterUpdateCallback(callback, threaded);
326 void DeviceParameters::Pimpl::transactionStartQueue() {
327 paramTrans.transactionStartQueue();
330 void DeviceParameters::Pimpl::transactionCommitQueue(
int maxWaitMilliseconds) {
331 paramTrans.transactionCommitQueue(maxWaitMilliseconds);
334 void DeviceParameters::Pimpl::persistParameters(
const std::vector<std::string>& uids,
bool blocking) {
335 paramTrans.persistParameters(uids, blocking);
338 void DeviceParameters::Pimpl::setConnectionStateChangeCallback(std::function<
void(visiontransfer::ConnectionState)> callback) {
339 paramTrans.setConnectionStateChangeCallback(callback);