mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-19 00:10:36 +08:00
Using std::function<> for callbacks with C++11
This commit is contained in:
@@ -4,9 +4,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
#include <uavcan/node/generic_publisher.hpp>
|
||||
#include <uavcan/node/generic_subscriber.hpp>
|
||||
|
||||
#if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11)
|
||||
# error UAVCAN_CPP_VERSION
|
||||
#endif
|
||||
|
||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
||||
# include <functional>
|
||||
#endif
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
@@ -60,7 +69,13 @@ static Stream& operator<<(Stream& s, const ServiceCallResult<DataType>& scr)
|
||||
}
|
||||
|
||||
|
||||
template <typename DataType_, typename Callback = void (*)(const ServiceCallResult<DataType_>&)>
|
||||
template <typename DataType_,
|
||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
||||
typename Callback = std::function<void (const ServiceCallResult<DataType_>&)>
|
||||
#else
|
||||
typename Callback = void (*)(const ServiceCallResult<DataType_>&)
|
||||
#endif
|
||||
>
|
||||
class ServiceClient
|
||||
: public GenericSubscriber<DataType_, typename DataType_::Response,
|
||||
typename ServiceResponseTransferListenerInstantiationHelper<DataType_>::Type >
|
||||
|
||||
@@ -4,15 +4,29 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
#include <uavcan/node/generic_publisher.hpp>
|
||||
#include <uavcan/node/generic_subscriber.hpp>
|
||||
|
||||
#if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11)
|
||||
# error UAVCAN_CPP_VERSION
|
||||
#endif
|
||||
|
||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
||||
# include <functional>
|
||||
#endif
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
template <typename DataType_,
|
||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
||||
typename Callback = std::function<void (const ReceivedDataStructure<typename DataType_::Request>&,
|
||||
typename DataType_::Response&)>,
|
||||
#else
|
||||
typename Callback = void (*)(const ReceivedDataStructure<typename DataType_::Request>&,
|
||||
typename DataType_::Response&),
|
||||
#endif
|
||||
unsigned int NumStaticReceivers = 2,
|
||||
unsigned int NumStaticBufs = 1>
|
||||
class ServiceServer : public GenericSubscriber<DataType_, typename DataType_::Request,
|
||||
|
||||
@@ -5,13 +5,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
#include <uavcan/node/generic_subscriber.hpp>
|
||||
|
||||
#if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11)
|
||||
# error UAVCAN_CPP_VERSION
|
||||
#endif
|
||||
|
||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
||||
# include <functional>
|
||||
#endif
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
template <typename DataType_,
|
||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
||||
typename Callback = std::function<void (const ReceivedDataStructure<DataType_>&)>,
|
||||
#else
|
||||
typename Callback = void (*)(const ReceivedDataStructure<DataType_>&),
|
||||
#endif
|
||||
unsigned int NumStaticReceivers = 2,
|
||||
unsigned int NumStaticBufs = 1>
|
||||
class Subscriber : public GenericSubscriber<DataType_, DataType_,
|
||||
|
||||
@@ -6,10 +6,19 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <uavcan/debug.hpp>
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
#include <uavcan/node/subscriber.hpp>
|
||||
#include <uavcan/util/method_binder.hpp>
|
||||
#include <uavcan/protocol/Panic.hpp>
|
||||
|
||||
#if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11)
|
||||
# error UAVCAN_CPP_VERSION
|
||||
#endif
|
||||
|
||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
||||
# include <functional>
|
||||
#endif
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
/**
|
||||
@@ -19,7 +28,13 @@ namespace uavcan
|
||||
* void (const protocol::Panic&)
|
||||
* The listener can be stopped from the callback.
|
||||
*/
|
||||
template <typename Callback = void (*)(const ReceivedDataStructure<protocol::Panic>&)>
|
||||
template <
|
||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
||||
typename Callback = std::function<void (const ReceivedDataStructure<protocol::Panic>&)>
|
||||
#else
|
||||
typename Callback = void (*)(const ReceivedDataStructure<protocol::Panic>&)
|
||||
#endif
|
||||
>
|
||||
class PanicListener : Noncopyable
|
||||
{
|
||||
typedef MethodBinder<PanicListener*, void (PanicListener::*)(const ReceivedDataStructure<protocol::Panic>&)>
|
||||
|
||||
Reference in New Issue
Block a user