Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New class for return values of interface methods PART3 #3169

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 107 additions & 77 deletions src/devices/frameTransformClient/FrameTransformClient.cpp

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions src/devices/frameTransformClient/FrameTransformClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,20 @@ class FrameTransformClient :
bool read(yarp::os::ConnectionReader& connection) override;

//IFrameTransform
bool allFramesAsString(std::string &all_frames) override;
bool canTransform(const std::string &target_frame, const std::string &source_frame) override;
bool clear() override;
bool frameExists(const std::string &frame_id) override;
bool getAllFrameIds(std::vector< std::string > &ids) override;
bool getParent(const std::string &frame_id, std::string &parent_frame_id) override;
bool getTransform(const std::string &target_frame_id, const std::string &source_frame_id, yarp::sig::Matrix &transform) override;
bool setTransform(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Matrix &transform) override;
bool setTransformStatic(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Matrix &transform) override;
bool deleteTransform(const std::string &target_frame_id, const std::string &source_frame_id) override;
bool transformPoint(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Vector &input_point, yarp::sig::Vector &transformed_point) override;
bool transformPose(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Vector &input_pose, yarp::sig::Vector &transformed_pose) override;
bool transformQuaternion(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::math::Quaternion &input_quaternion, yarp::math::Quaternion &transformed_quaternion) override;
bool waitForTransform(const std::string &target_frame_id, const std::string &source_frame_id, const double &timeout) override;
yarp::dev::ReturnValue allFramesAsString(std::string &all_frames) override;
yarp::dev::ReturnValue canTransform(const std::string &target_frame, const std::string &source_frame, bool& exists) override;
yarp::dev::ReturnValue clear() override;
yarp::dev::ReturnValue frameExists(const std::string &frame_id, bool& exists) override;
yarp::dev::ReturnValue getAllFrameIds(std::vector< std::string > &ids) override;
yarp::dev::ReturnValue getParent(const std::string &frame_id, std::string &parent_frame_id) override;
yarp::dev::ReturnValue getTransform(const std::string &target_frame_id, const std::string &source_frame_id, yarp::sig::Matrix &transform) override;
yarp::dev::ReturnValue setTransform(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Matrix &transform) override;
yarp::dev::ReturnValue setTransformStatic(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Matrix &transform) override;
yarp::dev::ReturnValue deleteTransform(const std::string &target_frame_id, const std::string &source_frame_id) override;
yarp::dev::ReturnValue transformPoint(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Vector &input_point, yarp::sig::Vector &transformed_point) override;
yarp::dev::ReturnValue transformPose(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Vector &input_pose, yarp::sig::Vector &transformed_pose) override;
yarp::dev::ReturnValue transformQuaternion(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::math::Quaternion &input_quaternion, yarp::math::Quaternion &transformed_quaternion) override;
yarp::dev::ReturnValue waitForTransform(const std::string &target_frame_id, const std::string &source_frame_id, const double &timeout) override;

//PeriodicThread
bool threadInit() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool FrameTransformGetMultiplexer::attachAll(const yarp::dev::PolyDriverList& de
}


bool FrameTransformGetMultiplexer::getTransforms(std::vector<yarp::math::FrameTransform>& transforms) const
yarp::dev::ReturnValue FrameTransformGetMultiplexer::getTransforms(std::vector<yarp::math::FrameTransform>& transforms) const
{
for (size_t i = 0; i < m_iFrameTransformStorageGetList.size(); i++)
{
Expand All @@ -86,10 +86,11 @@ bool FrameTransformGetMultiplexer::getTransforms(std::vector<yarp::math::FrameTr
localTransform.begin(),
localTransform.end());
}
else {
else
{
yCError(FRAMETRANSFORMGETMULTIPLEXER) << "pointer to interface IFrameTransformStorageGet not valid";
return false;
return ReturnValue::return_code::return_value_error_method_failed;
}
}
return true;
return ReturnValue_ok;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FrameTransformGetMultiplexer:
bool detachAll() override;

// yarp::dev::IFrameTransformStorageGet
bool getTransforms(std::vector<yarp::math::FrameTransform>& transforms) const override;
yarp::dev::ReturnValue getTransforms(std::vector<yarp::math::FrameTransform>& transforms) const override;

private:
int m_verbose{4};
Expand Down
12 changes: 7 additions & 5 deletions src/devices/frameTransformGet/FrameTransformGet_nwc_yarp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <yarp/os/LogComponent.h>
#include <yarp/os/LogStream.h>

using namespace yarp::dev;

YARP_LOG_COMPONENT(FRAMETRANSFORMGETNWCYARP, "yarp.devices.FrameTransformGet_nwc_yarp")


Expand Down Expand Up @@ -136,18 +138,18 @@ bool FrameTransformGet_nwc_yarp::close()
}


