]>
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 <list> | |
27 | ||
28 | #include <boost/optional.hpp> | |
29 | #include <boost/shared_ptr.hpp> | |
30 | #include <boost/thread.hpp> | |
31 | ||
32 | #include <QObject> | |
33 | #include <QString> | |
34 | ||
35 | #include <pv/data/decode/row.h> | |
36 | #include <pv/data/decode/rowdata.h> | |
37 | ||
38 | struct srd_decoder; | |
39 | struct srd_decoder_annotation_row; | |
40 | struct srd_probe; | |
41 | struct srd_proto_data; | |
42 | struct srd_session; | |
43 | ||
44 | namespace DecoderStackTest { | |
45 | class TwoDecoderStack; | |
46 | } | |
47 | ||
48 | namespace pv { | |
49 | ||
50 | class SigSession; | |
51 | ||
52 | namespace view { | |
53 | class LogicSignal; | |
54 | } | |
55 | ||
56 | namespace data { | |
57 | ||
58 | class LogicSnapshot; | |
59 | ||
60 | namespace decode { | |
61 | class Annotation; | |
62 | class Decoder; | |
63 | } | |
64 | ||
65 | class Logic; | |
66 | ||
67 | class DecoderStack : public QObject, public SignalData | |
68 | { | |
69 | Q_OBJECT | |
70 | ||
71 | private: | |
72 | static const double DecodeMargin; | |
73 | static const double DecodeThreshold; | |
74 | static const int64_t DecodeChunkLength; | |
75 | ||
76 | public: | |
77 | DecoderStack(pv::SigSession &_session, | |
78 | const srd_decoder *const decoder); | |
79 | ||
80 | virtual ~DecoderStack(); | |
81 | ||
82 | const std::list< boost::shared_ptr<decode::Decoder> >& stack() const; | |
83 | void push(boost::shared_ptr<decode::Decoder> decoder); | |
84 | void remove(int index); | |
85 | ||
86 | int64_t samples_decoded() const; | |
87 | ||
88 | std::vector<decode::Row> get_visible_rows() const; | |
89 | ||
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, | |
95 | const decode::Row &row, uint64_t start_sample, | |
96 | uint64_t end_sample) const; | |
97 | ||
98 | QString error_message(); | |
99 | ||
100 | void clear(); | |
101 | ||
102 | uint64_t get_max_sample_count() const; | |
103 | ||
104 | void begin_decode(); | |
105 | ||
106 | private: | |
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); | |
111 | ||
112 | void decode_proc(boost::shared_ptr<data::Logic> data); | |
113 | ||
114 | static void annotation_callback(srd_proto_data *pdata, | |
115 | void *decoder); | |
116 | ||
117 | private slots: | |
118 | void on_new_frame(); | |
119 | ||
120 | void on_data_received(); | |
121 | ||
122 | void on_frame_ended(); | |
123 | ||
124 | signals: | |
125 | void new_decode_data(); | |
126 | ||
127 | private: | |
128 | pv::SigSession &_session; | |
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 | ||
138 | std::list< boost::shared_ptr<decode::Decoder> > _stack; | |
139 | ||
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 | ||
147 | mutable boost::mutex _output_mutex; | |
148 | int64_t _samples_decoded; | |
149 | ||
150 | std::map<const decode::Row, decode::RowData> _rows; | |
151 | ||
152 | std::map<std::pair<const srd_decoder*, int>, decode::Row> _class_rows; | |
153 | ||
154 | QString _error_message; | |
155 | ||
156 | boost::thread _decode_thread; | |
157 | ||
158 | friend class DecoderStackTest::TwoDecoderStack; | |
159 | }; | |
160 | ||
161 | } // namespace data | |
162 | } // namespace pv | |
163 | ||
164 | #endif // PULSEVIEW_PV_DATA_DECODERSTACK_H |