]> sigrok.org Git - pulseview.git/blame - pv/data/decoderstack.h
Make member variable underscores a suffix instead of a prefix
[pulseview.git] / pv / data / decoderstack.h
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
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
6e89374a
JH
21#ifndef PULSEVIEW_PV_DATA_DECODERSTACK_H
22#define PULSEVIEW_PV_DATA_DECODERSTACK_H
119aff65
JH
23
24#include "signaldata.h"
25
3b68d03d
JH
26#include <atomic>
27#include <condition_variable>
7491a29f 28#include <list>
3b68d03d 29#include <map>
f9abf97e 30#include <memory>
3b68d03d 31#include <thread>
708c5523 32
f70d8673 33#include <boost/optional.hpp>
708c5523 34
e0fc5810 35#include <QObject>
b6b267bb 36#include <QString>
e0fc5810 37
f9101a91
JH
38#include <pv/data/decode/row.h>
39#include <pv/data/decode/rowdata.h>
40
119aff65 41struct srd_decoder;
f9101a91 42struct srd_decoder_annotation_row;
8bd26d8b 43struct srd_channel;
b213ef09 44struct srd_proto_data;
f67d9e9b 45struct srd_session;
b6b267bb 46
6e89374a 47namespace DecoderStackTest {
9e587572 48struct TwoDecoderStack;
b6b267bb 49}
119aff65
JH
50
51namespace pv {
708c5523 52
bdc5c3b0
JH
53class SigSession;
54
708c5523 55namespace view {
3045c869 56class LogicSignal;
708c5523
JH
57}
58
119aff65
JH
59namespace data {
60
f67d9e9b
JH
61class LogicSnapshot;
62
7491a29f 63namespace decode {
06e810f2 64class Annotation;
7491a29f
JH
65class Decoder;
66}
67
640d69ce
JH
68class Logic;
69
6e89374a 70class DecoderStack : public QObject, public SignalData
119aff65 71{
e0fc5810
JH
72 Q_OBJECT
73
74private:
75 static const double DecodeMargin;
76 static const double DecodeThreshold;
77 static const int64_t DecodeChunkLength;
4c581c79 78 static const unsigned int DecodeNotifyPeriod;
e0fc5810 79
119aff65 80public:
8dbbc7f0 81 DecoderStack(pv::SigSession &session_,
bdc5c3b0 82 const srd_decoder *const decoder);
119aff65 83
6e89374a 84 virtual ~DecoderStack();
640d69ce 85
f9abf97e
JH
86 const std::list< std::shared_ptr<decode::Decoder> >& stack() const;
87 void push(std::shared_ptr<decode::Decoder> decoder);
613d097c 88 void remove(int index);
119aff65 89
5dfeb70f
JH
90 int64_t samples_decoded() const;
91
dd048a7e 92 std::vector<decode::Row> get_visible_rows() const;
f9101a91 93
92421299
JH
94 /**
95 * Extracts sorted annotations between two period into a vector.
96 */
97 void get_annotation_subset(
98 std::vector<pv::data::decode::Annotation> &dest,
f9101a91
JH
99 const decode::Row &row, uint64_t start_sample,
100 uint64_t end_sample) const;
640d69ce 101
b6b267bb
JH
102 QString error_message();
103
caabb84c 104 void clear();
119aff65 105
a007f5ad
JH
106 uint64_t get_max_sample_count() const;
107
e0fc5810
JH
108 void begin_decode();
109
7491a29f 110private:
f70d8673
JH
111 boost::optional<int64_t> wait_for_data() const;
112
113 void decode_data(const int64_t sample_count,
114 const unsigned int unit_size, srd_session *const session);
f67d9e9b 115
c1b2865e 116 void decode_proc();
640d69ce 117
e0fc5810
JH
118 static void annotation_callback(srd_proto_data *pdata,
119 void *decoder);
120
e9213170 121private Q_SLOTS:
82f50b10
JH
122 void on_new_frame();
123
f70d8673
JH
124 void on_data_received();
125
126 void on_frame_ended();
127
e9213170 128Q_SIGNALS:
9cef9567
JH
129 void new_decode_data();
130
119aff65 131private:
8dbbc7f0 132 pv::SigSession &session_;
fe89c961
JH
133
134 /**
135 * This mutex prevents more than one decode operation occuring
136 * concurrently.
137 * @todo A proper solution should be implemented to allow multiple
138 * decode operations.
139 */
8dbbc7f0 140 static std::mutex global_decode_mutex_;
fe89c961 141
8dbbc7f0 142 std::list< std::shared_ptr<decode::Decoder> > stack_;
e332f6d3 143
8dbbc7f0 144 std::shared_ptr<pv::data::LogicSnapshot> snapshot_;
f70d8673 145
8dbbc7f0
JH
146 mutable std::mutex input_mutex_;
147 mutable std::condition_variable input_cond_;
148 int64_t sample_count_;
149 bool frame_complete_;
f70d8673 150
8dbbc7f0
JH
151 mutable std::mutex output_mutex_;
152 int64_t samples_decoded_;
92421299 153
8dbbc7f0 154 std::map<const decode::Row, decode::RowData> rows_;
f9101a91 155
8dbbc7f0 156 std::map<std::pair<const srd_decoder*, int>, decode::Row> class_rows_;
92421299 157
8dbbc7f0 158 QString error_message_;
e0fc5810 159
8dbbc7f0
JH
160 std::thread decode_thread_;
161 std::atomic<bool> interrupt_;
b6b267bb 162
9e587572 163 friend struct DecoderStackTest::TwoDecoderStack;
119aff65
JH
164};
165
166} // namespace data
167} // namespace pv
168
6e89374a 169#endif // PULSEVIEW_PV_DATA_DECODERSTACK_H