]>
Commit | Line | Data |
---|---|---|
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 | |
119aff65 | 34 | struct srd_decoder; |
708c5523 | 35 | struct srd_probe; |
b213ef09 | 36 | struct srd_proto_data; |
b6b267bb | 37 | |
6e89374a JH |
38 | namespace DecoderStackTest { |
39 | class TwoDecoderStack; | |
b6b267bb | 40 | } |
119aff65 JH |
41 | |
42 | namespace pv { | |
708c5523 JH |
43 | |
44 | namespace view { | |
3045c869 | 45 | class LogicSignal; |
708c5523 JH |
46 | } |
47 | ||
119aff65 JH |
48 | namespace data { |
49 | ||
7491a29f | 50 | namespace decode { |
06e810f2 | 51 | class Annotation; |
7491a29f JH |
52 | class Decoder; |
53 | } | |
54 | ||
640d69ce JH |
55 | class Logic; |
56 | ||
6e89374a | 57 | class DecoderStack : public QObject, public SignalData |
119aff65 | 58 | { |
e0fc5810 JH |
59 | Q_OBJECT |
60 | ||
61 | private: | |
62 | static const double DecodeMargin; | |
63 | static const double DecodeThreshold; | |
64 | static const int64_t DecodeChunkLength; | |
65 | ||
119aff65 | 66 | public: |
6e89374a | 67 | DecoderStack(const srd_decoder *const decoder); |
119aff65 | 68 | |
6e89374a | 69 | virtual ~DecoderStack(); |
640d69ce | 70 | |
7491a29f JH |
71 | const std::list< boost::shared_ptr<decode::Decoder> >& stack() const; |
72 | void push(boost::shared_ptr<decode::Decoder> decoder); | |
613d097c | 73 | void remove(int index); |
119aff65 | 74 | |
5dfeb70f JH |
75 | int64_t samples_decoded() const; |
76 | ||
92421299 JH |
77 | /** |
78 | * Extracts sorted annotations between two period into a vector. | |
79 | */ | |
80 | void get_annotation_subset( | |
81 | std::vector<pv::data::decode::Annotation> &dest, | |
82 | uint64_t start_sample, uint64_t end_sample) const; | |
640d69ce | 83 | |
b6b267bb JH |
84 | QString error_message(); |
85 | ||
caabb84c | 86 | void clear(); |
119aff65 | 87 | |
a007f5ad JH |
88 | uint64_t get_max_sample_count() const; |
89 | ||
e0fc5810 JH |
90 | void begin_decode(); |
91 | ||
7491a29f | 92 | private: |
640d69ce JH |
93 | void decode_proc(boost::shared_ptr<data::Logic> data); |
94 | ||
92421299 JH |
95 | bool index_entry_start_sample_gt( |
96 | const uint64_t sample, const size_t index) const; | |
97 | bool index_entry_end_sample_lt( | |
98 | const size_t index, const uint64_t sample) const; | |
99 | bool index_entry_end_sample_gt( | |
100 | const uint64_t sample, const size_t index) const; | |
101 | ||
102 | void insert_annotation_into_start_index( | |
103 | const pv::data::decode::Annotation &a, | |
104 | const size_t storage_offset); | |
105 | void insert_annotation_into_end_index( | |
106 | const pv::data::decode::Annotation &a, | |
107 | const size_t storage_offset); | |
108 | ||
e0fc5810 JH |
109 | static void annotation_callback(srd_proto_data *pdata, |
110 | void *decoder); | |
111 | ||
9cef9567 JH |
112 | signals: |
113 | void new_decode_data(); | |
114 | ||
119aff65 | 115 | private: |
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; |
06e810f2 | 129 | std::vector<pv::data::decode::Annotation> _annotations; |
92421299 JH |
130 | |
131 | /** | |
132 | * _ann_start_index and _ann_end_index contain lists of annotions | |
133 | * (represented by offsets in the _annotations vector), sorted in | |
134 | * ascending ordered by the start_sample and end_sample respectively. | |
135 | */ | |
136 | std::vector<size_t> _ann_start_index, _ann_end_index; | |
137 | ||
b6b267bb | 138 | QString _error_message; |
e0fc5810 | 139 | |
640d69ce | 140 | boost::thread _decode_thread; |
b6b267bb | 141 | |
6e89374a | 142 | friend class DecoderStackTest::TwoDecoderStack; |
119aff65 JH |
143 | }; |
144 | ||
145 | } // namespace data | |
146 | } // namespace pv | |
147 | ||
6e89374a | 148 | #endif // PULSEVIEW_PV_DATA_DECODERSTACK_H |