From 062170c995ef7377b9920f4854a41057cfbd662c Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Fri, 28 Mar 2014 02:17:00 +0400 Subject: [PATCH] Using std::function<> for callbacks with C++11 --- .../include/uavcan/node/service_client.hpp | 17 ++++++++++++++++- .../include/uavcan/node/service_server.hpp | 14 ++++++++++++++ libuavcan/include/uavcan/node/subscriber.hpp | 13 +++++++++++++ .../include/uavcan/protocol/panic_listener.hpp | 17 ++++++++++++++++- 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/libuavcan/include/uavcan/node/service_client.hpp b/libuavcan/include/uavcan/node/service_client.hpp index 2ed6f9cff7..40f7ace84b 100644 --- a/libuavcan/include/uavcan/node/service_client.hpp +++ b/libuavcan/include/uavcan/node/service_client.hpp @@ -4,9 +4,18 @@ #pragma once +#include #include #include +#if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11) +# error UAVCAN_CPP_VERSION +#endif + +#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 +# include +#endif + namespace uavcan { @@ -60,7 +69,13 @@ static Stream& operator<<(Stream& s, const ServiceCallResult& scr) } -template &)> +template = UAVCAN_CPP11 + typename Callback = std::function&)> +#else + typename Callback = void (*)(const ServiceCallResult&) +#endif + > class ServiceClient : public GenericSubscriber::Type > diff --git a/libuavcan/include/uavcan/node/service_server.hpp b/libuavcan/include/uavcan/node/service_server.hpp index b8462e4682..3e55495c1c 100644 --- a/libuavcan/include/uavcan/node/service_server.hpp +++ b/libuavcan/include/uavcan/node/service_server.hpp @@ -4,15 +4,29 @@ #pragma once +#include #include #include +#if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11) +# error UAVCAN_CPP_VERSION +#endif + +#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 +# include +#endif + namespace uavcan { template = UAVCAN_CPP11 + typename Callback = std::function&, + typename DataType_::Response&)>, +#else typename Callback = void (*)(const ReceivedDataStructure&, typename DataType_::Response&), +#endif unsigned int NumStaticReceivers = 2, unsigned int NumStaticBufs = 1> class ServiceServer : public GenericSubscriber +#include #include +#if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11) +# error UAVCAN_CPP_VERSION +#endif + +#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 +# include +#endif + namespace uavcan { template = UAVCAN_CPP11 + typename Callback = std::function&)>, +#else typename Callback = void (*)(const ReceivedDataStructure&), +#endif unsigned int NumStaticReceivers = 2, unsigned int NumStaticBufs = 1> class Subscriber : public GenericSubscriber #include +#include #include #include #include +#if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11) +# error UAVCAN_CPP_VERSION +#endif + +#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 +# include +#endif + namespace uavcan { /** @@ -19,7 +28,13 @@ namespace uavcan * void (const protocol::Panic&) * The listener can be stopped from the callback. */ -template &)> +template < +#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 + typename Callback = std::function&)> +#else + typename Callback = void (*)(const ReceivedDataStructure&) +#endif + > class PanicListener : Noncopyable { typedef MethodBinder&)>