]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2012-14 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_SESSION_HPP | |
22 | #define PULSEVIEW_PV_SESSION_HPP | |
23 | ||
24 | #include <map> | |
25 | #include <memory> | |
26 | #include <mutex> | |
27 | #include <set> | |
28 | #include <string> | |
29 | #include <thread> | |
30 | #include <unordered_set> | |
31 | #include <vector> | |
32 | ||
33 | #ifdef _WIN32 | |
34 | // Windows: Avoid boost/thread namespace pollution (which includes windows.h). | |
35 | #define NOGDI | |
36 | #define NORESOURCE | |
37 | #endif | |
38 | #include <boost/thread/shared_mutex.hpp> | |
39 | ||
40 | #include <QObject> | |
41 | #include <QString> | |
42 | ||
43 | #include "util.hpp" | |
44 | ||
45 | struct srd_decoder; | |
46 | struct srd_channel; | |
47 | ||
48 | namespace sigrok { | |
49 | class Analog; | |
50 | class Channel; | |
51 | class Device; | |
52 | class Logic; | |
53 | class Meta; | |
54 | class Packet; | |
55 | class Session; | |
56 | } | |
57 | ||
58 | namespace pv { | |
59 | ||
60 | class DeviceManager; | |
61 | ||
62 | namespace data { | |
63 | class Analog; | |
64 | class AnalogSegment; | |
65 | class Logic; | |
66 | class LogicSegment; | |
67 | class SignalData; | |
68 | } | |
69 | ||
70 | namespace devices { | |
71 | class Device; | |
72 | } | |
73 | ||
74 | namespace view { | |
75 | class DecodeTrace; | |
76 | class LogicSignal; | |
77 | class Signal; | |
78 | } | |
79 | ||
80 | class Session : public QObject | |
81 | { | |
82 | Q_OBJECT | |
83 | ||
84 | public: | |
85 | enum capture_state { | |
86 | Stopped, | |
87 | AwaitingTrigger, | |
88 | Running | |
89 | }; | |
90 | ||
91 | public: | |
92 | Session(DeviceManager &device_manager); | |
93 | ||
94 | ~Session(); | |
95 | ||
96 | DeviceManager& device_manager(); | |
97 | ||
98 | const DeviceManager& device_manager() const; | |
99 | ||
100 | std::shared_ptr<sigrok::Session> session() const; | |
101 | ||
102 | std::shared_ptr<devices::Device> device() const; | |
103 | ||
104 | /** | |
105 | * Sets device instance that will be used in the next capture session. | |
106 | */ | |
107 | void set_device(std::shared_ptr<devices::Device> device); | |
108 | ||
109 | void set_default_device(); | |
110 | ||
111 | capture_state get_capture_state() const; | |
112 | ||
113 | void start_capture(std::function<void (const QString)> error_handler); | |
114 | ||
115 | void stop_capture(); | |
116 | ||
117 | double get_samplerate() const; | |
118 | ||
119 | const std::unordered_set< std::shared_ptr<view::Signal> > | |
120 | signals() const; | |
121 | ||
122 | #ifdef ENABLE_DECODE | |
123 | bool add_decoder(srd_decoder *const dec); | |
124 | ||
125 | std::vector< std::shared_ptr<view::DecodeTrace> > | |
126 | get_decode_signals() const; | |
127 | ||
128 | void remove_decode_signal(view::DecodeTrace *signal); | |
129 | #endif | |
130 | ||
131 | private: | |
132 | void set_capture_state(capture_state state); | |
133 | ||
134 | void update_signals(); | |
135 | ||
136 | std::shared_ptr<view::Signal> signal_from_channel( | |
137 | std::shared_ptr<sigrok::Channel> channel) const; | |
138 | ||
139 | private: | |
140 | void sample_thread_proc(std::shared_ptr<devices::Device> device, | |
141 | std::function<void (const QString)> error_handler); | |
142 | ||
143 | void feed_in_header(); | |
144 | ||
145 | void feed_in_meta(std::shared_ptr<sigrok::Meta> meta); | |
146 | ||
147 | void feed_in_trigger(); | |
148 | ||
149 | void feed_in_frame_begin(); | |
150 | ||
151 | void feed_in_logic(std::shared_ptr<sigrok::Logic> logic); | |
152 | ||
153 | void feed_in_analog(std::shared_ptr<sigrok::Analog> analog); | |
154 | ||
155 | void data_feed_in(std::shared_ptr<sigrok::Device> device, | |
156 | std::shared_ptr<sigrok::Packet> packet); | |
157 | ||
158 | private: | |
159 | DeviceManager &device_manager_; | |
160 | std::shared_ptr<devices::Device> device_; | |
161 | ||
162 | std::vector< std::shared_ptr<view::DecodeTrace> > decode_traces_; | |
163 | ||
164 | mutable std::mutex sampling_mutex_; //!< Protects access to capture_state_. | |
165 | capture_state capture_state_; | |
166 | ||
167 | mutable boost::shared_mutex signals_mutex_; | |
168 | std::unordered_set< std::shared_ptr<view::Signal> > signals_; | |
169 | std::set< std::shared_ptr<data::SignalData> > all_signal_data_; | |
170 | ||
171 | mutable std::recursive_mutex data_mutex_; | |
172 | std::shared_ptr<data::Logic> logic_data_; | |
173 | uint64_t cur_samplerate_; | |
174 | std::shared_ptr<data::LogicSegment> cur_logic_segment_; | |
175 | std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSegment> > | |
176 | cur_analog_segments_; | |
177 | ||
178 | std::thread sampling_thread_; | |
179 | ||
180 | bool out_of_memory_; | |
181 | ||
182 | Q_SIGNALS: | |
183 | void capture_state_changed(int state); | |
184 | void device_selected(); | |
185 | ||
186 | void signals_changed(); | |
187 | ||
188 | void trigger_event(util::Timestamp location); | |
189 | ||
190 | void frame_began(); | |
191 | ||
192 | void data_received(); | |
193 | ||
194 | void frame_ended(); | |
195 | }; | |
196 | ||
197 | } // namespace pv | |
198 | ||
199 | #endif // PULSEVIEW_PV_SESSION_HPP |