]> sigrok.org Git - pulseview.git/blame - pv/session.hpp
MainWindow: Make session naming consistent
[pulseview.git] / pv / session.hpp
CommitLineData
2953961c 1/*
b3f22de0 2 * This file is part of the PulseView project.
2953961c 3 *
1bc6525b 4 * Copyright (C) 2012-14 Joel Holdsworth <joel@airwebreathe.org.uk>
2953961c
JH
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
8e99ef96
JH
21#ifndef PULSEVIEW_PV_SESSION_HPP
22#define PULSEVIEW_PV_SESSION_HPP
2953961c 23
708c5523 24#include <map>
f9abf97e 25#include <memory>
3b68d03d 26#include <mutex>
bfc9f61e 27#include <set>
28a4c9c5 28#include <string>
3b68d03d 29#include <thread>
78b0af3e 30#include <unordered_set>
e3f65ace 31#include <vector>
28a4c9c5 32
627ffe3f 33#ifdef _WIN32
35750e4d 34// Windows: Avoid boost/thread namespace pollution (which includes windows.h).
627ffe3f
VI
35#define NOGDI
36#define NORESOURCE
37#endif
e71eb81c 38#include <boost/thread/shared_mutex.hpp>
aca64cac 39
009e1503 40#include <QObject>
101e7a9b 41#include <QSettings>
f2edb557 42#include <QString>
009e1503 43
48257a69 44#include "util.hpp"
3a21afa6 45#include "view/viewwidget.hpp"
48257a69 46
82c7f640 47struct srd_decoder;
8bd26d8b 48struct srd_channel;
82c7f640 49
e8d00928 50namespace sigrok {
7d80a651
JH
51class Analog;
52class Channel;
53class Device;
54class Logic;
55class Meta;
56class Packet;
57class Session;
e8d00928
ML
58}
59
51e77110
JH
60namespace pv {
61
dc0867ff
JH
62class DeviceManager;
63
1b1ec774
JH
64namespace data {
65class Analog;
f3d66e52 66class AnalogSegment;
1b1ec774 67class Logic;
f3d66e52 68class LogicSegment;
bf0edd2b 69class SignalBase;
02412f0b 70class SignalData;
1b1ec774 71}
8d634081 72
da30ecb7
JH
73namespace devices {
74class Device;
75}
76
0f8f8c18
SA
77namespace toolbars {
78class MainBar;
79}
80
8d634081 81namespace view {
47e9e7bb 82class View;
8d634081 83}
2953961c 84
2b81ae46 85class Session : public QObject
2953961c 86{
009e1503
JH
87 Q_OBJECT
88
5b7cf66c
JH
89public:
90 enum capture_state {
91 Stopped,
2b49eeb0 92 AwaitingTrigger,
5b7cf66c
JH
93 Running
94 };
95
2953961c 96public:
101e7a9b 97 Session(DeviceManager &device_manager, QString name);
2953961c 98
2b81ae46 99 ~Session();
2953961c 100
4cb0b033
JH
101 DeviceManager& device_manager();
102
103 const DeviceManager& device_manager() const;
104
da30ecb7 105 std::shared_ptr<sigrok::Session> session() const;
1f4caa77 106
da30ecb7 107 std::shared_ptr<devices::Device> device() const;
dc0867ff 108
101e7a9b
SA
109 QString name() const;
110
111 void set_name(QString name);
112
36a8185e
SA
113 const std::list< std::shared_ptr<pv::view::View> > views() const;
114
0f8f8c18
SA
115 std::shared_ptr<pv::view::View> main_view() const;
116
117 void set_main_bar(std::shared_ptr<pv::toolbars::MainBar> main_bar);
118
119 std::shared_ptr<pv::toolbars::MainBar> main_bar() const;
120
101e7a9b
SA
121 void save_settings(QSettings &settings) const;
122
123 void restore_settings(QSettings &settings);
124
d64d1596
JH
125 /**
126 * Sets device instance that will be used in the next capture session.
127 */
da30ecb7 128 void set_device(std::shared_ptr<devices::Device> device);
dc0867ff 129
6fd0b639
JH
130 void set_default_device();
131
5b7cf66c
JH
132 capture_state get_capture_state() const;
133
d2344534 134 void start_capture(std::function<void (const QString)> error_handler);
274d4f13 135
5b7cf66c
JH
136 void stop_capture();
137
2220e942
SA
138 double get_samplerate() const;
139
47e9e7bb
SA
140 void register_view(std::shared_ptr<pv::view::View> view);
141
142 void deregister_view(std::shared_ptr<pv::view::View> view);
143
101e7a9b
SA
144 bool has_view(std::shared_ptr<pv::view::View> view);
145
47e9e7bb
SA
146 const std::unordered_set< std::shared_ptr<data::SignalBase> >
147 signalbases() const;
e3f65ace 148
269528f5 149#ifdef ENABLE_DECODE
4e5a4405 150 bool add_decoder(srd_decoder *const dec);
82c7f640 151
bb7dd726 152 void remove_decode_signal(std::shared_ptr<data::SignalBase> signalbase);
269528f5 153#endif
c51482b3 154
6ac96c2e
JH
155private:
156 void set_capture_state(capture_state state);
157
ffe00119 158 void update_signals();
b087ba7f 159
cbd2a2de 160 std::shared_ptr<data::SignalBase> signalbase_from_channel(
e8d00928 161 std::shared_ptr<sigrok::Channel> channel) const;
3ddcc083 162
2953961c 163private:
2b05d311 164 void sample_thread_proc(std::function<void (const QString)> error_handler);
2e2946fe 165
da30ecb7 166 void feed_in_header();
eec446e1 167
da30ecb7 168 void feed_in_meta(std::shared_ptr<sigrok::Meta> meta);
aba1dd16 169
48257a69
SA
170 void feed_in_trigger();
171
82f50b10
JH
172 void feed_in_frame_begin();
173
e8d00928 174 void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
aba1dd16 175
e8d00928 176 void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
2953961c 177
e8d00928
ML
178 void data_feed_in(std::shared_ptr<sigrok::Device> device,
179 std::shared_ptr<sigrok::Packet> packet);
2953961c
JH
180
181private:
8dbbc7f0 182 DeviceManager &device_manager_;
da30ecb7 183 std::shared_ptr<devices::Device> device_;
101e7a9b 184 QString default_name_, name_;
d64d1596 185
3a21afa6 186 std::list< std::shared_ptr<pv::view::View> > views_;
0f8f8c18
SA
187 std::shared_ptr<pv::view::View> main_view_;
188
189 std::shared_ptr<pv::toolbars::MainBar> main_bar_;
47e9e7bb 190
8f6b98ff 191 mutable std::mutex sampling_mutex_; //!< Protects access to capture_state_.
8dbbc7f0 192 capture_state capture_state_;
5b7cf66c 193
47e9e7bb
SA
194 std::unordered_set< std::shared_ptr<data::SignalBase> > signalbases_;
195 std::unordered_set< std::shared_ptr<data::SignalData> > all_signal_data_;
3868e5fa 196
8524a597 197 mutable std::recursive_mutex data_mutex_;
8dbbc7f0 198 std::shared_ptr<data::Logic> logic_data_;
ff008de6 199 uint64_t cur_samplerate_;
f3d66e52
JH
200 std::shared_ptr<data::LogicSegment> cur_logic_segment_;
201 std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSegment> >
202 cur_analog_segments_;
009e1503 203
8dbbc7f0 204 std::thread sampling_thread_;
2e2946fe 205
e7216ae0
SA
206 bool out_of_memory_;
207
e9213170 208Q_SIGNALS:
6ac96c2e 209 void capture_state_changed(int state);
91f8fe8c 210 void device_changed();
6ac96c2e 211
69dd2b03
JH
212 void signals_changed();
213
101e7a9b
SA
214 void name_changed();
215
48257a69
SA
216 void trigger_event(util::Timestamp location);
217
82f50b10
JH
218 void frame_began();
219
1f374035
JH
220 void data_received();
221
222 void frame_ended();
3a21afa6
SA
223
224 void add_view(const QString &title, view::ViewType type,
225 Session *session);
2953961c
JH
226};
227
51e77110
JH
228} // namespace pv
229
8e99ef96 230#endif // PULSEVIEW_PV_SESSION_HPP