diff options
Diffstat (limited to 'include/mts/MTS_BasicSubscriber.h')
-rw-r--r-- | include/mts/MTS_BasicSubscriber.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/include/mts/MTS_BasicSubscriber.h b/include/mts/MTS_BasicSubscriber.h new file mode 100644 index 0000000..908dde9 --- /dev/null +++ b/include/mts/MTS_BasicSubscriber.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_BasicSubscriber.h + \brief A simple subscriber + \date 28MAR12 + \author Sean Godinez + + A subscriber. + */ +#ifndef _MTS_BASICSUBSCRIBER_H_ +#define _MTS_BASICSUBSCRIBER_H_ + +#include <mts/MTS_Subscriber.h> +#include <mts/MTS_Callback.h> + +namespace MTS { + + //! A basic subscriber + /*! + A basic subscriber provides simple subscribing functionality. + + \sa Publisher, Subscriber, BasicPublisher + */ + template<class T> class BasicSubscriber: public Subscriber<T> { + + public: + explicit BasicSubscriber(const Callback<T>& callback, const std::string& name = ""); //!< Constructor + virtual ~BasicSubscriber();//!< Destructor + + virtual void update(const T& object); //!< Invokes callback with published data T + + private: + Callback<T>* callback; + + //Prevent Copy and Assignment operators from being called + BasicSubscriber(const BasicSubscriber&); + BasicSubscriber& operator=(const BasicSubscriber&); + }; + + template<class T> BasicSubscriber<T>::BasicSubscriber(const Callback<T>& callback, const std::string& name) + : Subscriber<T>(name), callback(callback.clone()) { + } + + template<class T> BasicSubscriber<T>::~BasicSubscriber() { + delete callback; + } + + template<class T> void BasicSubscriber<T>::update(const T& object) { + callback->invoke(object); + } +} + +#endif |