YARP
Yet Another Robot Platform
ControlBoardWrapperRemoteVariables.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
10 
12 
13 using yarp::os::Bottle;
14 
16 {
17  bool b = true;
18 
19  for (size_t i = 0; i < device.subdevices.size(); i++) {
21 
22  if (!p) {
23  return false;
24  }
25  if (!p->iVar) {
26  return false;
27  }
28  yarp::os::Bottle tmpval;
29  b &= p->iVar->getRemoteVariable(key, tmpval);
30  if (b) {
31  val.append(tmpval);
32  }
33  }
34 
35  return b;
36 }
37 
39 {
40  size_t bottle_size = val.size();
41  size_t device_size = device.subdevices.size();
42  if (bottle_size != device_size) {
43  yCError(CONTROLBOARDWRAPPER, "setRemoteVariable bottle_size != device_size failure");
44  return false;
45  }
46 
47  bool b = true;
48  for (size_t i = 0; i < device_size; i++) {
50  if (!p) {
51  yCError(CONTROLBOARDWRAPPER, "setRemoteVariable !p failure");
52  return false;
53  }
54  if (!p->iVar) {
55  yCError(CONTROLBOARDWRAPPER, "setRemoteVariable !p->iVar failure");
56  return false;
57  }
58  Bottle* partial_val = val.get(i).asList();
59  if (partial_val) {
60  b &= p->iVar->setRemoteVariable(key, *partial_val);
61  } else {
62  yCError(CONTROLBOARDWRAPPER, "setRemoteVariable general failure");
63  return false;
64  }
65  }
66 
67  return b;
68 }
69 
71 {
72  //int off = device.lut[0].offset;
73  size_t subIndex = device.lut[0].deviceEntry;
74  SubDevice* p = device.getSubdevice(subIndex);
75 
76  if (!p) {
77  return false;
78  }
79 
80  if (p->iVar) {
81  return p->iVar->getRemoteVariablesList(listOfKeys);
82  }
83  return false;
84 }
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
SubDevice::iVar
yarp::dev::IRemoteVariables * iVar
Definition: SubDevice.h:86
ControlBoardWrapperLogComponent.h
yarp::os::Bottle::size
size_type size() const
Gets the number of elements in the bottle.
Definition: Bottle.cpp:254
yarp::dev::IRemoteVariables::getRemoteVariablesList
virtual bool getRemoteVariablesList(yarp::os::Bottle *listOfKeys)=0
yarp::dev::IRemoteVariables::setRemoteVariable
virtual bool setRemoteVariable(std::string key, const yarp::os::Bottle &val)=0
ControlBoardWrapperRemoteVariables::getRemoteVariable
bool getRemoteVariable(std::string key, yarp::os::Bottle &val) override
Definition: ControlBoardWrapperRemoteVariables.cpp:15
ControlBoardWrapperRemoteVariables::setRemoteVariable
bool setRemoteVariable(std::string key, const yarp::os::Bottle &val) override
Definition: ControlBoardWrapperRemoteVariables.cpp:38
yarp::os::Bottle::get
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition: Bottle.cpp:249
CONTROLBOARDWRAPPER
const yarp::os::LogComponent & CONTROLBOARDWRAPPER()
Definition: ControlBoardWrapperLogComponent.cpp:11
WrappedDevice::getSubdevice
SubDevice * getSubdevice(size_t i)
Definition: SubDevice.h:129
WrappedDevice::subdevices
SubDeviceVector subdevices
Definition: SubDevice.h:125
ControlBoardWrapperRemoteVariables::getRemoteVariablesList
bool getRemoteVariablesList(yarp::os::Bottle *listOfKeys) override
Definition: ControlBoardWrapperRemoteVariables.cpp:70
ControlBoardWrapperCommon::device
WrappedDevice device
Definition: ControlBoardWrapperCommon.h:22
yCError
#define yCError(component,...)
Definition: LogComponent.h:157
WrappedDevice::lut
std::vector< DevicesLutEntry > lut
Definition: SubDevice.h:126
yarp::dev::IRemoteVariables::getRemoteVariable
virtual bool getRemoteVariable(std::string key, yarp::os::Bottle &val)=0
yarp::os::Value::asList
virtual Bottle * asList() const
Get list value.
Definition: Value.cpp:243
ControlBoardWrapperRemoteVariables.h
SubDevice
Definition: SubDevice.h:55
yarp::os::Bottle::append
void append(const Bottle &alt)
Append the content of the given bottle to the current list.
Definition: Bottle.cpp:383