]> sigrok.org Git - pulseview.git/blame - pv/sigsession.h
Header: Do not clip away the selection.
[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
2953961c 35#include <libsigrok/libsigrok.h>
2953961c 36
82c7f640 37struct srd_decoder;
8bd26d8b 38struct srd_channel;
82c7f640 39
51e77110
JH
40namespace pv {
41
dc0867ff
JH
42class DeviceManager;
43
1b1ec774
JH
44namespace data {
45class Analog;
46class AnalogSnapshot;
47class Logic;
48class LogicSnapshot;
02412f0b 49class SignalData;
1b1ec774 50}
8d634081 51
94574501
JH
52namespace device {
53class DevInst;
54}
55
8d634081 56namespace view {
b9329558 57class DecodeTrace;
3045c869 58class LogicSignal;
28a4c9c5 59class Signal;
8d634081 60}
2953961c 61
009e1503 62class SigSession : public QObject
2953961c 63{
009e1503
JH
64 Q_OBJECT
65
5b7cf66c
JH
66public:
67 enum capture_state {
68 Stopped,
2b49eeb0 69 AwaitingTrigger,
5b7cf66c
JH
70 Running
71 };
72
2953961c 73public:
dc0867ff 74 SigSession(DeviceManager &device_manager);
2953961c
JH
75
76 ~SigSession();
77
f9abf97e 78 std::shared_ptr<device::DevInst> get_device() const;
dc0867ff 79
d64d1596
JH
80 /**
81 * Sets device instance that will be used in the next capture session.
82 */
f9abf97e 83 void set_device(std::shared_ptr<device::DevInst> dev_inst)
ae2d1bc5 84 throw(QString);
d64d1596 85
ae2d1bc5
JH
86 void set_file(const std::string &name)
87 throw(QString);
dc0867ff 88
6fd0b639
JH
89 void set_default_device();
90
ae2d1bc5 91 void release_device(device::DevInst *dev_inst);
2953961c 92
5b7cf66c
JH
93 capture_state get_capture_state() const;
94
d2344534 95 void start_capture(std::function<void (const QString)> error_handler);
274d4f13 96
5b7cf66c
JH
97 void stop_capture();
98
f9abf97e 99 std::set< std::shared_ptr<data::SignalData> > get_data() const;
02412f0b 100
f9abf97e 101 std::vector< std::shared_ptr<view::Signal> >
38eeddea 102 get_signals() const;
e3f65ace 103
269528f5 104#ifdef ENABLE_DECODE
4e5a4405 105 bool add_decoder(srd_decoder *const dec);
82c7f640 106
f9abf97e 107 std::vector< std::shared_ptr<view::DecodeTrace> >
38eeddea
JH
108 get_decode_signals() const;
109
b9329558 110 void remove_decode_signal(view::DecodeTrace *signal);
269528f5 111#endif
c51482b3 112
6ac96c2e
JH
113private:
114 void set_capture_state(capture_state state);
115
f9abf97e 116 void update_signals(std::shared_ptr<device::DevInst> dev_inst);
b087ba7f 117
f9abf97e 118 std::shared_ptr<view::Signal> signal_from_probe(
4871ed92 119 const sr_channel *probe) const;
3ddcc083 120
deef291c
JH
121 void read_sample_rate(const sr_dev_inst *const sdi);
122
2953961c 123private:
728e5ef7
JH
124 /**
125 * Attempts to autodetect the format. Failing that
126 * @param filename The filename of the input file.
127 * @return A pointer to the 'struct sr_input_format' that should be
128 * used, or NULL if no input format was selected or
129 * auto-detected.
130 */
131 static sr_input_format* determine_input_file_format(
132 const std::string &filename);
133
134 static sr_input* load_input_file_format(
135 const std::string &filename,
d2344534 136 std::function<void (const QString)> error_handler,
728e5ef7
JH
137 sr_input_format *format = NULL);
138
f9abf97e 139 void sample_thread_proc(std::shared_ptr<device::DevInst> dev_inst,
d2344534 140 std::function<void (const QString)> error_handler);
2e2946fe 141
eec446e1
JH
142 void feed_in_header(const sr_dev_inst *sdi);
143
be73bdfa
JH
144 void feed_in_meta(const sr_dev_inst *sdi,
145 const sr_datafeed_meta &meta);
aba1dd16 146
82f50b10
JH
147 void feed_in_frame_begin();
148
9c112671
JH
149 void feed_in_logic(const sr_datafeed_logic &logic);
150
aba1dd16
JH
151 void feed_in_analog(const sr_datafeed_analog &analog);
152
04abfae9 153 void data_feed_in(const struct sr_dev_inst *sdi,
bc5c1a99 154 const struct sr_datafeed_packet *packet);
2953961c 155
04abfae9 156 static void data_feed_in_proc(const struct sr_dev_inst *sdi,
5045f16d 157 const struct sr_datafeed_packet *packet, void *cb_data);
2953961c
JH
158
159private:
dc0867ff 160 DeviceManager &_device_manager;
d64d1596
JH
161
162 /**
163 * The device instance that will be used in the next capture session.
164 */
f9abf97e 165 std::shared_ptr<device::DevInst> _dev_inst;
d64d1596 166
f9abf97e 167 std::vector< std::shared_ptr<view::DecodeTrace> > _decode_traces;
82c7f640 168
3b68d03d 169 mutable std::mutex _sampling_mutex;
5b7cf66c
JH
170 capture_state _capture_state;
171
3b68d03d 172 mutable std::mutex _signals_mutex;
f9abf97e 173 std::vector< std::shared_ptr<view::Signal> > _signals;
3868e5fa 174
3b68d03d 175 mutable std::mutex _data_mutex;
f9abf97e
JH
176 std::shared_ptr<data::Logic> _logic_data;
177 std::shared_ptr<data::LogicSnapshot> _cur_logic_snapshot;
178 std::map< const sr_channel*, std::shared_ptr<data::AnalogSnapshot> >
bb2cdfff 179 _cur_analog_snapshots;
009e1503 180
3b68d03d 181 std::thread _sampling_thread;
2e2946fe 182
009e1503 183signals:
6ac96c2e
JH
184 void capture_state_changed(int state);
185
69dd2b03
JH
186 void signals_changed();
187
82f50b10
JH
188 void frame_began();
189
1f374035
JH
190 void data_received();
191
192 void frame_ended();
2953961c
JH
193
194private:
195 // TODO: This should not be necessary. Multiple concurrent
196 // sessions should should be supported and it should be
197 // possible to associate a pointer with a sr_session.
04abfae9 198 static SigSession *_session;
2953961c
JH
199};
200
51e77110
JH
201} // namespace pv
202
640d091b 203#endif // PULSEVIEW_PV_SIGSESSION_H