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>
9 #include <yarp/os/LogComponent.h>
10 #include <yarp/os/LogStream.h>
11 
12 using namespace yarp::dev;
13 using namespace yarp::os;
14 using namespace yarp::sig;
15 using namespace yarp::math;
16 
17 namespace {
18 YARP_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 
91 bool 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 
103 bool 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.
A container for a device driver.
Definition: PolyDriver.h:24
static bool checkNetwork()
Check if the YARP Network is up and running.
Definition: Network.cpp:1377
A base class for nested structures that can be searched.
Definition: Searchable.h:66
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string asString() const
Get string value.
Definition: Value.cpp:234
#define yCError(component,...)
Definition: LogComponent.h:154
#define yCWarning(component,...)
Definition: LogComponent.h:143
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:77
An interface for the device drivers.
An interface to the operating system, including Port based communication.
Signal processing.
Definition: Image.h:22
The main, catch-all namespace for YARP.
Definition: dirs.h:16