/* * Copyright (C) 2014 Pavel Kirienko */ #pragma once #include #include namespace uavcan { template &), unsigned int NumStaticReceivers = 2, unsigned int NumStaticBufs = 1> class Subscriber : public GenericSubscriber { 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; Subscriber(Scheduler& scheduler, IAllocator& allocator) : BaseType(scheduler, allocator) , callback_() { StaticAssert::check(); } int start(Callback callback) { stop(); if (!try_implicit_cast(callback, true)) { UAVCAN_TRACE("Subscriber", "Invalid callback"); return -1; } callback_ = callback; return BaseType::startAsMessageListener(); } using BaseType::stop; }; }