forked from volkszaehler/vzlogger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeterMap.hpp
More file actions
119 lines (103 loc) · 3.26 KB
/
MeterMap.hpp
File metadata and controls
119 lines (103 loc) · 3.26 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/***********************************************************************/
/** @file MeterMap.hpp
*
* @author Kai Krueger
* @date 2012-03-13
* @email kai.krueger@itwm.fraunhofer.de
*
* (C) Fraunhofer ITWM
**/
/*---------------------------------------------------------------------*/
/**
* Protocol interface
*
* @package vzlogger
* @copyright Copyright (c) 2011, The volkszaehler.org project
* @license http://www.gnu.org/licenses/gpl.txt GNU Public License
* @author Steffen Vogel <info@steffenvogel.de>
*/
/*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _MeterMap_hpp_
#define _MeterMap_hpp_
#include <pthread.h>
#include <vector>
#include <Channel.hpp>
#include <Meter.hpp>
#include <Options.hpp>
#include <common.h>
/**
The MeterMap is intend to keep the list of all configured channel for a given meter.
*/
class MeterMap {
public:
typedef vz::shared_ptr<MeterMap> Ptr;
typedef std::vector<Channel::Ptr>::iterator iterator;
typedef std::vector<Channel::Ptr>::const_iterator const_iterator;
MeterMap(const std::list<Option> &options) : _meter(new Meter(options)) {
_thread_running = false;
}
MeterMap(Meter *m) : _meter(m), _thread_running(false){};
~MeterMap(){};
Meter::Ptr meter() { return _meter; }
/**
If the meter is enabled, start the meter and all its channels.
*/
void start();
/**
* cancel all channels for this meter.
*/
void cancel();
/**
* send device-registration for each channel
*/
void registration();
/**
* Accessor to the channel list
*/
inline void push_back(Channel::Ptr channel) { _channels.push_back(channel); }
inline iterator begin() { return _channels.begin(); }
inline iterator end() { return _channels.end(); }
inline size_t size() { return _channels.size(); }
bool running() const { return _thread_running; }
private:
Meter::Ptr _meter;
std::vector<Channel::Ptr> _channels;
bool _thread_running; // flag if thread is started
pthread_t _thread; // Thread data for meter (reading)
};
/**
This container is intend to keep the list of all configured meters.
*/
class MapContainer {
public:
typedef vz::shared_ptr<MapContainer> Ptr;
typedef std::vector<MeterMap>::iterator iterator;
typedef std::vector<MeterMap>::const_iterator const_iterator;
MapContainer(){};
~MapContainer(){};
/**
* Accessor to the MeterMap (meter and its channels) list
*/
inline void push_back(const MeterMap &map) { _mappings.push_back(map); }
inline iterator begin() { return _mappings.begin(); }
inline iterator end() { return _mappings.end(); }
inline size_t size() const { return _mappings.size(); }
private:
std::vector<MeterMap> _mappings;
};
#endif /* _MeterMap_hpp_ */