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>&,
113 if (coerceOrFallback<bool>(callback_,
true))
116 callback_(request, response);
123 if (response.isResponseEnabled())
131 UAVCAN_TRACE(
"ServiceServer",
"Response publication failure: %i", res);
133 response_failure_count_++;
138 UAVCAN_TRACE(
"ServiceServer",
"Response was suppressed by the application");
144 : SubscriberType(node)
145 , publisher_(node, getDefaultTxTimeout())
147 , response_failure_count_(0)
151 StaticAssert<DataTypeKind(DataType::DataTypeKind) == DataTypeKindService>::check();
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
MonotonicDuration getTxTimeout() const
void setPriority(const TransferPriority prio)
uint32_t getResponseFailureCount() const
NodeID getSrcNodeID() const
GenericPublisher< DataType, ResponseType > PublisherType
Dispatcher & getDispatcher()
uint32_t getRequestFailureCount() const
UAVCAN_EXPORT void handleFatalError(const char *msg)
static MonotonicDuration getDefaultTxTimeout()
virtual void handleReceivedDataStruct(ReceivedDataStructure< RequestType > &request)
void setTxTimeout(MonotonicDuration tx_timeout)
void setTxTimeout(MonotonicDuration tx_timeout)
void setResponseEnabled(bool x)
#define UAVCAN_TRACE(...)
ServiceServer(INode &node)
bool isResponseEnabled() const
const TransferPerfCounter & getTransferPerfCounter() const
static MonotonicDuration getMaxTxTimeout()
DataType::Request RequestType
GenericSubscriber< DataType, RequestType, TransferListener > SubscriberType
uint32_t response_failure_count_
int start(const Callback &callback)
int publish(const DataStruct &message, TransferType transfer_type, NodeID dst_node_id, MonotonicTime blocking_deadline=MonotonicTime())
ServiceResponseDataStructure()
DataType::Response ResponseType
ResponseDataType_ ResponseDataType
static MonotonicDuration fromMSec(int64_t ms)
TransferID getTransferID() const
TransferPriority getPriority() const
const std::string response
MonotonicDuration getTxTimeout() const
static MonotonicDuration getMinTxTimeout()
TransferType getTransferType() const