]> sigrok.org Git - pulseview.git/blame_incremental - pv/data/decoderstack.hpp
LogicSegment: Remove constructor requiring sigrok::Logic
[pulseview.git] / pv / data / decoderstack.hpp
... / ...
CommitLineData
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef PULSEVIEW_PV_DATA_DECODERSTACK_HPP
21#define PULSEVIEW_PV_DATA_DECODERSTACK_HPP
22
23#include "signaldata.hpp"
24
25#include <atomic>
26#include <condition_variable>
27#include <list>
28#include <map>
29#include <memory>
30#include <thread>
31
32#include <boost/optional.hpp>
33
34#include <QObject>
35#include <QString>
36
37#include <pv/data/decode/row.hpp>
38#include <pv/data/decode/rowdata.hpp>
39#include <pv/util.hpp>
40
41using std::atomic;
42using std::condition_variable;
43using std::list;
44using std::map;
45using std::mutex;
46using std::pair;
47using std::shared_ptr;
48using std::vector;
49
50struct srd_decoder;
51struct srd_decoder_annotation_row;
52struct srd_channel;
53struct srd_proto_data;
54struct srd_session;
55
56namespace DecoderStackTest {
57struct TwoDecoderStack;
58}
59
60namespace pv {
61
62class Session;
63
64namespace view {
65class LogicSignal;
66}
67
68namespace data {
69
70class LogicSegment;
71
72namespace decode {
73class Annotation;
74class Decoder;
75}
76
77class Logic;
78
79class DecoderStack : public QObject
80{
81 Q_OBJECT
82
83private:
84 static const double DecodeMargin;
85 static const double DecodeThreshold;
86 static const int64_t DecodeChunkLength;
87 static const unsigned int DecodeNotifyPeriod;
88
89public:
90 DecoderStack(pv::Session &session, const srd_decoder *const dec);
91
92 virtual ~DecoderStack();
93
94 const list< shared_ptr<decode::Decoder> >& stack() const;
95 void push(shared_ptr<decode::Decoder> decoder);
96 void remove(int index);
97
98 double samplerate() const;
99
100 const pv::util::Timestamp& start_time() const;
101
102 int64_t samples_decoded() const;
103
104 vector<decode::Row> get_visible_rows() const;
105
106 /**
107 * Extracts sorted annotations between two period into a vector.
108 */
109 void get_annotation_subset(
110 vector<pv::data::decode::Annotation> &dest,
111 const decode::Row &row, uint64_t start_sample,
112 uint64_t end_sample) const;
113
114 QString error_message();
115
116 void clear();
117
118 uint64_t max_sample_count() const;
119
120 void begin_decode();
121
122private:
123 boost::optional<int64_t> wait_for_data() const;
124
125 void decode_data(const int64_t abs_start_samplenum, const int64_t sample_count,
126 const unsigned int unit_size, srd_session *const session);
127
128 void decode_proc();
129
130 static void annotation_callback(srd_proto_data *pdata,
131 void *decoder);
132
133private Q_SLOTS:
134 void on_new_frame();
135
136 void on_data_received();
137
138 void on_frame_ended();
139
140Q_SIGNALS:
141 void new_decode_data();
142
143private:
144 pv::Session &session_;
145
146 pv::util::Timestamp start_time_;
147 double samplerate_;
148
149 /**
150 * This mutex prevents more than one thread from accessing
151 * libsigrokdecode concurrently.
152 * @todo A proper solution should be implemented to allow multiple
153 * decode operations in parallel.
154 */
155 static mutex global_srd_mutex_;
156
157 list< shared_ptr<decode::Decoder> > stack_;
158
159 shared_ptr<pv::data::LogicSegment> segment_;
160
161 mutable mutex input_mutex_;
162 mutable condition_variable input_cond_;
163 int64_t sample_count_;
164 bool frame_complete_;
165
166 mutable mutex output_mutex_;
167 int64_t samples_decoded_;
168
169 map<const decode::Row, decode::RowData> rows_;
170
171 map<pair<const srd_decoder*, int>, decode::Row> class_rows_;
172
173 QString error_message_;
174
175 std::thread decode_thread_;
176 atomic<bool> interrupt_;
177
178 friend struct DecoderStackTest::TwoDecoderStack;
179};
180
181} // namespace data
182} // namespace pv
183
184#endif // PULSEVIEW_PV_DATA_DECODERSTACK_HPP