bool FrameTransformGet_nwc_yarp::getTransforms(std::vector<yarp::math::FrameTransform>& transforms) const
ReturnValue FrameTransformGet_nwc_yarp::getTransforms(std::vector<yarp::math::FrameTransform>& transforms) const
{
if (!m_streaming_port_enabled)
{
return_getAllTransforms retrievedFromRPC = m_frameTransformStorageGetRPC.getTransformsRPC();
if(!retrievedFromRPC.retvalue)
{
yCError(FRAMETRANSFORMGETNWCYARP, "Unable to get transformations");
return false;
return retrievedFromRPC.retvalue;
}
transforms = retrievedFromRPC.transforms_list;
return true;
return retrievedFromRPC.retvalue;
}
else
{
Expand All @@ -156,10 +158,10 @@ bool FrameTransformGet_nwc_yarp::getTransforms(std::vector<yarp::math::FrameTran
return_getAllTransforms retrievedFromSteaming;
m_dataReader->getData(retrievedFromSteaming);
transforms = retrievedFromSteaming.transforms_list;
return true;
return retrievedFromSteaming.retvalue;
}
yCError(FRAMETRANSFORMGETNWCYARP, "Unable to get transformations");
return false;
return yarp::dev::ReturnValue::return_code::return_value_error_generic;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class FrameTransformGet_nwc_yarp:
bool close() override;

// yarp::dev::IFrameTransformStorageGet
bool getTransforms(std::vector<yarp::math::FrameTransform>& transforms) const override;
yarp::dev::ReturnValue getTransforms(std::vector<yarp::math::FrameTransform>& transforms) const override;

private:
int m_verbose{4};
Expand Down
23 changes: 18 additions & 5 deletions src/devices/frameTransformGet/FrameTransformGet_nws_yarp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

#include <yarp/os/LogComponent.h>
#include <yarp/os/LogStream.h>
#include <yarp/dev/ReturnValue.h>

using namespace yarp::dev;

YARP_LOG_COMPONENT(FRAMETRANSFORMGETNWSYARP, "yarp.devices.FrameTransformGet_nws_yarp")

Expand Down Expand Up @@ -143,26 +145,37 @@ bool FrameTransformGet_nws_yarp::attach( yarp::dev::PolyDriver* deviceToAttach)
return_getAllTransforms FrameTransformGet_nws_yarp::getTransformsRPC()
{
std::lock_guard<std::mutex> m_lock(m_mutex);
if (m_iFrameTransformStorageGet != nullptr) {

return_getAllTransforms ret;
if (m_iFrameTransformStorageGet != nullptr)
{
std::vector<yarp::math::FrameTransform> localTransform;
if (m_iFrameTransformStorageGet->getTransforms(localTransform)) {
return return_getAllTransforms(true, localTransform);
if (m_iFrameTransformStorageGet->getTransforms(localTransform))
{
ret.transforms_list = localTransform;
ret.retvalue = ReturnValue_ok;
return ret;
}
}
yCError(FRAMETRANSFORMGETNWSYARP) << "error getting transform from interface";
return return_getAllTransforms(false, std::vector<yarp::math::FrameTransform>());;
ret.transforms_list = std::vector<yarp::math::FrameTransform>();
ret.retvalue = ReturnValue::return_code::return_value_error_method_failed;
return ret;

}

void FrameTransformGet_nws_yarp::run()
{
std::lock_guard<std::mutex> m_lock(m_mutex);

if (m_iFrameTransformStorageGet != nullptr)
{
std::vector<yarp::math::FrameTransform> localTransform;
if (m_iFrameTransformStorageGet->getTransforms(localTransform))
{
return_getAllTransforms rgt(true, localTransform);
return_getAllTransforms rgt;
rgt.retvalue = ReturnValue_ok;
rgt.transforms_list = localTransform;
m_streaming_port.write(rgt);
}
}
Expand Down
38 changes: 22 additions & 16 deletions src/devices/frameTransformSet/FrameTransformSetMultiplexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,38 +78,40 @@ bool FrameTransformSetMultiplexer::attachAll(const yarp::dev::PolyDriverList& de
}


bool FrameTransformSetMultiplexer::setTransforms(const std::vector<yarp::math::FrameTransform>& transforms)
yarp::dev::ReturnValue FrameTransformSetMultiplexer::setTransforms(const std::vector<yarp::math::FrameTransform>& transforms)
{
for (size_t i = 0; i < m_iFrameTransformStorageSetList.size(); i++)
{
if (m_iFrameTransformStorageSetList[i] != nullptr) {
m_iFrameTransformStorageSetList[i]->setTransforms(transforms);
}
else {
else
{
yCError(FRAMETRANSFORMSETMULTIPLEXER) << "pointer to interface IFrameTransformStorageSet not valid";
return false;
return ReturnValue::return_code::return_value_error_method_failed;
}
}
return true;
return ReturnValue_ok;
}


bool FrameTransformSetMultiplexer::setTransform(const yarp::math::FrameTransform& transform)
yarp::dev::ReturnValue FrameTransformSetMultiplexer::setTransform(const yarp::math::FrameTransform& transform)
{
for (size_t i = 0; i < m_iFrameTransformStorageSetList.size(); i++)
{
if (m_iFrameTransformStorageSetList[i] != nullptr) {
m_iFrameTransformStorageSetList[i]->setTransform(transform);
}
else {
else
{
yCError(FRAMETRANSFORMSETMULTIPLEXER) << "pointer to interface IFrameTransformStorageSet not valid";
return false;
return ReturnValue::return_code::return_value_error_method_failed;
}
}
return true;
return ReturnValue_ok;
}

bool FrameTransformSetMultiplexer::deleteTransform(std::string t1, std::string t2)
yarp::dev::ReturnValue FrameTransformSetMultiplexer::deleteTransform(std::string t1, std::string t2)
{
//stopThreads();

Expand All @@ -121,18 +123,21 @@ bool FrameTransformSetMultiplexer::deleteTransform(std::string t1, std::string t
{
frame_deleted &= m_iFrameTransformStorageSetList[i]->deleteTransform(t1,t2);
}
else {
else
{
yCError(FRAMETRANSFORMSETMULTIPLEXER) << "pointer to interface IFrameTransformStorageSet not valid";
return false;
return ReturnValue::return_code::return_value_error_method_failed;
}
}

//startThreads();

return frame_deleted;
if (frame_deleted) { return ReturnValue_ok; }

return ReturnValue::return_code::return_value_error_method_failed;
}

bool FrameTransformSetMultiplexer::clearAll()
yarp::dev::ReturnValue FrameTransformSetMultiplexer::clearAll()
{
//stopThreads();

Expand All @@ -141,15 +146,16 @@ bool FrameTransformSetMultiplexer::clearAll()
if (m_iFrameTransformStorageSetList[i] != nullptr) {
m_iFrameTransformStorageSetList[i]->clearAll();
}
else {
else
{
yCError(FRAMETRANSFORMSETMULTIPLEXER) << "pointer to interface IFrameTransformStorageSet not valid";
return false;
return ReturnValue::return_code::return_value_error_method_failed;
}
}

//startThreads();

return true;
return ReturnValue_ok;
}

void FrameTransformSetMultiplexer::stopThreads()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class FrameTransformSetMultiplexer:
bool detachAll() override;

// yarp::dev::IFrameTransformStorageSet
bool setTransform(const yarp::math::FrameTransform& transform) override;
bool setTransforms(const std::vector<yarp::math::FrameTransform>& transforms) override;
virtual bool deleteTransform(std::string t1, std::string t2) override;
virtual bool clearAll() override;
yarp::dev::ReturnValue setTransform(const yarp::math::FrameTransform& transform) override;
yarp::dev::ReturnValue setTransforms(const std::vector<yarp::math::FrameTransform>& transforms) override;
yarp::dev::ReturnValue deleteTransform(std::string t1, std::string t2) override;
yarp::dev::ReturnValue clearAll() override;

void startThreads();
void stopThreads();
Expand Down
40 changes: 24 additions & 16 deletions src/devices/frameTransformSet/FrameTransformSet_nwc_yarp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,46 +91,54 @@ bool FrameTransformSet_nwc_yarp::close()
return true;
}

bool FrameTransformSet_nwc_yarp::setTransform(const yarp::math::FrameTransform& transform)
ReturnValue FrameTransformSet_nwc_yarp::setTransform(const yarp::math::FrameTransform& transform)
{
std::lock_guard <std::mutex> lg(m_pd_mutex);
if(!m_setRPC.setTransformRPC(transform))

auto ret = m_setRPC.setTransformRPC(transform);
if(!ret)
{
yCError(FRAMETRANSFORMSETNWCYARP, "Unable to set transformation");
return false;
return ret;
}
return true;
return ret;
}

bool FrameTransformSet_nwc_yarp::setTransforms(const std::vector<yarp::math::FrameTransform>& transforms)
ReturnValue FrameTransformSet_nwc_yarp::setTransforms(const std::vector<yarp::math::FrameTransform>& transforms)
{
std::lock_guard <std::mutex> lg(m_pd_mutex);
if(!m_setRPC.setTransformsRPC(transforms))

auto ret = m_setRPC.setTransformsRPC(transforms);
if(!ret)
{
yCError(FRAMETRANSFORMSETNWCYARP, "Unable to set transformations");
return false;
return ret;
}
return true;
return ret;
}

bool FrameTransformSet_nwc_yarp::deleteTransform(std::string t1, std::string t2)
ReturnValue FrameTransformSet_nwc_yarp::deleteTransform(std::string t1, std::string t2)
{
std::lock_guard <std::mutex> lg(m_pd_mutex);
if (!m_setRPC.deleteTransformRPC(t1,t2))

auto ret = m_setRPC.deleteTransformRPC(t1, t2);
if (!ret)
{
yCError(FRAMETRANSFORMSETNWCYARP, "Unable to delete transformation");
return false;
return ret;
}
return true;
return ret;
}

bool FrameTransformSet_nwc_yarp::clearAll()
ReturnValue FrameTransformSet_nwc_yarp::clearAll()
{
std::lock_guard <std::mutex> lg(m_pd_mutex);
if (!m_setRPC.clearAllRPC())

auto ret = m_setRPC.clearAllRPC();
if (!ret)
{
yCError(FRAMETRANSFORMSETNWCYARP, "Unable to clear all transformations");
return false;
return ret;
}
return true;
return ret;
}
8 changes: 4 additions & 4 deletions src/devices/frameTransformSet/FrameTransformSet_nwc_yarp.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ class FrameTransformSet_nwc_yarp :
bool close() override;

//FrameTransformStorageSetRPC functions
bool setTransforms(const std::vector<yarp::math::FrameTransform>& transforms) override;
bool setTransform(const yarp::math::FrameTransform& transform) override;
bool deleteTransform(std::string t1, std::string t2) override;
bool clearAll() override;
yarp::dev::ReturnValue setTransforms(const std::vector<yarp::math::FrameTransform>& transforms) override;
yarp::dev::ReturnValue setTransform(const yarp::math::FrameTransform& transform) override;
yarp::dev::ReturnValue deleteTransform(std::string t1, std::string t2) override;
yarp::dev::ReturnValue clearAll() override;

private:
mutable std::mutex m_trf_mutex;
Expand Down
Loading
Loading