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