YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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
66
68{
69 if(m_thriftPort.isOpen())
70 {
71 m_thriftPort.close();
72 }
73 return true;
74}
75
77{
78 std::lock_guard <std::mutex> lg(m_pd_mutex);
79 m_iSetIf = nullptr;
80 return true;
81}
82
84{
85 std::lock_guard <std::mutex> lg(m_pd_mutex);
86
87 auto ret = m_iSetIf->setTransform(transform);
88 if(!ret)
89 {
90 yCError(FRAMETRANSFORMSETNWSYARP, "Unable to set transform");
91 return ret;
92 }
93
94 return ret;
95}
96
97ReturnValue FrameTransformSet_nws_yarp::setTransformsRPC(const std::vector<yarp::math::FrameTransform>& transforms)
98{
99 std::lock_guard <std::mutex> lg(m_pd_mutex);
100
101 auto ret = m_iSetIf->setTransforms(transforms);
102 if(!ret)
103 {
104 yCError(FRAMETRANSFORMSETNWSYARP, "Unable to set transformations");
105 return ret;
106 }
107
108 return ret;
109}
110
111ReturnValue FrameTransformSet_nws_yarp::deleteTransformRPC(const std::string& src, const std::string& dst)
112{
113 std::lock_guard <std::mutex> lg(m_pd_mutex);
114
115 auto ret = m_iSetIf->deleteTransform(src, dst);
116 if (!ret)
117 {
118 yCError(FRAMETRANSFORMSETNWSYARP, "Unable to delete transforms");
119 return ret;
120 }
121
122 return ret;
123}
124
126{
127 std::lock_guard <std::mutex> lg(m_pd_mutex);
128
129 auto ret = m_iSetIf->clearAll();
130 if (!ret)
131 {
132 yCError(FRAMETRANSFORMSETNWSYARP, "Unable to clear all transforms");
133 return ret;
134 }
135
136 return ret;
137}
138
139
141{
142 std::lock_guard <std::mutex> lg(m_pd_mutex);
143 m_pDriver = device2attach;
144
145 if(!m_pDriver->isValid() ||
146 (!m_pDriver->view(m_iSetIf) || m_iSetIf == nullptr) ||
147 (!m_pDriver->view(m_iUtilsIf) || m_iUtilsIf == nullptr))
148 {
149 yCError(FRAMETRANSFORMSETNWSYARP, "Attach failed");
150 return false;
151 }
152 return true;
153}
bool ret
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue setTransformRPC(const yarp::math::FrameTransform &transform) override
yarp::dev::ReturnValue setTransformsRPC(const std::vector< yarp::math::FrameTransform > &transforms) override
yarp::dev::ReturnValue clearAllRPC() override
bool detach() override
Detach the object (you must have first called attach).
bool attach(yarp::dev::PolyDriver *device2attach) override
Attach to another object.
yarp::dev::ReturnValue deleteTransformRPC(const std::string &src, const std::string &dst) override
bool close() override
Close the DeviceDriver.
bool view(T *&x)
Get an interface to the device driver.
virtual yarp::dev::ReturnValue setTransforms(const std::vector< yarp::math::FrameTransform > &transforms)=0
Save some frame transforms in a storage.
virtual yarp::dev::ReturnValue clearAll()=0
Delete all transforms in a storage.
virtual yarp::dev::ReturnValue setTransform(const yarp::math::FrameTransform &transform)=0
Save a frame transform in a storage.
virtual yarp::dev::ReturnValue deleteTransform(std::string src, std::string dst)=0
Delete a single transform in the storage.
A container for a device driver.
Definition PolyDriver.h:23
bool isValid() const
Check if device is valid.
A mini-server for performing network communication in the background.
static bool checkNetwork()
Check if the YARP Network is up and running.
Definition Network.cpp:1370
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:31
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.
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition Wire.h:28
#define yCError(component,...)
#define yCWarning(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.