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_probe(
119 const sr_channel *probe) const;
121 void read_sample_rate(const sr_dev_inst *const sdi);
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
131 static sr_input_format* determine_input_file_format(
132 const std::string &filename);
134 static sr_input* load_input_file_format(
135 const std::string &filename,
136 std::function<void (const QString)> error_handler,
137 sr_input_format *format = NULL);
139 void sample_thread_proc(std::shared_ptr<device::DevInst> dev_inst,
140 std::function<void (const QString)> error_handler);
142 void feed_in_header(const sr_dev_inst *sdi);
144 void feed_in_meta(const sr_dev_inst *sdi,
145 const sr_datafeed_meta &meta);
147 void feed_in_frame_begin();
149 void feed_in_logic(const sr_datafeed_logic &logic);
151 void feed_in_analog(const sr_datafeed_analog &analog);
153 void data_feed_in(const struct sr_dev_inst *sdi,
154 const struct sr_datafeed_packet *packet);
156 static void data_feed_in_proc(const struct sr_dev_inst *sdi,
157 const struct sr_datafeed_packet *packet, void *cb_data);
160 DeviceManager &_device_manager;
163 * The device instance that will be used in the next capture session.
165 std::shared_ptr<device::DevInst> _dev_inst;
167 std::vector< std::shared_ptr<view::DecodeTrace> > _decode_traces;
169 mutable std::mutex _sampling_mutex;
170 capture_state _capture_state;
172 mutable std::mutex _signals_mutex;
173 std::vector< std::shared_ptr<view::Signal> > _signals;
175 mutable std::mutex _data_mutex;
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> >
179 _cur_analog_snapshots;
181 std::thread _sampling_thread;
184 void capture_state_changed(int state);
186 void signals_changed();
190 void data_received();
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.
198 static SigSession *_session;
201 // TODO: Even more of a hack. The libsigrok API now allows for
202 // multiple sessions. However sr_session_* calls are scattered
203 // around the PV architecture and a single SigSession object is
204 // being used across multiple sequential sessions, which are
205 // created and destroyed in other classes in pv::device. This
206 // is a mess. For now just keep a single sr_session pointer here
207 // which we can use for all those scattered calls.
208 static struct sr_session *_sr_session;
213 #endif // PULSEVIEW_PV_SIGSESSION_H