]> sigrok.org Git - pulseview.git/blame - pv/session.hpp
Implement views::trace::StandardBar and derive MainBar from it
[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"
f4e57597 45#include "views/viewbase.hpp"
48257a69 46
82c7f640 47struct srd_decoder;
8bd26d8b 48struct srd_channel;
82c7f640 49
e8d00928 50namespace sigrok {
7d80a651
JH
51class Analog;
52class Channel;
53class Device;
fd22c71c 54class InputFormat;
7d80a651
JH
55class Logic;
56class Meta;
fd22c71c 57class OutputFormat;
7d80a651
JH
58class Packet;
59class Session;
e8d00928
ML
60}
61
51e77110
JH
62namespace pv {
63
dc0867ff
JH
64class DeviceManager;
65
1b1ec774
JH
66namespace data {
67class Analog;
f3d66e52 68class AnalogSegment;
1b1ec774 69class Logic;
f3d66e52 70class LogicSegment;
bf0edd2b 71class SignalBase;
02412f0b 72class SignalData;
1b1ec774 73}
8d634081 74
da30ecb7
JH
75namespace devices {
76class Device;
77}
78
0f8f8c18
SA
79namespace toolbars {
80class MainBar;
81}
82
f4e57597
SA
83namespace views {
84class ViewBase;
8d634081 85}
2953961c 86
2b81ae46 87class Session : public QObject
2953961c 88{
009e1503
JH
89 Q_OBJECT
90
5b7cf66c
JH
91public:
92 enum capture_state {
93 Stopped,
2b49eeb0 94 AwaitingTrigger,
5b7cf66c
JH
95 Running
96 };
97
2953961c 98public:
101e7a9b 99 Session(DeviceManager &device_manager, QString name);
2953961c 100
2b81ae46 101 ~Session();
2953961c 102
4cb0b033
JH
103 DeviceManager& device_manager();
104
105 const DeviceManager& device_manager() const;
106
da30ecb7 107 std::shared_ptr<sigrok::Session> session() const;
1f4caa77 108
da30ecb7 109 std::shared_ptr<devices::Device> device() const;
dc0867ff 110
101e7a9b
SA
111 QString name() const;
112
113 void set_name(QString name);
114
f4e57597 115 const std::list< std::shared_ptr<views::ViewBase> > views() const;
36a8185e 116
f4e57597 117 std::shared_ptr<views::ViewBase> main_view() const;
0f8f8c18 118
0f8f8c18
SA
119 std::shared_ptr<pv::toolbars::MainBar> main_bar() const;
120
fd22c71c
SA
121 void set_main_bar(std::shared_ptr<pv::toolbars::MainBar> main_bar);
122
101e7a9b
SA
123 void save_settings(QSettings &settings) const;
124
125 void restore_settings(QSettings &settings);
126
fd22c71c
SA
127 /**
128 * Attempts to set device instance, may fall back to demo if needed
129 */
130 void select_device(std::shared_ptr<devices::Device> device);
131
d64d1596
JH
132 /**
133 * Sets device instance that will be used in the next capture session.
134 */
da30ecb7 135 void set_device(std::shared_ptr<devices::Device> device);
dc0867ff 136
6fd0b639
JH
137 void set_default_device();
138
fd22c71c
SA
139 void load_init_file(const std::string &file_name,
140 const std::string &format);
141
142 void load_file(QString file_name,
143 std::shared_ptr<sigrok::InputFormat> format = nullptr,
144 const std::map<std::string, Glib::VariantBase> &options =
145 std::map<std::string, Glib::VariantBase>());
146
5b7cf66c
JH
147 capture_state get_capture_state() const;
148
d2344534 149 void start_capture(std::function<void (const QString)> error_handler);
274d4f13 150
5b7cf66c
JH
151 void stop_capture();
152
2220e942
SA
153 double get_samplerate() const;
154
f4e57597 155 void register_view(std::shared_ptr<views::ViewBase> view);
47e9e7bb 156
f4e57597 157 void deregister_view(std::shared_ptr<views::ViewBase> view);
47e9e7bb 158
f4e57597 159 bool has_view(std::shared_ptr<views::ViewBase> view);
101e7a9b 160
47e9e7bb
SA
161 const std::unordered_set< std::shared_ptr<data::SignalBase> >
162 signalbases() const;
e3f65ace 163
269528f5 164#ifdef ENABLE_DECODE
4e5a4405 165 bool add_decoder(srd_decoder *const dec);
82c7f640 166
bb7dd726 167 void remove_decode_signal(std::shared_ptr<data::SignalBase> signalbase);
269528f5 168#endif
c51482b3 169
6ac96c2e
JH
170private:
171 void set_capture_state(capture_state state);
172
ffe00119 173 void update_signals();
b087ba7f 174
cbd2a2de 175 std::shared_ptr<data::SignalBase> signalbase_from_channel(
e8d00928 176 std::shared_ptr<sigrok::Channel> channel) const;
3ddcc083 177
2953961c 178private:
2b05d311 179 void sample_thread_proc(std::function<void (const QString)> error_handler);
2e2946fe 180
da30ecb7 181 void feed_in_header();
eec446e1 182
da30ecb7 183 void feed_in_meta(std::shared_ptr<sigrok::Meta> meta);
aba1dd16 184
48257a69
SA
185 void feed_in_trigger();
186
82f50b10
JH
187 void feed_in_frame_begin();
188
e8d00928 189 void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
aba1dd16 190
e8d00928 191 void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
2953961c 192
e8d00928
ML
193 void data_feed_in(std::shared_ptr<sigrok::Device> device,
194 std::shared_ptr<sigrok::Packet> packet);
2953961c
JH
195
196private:
8dbbc7f0 197 DeviceManager &device_manager_;
da30ecb7 198 std::shared_ptr<devices::Device> device_;
101e7a9b 199 QString default_name_, name_;
d64d1596 200
f4e57597
SA
201 std::list< std::shared_ptr<views::ViewBase> > views_;
202 std::shared_ptr<pv::views::ViewBase> main_view_;
0f8f8c18
SA
203
204 std::shared_ptr<pv::toolbars::MainBar> main_bar_;
47e9e7bb 205
8f6b98ff 206 mutable std::mutex sampling_mutex_; //!< Protects access to capture_state_.
8dbbc7f0 207 capture_state capture_state_;
5b7cf66c 208
47e9e7bb
SA
209 std::unordered_set< std::shared_ptr<data::SignalBase> > signalbases_;
210 std::unordered_set< std::shared_ptr<data::SignalData> > all_signal_data_;
3868e5fa 211
8524a597 212 mutable std::recursive_mutex data_mutex_;
8dbbc7f0 213 std::shared_ptr<data::Logic> logic_data_;
ff008de6 214 uint64_t cur_samplerate_;
f3d66e52
JH
215 std::shared_ptr<data::LogicSegment> cur_logic_segment_;
216 std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSegment> >
217 cur_analog_segments_;
009e1503 218
8dbbc7f0 219 std::thread sampling_thread_;
2e2946fe 220
e7216ae0
SA
221 bool out_of_memory_;
222
e9213170 223Q_SIGNALS:
6ac96c2e 224 void capture_state_changed(int state);
91f8fe8c 225 void device_changed();
6ac96c2e 226
69dd2b03
JH
227 void signals_changed();
228
101e7a9b
SA
229 void name_changed();
230
48257a69
SA
231 void trigger_event(util::Timestamp location);
232
82f50b10
JH
233 void frame_began();
234
1f374035
JH
235 void data_received();
236
237 void frame_ended();
3a21afa6 238
f4e57597 239 void add_view(const QString &title, views::ViewType type,
3a21afa6 240 Session *session);
2953961c
JH
241};
242
51e77110
JH
243} // namespace pv
244
8e99ef96 245#endif // PULSEVIEW_PV_SESSION_HPP