15 #include "visiontransfer/deviceparameters.h" 16 #include "visiontransfer/parametertransfer.h" 17 #include "visiontransfer/exceptions.h" 18 #include "visiontransfer/common.h" 27 class DeviceParameters::Pimpl {
30 Pimpl(
const char* address,
const char* service);
32 int readIntParameter(
int id);
33 double readDoubleParameter(
int id);
34 bool readBoolParameter(
int id);
36 void writeIntParameter(
int id,
int value);
37 void writeDoubleParameter(
int id,
double value);
38 void writeBoolParameter(
int id,
bool value);
40 std::map<std::string, ParameterInfo> getAllParameters();
44 void setParameter_impl(StandardParameterIDs::ParameterID
id, ParameterInfo::ParameterType type, T value, ...)
46 int cid =
static_cast<int>(id);
48 case ParameterInfo::TYPE_INT: {
49 writeIntParameter(cid, static_cast<int>(value));
52 case ParameterInfo::TYPE_BOOL: {
53 writeBoolParameter(cid, value != 0);
56 case ParameterInfo::TYPE_DOUBLE: {
57 writeDoubleParameter(cid, static_cast<double>(value));
64 template<typename T, typename std::enable_if<std::is_floating_point<T>::value>::type* =
nullptr>
65 void setParameter_impl(StandardParameterIDs::ParameterID
id, ParameterInfo::ParameterType type, T value,
double)
67 int cid =
static_cast<int>(id);
69 case ParameterInfo::TYPE_DOUBLE: {
70 writeDoubleParameter(cid, value);
73 case ParameterInfo::TYPE_INT: {
74 writeIntParameter(cid, static_cast<int>(value));
77 case ParameterInfo::TYPE_BOOL: {
78 writeBoolParameter(cid, value != 0);
85 void setParameter(StandardParameterIDs::ParameterID
id, ParameterInfo::ParameterType type, T t) {
86 setParameter_impl<T>(id, type, t,
double{});
91 void lookupIDAndType(
const std::string& name, internal::StandardParameterIDs::ParameterID&
id, ParameterInfo::ParameterType& type);
94 std::map<std::string, ParameterInfo> serverSideEnumeration;
96 std::map<std::string, ParameterInfo> getAllParametersInternal();
98 #ifndef DOXYGEN_SHOULD_SKIP_THIS 100 void setNamedParameterInternal(
const std::string& name, T value);
109 pimpl(new Pimpl(device)) {
114 pimpl(new Pimpl(address, service)) {
118 DeviceParameters::~DeviceParameters() {
122 int DeviceParameters::readIntParameter(
int id) {
123 return pimpl->readIntParameter(
id);
126 double DeviceParameters::readDoubleParameter(
int id) {
127 return pimpl->readDoubleParameter(
id);
130 bool DeviceParameters::readBoolParameter(
int id) {
131 return pimpl->readBoolParameter(
id);
134 void DeviceParameters::writeIntParameter(
int id,
int value) {
135 pimpl->writeIntParameter(
id, value);
138 void DeviceParameters::writeDoubleParameter(
int id,
double value) {
139 pimpl->writeDoubleParameter(
id, value);
142 void DeviceParameters::writeBoolParameter(
int id,
bool value) {
143 pimpl->writeBoolParameter(
id, value);
146 void DeviceParameters::Pimpl::lookupIDAndType(
const std::string& name, StandardParameterIDs::ParameterID&
id, ParameterInfo::ParameterType& type) {
147 if (serverSideEnumeration.size() == 0) {
151 id = StandardParameterIDs::getParameterIDForName(name);
152 if (
id == StandardParameterIDs::ParameterID::UNDEFINED) {
156 auto it = serverSideEnumeration.find(name);
157 if (it == serverSideEnumeration.end()) {
158 ParameterException ex(
"Server did not report the parameter in the supported list: " + name);
161 type = it->second.getType();
166 return pimpl->getAllParameters();
169 #ifndef DOXYGEN_SHOULD_SKIP_THIS 172 StandardParameterIDs::ParameterID id;
173 ParameterInfo::ParameterType type;
174 pimpl->lookupIDAndType(name,
id, type);
175 pimpl->setParameter<
double>(id, type, value);
179 StandardParameterIDs::ParameterID id;
180 ParameterInfo::ParameterType type;
181 pimpl->lookupIDAndType(name,
id, type);
182 pimpl->setParameter<
int>(id, type, value);
186 StandardParameterIDs::ParameterID id;
187 ParameterInfo::ParameterType type;
188 pimpl->lookupIDAndType(name,
id, type);
189 pimpl->setParameter<
bool>(id, type, value);
194 StandardParameterIDs::ParameterID id;
195 ParameterInfo::ParameterType type;
196 pimpl->lookupIDAndType(name,
id, type);
197 return pimpl->getParameter(name).getValue<
int>();
201 StandardParameterIDs::ParameterID id;
202 ParameterInfo::ParameterType type;
203 pimpl->lookupIDAndType(name,
id, type);
204 return pimpl->getParameter(name).getValue<
double>();
208 StandardParameterIDs::ParameterID id;
209 ParameterInfo::ParameterType type;
210 pimpl->lookupIDAndType(name,
id, type);
211 return pimpl->getParameter(name).getValue<
bool>();
217 DeviceParameters::Pimpl::Pimpl(
const char* address,
const char* service)
218 : paramTrans(address, service) {
221 DeviceParameters::Pimpl::Pimpl(
const DeviceInfo& device)
225 int DeviceParameters::Pimpl::readIntParameter(
int id) {
226 return paramTrans.readIntParameter(
id);
229 double DeviceParameters::Pimpl::readDoubleParameter(
int id) {
230 return paramTrans.readDoubleParameter(
id);
233 bool DeviceParameters::Pimpl::readBoolParameter(
int id) {
234 return paramTrans.readBoolParameter(
id);
237 void DeviceParameters::Pimpl::writeIntParameter(
int id,
int value) {
238 paramTrans.writeIntParameter(
id, value);
241 void DeviceParameters::Pimpl::writeDoubleParameter(
int id,
double value) {
242 paramTrans.writeDoubleParameter(
id, value);
245 void DeviceParameters::Pimpl::writeBoolParameter(
int id,
bool value) {
246 paramTrans.writeBoolParameter(
id, value);
249 std::map<std::string, ParameterInfo> DeviceParameters::Pimpl::getAllParameters() {
250 serverSideEnumeration = paramTrans.getAllParameters();
251 return serverSideEnumeration;
255 ParameterInfo DeviceParameters::Pimpl::getParameter(
const std::string& name)
257 return serverSideEnumeration[name];
std::map< std::string, ParameterInfo > getAllParameters()
Enumerates all parameters as reported by the device.
Allows a configuration of device parameters over the network.
std::string getIpAddress() const
Gets the IP address of the device.
Exception class that is used for all parameter-related exceptions.
T getNamedParameter(const std::string &name)
Get a parameter by name, specifying the return type (int, double or bool). ParameterException for inv...
Aggregates information about a discovered device.
DeviceParameters(const DeviceInfo &device)
Connects to parameter server of a Nerian stereo device by using the device information from device en...
void setNamedParameter(const std::string &name, T value)
Set a parameter by name. ParameterException for invalid names.