Go to the documentation of this file.
5 #ifndef UAVCAN_NODE_SERVICE_SERVER_HPP_INCLUDED
6 #define UAVCAN_NODE_SERVICE_SERVER_HPP_INCLUDED
12 #if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11)
13 # error UAVCAN_CPP_VERSION
16 #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
17 # include <functional>
39 template <
typename ResponseDataType_>
81 template <
typename DataType_,
82 #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
83 typename Callback_ = std::function<void (
const ReceivedDataStructure<typename DataType_::Request>&,
84 ServiceResponseDataStructure<typename DataType_::Response>&)>
86 typename Callback_ = void (*)(
const ReceivedDataStructure<typename DataType_::Request>&,
87 ServiceResponseDataStructure<typename DataType_::Response>&)
113 if (coerceOrFallback<bool>(callback_,
true))
131 UAVCAN_TRACE(
"ServiceServer",
"Response publication failure: %i", res);
133 response_failure_count_++;
138 UAVCAN_TRACE(
"ServiceServer",
"Response was suppressed by the application");
145 , publisher_(
node, getDefaultTxTimeout())
147 , response_failure_count_(0)
162 if (!coerceOrFallback<bool>(callback,
true))
165 return -ErrInvalidParam;
167 callback_ = callback;
169 const int publisher_res = publisher_.
init();
170 if (publisher_res < 0)
172 UAVCAN_TRACE(
"ServiceServer",
"Publisher initialization failure: %i", publisher_res);
173 return publisher_res;
175 return SubscriberType::startAsServiceRequestListener();
181 using SubscriberType::stop;
201 #endif // UAVCAN_NODE_SERVICE_SERVER_HPP_INCLUDED
const std::string response
ServiceResponseDataStructure()
static MonotonicDuration getDefaultTxTimeout()
uint32_t response_failure_count_
void setTxTimeout(MonotonicDuration tx_timeout)
bool isResponseEnabled() const
@ TransferTypeServiceResponse
static MonotonicDuration fromMSec(int64_t ms)
Dispatcher & getDispatcher()
#define UAVCAN_TRACE(...)
struct UAVCAN_EXPORT StaticAssert
static MonotonicDuration getMinTxTimeout()
DataType::Response ResponseType
@ TransferTypeServiceRequest
int publish(const DataStruct &message, TransferType transfer_type, NodeID dst_node_id, MonotonicTime blocking_deadline=MonotonicTime())
virtual void handleReceivedDataStruct(ReceivedDataStructure< RequestType > &request)
GenericPublisher< DataType, ResponseType > PublisherType
uint32_t getRequestFailureCount() const
TransferPriority getPriority() const
TransferID getTransferID() const
static MonotonicDuration getMaxTxTimeout()
uint32_t getResponseFailureCount() const
int start(const Callback &callback)
DataType::Request RequestType
TransferType getTransferType() const
ServiceServer(INode &node)
const TransferPerfCounter & getTransferPerfCounter() const
UAVCAN_EXPORT void handleFatalError(const char *msg)
MonotonicDuration getTxTimeout() const
GenericSubscriber< DataType, RequestType, TransferListener > SubscriberType
void setResponseEnabled(bool x)
MonotonicDuration getTxTimeout() const
void setPriority(const TransferPriority prio)
NodeID getSrcNodeID() const
void setTxTimeout(MonotonicDuration tx_timeout)
ResponseDataType_ ResponseDataType