2 * This file is part of the PulseView project.
4 * Copyright (C) 2012-14 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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
21 #ifndef PULSEVIEW_PV_SIGSESSION_H
22 #define PULSEVIEW_PV_SIGSESSION_H
66 class SigSession : public QObject
78 SigSession(DeviceManager &device_manager);
82 std::shared_ptr<sigrok::Device> get_device() const;
85 * Sets device instance that will be used in the next capture session.
87 void set_device(std::shared_ptr<sigrok::Device> device);
89 void set_file(const std::string &name);
91 void set_default_device();
93 capture_state get_capture_state() const;
95 void start_capture(std::function<void (const QString)> error_handler);
99 std::set< std::shared_ptr<data::SignalData> > get_data() const;
101 std::vector< std::shared_ptr<view::Signal> >
105 bool add_decoder(srd_decoder *const dec);
107 std::vector< std::shared_ptr<view::DecodeTrace> >
108 get_decode_signals() const;
110 void remove_decode_signal(view::DecodeTrace *signal);
114 void set_capture_state(capture_state state);
116 void update_signals(std::shared_ptr<sigrok::Device> device);
118 std::shared_ptr<view::Signal> signal_from_channel(
119 std::shared_ptr<sigrok::Channel> channel) const;
121 void read_sample_rate(std::shared_ptr<sigrok::Device>);
124 void sample_thread_proc(std::shared_ptr<sigrok::Device> device,
125 std::function<void (const QString)> error_handler);
127 void feed_in_header(std::shared_ptr<sigrok::Device> device);
129 void feed_in_meta(std::shared_ptr<sigrok::Device> device,
130 std::shared_ptr<sigrok::Meta> meta);
132 void feed_in_frame_begin();
134 void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
136 void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
138 void data_feed_in(std::shared_ptr<sigrok::Device> device,
139 std::shared_ptr<sigrok::Packet> packet);
142 DeviceManager &_device_manager;
145 * The device instance that will be used in the next capture session.
147 std::shared_ptr<sigrok::Device> _device;
149 std::vector< std::shared_ptr<view::DecodeTrace> > _decode_traces;
151 mutable std::mutex _sampling_mutex;
152 capture_state _capture_state;
154 mutable std::mutex _signals_mutex;
155 std::vector< std::shared_ptr<view::Signal> > _signals;
157 mutable std::mutex _data_mutex;
158 std::shared_ptr<data::Logic> _logic_data;
159 std::shared_ptr<data::LogicSnapshot> _cur_logic_snapshot;
160 std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSnapshot> >
161 _cur_analog_snapshots;
163 std::thread _sampling_thread;
166 void capture_state_changed(int state);
168 void signals_changed();
172 void data_received();
177 // Hack. The libsigrok API now allows for multiple sessions. However,
178 // sigrok::Session calls are scattered around the PV architecture and a
179 // single SigSession object is being used across multiple sequential
180 // sessions. This is a mess. For now just keep a single sigrok::Session
181 // pointer here which we can use for all those scattered calls.
182 static std::shared_ptr<sigrok::Session> _sr_session;
187 #endif // PULSEVIEW_PV_SIGSESSION_H