From 9ac2813cea087e937ee69bad8069075af56ab0a2 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Tue, 9 Jun 2015 22:58:00 +0300 Subject: [PATCH] Cleaner type definitions in Linux driver --- .../linux/include/uavcan_linux/helpers.hpp | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/libuavcan_drivers/linux/include/uavcan_linux/helpers.hpp b/libuavcan_drivers/linux/include/uavcan_linux/helpers.hpp index ee75075ea9..4c958d2e27 100644 --- a/libuavcan_drivers/linux/include/uavcan_linux/helpers.hpp +++ b/libuavcan_drivers/linux/include/uavcan_linux/helpers.hpp @@ -143,8 +143,24 @@ struct DriverPack typedef std::shared_ptr DriverPackPtr; typedef std::shared_ptr INodePtr; + typedef std::shared_ptr TimerPtr; +template +using SubscriberPtr = std::shared_ptr>; + +template +using PublisherPtr = std::shared_ptr>; + +template +using ServiceServerPtr = std::shared_ptr>; + +template +using ServiceClientPtr = std::shared_ptr>; + +template +using BlockingServiceClientPtr = std::shared_ptr>; + static constexpr std::size_t NodeMemPoolSize = 1024 * 512; ///< This shall be enough for any possible use case /** @@ -194,10 +210,9 @@ public: * @throws uavcan_linux::Exception. */ template - std::shared_ptr> - makeSubscriber(const typename uavcan::Subscriber::Callback& cb) + SubscriberPtr makeSubscriber(const typename uavcan::Subscriber::Callback& cb) { - std::shared_ptr> p(new uavcan::Subscriber(*this)); + SubscriberPtr p(new uavcan::Subscriber(*this)); enforce(p->start(cb), "Subscriber start failure " + getDataTypeName()); return p; } @@ -208,10 +223,10 @@ public: * @throws uavcan_linux::Exception. */ template - std::shared_ptr> - makePublisher(uavcan::MonotonicDuration tx_timeout = uavcan::Publisher::getDefaultTxTimeout()) + PublisherPtr makePublisher(uavcan::MonotonicDuration tx_timeout = + uavcan::Publisher::getDefaultTxTimeout()) { - std::shared_ptr> p(new uavcan::Publisher(*this)); + PublisherPtr p(new uavcan::Publisher(*this)); enforce(p->init(), "Publisher init failure " + getDataTypeName()); p->setTxTimeout(tx_timeout); return p; @@ -223,10 +238,9 @@ public: * @throws uavcan_linux::Exception. */ template - std::shared_ptr> - makeServiceServer(const typename uavcan::ServiceServer::Callback& cb) + ServiceServerPtr makeServiceServer(const typename uavcan::ServiceServer::Callback& cb) { - std::shared_ptr> p(new uavcan::ServiceServer(*this)); + ServiceServerPtr p(new uavcan::ServiceServer(*this)); enforce(p->start(cb), "ServiceServer start failure " + getDataTypeName()); return p; } @@ -237,10 +251,9 @@ public: * @throws uavcan_linux::Exception. */ template - std::shared_ptr> - makeServiceClient(const typename uavcan::ServiceClient::Callback& cb) + ServiceClientPtr makeServiceClient(const typename uavcan::ServiceClient::Callback& cb) { - std::shared_ptr> p(new uavcan::ServiceClient(*this)); + ServiceClientPtr p(new uavcan::ServiceClient(*this)); enforce(p->init(), "ServiceClient init failure " + getDataTypeName()); p->setCallback(cb); return p; @@ -252,10 +265,9 @@ public: * @throws uavcan_linux::Exception. */ template - std::shared_ptr> - makeBlockingServiceClient() + BlockingServiceClientPtr makeBlockingServiceClient() { - std::shared_ptr> p(new BlockingServiceClient(*this)); + BlockingServiceClientPtr p(new BlockingServiceClient(*this)); enforce(p->init(), "BlockingServiceClient init failure " + getDataTypeName()); return p; }