summaryrefslogtreecommitdiff
path: root/include/mts/MTS_Component.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/mts/MTS_Component.h')
-rw-r--r--include/mts/MTS_Component.h84
1 files changed, 84 insertions, 0 deletions
diff --git a/include/mts/MTS_Component.h b/include/mts/MTS_Component.h
new file mode 100644
index 0000000..215add5
--- /dev/null
+++ b/include/mts/MTS_Component.h
@@ -0,0 +1,84 @@
+/*
+ * 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_Component.h
+ \brief A threaded sub-pub object
+ \date 28MAR12
+ \author Sean Godinez
+
+ A threaded subscriber-publisher object.
+ */
+
+#ifndef _MTS_COMPONENT_H_
+#define _MTS_COMPONENT_H_
+
+#include <mts/MTS_Thread.h>
+#include <mts/MTS_NonCopyable.h>
+#include <mts/MTS_SubscriberQueue.h>
+#include <mts/MTS_BasicPublisher.h>
+#include <mts/MTS_Stdint.h>
+#include <string>
+
+namespace MTS {
+
+ template<class S, class P> class Component: public Thread {
+
+ public:
+ virtual ~Component();
+
+ Subscriber<S>& getSubscriber();
+ Publisher<P>& getPublisher();
+
+ virtual void stop();
+
+ protected:
+ explicit Component(const std::string& sName, uint32_t iCapacity = UINT32_MAX, bool bManaged = true);
+
+ SubscriberQueue<S> m_oSubscriber;
+ BasicPublisher<P> m_oPublisher;
+
+ private:
+
+ };
+
+ template<class S, class P> Component<S, P>::Component(
+ const std::string& name, uint32_t capacity, bool managed)
+ : Thread(name, managed), m_oSubscriber(name, capacity) {
+ }
+
+ template<class S, class P> Component<S, P>::~Component() {
+ Component::stop();
+ }
+
+ template<class S, class P> Subscriber<S>& Component<S, P>::getSubscriber() {
+ return m_oSubscriber;
+ }
+
+ template<class S, class P> Publisher<P>& Component<S, P>::getPublisher() {
+ return m_oPublisher;
+ }
+
+ template<class S, class P> void Component<S, P>::stop() {
+ Thread::stop();
+ m_oSubscriber.clear();
+ }
+}
+
+#endif