summaryrefslogtreecommitdiff
path: root/include/mts/MTS_Component.h
blob: 215add5b79182c2ac016ac11fe4d308281699895 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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