]> sigrok.org Git - pulseview.git/blame - pv/data/segment.hpp
Rework signals for modularity
[pulseview.git] / pv / data / segment.hpp
CommitLineData
28a4c9c5 1/*
b3f22de0 2 * This file is part of the PulseView project.
28a4c9c5 3 *
26a883ed 4 * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
28a4c9c5
JH
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
efdec55a 18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28a4c9c5
JH
19 */
20
a38268f0
SA
21#ifndef PULSEVIEW_PV_DATA_SEGMENT_HPP
22#define PULSEVIEW_PV_DATA_SEGMENT_HPP
640d091b 23
60d9b99a
JS
24#include "pv/util.hpp"
25
3b68d03d 26#include <mutex>
aca9aa83 27#include <thread>
c82c7e4e 28#include <vector>
7d29656f 29
8c339741
SA
30#include <QObject>
31
6f925ba9
UH
32using std::recursive_mutex;
33using std::vector;
34
26a883ed
SA
35namespace SegmentTest {
36struct SmallSize8Single;
37struct MediumSize8Single;
38struct MaxSize8Single;
39struct MediumSize24Single;
40struct MediumSize32Single;
41struct MaxSize32Single;
42struct MediumSize32Multi;
43struct MaxSize32Multi;
207ae8f6 44struct MaxSize32MultiAtOnce;
26a883ed 45struct MaxSize32MultiIterated;
870ea3db 46} // namespace SegmentTest
26a883ed 47
51e77110 48namespace pv {
1b1ec774 49namespace data {
51e77110 50
26a883ed
SA
51typedef struct {
52 uint64_t sample_index, chunk_num, chunk_offs;
53 uint8_t* chunk;
65c92359 54} SegmentDataIterator;
26a883ed 55
8c339741 56class Segment : public QObject
28a4c9c5 57{
8c339741
SA
58 Q_OBJECT
59
26a883ed 60private:
dd3f9a41 61 static const uint64_t MaxChunkSize;
26a883ed 62
28a4c9c5 63public:
85a70280 64 Segment(uint32_t segment_id, uint64_t samplerate, unsigned int unit_size);
f556bc6a 65
f3d66e52 66 virtual ~Segment();
28a4c9c5 67
e7c6e898 68 uint64_t get_sample_count() const;
28a4c9c5 69
60d9b99a 70 const pv::util::Timestamp& start_time() const;
7f4038d6 71
ff008de6
JH
72 double samplerate() const;
73 void set_samplerate(double samplerate);
74
5ad3b48b 75 unsigned int unit_size() const;
6fd14a32 76
85a70280
SA
77 uint32_t segment_id() const;
78
558ad6ce
SA
79 void set_complete();
80 bool is_complete() const;
81
5e6967cb
SA
82 void free_unused_memory();
83
28a4c9c5 84protected:
26a883ed
SA
85 void append_single_sample(void *data);
86 void append_samples(void *data, uint64_t samples);
b82243f7 87 void get_raw_samples(uint64_t start, uint64_t count, uint8_t *dest) const;
26a883ed 88
65c92359
SA
89 SegmentDataIterator* begin_sample_iteration(uint64_t start);
90 void continue_sample_iteration(SegmentDataIterator* it, uint64_t increase);
91 void end_sample_iteration(SegmentDataIterator* it);
92 uint8_t* get_iterator_value(SegmentDataIterator* it);
50e56db0 93 uint64_t get_iterator_valid_length(SegmentDataIterator* it);
f556bc6a 94
85a70280 95 uint32_t segment_id_;
6f925ba9
UH
96 mutable recursive_mutex mutex_;
97 vector<uint8_t*> data_chunks_;
26a883ed
SA
98 uint8_t* current_chunk_;
99 uint64_t used_samples_, unused_samples_;
8dbbc7f0 100 uint64_t sample_count_;
60d9b99a 101 pv::util::Timestamp start_time_;
ff008de6 102 double samplerate_;
26a883ed 103 uint64_t chunk_size_;
8dbbc7f0 104 unsigned int unit_size_;
c70e3464
SA
105 int iterator_count_;
106 bool mem_optimization_requested_;
558ad6ce 107 bool is_complete_;
26a883ed
SA
108
109 friend struct SegmentTest::SmallSize8Single;
110 friend struct SegmentTest::MediumSize8Single;
111 friend struct SegmentTest::MaxSize8Single;
112 friend struct SegmentTest::MediumSize24Single;
113 friend struct SegmentTest::MediumSize32Single;
114 friend struct SegmentTest::MaxSize32Single;
115 friend struct SegmentTest::MediumSize32Multi;
116 friend struct SegmentTest::MaxSize32Multi;
207ae8f6 117 friend struct SegmentTest::MaxSize32MultiAtOnce;
26a883ed 118 friend struct SegmentTest::MaxSize32MultiIterated;
28a4c9c5 119};
51e77110 120
1b1ec774 121} // namespace data
51e77110 122} // namespace pv
640d091b 123
1f3033cb
SA
124Q_DECLARE_METATYPE(pv::data::Segment);
125
a38268f0 126#endif // PULSEVIEW_PV_DATA_SEGMENT_HPP