]> sigrok.org Git - pulseview.git/blame - pv/data/decoderstack.hpp
LogicSegment: Make constructor and append_payload() more generic
[pulseview.git] / pv / data / decoderstack.hpp
CommitLineData
119aff65
JH
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
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
119aff65
JH
18 */
19
7a01bd36
JH
20#ifndef PULSEVIEW_PV_DATA_DECODERSTACK_HPP
21#define PULSEVIEW_PV_DATA_DECODERSTACK_HPP
119aff65 22
2acdb232 23#include "signaldata.hpp"
119aff65 24
3b68d03d
JH
25#include <atomic>
26#include <condition_variable>
7491a29f 27#include <list>
3b68d03d 28#include <map>
f9abf97e 29#include <memory>
3b68d03d 30#include <thread>
708c5523 31
f70d8673 32#include <boost/optional.hpp>
708c5523 33
e0fc5810 34#include <QObject>
b6b267bb 35#include <QString>
e0fc5810 36
2acdb232
JH
37#include <pv/data/decode/row.hpp>
38#include <pv/data/decode/rowdata.hpp>
60d9b99a 39#include <pv/util.hpp>
f9101a91 40
6f925ba9
UH
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
119aff65 50struct srd_decoder;
f9101a91 51struct srd_decoder_annotation_row;
8bd26d8b 52struct srd_channel;
b213ef09 53struct srd_proto_data;
f67d9e9b 54struct srd_session;
b6b267bb 55
6e89374a 56namespace DecoderStackTest {
9e587572 57struct TwoDecoderStack;
b6b267bb 58}
119aff65
JH
59
60namespace pv {
708c5523 61
2b81ae46 62class Session;
bdc5c3b0 63
708c5523 64namespace view {
3045c869 65class LogicSignal;
708c5523
JH
66}
67
119aff65
JH
68namespace data {
69
f3d66e52 70class LogicSegment;
f67d9e9b 71
7491a29f 72namespace decode {
06e810f2 73class Annotation;
7491a29f
JH
74class Decoder;
75}
76
640d69ce
JH
77class Logic;
78
f054289f 79class DecoderStack : public QObject
119aff65 80{
e0fc5810
JH
81 Q_OBJECT
82
83private:
84 static const double DecodeMargin;
85 static const double DecodeThreshold;
86 static const int64_t DecodeChunkLength;
4c581c79 87 static const unsigned int DecodeNotifyPeriod;
e0fc5810 88
119aff65 89public:
520362f8 90 DecoderStack(pv::Session &session, const srd_decoder *const dec);
119aff65 91
6e89374a 92 virtual ~DecoderStack();
640d69ce 93
6f925ba9
UH
94 const list< shared_ptr<decode::Decoder> >& stack() const;
95 void push(shared_ptr<decode::Decoder> decoder);
613d097c 96 void remove(int index);
119aff65 97
f054289f
JH
98 double samplerate() const;
99
60d9b99a 100 const pv::util::Timestamp& start_time() const;
f054289f 101
5dfeb70f
JH
102 int64_t samples_decoded() const;
103
6f925ba9 104 vector<decode::Row> get_visible_rows() const;
f9101a91 105
92421299
JH
106 /**
107 * Extracts sorted annotations between two period into a vector.
108 */
109 void get_annotation_subset(
6f925ba9 110 vector<pv::data::decode::Annotation> &dest,
f9101a91
JH
111 const decode::Row &row, uint64_t start_sample,
112 uint64_t end_sample) const;
640d69ce 113
b6b267bb
JH
114 QString error_message();
115
caabb84c 116 void clear();
119aff65 117
e45b13b5 118 uint64_t max_sample_count() const;
a007f5ad 119
e0fc5810
JH
120 void begin_decode();
121
7491a29f 122private:
f70d8673
JH
123 boost::optional<int64_t> wait_for_data() const;
124
e8bb7c69 125 void decode_data(const int64_t abs_start_samplenum, const int64_t sample_count,
f70d8673 126 const unsigned int unit_size, srd_session *const session);
f67d9e9b 127
c1b2865e 128 void decode_proc();
640d69ce 129
e0fc5810
JH
130 static void annotation_callback(srd_proto_data *pdata,
131 void *decoder);
132
e9213170 133private Q_SLOTS:
82f50b10
JH
134 void on_new_frame();
135
f70d8673
JH
136 void on_data_received();
137
138 void on_frame_ended();
139
e9213170 140Q_SIGNALS:
9cef9567
JH
141 void new_decode_data();
142
119aff65 143private:
2b81ae46 144 pv::Session &session_;
fe89c961 145
60d9b99a 146 pv::util::Timestamp start_time_;
f054289f
JH
147 double samplerate_;
148
fe89c961 149 /**
a1a3656b
SA
150 * This mutex prevents more than one thread from accessing
151 * libsigrokdecode concurrently.
fe89c961 152 * @todo A proper solution should be implemented to allow multiple
a1a3656b 153 * decode operations in parallel.
fe89c961 154 */
6f925ba9 155 static mutex global_srd_mutex_;
fe89c961 156
6f925ba9 157 list< shared_ptr<decode::Decoder> > stack_;
e332f6d3 158
6f925ba9 159 shared_ptr<pv::data::LogicSegment> segment_;
f70d8673 160
6f925ba9
UH
161 mutable mutex input_mutex_;
162 mutable condition_variable input_cond_;
8dbbc7f0
JH
163 int64_t sample_count_;
164 bool frame_complete_;
f70d8673 165
6f925ba9 166 mutable mutex output_mutex_;
8dbbc7f0 167 int64_t samples_decoded_;
92421299 168
6f925ba9 169 map<const decode::Row, decode::RowData> rows_;
f9101a91 170
6f925ba9 171 map<pair<const srd_decoder*, int>, decode::Row> class_rows_;
92421299 172
8dbbc7f0 173 QString error_message_;
e0fc5810 174
8dbbc7f0 175 std::thread decode_thread_;
6f925ba9 176 atomic<bool> interrupt_;
b6b267bb 177
9e587572 178 friend struct DecoderStackTest::TwoDecoderStack;
119aff65
JH
179};
180
181} // namespace data
182} // namespace pv
183
7a01bd36 184#endif // PULSEVIEW_PV_DATA_DECODERSTACK_HPP