YARP
Yet Another Robot Platform
ControlBoardWrapperRemoteVariables.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
7 
9 
10 using yarp::os::Bottle;
11 
13 {
14  bool b = true;
15 
16  for (size_t i = 0; i < device.subdevices.size(); i++) {
18 
19  if (!p) {
20  return false;
21  }
22  if (!p->iVar) {
23  return false;
24  }
25  yarp::os::Bottle tmpval;
26  b &= p->iVar->getRemoteVariable(key, tmpval);
27  if (b) {
28  val.append(tmpval);
29  }
30  }
31 
32  return b;
33 }
34 
36 {
37  size_t bottle_size = val.size();
38  size_t device_size = device.subdevices.size();
39  if (bottle_size != device_size) {
40  yCError(CONTROLBOARD, "setRemoteVariable bottle_size != device_size failure");
41  return false;
42  }
43 
44  bool b = true;
45  for (size_t i = 0; i < device_size; i++) {
47  if (!p) {
48  yCError(CONTROLBOARD, "setRemoteVariable !p failure");
49  return false;
50  }
51  if (!p->iVar) {
52  yCError(CONTROLBOARD, "setRemoteVariable !p->iVar failure");
53  return false;
54  }
55  Bottle* partial_val = val.get(i).asList();
56  if (partial_val) {
57  b &= p->iVar->setRemoteVariable(key, *partial_val);
58  } else {
59  yCError(CONTROLBOARD, "setRemoteVariable general failure");
60  return false;
61  }
62  }
63 
64  return b;
65 }
66 
68 {
69  //int off = device.lut[0].offset;
70  size_t subIndex = device.lut[0].deviceEntry;
71  SubDevice* p = device.getSubdevice(subIndex);
72 
73  if (!p) {
74  return false;
75  }
76 
77  if (p->iVar) {
78  return p->iVar->getRemoteVariablesList(listOfKeys);
79  }
80  return false;
81 }
const yarp::os::LogComponent & CONTROLBOARD()
bool getRemoteVariablesList(yarp::os::Bottle *listOfKeys) override
bool setRemoteVariable(std::string key, const yarp::os::Bottle &val) override
bool getRemoteVariable(std::string key, yarp::os::Bottle &val) override
yarp::dev::IRemoteVariables * iVar
Definition: SubDevice.h:83
std::vector< DevicesLutEntry > lut
Definition: SubDevice.h:122
SubDevice * getSubdevice(size_t i)
Definition: SubDevice.h:125
SubDeviceVector subdevices
Definition: SubDevice.h:121
virtual bool setRemoteVariable(std::string key, const yarp::os::Bottle &val)=0
virtual bool getRemoteVariable(std::string key, yarp::os::Bottle &val)=0
virtual bool getRemoteVariablesList(yarp::os::Bottle *listOfKeys)=0
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
void append(const Bottle &alt)
Append the content of the given bottle to the current list.
Definition: Bottle.cpp:380
size_type size() const
Gets the number of elements in the bottle.
Definition: Bottle.cpp:251
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition: Bottle.cpp:246
virtual Bottle * asList() const
Get list value.
Definition: Value.cpp:240
#define yCError(component,...)
Definition: LogComponent.h:154