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