]> sigrok.org Git - pulseview.git/blame - pv/data/decoderstack.h
Implemented threaded decode
[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
7491a29f 26#include <list>
708c5523 27
f70d8673 28#include <boost/optional.hpp>
708c5523 29#include <boost/shared_ptr.hpp>
640d69ce 30#include <boost/thread.hpp>
708c5523 31
e0fc5810 32#include <QObject>
b6b267bb 33#include <QString>
e0fc5810 34
f9101a91
JH
35#include <pv/data/decode/row.h>
36#include <pv/data/decode/rowdata.h>
37
119aff65 38struct srd_decoder;
f9101a91 39struct srd_decoder_annotation_row;
708c5523 40struct srd_probe;
b213ef09 41struct srd_proto_data;
f67d9e9b 42struct srd_session;
b6b267bb 43
6e89374a
JH
44namespace DecoderStackTest {
45class TwoDecoderStack;
b6b267bb 46}
119aff65
JH
47
48namespace pv {
708c5523 49
bdc5c3b0
JH
50class SigSession;
51
708c5523 52namespace view {
3045c869 53class LogicSignal;
708c5523
JH
54}
55
119aff65
JH
56namespace data {
57
f67d9e9b
JH
58class LogicSnapshot;
59
7491a29f 60namespace decode {
06e810f2 61class Annotation;
7491a29f
JH
62class Decoder;
63}
64
640d69ce
JH
65class Logic;
66
6e89374a 67class DecoderStack : public QObject, public SignalData
119aff65 68{
e0fc5810
JH
69 Q_OBJECT
70
71private:
72 static const double DecodeMargin;
73 static const double DecodeThreshold;
74 static const int64_t DecodeChunkLength;
75
119aff65 76public:
bdc5c3b0
JH
77 DecoderStack(pv::SigSession &_session,
78 const srd_decoder *const decoder);
119aff65 79
6e89374a 80 virtual ~DecoderStack();
640d69ce 81
7491a29f
JH
82 const std::list< boost::shared_ptr<decode::Decoder> >& stack() const;
83 void push(boost::shared_ptr<decode::Decoder> decoder);
613d097c 84 void remove(int index);
119aff65 85
5dfeb70f
JH
86 int64_t samples_decoded() const;
87
dd048a7e 88 std::vector<decode::Row> get_visible_rows() const;
f9101a91 89
92421299
JH
90 /**
91 * Extracts sorted annotations between two period into a vector.
92 */
93 void get_annotation_subset(
94 std::vector<pv::data::decode::Annotation> &dest,
f9101a91
JH
95 const decode::Row &row, uint64_t start_sample,
96 uint64_t end_sample) const;
640d69ce 97
b6b267bb
JH
98 QString error_message();
99
caabb84c 100 void clear();
119aff65 101
a007f5ad
JH
102 uint64_t get_max_sample_count() const;
103
e0fc5810
JH
104 void begin_decode();
105
7491a29f 106private:
f70d8673
JH
107 boost::optional<int64_t> wait_for_data() const;
108
109 void decode_data(const int64_t sample_count,
110 const unsigned int unit_size, srd_session *const session);
f67d9e9b 111
640d69ce
JH
112 void decode_proc(boost::shared_ptr<data::Logic> data);
113
e0fc5810
JH
114 static void annotation_callback(srd_proto_data *pdata,
115 void *decoder);
116
82f50b10
JH
117private slots:
118 void on_new_frame();
119
f70d8673
JH
120 void on_data_received();
121
122 void on_frame_ended();
123
9cef9567
JH
124signals:
125 void new_decode_data();
126
119aff65 127private:
bdc5c3b0 128 pv::SigSession &_session;
fe89c961
JH
129
130 /**
131 * This mutex prevents more than one decode operation occuring
132 * concurrently.
133 * @todo A proper solution should be implemented to allow multiple
134 * decode operations.
135 */
136 static boost::mutex _global_decode_mutex;
137
7491a29f 138 std::list< boost::shared_ptr<decode::Decoder> > _stack;
e332f6d3 139
f70d8673
JH
140 boost::shared_ptr<pv::data::LogicSnapshot> _snapshot;
141
142 mutable boost::mutex _input_mutex;
143 mutable boost::condition_variable _input_cond;
144 int64_t _sample_count;
145 bool _frame_complete;
146
28b9cc08 147 mutable boost::mutex _output_mutex;
5dfeb70f 148 int64_t _samples_decoded;
92421299 149
f9101a91
JH
150 std::map<const decode::Row, decode::RowData> _rows;
151
152 std::map<std::pair<const srd_decoder*, int>, decode::Row> _class_rows;
92421299 153
b6b267bb 154 QString _error_message;
e0fc5810 155
640d69ce 156 boost::thread _decode_thread;
b6b267bb 157
6e89374a 158 friend class DecoderStackTest::TwoDecoderStack;
119aff65
JH
159};
160
161} // namespace data
162} // namespace pv
163
6e89374a 164#endif // PULSEVIEW_PV_DATA_DECODERSTACK_H