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
35 #include <libsigrok/libsigrok.h>
62 class SigSession : public QObject
74 SigSession(DeviceManager &device_manager);
78 std::shared_ptr<device::DevInst> get_device() const;
81 * Sets device instance that will be used in the next capture session.
83 void set_device(std::shared_ptr<device::DevInst> dev_inst)
86 void set_file(const std::string &name)
89 void set_default_device();
91 void release_device(device::DevInst *dev_inst);
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<device::DevInst> dev_inst);
118 std::shared_ptr<view::Signal> signal_from_channel(
119 const sr_channel *channel) const;
121 void read_sample_rate(const sr_dev_inst *const sdi);
124 void sample_thread_proc(std::shared_ptr<device::DevInst> dev_inst,
125 std::function<void (const QString)> error_handler);
127 void feed_in_header(const sr_dev_inst *sdi);
129 void feed_in_meta(const sr_dev_inst *sdi,
130 const sr_datafeed_meta &meta);
132 void feed_in_frame_begin();
134 void feed_in_logic(const sr_datafeed_logic &logic);
136 void feed_in_analog(const sr_datafeed_analog &analog);
138 void data_feed_in(const struct sr_dev_inst *sdi,
139 const struct sr_datafeed_packet *packet);
141 static void data_feed_in_proc(const struct sr_dev_inst *sdi,
142 const struct sr_datafeed_packet *packet, void *cb_data);
145 DeviceManager &_device_manager;
148 * The device instance that will be used in the next capture session.
150 std::shared_ptr<device::DevInst> _dev_inst;
152 std::vector< std::shared_ptr<view::DecodeTrace> > _decode_traces;
154 mutable std::mutex _sampling_mutex;
155 capture_state _capture_state;
157 mutable std::mutex _signals_mutex;
158 std::vector< std::shared_ptr<view::Signal> > _signals;
160 mutable std::mutex _data_mutex;
161 std::shared_ptr<data::Logic> _logic_data;
162 std::shared_ptr<data::LogicSnapshot> _cur_logic_snapshot;
163 std::map< const sr_channel*, std::shared_ptr<data::AnalogSnapshot> >
164 _cur_analog_snapshots;
166 std::thread _sampling_thread;
169 void capture_state_changed(int state);
171 void signals_changed();
175 void data_received();
180 // TODO: This should not be necessary. Multiple concurrent
181 // sessions should should be supported and it should be
182 // possible to associate a pointer with a sr_session.
183 static SigSession *_session;
186 // TODO: Even more of a hack. The libsigrok API now allows for
187 // multiple sessions. However sr_session_* calls are scattered
188 // around the PV architecture and a single SigSession object is
189 // being used across multiple sequential sessions, which are
190 // created and destroyed in other classes in pv::device. This
191 // is a mess. For now just keep a single sr_session pointer here
192 // which we can use for all those scattered calls.
193 static struct sr_session *_sr_session;
198 #endif // PULSEVIEW_PV_SIGSESSION_H