YARP
Yet Another Robot Platform
FrameTransformSet_nws_yarp.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
8#include <yarp/os/Log.h>
10#include <yarp/os/LogStream.h>
11
12using namespace yarp::dev;
13using namespace yarp::os;
14using namespace yarp::sig;
15using namespace yarp::math;
16
17namespace {
18YARP_LOG_COMPONENT(FRAMETRANSFORMSETNWSYARP, "yarp.device.frameTransformSet_nws_yarp")
19}
20
21//------------------------------------------------------------------------------------------------------------------------------
22
24{
26 yCError(FRAMETRANSFORMSETNWSYARP,"Error! YARP Network is not initialized");
27 return false;
28 }
29
30 std::string prefix;
31 //checking default config param
32 bool default_config = true;
33 if(config.check("default-config")) {
34 default_config = config.find("default-config").asString() == "true";
35 }
36 // configuration
37 if (config.check("nws_thrift_port_prefix")){
38 prefix = config.find("nws_thrift_port_prefix").asString() + (default_config ? m_defaultConfigPrefix : "");
39 if(prefix[0] != '/') {prefix = "/"+prefix;}
40 m_thriftPortName = prefix + "/" + m_deviceName + "/thrift";
41 }
42 else {
43 prefix = default_config ? m_defaultConfigPrefix : "";
44 m_thriftPortName = prefix + "/" + m_deviceName + "/thrift";
45 yCWarning(FRAMETRANSFORMSETNWSYARP) << "no nws_thrift_port_prefix param found. The resulting port name will be: " << m_thriftPortName;
46 }
47
48 if(!m_thriftPort.open(m_thriftPortName))
49 {
50 yCError(FRAMETRANSFORMSETNWSYARP,"Could not open \"%s\" port",m_thriftPortName.c_str());
51 return false;
52 }
53 if(!this->yarp().attachAsServer(m_thriftPort))
54 {
55 yCError(FRAMETRANSFORMSETNWSYARP,"Error! Cannot attach the port as a server");
56 return false;
57 }
58
59 return true;
60}
61
63{
64 if(m_thriftPort.isOpen())
65 {
66 m_thriftPort.close();
67 }
68 return true;
69}
70
72{
73 std::lock_guard <std::mutex> lg(m_pd_mutex);
74 m_iSetIf = nullptr;
75 return true;
76}
77
79{
80 std::lock_guard <std::mutex> lg(m_pd_mutex);
81
82 if(!m_iSetIf->setTransform(transform))
83 {
84 yCError(FRAMETRANSFORMSETNWSYARP, "Unable to set transform");
85 return false;
86 }
87
88 return true;
89}
90
91bool FrameTransformSet_nws_yarp::setTransformsRPC(const std::vector<yarp::math::FrameTransform>& transforms)
92{
93 std::lock_guard <std::mutex> lg(m_pd_mutex);
94 if(!m_iSetIf->setTransforms(transforms))
95 {
96 yCError(FRAMETRANSFORMSETNWSYARP, "Unable to set transformations");
97 return false;
98 }
99
100 return true;
101}
102
103bool FrameTransformSet_nws_yarp::deleteTransformRPC(const std::string& src, const std::string& dst)
104{
105 std::lock_guard <std::mutex> lg(m_pd_mutex);
106 if (!m_iSetIf->deleteTransform(src,dst))
107 {
108 yCError(FRAMETRANSFORMSETNWSYARP, "Unable to delete transforms");
109 return false;
110 }
111
112 return true;
113}
114
116{
117 std::lock_guard <std::mutex> lg(m_pd_mutex);
118 if (!m_iSetIf->clearAll())
119 {
120 yCError(FRAMETRANSFORMSETNWSYARP, "Unable to clear all transforms");
121 return false;
122 }
123
124 return true;
125}
126
127
129{
130 std::lock_guard <std::mutex> lg(m_pd_mutex);
131 m_pDriver = device2attach;
132
133 if(!m_pDriver->isValid() ||
134 (!m_pDriver->view(m_iSetIf) || m_iSetIf == nullptr) ||
135 (!m_pDriver->view(m_iUtilsIf) || m_iUtilsIf == nullptr))
136 {
137 yCError(FRAMETRANSFORMSETNWSYARP, "Attach failed");
138 return false;
139 }
140 return true;
141}
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool setTransformsRPC(const std::vector< yarp::math::FrameTransform > &transforms) override
bool setTransformRPC(const yarp::math::FrameTransform &transform) override
bool deleteTransformRPC(const std::string &src, const std::string &dst) override
bool detach() override
Detach the object (you must have first called attach).
bool attach(yarp::dev::PolyDriver *device2attach) override
Attach to another object.
bool close() override
Close the DeviceDriver.
bool view(T *&x)
Get an interface to the device driver.
Definition: DeviceDriver.h:88
virtual bool deleteTransform(std::string src, std::string dst)=0
Delete a single transform in the storage.
virtual bool setTransform(const yarp::math::FrameTransform &transform)=0
Save a frame transform in a storage.
virtual bool setTransforms(const std::vector< yarp::math::FrameTransform > &transforms)=0
Save some frame transforms in a storage.
virtual bool clearAll()=0
Delete all transforms in a storage.
A container for a device driver.
Definition: PolyDriver.h:23
bool isValid() const
Check if device is valid.
Definition: PolyDriver.cpp:196
static bool checkNetwork()
Check if the YARP Network is up and running.
Definition: Network.cpp:1377
void close() override
Stop port activity.
Definition: Port.cpp:363
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition: Port.cpp:79
bool isOpen() const
Check if the port has been opened.
Definition: Port.cpp:677
A base class for nested structures that can be searched.
Definition: Searchable.h:63
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual std::string asString() const
Get string value.
Definition: Value.cpp:234
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition: Wire.h:28
#define yCError(component,...)
Definition: LogComponent.h:213
#define yCWarning(component,...)
Definition: LogComponent.h:192
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:76
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.