/* * Copyright (C) 2014 Pavel Kirienko */ #pragma once #include #include namespace uavcan { template &), unsigned int NumStaticReceivers = 2, unsigned int NumStaticBufs = 1> class Subscriber : public GenericSubscriber::Type> { typedef typename TransferListenerInstantiationHelper::Type TransferListenerType; typedef GenericSubscriber BaseType; Callback callback_; void handleReceivedDataStruct(ReceivedDataStructure& msg) { if (try_implicit_cast(callback_, true)) callback_(msg); else handleFatalError("Invalid subscriber callback"); } public: typedef DataType_ DataType; explicit Subscriber(INode& node) : BaseType(node) , callback_() { StaticAssert::check(); } int start(const Callback& callback) { stop(); if (!try_implicit_cast(callback, true)) { UAVCAN_TRACE("Subscriber", "Invalid callback"); return -1; } callback_ = callback; return BaseType::startAsMessageListener(); } using BaseType::stop; using BaseType::getFailureCount; }; }