]> sigrok.org Git - pulseview.git/blob - pv/data/segment.hpp
Don't use std:: in the code directly (where possible).
[pulseview.git] / pv / data / segment.hpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
5  * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #ifndef PULSEVIEW_PV_DATA_SEGMENT_HPP
22 #define PULSEVIEW_PV_DATA_SEGMENT_HPP
23
24 #include "pv/util.hpp"
25
26 #include <thread>
27 #include <mutex>
28 #include <vector>
29
30 using std::recursive_mutex;
31 using std::vector;
32
33 namespace SegmentTest {
34 struct SmallSize8Single;
35 struct MediumSize8Single;
36 struct MaxSize8Single;
37 struct MediumSize24Single;
38 struct MediumSize32Single;
39 struct MaxSize32Single;
40 struct MediumSize32Multi;
41 struct MaxSize32Multi;
42 struct MaxSize32MultiIterated;
43 }
44
45 namespace pv {
46 namespace data {
47
48 typedef struct {
49         uint64_t sample_index, chunk_num, chunk_offs;
50         uint8_t* chunk;
51         uint8_t* value;
52 } SegmentRawDataIterator;
53
54 class Segment
55 {
56 private:
57         static const uint64_t MaxChunkSize;
58
59 public:
60         Segment(uint64_t samplerate, unsigned int unit_size);
61
62         virtual ~Segment();
63
64         uint64_t get_sample_count() const;
65
66         const pv::util::Timestamp& start_time() const;
67
68         double samplerate() const;
69         void set_samplerate(double samplerate);
70
71         unsigned int unit_size() const;
72
73         void free_unused_memory();
74
75 protected:
76         void append_single_sample(void *data);
77         void append_samples(void *data, uint64_t samples);
78         uint8_t* get_raw_samples(uint64_t start, uint64_t count) const;
79
80         SegmentRawDataIterator* begin_raw_sample_iteration(uint64_t start);
81         void continue_raw_sample_iteration(SegmentRawDataIterator* it, uint64_t increase);
82         void end_raw_sample_iteration(SegmentRawDataIterator* it);
83
84         mutable recursive_mutex mutex_;
85         vector<uint8_t*> data_chunks_;
86         uint8_t* current_chunk_;
87         uint64_t used_samples_, unused_samples_;
88         uint64_t sample_count_;
89         pv::util::Timestamp start_time_;
90         double samplerate_;
91         uint64_t chunk_size_;
92         unsigned int unit_size_;
93         int iterator_count_;
94         bool mem_optimization_requested_;
95
96         friend struct SegmentTest::SmallSize8Single;
97         friend struct SegmentTest::MediumSize8Single;
98         friend struct SegmentTest::MaxSize8Single;
99         friend struct SegmentTest::MediumSize24Single;
100         friend struct SegmentTest::MediumSize32Single;
101         friend struct SegmentTest::MaxSize32Single;
102         friend struct SegmentTest::MediumSize32Multi;
103         friend struct SegmentTest::MaxSize32Multi;
104         friend struct SegmentTest::MaxSize32MultiIterated;
105 };
106
107 } // namespace data
108 } // namespace pv
109
110 #endif // PULSEVIEW_PV_DATA_SEGMENT_HPP