]> sigrok.org Git - pulseview.git/blame_incremental - pv/session.hpp
CursorPair: Moved in ViewportFillColour
[pulseview.git] / pv / session.hpp
... / ...
CommitLineData
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2012-14 Joel Holdsworth <joel@airwebreathe.org.uk>
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
21#ifndef PULSEVIEW_PV_SIGSESSION_H
22#define PULSEVIEW_PV_SIGSESSION_H
23
24#include <map>
25#include <memory>
26#include <mutex>
27#include <set>
28#include <string>
29#include <thread>
30#include <vector>
31
32#include <boost/thread.hpp>
33
34#include <QObject>
35#include <QString>
36
37struct srd_decoder;
38struct srd_channel;
39
40namespace sigrok {
41 class Analog;
42 class Channel;
43 class Device;
44 class Logic;
45 class Meta;
46 class Packet;
47 class Session;
48}
49
50namespace pv {
51
52class DeviceManager;
53
54namespace data {
55class Analog;
56class AnalogSegment;
57class Logic;
58class LogicSegment;
59class SignalData;
60}
61
62namespace view {
63class DecodeTrace;
64class LogicSignal;
65class Signal;
66}
67
68class Session : public QObject
69{
70 Q_OBJECT
71
72public:
73 enum capture_state {
74 Stopped,
75 AwaitingTrigger,
76 Running
77 };
78
79public:
80 Session(DeviceManager &device_manager);
81
82 ~Session();
83
84 DeviceManager& device_manager();
85
86 const DeviceManager& device_manager() const;
87
88 const std::shared_ptr<sigrok::Session>& session() const;
89
90 std::shared_ptr<sigrok::Device> device() const;
91
92 /**
93 * Sets device instance that will be used in the next capture session.
94 */
95 void set_device(std::shared_ptr<sigrok::Device> device);
96
97 void set_file(const std::string &name);
98
99 void set_default_device();
100
101 capture_state get_capture_state() const;
102
103 void start_capture(std::function<void (const QString)> error_handler);
104
105 void stop_capture();
106
107 std::set< std::shared_ptr<data::SignalData> > get_data() const;
108
109 boost::shared_mutex& signals_mutex() const;
110
111 const std::vector< std::shared_ptr<view::Signal> >& signals() const;
112
113#ifdef ENABLE_DECODE
114 bool add_decoder(srd_decoder *const dec);
115
116 std::vector< std::shared_ptr<view::DecodeTrace> >
117 get_decode_signals() const;
118
119 void remove_decode_signal(view::DecodeTrace *signal);
120#endif
121
122private:
123 void set_capture_state(capture_state state);
124
125 void update_signals(std::shared_ptr<sigrok::Device> device);
126
127 std::shared_ptr<view::Signal> signal_from_channel(
128 std::shared_ptr<sigrok::Channel> channel) const;
129
130 void read_sample_rate(std::shared_ptr<sigrok::Device>);
131
132private:
133 void sample_thread_proc(std::shared_ptr<sigrok::Device> device,
134 std::function<void (const QString)> error_handler);
135
136 void feed_in_header(std::shared_ptr<sigrok::Device> device);
137
138 void feed_in_meta(std::shared_ptr<sigrok::Device> device,
139 std::shared_ptr<sigrok::Meta> meta);
140
141 void feed_in_frame_begin();
142
143 void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
144
145 void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
146
147 void data_feed_in(std::shared_ptr<sigrok::Device> device,
148 std::shared_ptr<sigrok::Packet> packet);
149
150private:
151 DeviceManager &device_manager_;
152 std::shared_ptr<sigrok::Session> session_;
153
154 /**
155 * The device instance that will be used in the next capture session.
156 */
157 std::shared_ptr<sigrok::Device> device_;
158
159 std::vector< std::shared_ptr<view::DecodeTrace> > decode_traces_;
160
161 mutable std::mutex sampling_mutex_;
162 capture_state capture_state_;
163
164 mutable boost::shared_mutex signals_mutex_;
165 std::vector< std::shared_ptr<view::Signal> > signals_;
166
167 mutable std::mutex data_mutex_;
168 std::shared_ptr<data::Logic> logic_data_;
169 uint64_t cur_samplerate_;
170 std::shared_ptr<data::LogicSegment> cur_logic_segment_;
171 std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSegment> >
172 cur_analog_segments_;
173
174 std::thread sampling_thread_;
175
176Q_SIGNALS:
177 void capture_state_changed(int state);
178 void device_selected();
179
180 void signals_changed();
181
182 void frame_began();
183
184 void data_received();
185
186 void frame_ended();
187};
188
189} // namespace pv
190
191#endif // PULSEVIEW_PV_SIGSESSION_H