]> sigrok.org Git - pulseview.git/blame_incremental - pv/session.hpp
MainWindow: Enable dock nesting
[pulseview.git] / pv / session.hpp
... / ...
CommitLineData
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 <QSettings>
42#include <QString>
43
44#include "util.hpp"
45#include "view/viewwidget.hpp"
46
47struct srd_decoder;
48struct srd_channel;
49
50namespace sigrok {
51class Analog;
52class Channel;
53class Device;
54class Logic;
55class Meta;
56class Packet;
57class Session;
58}
59
60namespace pv {
61
62class DeviceManager;
63
64namespace data {
65class Analog;
66class AnalogSegment;
67class Logic;
68class LogicSegment;
69class SignalBase;
70class SignalData;
71}
72
73namespace devices {
74class Device;
75}
76
77namespace toolbars {
78class MainBar;
79}
80
81namespace view {
82class View;
83}
84
85class Session : public QObject
86{
87 Q_OBJECT
88
89public:
90 enum capture_state {
91 Stopped,
92 AwaitingTrigger,
93 Running
94 };
95
96public:
97 Session(DeviceManager &device_manager, QString name);
98
99 ~Session();
100
101 DeviceManager& device_manager();
102
103 const DeviceManager& device_manager() const;
104
105 std::shared_ptr<sigrok::Session> session() const;
106
107 std::shared_ptr<devices::Device> device() const;
108
109 QString name() const;
110
111 void set_name(QString name);
112
113 std::shared_ptr<pv::view::View> main_view() const;
114
115 void set_main_bar(std::shared_ptr<pv::toolbars::MainBar> main_bar);
116
117 std::shared_ptr<pv::toolbars::MainBar> main_bar() const;
118
119 void save_settings(QSettings &settings) const;
120
121 void restore_settings(QSettings &settings);
122
123 /**
124 * Sets device instance that will be used in the next capture session.
125 */
126 void set_device(std::shared_ptr<devices::Device> device);
127
128 void set_default_device();
129
130 capture_state get_capture_state() const;
131
132 void start_capture(std::function<void (const QString)> error_handler);
133
134 void stop_capture();
135
136 double get_samplerate() const;
137
138 void register_view(std::shared_ptr<pv::view::View> view);
139
140 void deregister_view(std::shared_ptr<pv::view::View> view);
141
142 bool has_view(std::shared_ptr<pv::view::View> view);
143
144 const std::unordered_set< std::shared_ptr<data::SignalBase> >
145 signalbases() const;
146
147#ifdef ENABLE_DECODE
148 bool add_decoder(srd_decoder *const dec);
149
150 void remove_decode_signal(std::shared_ptr<data::SignalBase> signalbase);
151#endif
152
153private:
154 void set_capture_state(capture_state state);
155
156 void update_signals();
157
158 std::shared_ptr<data::SignalBase> signalbase_from_channel(
159 std::shared_ptr<sigrok::Channel> channel) const;
160
161private:
162 void sample_thread_proc(std::function<void (const QString)> error_handler);
163
164 void feed_in_header();
165
166 void feed_in_meta(std::shared_ptr<sigrok::Meta> meta);
167
168 void feed_in_trigger();
169
170 void feed_in_frame_begin();
171
172 void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
173
174 void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
175
176 void data_feed_in(std::shared_ptr<sigrok::Device> device,
177 std::shared_ptr<sigrok::Packet> packet);
178
179private:
180 DeviceManager &device_manager_;
181 std::shared_ptr<devices::Device> device_;
182 QString default_name_, name_;
183
184 std::list< std::shared_ptr<pv::view::View> > views_;
185 std::shared_ptr<pv::view::View> main_view_;
186
187 std::shared_ptr<pv::toolbars::MainBar> main_bar_;
188
189 mutable std::mutex sampling_mutex_; //!< Protects access to capture_state_.
190 capture_state capture_state_;
191
192 std::unordered_set< std::shared_ptr<data::SignalBase> > signalbases_;
193 std::unordered_set< std::shared_ptr<data::SignalData> > all_signal_data_;
194
195 mutable std::recursive_mutex data_mutex_;
196 std::shared_ptr<data::Logic> logic_data_;
197 uint64_t cur_samplerate_;
198 std::shared_ptr<data::LogicSegment> cur_logic_segment_;
199 std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSegment> >
200 cur_analog_segments_;
201
202 std::thread sampling_thread_;
203
204 bool out_of_memory_;
205
206Q_SIGNALS:
207 void capture_state_changed(int state);
208 void device_changed();
209
210 void signals_changed();
211
212 void name_changed();
213
214 void trigger_event(util::Timestamp location);
215
216 void frame_began();
217
218 void data_received();
219
220 void frame_ended();
221
222 void add_view(const QString &title, view::ViewType type,
223 Session *session);
224};
225
226} // namespace pv
227
228#endif // PULSEVIEW_PV_SESSION_HPP