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