]> sigrok.org Git - pulseview.git/blame - pv/sigsession.h
SigSession: Added signals_mutex(), and made signals() give a reference
[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
c3a740dd
JH
107 std::mutex& signals_mutex() const;
108
109 const std::vector< std::shared_ptr<view::Signal> >& signals() const;
e3f65ace 110
269528f5 111#ifdef ENABLE_DECODE
4e5a4405 112 bool add_decoder(srd_decoder *const dec);
82c7f640 113
f9abf97e 114 std::vector< std::shared_ptr<view::DecodeTrace> >
38eeddea
JH
115 get_decode_signals() const;
116
b9329558 117 void remove_decode_signal(view::DecodeTrace *signal);
269528f5 118#endif
c51482b3 119
6ac96c2e
JH
120private:
121 void set_capture_state(capture_state state);
122
e8d00928 123 void update_signals(std::shared_ptr<sigrok::Device> device);
b087ba7f 124
6ac6242b 125 std::shared_ptr<view::Signal> signal_from_channel(
e8d00928 126 std::shared_ptr<sigrok::Channel> channel) const;
3ddcc083 127
e8d00928 128 void read_sample_rate(std::shared_ptr<sigrok::Device>);
deef291c 129
2953961c 130private:
e8d00928 131 void sample_thread_proc(std::shared_ptr<sigrok::Device> device,
d2344534 132 std::function<void (const QString)> error_handler);
2e2946fe 133
e8d00928 134 void feed_in_header(std::shared_ptr<sigrok::Device> device);
eec446e1 135
e8d00928
ML
136 void feed_in_meta(std::shared_ptr<sigrok::Device> device,
137 std::shared_ptr<sigrok::Meta> meta);
aba1dd16 138
82f50b10
JH
139 void feed_in_frame_begin();
140
e8d00928 141 void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
aba1dd16 142
e8d00928 143 void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
2953961c 144
e8d00928
ML
145 void data_feed_in(std::shared_ptr<sigrok::Device> device,
146 std::shared_ptr<sigrok::Packet> packet);
2953961c
JH
147
148private:
dc0867ff 149 DeviceManager &_device_manager;
1f4caa77 150 std::shared_ptr<sigrok::Session> _session;
d64d1596
JH
151
152 /**
153 * The device instance that will be used in the next capture session.
154 */
e8d00928 155 std::shared_ptr<sigrok::Device> _device;
d64d1596 156
f9abf97e 157 std::vector< std::shared_ptr<view::DecodeTrace> > _decode_traces;
82c7f640 158
3b68d03d 159 mutable std::mutex _sampling_mutex;
5b7cf66c
JH
160 capture_state _capture_state;
161
3b68d03d 162 mutable std::mutex _signals_mutex;
f9abf97e 163 std::vector< std::shared_ptr<view::Signal> > _signals;
3868e5fa 164
3b68d03d 165 mutable std::mutex _data_mutex;
f9abf97e
JH
166 std::shared_ptr<data::Logic> _logic_data;
167 std::shared_ptr<data::LogicSnapshot> _cur_logic_snapshot;
e8d00928 168 std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSnapshot> >
bb2cdfff 169 _cur_analog_snapshots;
009e1503 170
3b68d03d 171 std::thread _sampling_thread;
2e2946fe 172
e9213170 173Q_SIGNALS:
6ac96c2e
JH
174 void capture_state_changed(int state);
175
69dd2b03
JH
176 void signals_changed();
177
82f50b10
JH
178 void frame_began();
179
1f374035
JH
180 void data_received();
181
182 void frame_ended();
2953961c
JH
183};
184
51e77110
JH
185} // namespace pv
186
640d091b 187#endif // PULSEVIEW_PV_SIGSESSION_H