]> sigrok.org Git - pulseview.git/blame - pv/sigsession.h
SigSession: Added DeviceManager accessor functions
[pulseview.git] / pv / sigsession.h
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
640d091b
UH
21#ifndef PULSEVIEW_PV_SIGSESSION_H
22#define PULSEVIEW_PV_SIGSESSION_H
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>
e3f65ace 30#include <vector>
28a4c9c5 31
009e1503 32#include <QObject>
f2edb557 33#include <QString>
009e1503 34
82c7f640 35struct srd_decoder;
8bd26d8b 36struct srd_channel;
82c7f640 37
e8d00928
ML
38namespace sigrok {
39 class Analog;
40 class Channel;
41 class Device;
42 class Logic;
43 class Meta;
44 class Packet;
45 class Session;
46}
47
51e77110
JH
48namespace pv {
49
dc0867ff
JH
50class DeviceManager;
51
1b1ec774
JH
52namespace data {
53class Analog;
54class AnalogSnapshot;
55class Logic;
56class LogicSnapshot;
02412f0b 57class SignalData;
1b1ec774 58}
8d634081
JH
59
60namespace view {
b9329558 61class DecodeTrace;
3045c869 62class LogicSignal;
28a4c9c5 63class Signal;
8d634081 64}
2953961c 65
009e1503 66class SigSession : public QObject
2953961c 67{
009e1503
JH
68 Q_OBJECT
69
5b7cf66c
JH
70public:
71 enum capture_state {
72 Stopped,
2b49eeb0 73 AwaitingTrigger,
5b7cf66c
JH
74 Running
75 };
76
2953961c 77public:
dc0867ff 78 SigSession(DeviceManager &device_manager);
2953961c
JH
79
80 ~SigSession();
81
4cb0b033
JH
82 DeviceManager& device_manager();
83
84 const DeviceManager& device_manager() const;
85
1f4caa77
JH
86 const std::shared_ptr<sigrok::Session>& session() const;
87
d260d425 88 std::shared_ptr<sigrok::Device> device() const;
dc0867ff 89
d64d1596
JH
90 /**
91 * Sets device instance that will be used in the next capture session.
92 */
e8d00928 93 void set_device(std::shared_ptr<sigrok::Device> device);
d64d1596 94
e8d00928 95 void set_file(const std::string &name);
dc0867ff 96
6fd0b639
JH
97 void set_default_device();
98
5b7cf66c
JH
99 capture_state get_capture_state() const;
100
d2344534 101 void start_capture(std::function<void (const QString)> error_handler);
274d4f13 102
5b7cf66c
JH
103 void stop_capture();
104
f9abf97e 105 std::set< std::shared_ptr<data::SignalData> > get_data() const;
02412f0b 106
f9abf97e 107 std::vector< std::shared_ptr<view::Signal> >
38eeddea 108 get_signals() const;
e3f65ace 109
269528f5 110#ifdef ENABLE_DECODE
4e5a4405 111 bool add_decoder(srd_decoder *const dec);
82c7f640 112
f9abf97e 113 std::vector< std::shared_ptr<view::DecodeTrace> >
38eeddea
JH
114 get_decode_signals() const;
115
b9329558 116 void remove_decode_signal(view::DecodeTrace *signal);
269528f5 117#endif
c51482b3 118
6ac96c2e
JH
119private:
120 void set_capture_state(capture_state state);
121
e8d00928 122 void update_signals(std::shared_ptr<sigrok::Device> device);
b087ba7f 123
6ac6242b 124 std::shared_ptr<view::Signal> signal_from_channel(
e8d00928 125 std::shared_ptr<sigrok::Channel> channel) const;
3ddcc083 126
e8d00928 127 void read_sample_rate(std::shared_ptr<sigrok::Device>);
deef291c 128
2953961c 129private:
e8d00928 130 void sample_thread_proc(std::shared_ptr<sigrok::Device> device,
d2344534 131 std::function<void (const QString)> error_handler);
2e2946fe 132
e8d00928 133 void feed_in_header(std::shared_ptr<sigrok::Device> device);
eec446e1 134
e8d00928
ML
135 void feed_in_meta(std::shared_ptr<sigrok::Device> device,
136 std::shared_ptr<sigrok::Meta> meta);
aba1dd16 137
82f50b10
JH
138 void feed_in_frame_begin();
139
e8d00928 140 void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
aba1dd16 141
e8d00928 142 void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
2953961c 143
e8d00928
ML
144 void data_feed_in(std::shared_ptr<sigrok::Device> device,
145 std::shared_ptr<sigrok::Packet> packet);
2953961c
JH
146
147private:
dc0867ff 148 DeviceManager &_device_manager;
1f4caa77 149 std::shared_ptr<sigrok::Session> _session;
d64d1596
JH
150
151 /**
152 * The device instance that will be used in the next capture session.
153 */
e8d00928 154 std::shared_ptr<sigrok::Device> _device;
d64d1596 155
f9abf97e 156 std::vector< std::shared_ptr<view::DecodeTrace> > _decode_traces;
82c7f640 157
3b68d03d 158 mutable std::mutex _sampling_mutex;
5b7cf66c
JH
159 capture_state _capture_state;
160
3b68d03d 161 mutable std::mutex _signals_mutex;
f9abf97e 162 std::vector< std::shared_ptr<view::Signal> > _signals;
3868e5fa 163
3b68d03d 164 mutable std::mutex _data_mutex;
f9abf97e
JH
165 std::shared_ptr<data::Logic> _logic_data;
166 std::shared_ptr<data::LogicSnapshot> _cur_logic_snapshot;
e8d00928 167 std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSnapshot> >
bb2cdfff 168 _cur_analog_snapshots;
009e1503 169
3b68d03d 170 std::thread _sampling_thread;
2e2946fe 171
e9213170 172Q_SIGNALS:
6ac96c2e
JH
173 void capture_state_changed(int state);
174
69dd2b03
JH
175 void signals_changed();
176
82f50b10
JH
177 void frame_began();
178
1f374035
JH
179 void data_received();
180
181 void frame_ended();
2953961c
JH
182};
183
51e77110
JH
184} // namespace pv
185
640d091b 186#endif // PULSEVIEW_PV_SIGSESSION_H