]>
Commit | Line | Data |
---|---|---|
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 | ||
bee54d9e | 26 | #include <atomic> |
2802b9ec | 27 | #include <memory> |
3b68d03d | 28 | #include <mutex> |
aca9aa83 | 29 | #include <thread> |
27ff2925 | 30 | #include <deque> |
7d29656f | 31 | |
8c339741 SA |
32 | #include <QObject> |
33 | ||
bee54d9e | 34 | using std::atomic; |
6f925ba9 | 35 | using std::recursive_mutex; |
27ff2925 | 36 | using std::deque; |
6f925ba9 | 37 | |
26a883ed SA |
38 | namespace SegmentTest { |
39 | struct SmallSize8Single; | |
40 | struct MediumSize8Single; | |
41 | struct MaxSize8Single; | |
42 | struct MediumSize24Single; | |
43 | struct MediumSize32Single; | |
44 | struct MaxSize32Single; | |
45 | struct MediumSize32Multi; | |
46 | struct MaxSize32Multi; | |
207ae8f6 | 47 | struct MaxSize32MultiAtOnce; |
26a883ed | 48 | struct MaxSize32MultiIterated; |
870ea3db | 49 | } // namespace SegmentTest |
26a883ed | 50 | |
51e77110 | 51 | namespace pv { |
1b1ec774 | 52 | namespace data { |
51e77110 | 53 | |
26a883ed SA |
54 | typedef struct { |
55 | uint64_t sample_index, chunk_num, chunk_offs; | |
56 | uint8_t* chunk; | |
65c92359 | 57 | } SegmentDataIterator; |
26a883ed | 58 | |
8c339741 | 59 | class Segment : public QObject |
28a4c9c5 | 60 | { |
8c339741 SA |
61 | Q_OBJECT |
62 | ||
26a883ed | 63 | private: |
dd3f9a41 | 64 | static const uint64_t MaxChunkSize; |
26a883ed | 65 | |
28a4c9c5 | 66 | public: |
85a70280 | 67 | Segment(uint32_t segment_id, uint64_t samplerate, unsigned int unit_size); |
f556bc6a | 68 | |
f3d66e52 | 69 | virtual ~Segment(); |
28a4c9c5 | 70 | |
e7c6e898 | 71 | uint64_t get_sample_count() const; |
28a4c9c5 | 72 | |
60d9b99a | 73 | const pv::util::Timestamp& start_time() const; |
7f4038d6 | 74 | |
ff008de6 JH |
75 | double samplerate() const; |
76 | void set_samplerate(double samplerate); | |
77 | ||
5ad3b48b | 78 | unsigned int unit_size() const; |
6fd14a32 | 79 | |
85a70280 SA |
80 | uint32_t segment_id() const; |
81 | ||
558ad6ce SA |
82 | void set_complete(); |
83 | bool is_complete() const; | |
84 | ||
5e6967cb SA |
85 | void free_unused_memory(); |
86 | ||
bee54d9e SA |
87 | Q_SIGNALS: |
88 | void completed(); | |
89 | ||
28a4c9c5 | 90 | protected: |
26a883ed SA |
91 | void append_single_sample(void *data); |
92 | void append_samples(void *data, uint64_t samples); | |
27ff2925 | 93 | const uint8_t* get_raw_sample(uint64_t sample_num) const; |
b82243f7 | 94 | void get_raw_samples(uint64_t start, uint64_t count, uint8_t *dest) const; |
26a883ed | 95 | |
65c92359 SA |
96 | SegmentDataIterator* begin_sample_iteration(uint64_t start); |
97 | void continue_sample_iteration(SegmentDataIterator* it, uint64_t increase); | |
98 | void end_sample_iteration(SegmentDataIterator* it); | |
99 | uint8_t* get_iterator_value(SegmentDataIterator* it); | |
50e56db0 | 100 | uint64_t get_iterator_valid_length(SegmentDataIterator* it); |
f556bc6a | 101 | |
85a70280 | 102 | uint32_t segment_id_; |
6f925ba9 | 103 | mutable recursive_mutex mutex_; |
27ff2925 | 104 | deque<uint8_t*> data_chunks_; |
26a883ed SA |
105 | uint8_t* current_chunk_; |
106 | uint64_t used_samples_, unused_samples_; | |
bee54d9e | 107 | atomic<uint64_t> sample_count_; |
60d9b99a | 108 | pv::util::Timestamp start_time_; |
ff008de6 | 109 | double samplerate_; |
26a883ed | 110 | uint64_t chunk_size_; |
8dbbc7f0 | 111 | unsigned int unit_size_; |
c70e3464 SA |
112 | int iterator_count_; |
113 | bool mem_optimization_requested_; | |
558ad6ce | 114 | bool is_complete_; |
26a883ed SA |
115 | |
116 | friend struct SegmentTest::SmallSize8Single; | |
117 | friend struct SegmentTest::MediumSize8Single; | |
118 | friend struct SegmentTest::MaxSize8Single; | |
119 | friend struct SegmentTest::MediumSize24Single; | |
120 | friend struct SegmentTest::MediumSize32Single; | |
121 | friend struct SegmentTest::MaxSize32Single; | |
122 | friend struct SegmentTest::MediumSize32Multi; | |
123 | friend struct SegmentTest::MaxSize32Multi; | |
207ae8f6 | 124 | friend struct SegmentTest::MaxSize32MultiAtOnce; |
26a883ed | 125 | friend struct SegmentTest::MaxSize32MultiIterated; |
28a4c9c5 | 126 | }; |
51e77110 | 127 | |
1b1ec774 | 128 | } // namespace data |
51e77110 | 129 | } // namespace pv |
640d091b | 130 | |
720f4762 SA |
131 | typedef std::shared_ptr<pv::data::Segment> SharedPtrToSegment; |
132 | ||
133 | Q_DECLARE_METATYPE(SharedPtrToSegment); | |
1f3033cb | 134 | |
a38268f0 | 135 | #endif // PULSEVIEW_PV_DATA_SEGMENT_HPP |