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

C++20 support #3039

Merged
merged 6 commits into from
Nov 15, 2023
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
2 changes: 1 addition & 1 deletion cmake/YarpSystemCheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include(GNUInstallDirs)
# These variables are used by try_compile, so they must be set here

set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


Expand Down
10 changes: 10 additions & 0 deletions extern/catch2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ project(YARP_catch2)
add_library(YARP_catch2 STATIC)
add_library(YARP::YARP_catch2 ALIAS YARP_catch2)

if(MSVC)
#This is required because of https://github.com/catchorg/Catch2/issues/2174
if(CMAKE_GENERATOR MATCHES "Visual Studio")
target_compile_options(YARP_catch2 PRIVATE "/Zc:hiddenFriend-")
endif()
if(CMAKE_GENERATOR MATCHES "Ninja")
target_compile_options(YARP_catch2 PRIVATE "/Zc:hiddenFriend-")
endif()
endif(MSVC)

set(YARP_catch2_SRCS
catch2/catch_amalgamated.cpp
)
Expand Down
104 changes: 50 additions & 54 deletions src/devices/VirtualAnalogWrapper/VirtualAnalogWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,55 @@
// TODO add IVirtualAnalogSensor interface to have Channels number and status??


class AnalogSubDevice;
class AnalogSubDevice
{
public:
AnalogSubDevice();
~AnalogSubDevice();

bool attach(yarp::dev::PolyDriver* driver, const std::string& key);
void detach();

bool configure(int map0, int map1, const std::string& key);

bool isAttached() { return mIsAttached; }

void setTorque(int joint, double torque)
{
if (joint < mMap0 || mMap1 < joint) {
return;
}

mTorques[joint - mMap0] = torque;
}

void resetTorque()
{
mTorques.zero();
}

void flushTorques()
{
if (mpSensor) {
mpSensor->updateVirtualAnalogSensorMeasure(mTorques);
}
}

const std::string& getKey() { return mKey; }

protected:
std::string mKey;

int mMap0, mMap1;

yarp::sig::Vector mTorques;

bool mIsConfigured;
bool mIsAttached;
double lastRecvMsg{ 0.0 };
yarp::dev::PolyDriver* mpDevice;
yarp::dev::IVirtualAnalogSensor* mpSensor;
};

/**
* @ingroup dev_impl_wrapper
Expand All @@ -68,7 +116,7 @@ class VirtualAnalogWrapper :
VirtualAnalogWrapper& operator=(const VirtualAnalogWrapper&) = delete;
VirtualAnalogWrapper& operator=(VirtualAnalogWrapper&&) = delete;

~VirtualAnalogWrapper() override
~VirtualAnalogWrapper()
{
close();
}
Expand Down Expand Up @@ -106,56 +154,4 @@ class VirtualAnalogWrapper :
yarp::os::BufferedPort<yarp::os::Bottle> mPortInputTorques;
};


class AnalogSubDevice
{
public:
AnalogSubDevice();
~AnalogSubDevice();

bool attach(yarp::dev::PolyDriver *driver, const std::string &key);
void detach();

bool configure(int map0, int map1, const std::string &key);

bool isAttached(){ return mIsAttached; }

void setTorque(int joint,double torque)
{
if (joint < mMap0 || mMap1 < joint) {
return;
}

mTorques[joint-mMap0]=torque;
}

void resetTorque()
{
mTorques.zero();
}

void flushTorques()
{
if (mpSensor) {
mpSensor->updateVirtualAnalogSensorMeasure(mTorques);
}
}

const std::string& getKey(){ return mKey; }

protected:
std::string mKey;

int mMap0,mMap1;

yarp::sig::Vector mTorques;

bool mIsConfigured;
bool mIsAttached;
double lastRecvMsg{0.0};
yarp::dev::PolyDriver *mpDevice;
yarp::dev::IVirtualAnalogSensor *mpSensor;
};


#endif // YARP_DEV_VIRTUALANALOGWRAPPER_VIRTUALANALOGWRAPPER_H
13 changes: 11 additions & 2 deletions src/libYARP_os/src/yarp/os/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ class YARP_os_API Log
LogTypeReserved = 0xFF
};

static std::mutex* getLogMutex()
{
static std::mutex m;
return &m;
}

void trace(const char* msg, ...) const YARP_ATTRIBUTE_FORMAT(printf, 2, 3);
void debug(const char* msg, ...) const YARP_ATTRIBUTE_FORMAT(printf, 2, 3);
void info(const char* msg, ...) const YARP_ATTRIBUTE_FORMAT(printf, 2, 3);
Expand Down Expand Up @@ -191,11 +197,14 @@ class YARP_os_API Log
return !flag.test_and_set(); \
}

//The mutex definition was initially placed inside the lambda function below.
//It was moved outside because it seems that the destruction of the
//static mutex leads to a segfault on Windows platform when executing CI (LogTest.cpp).
#define YARP_THROTTLE_CALLBACK(period) \
[](){ \
static double last = -period; \
static std::mutex mutex; \
std::lock_guard<std::mutex> lock(mutex); \
std::mutex* mutex_throttle_callback = yarp::os::Log::getLogMutex(); \
std::lock_guard<std::mutex> lock(*mutex_throttle_callback);\
double now = yarp::os::SystemClock::nowSystem(); \
if (now >= last + period) { \
last = now; \
Expand Down
Loading