]> sigrok.org Git - pulseview.git/blame - pv/data/decoderstack.h
Replaced boost::shared_ptr with std::shared_ptr
[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>
f9abf97e 27#include <memory>
708c5523 28
f70d8673 29#include <boost/optional.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;
8bd26d8b 40struct srd_channel;
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;
4c581c79 75 static const unsigned int DecodeNotifyPeriod;
e0fc5810 76
119aff65 77public:
bdc5c3b0
JH
78 DecoderStack(pv::SigSession &_session,
79 const srd_decoder *const decoder);
119aff65 80
6e89374a 81 virtual ~DecoderStack();
640d69ce 82
f9abf97e
JH
83 const std::list< std::shared_ptr<decode::Decoder> >& stack() const;
84 void push(std::shared_ptr<decode::Decoder> decoder);
613d097c 85 void remove(int index);
119aff65 86
5dfeb70f
JH
87 int64_t samples_decoded() const;
88
dd048a7e 89 std::vector<decode::Row> get_visible_rows() const;
f9101a91 90
92421299
JH
91 /**
92 * Extracts sorted annotations between two period into a vector.
93 */
94 void get_annotation_subset(
95 std::vector<pv::data::decode::Annotation> &dest,
f9101a91
JH
96 const decode::Row &row, uint64_t start_sample,
97 uint64_t end_sample) const;
640d69ce 98
b6b267bb
JH
99 QString error_message();
100
caabb84c 101 void clear();
119aff65 102
a007f5ad
JH
103 uint64_t get_max_sample_count() const;
104
e0fc5810
JH
105 void begin_decode();
106
7491a29f 107private:
f70d8673
JH
108 boost::optional<int64_t> wait_for_data() const;
109
110 void decode_data(const int64_t sample_count,
111 const unsigned int unit_size, srd_session *const session);
f67d9e9b 112
c1b2865e 113 void decode_proc();
640d69ce 114
e0fc5810
JH
115 static void annotation_callback(srd_proto_data *pdata,
116 void *decoder);
117
82f50b10
JH
118private slots:
119 void on_new_frame();
120
f70d8673
JH
121 void on_data_received();
122
123 void on_frame_ended();
124
9cef9567
JH
125signals:
126 void new_decode_data();
127
119aff65 128private:
bdc5c3b0 129 pv::SigSession &_session;
fe89c961
JH
130
131 /**
132 * This mutex prevents more than one decode operation occuring
133 * concurrently.
134 * @todo A proper solution should be implemented to allow multiple
135 * decode operations.
136 */
137 static boost::mutex _global_decode_mutex;
138
f9abf97e 139 std::list< std::shared_ptr<decode::Decoder> > _stack;
e332f6d3 140
f9abf97e 141 std::shared_ptr<pv::data::LogicSnapshot> _snapshot;
f70d8673
JH
142
143 mutable boost::mutex _input_mutex;
144 mutable boost::condition_variable _input_cond;
145 int64_t _sample_count;
146 bool _frame_complete;
147
28b9cc08 148 mutable boost::mutex _output_mutex;
5dfeb70f 149 int64_t _samples_decoded;
92421299 150
f9101a91
JH
151 std::map<const decode::Row, decode::RowData> _rows;
152
153 std::map<std::pair<const srd_decoder*, int>, decode::Row> _class_rows;
92421299 154
b6b267bb 155 QString _error_message;
e0fc5810 156
640d69ce 157 boost::thread _decode_thread;
b6b267bb 158
6e89374a 159 friend class DecoderStackTest::TwoDecoderStack;
119aff65
JH
160};
161
162} // namespace data
163} // namespace pv
164
6e89374a 165#endif // PULSEVIEW_PV_DATA_DECODERSTACK_H