]>
Commit | Line | Data |
---|---|---|
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 | ||
21 | #ifndef PULSEVIEW_PV_DATA_DECODERSTACK_H | |
22 | #define PULSEVIEW_PV_DATA_DECODERSTACK_H | |
23 | ||
24 | #include "signaldata.h" | |
25 | ||
26 | #include <atomic> | |
27 | #include <condition_variable> | |
28 | #include <list> | |
29 | #include <map> | |
30 | #include <memory> | |
31 | #include <thread> | |
32 | ||
33 | #include <boost/optional.hpp> | |
34 | ||
35 | #include <QObject> | |
36 | #include <QString> | |
37 | ||
38 | #include <pv/data/decode/row.h> | |
39 | #include <pv/data/decode/rowdata.h> | |
40 | ||
41 | struct srd_decoder; | |
42 | struct srd_decoder_annotation_row; | |
43 | struct srd_channel; | |
44 | struct srd_proto_data; | |
45 | struct srd_session; | |
46 | ||
47 | namespace DecoderStackTest { | |
48 | struct TwoDecoderStack; | |
49 | } | |
50 | ||
51 | namespace pv { | |
52 | ||
53 | class SigSession; | |
54 | ||
55 | namespace view { | |
56 | class LogicSignal; | |
57 | } | |
58 | ||
59 | namespace data { | |
60 | ||
61 | class LogicSnapshot; | |
62 | ||
63 | namespace decode { | |
64 | class Annotation; | |
65 | class Decoder; | |
66 | } | |
67 | ||
68 | class Logic; | |
69 | ||
70 | class DecoderStack : public QObject, public SignalData | |
71 | { | |
72 | Q_OBJECT | |
73 | ||
74 | private: | |
75 | static const double DecodeMargin; | |
76 | static const double DecodeThreshold; | |
77 | static const int64_t DecodeChunkLength; | |
78 | static const unsigned int DecodeNotifyPeriod; | |
79 | ||
80 | public: | |
81 | DecoderStack(pv::SigSession &_session, | |
82 | const srd_decoder *const decoder); | |
83 | ||
84 | virtual ~DecoderStack(); | |
85 | ||
86 | const std::list< std::shared_ptr<decode::Decoder> >& stack() const; | |
87 | void push(std::shared_ptr<decode::Decoder> decoder); | |
88 | void remove(int index); | |
89 | ||
90 | int64_t samples_decoded() const; | |
91 | ||
92 | std::vector<decode::Row> get_visible_rows() const; | |
93 | ||
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, | |
99 | const decode::Row &row, uint64_t start_sample, | |
100 | uint64_t end_sample) const; | |
101 | ||
102 | QString error_message(); | |
103 | ||
104 | void clear(); | |
105 | ||
106 | uint64_t get_max_sample_count() const; | |
107 | ||
108 | void begin_decode(); | |
109 | ||
110 | private: | |
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); | |
115 | ||
116 | void decode_proc(); | |
117 | ||
118 | static void annotation_callback(srd_proto_data *pdata, | |
119 | void *decoder); | |
120 | ||
121 | private Q_SLOTS: | |
122 | void on_new_frame(); | |
123 | ||
124 | void on_data_received(); | |
125 | ||
126 | void on_frame_ended(); | |
127 | ||
128 | Q_SIGNALS: | |
129 | void new_decode_data(); | |
130 | ||
131 | private: | |
132 | pv::SigSession &_session; | |
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 | */ | |
140 | static std::mutex _global_decode_mutex; | |
141 | ||
142 | std::list< std::shared_ptr<decode::Decoder> > _stack; | |
143 | ||
144 | std::shared_ptr<pv::data::LogicSnapshot> _snapshot; | |
145 | ||
146 | mutable std::mutex _input_mutex; | |
147 | mutable std::condition_variable _input_cond; | |
148 | int64_t _sample_count; | |
149 | bool _frame_complete; | |
150 | ||
151 | mutable std::mutex _output_mutex; | |
152 | int64_t _samples_decoded; | |
153 | ||
154 | std::map<const decode::Row, decode::RowData> _rows; | |
155 | ||
156 | std::map<std::pair<const srd_decoder*, int>, decode::Row> _class_rows; | |
157 | ||
158 | QString _error_message; | |
159 | ||
160 | std::thread _decode_thread; | |
161 | std::atomic<bool> _interrupt; | |
162 | ||
163 | friend struct DecoderStackTest::TwoDecoderStack; | |
164 | }; | |
165 | ||
166 | } // namespace data | |
167 | } // namespace pv | |
168 | ||
169 | #endif // PULSEVIEW_PV_DATA_DECODERSTACK_H |