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_SESSION_HPP
22 #define PULSEVIEW_PV_SESSION_HPP
30 #include <unordered_set>
34 // Windows: Avoid boost/thread namespace pollution (which includes windows.h).
38 #include <boost/thread/shared_mutex.hpp>
45 #include "view/viewwidget.hpp"
85 class Session : public QObject
97 Session(DeviceManager &device_manager, QString name);
101 DeviceManager& device_manager();
103 const DeviceManager& device_manager() const;
105 std::shared_ptr<sigrok::Session> session() const;
107 std::shared_ptr<devices::Device> device() const;
109 QString name() const;
111 void set_name(QString name);
113 const std::list< std::shared_ptr<pv::view::View> > views() const;
115 std::shared_ptr<pv::view::View> main_view() const;
117 void set_main_bar(std::shared_ptr<pv::toolbars::MainBar> main_bar);
119 std::shared_ptr<pv::toolbars::MainBar> main_bar() const;
121 void save_settings(QSettings &settings) const;
123 void restore_settings(QSettings &settings);
126 * Sets device instance that will be used in the next capture session.
128 void set_device(std::shared_ptr<devices::Device> device);
130 void set_default_device();
132 capture_state get_capture_state() const;
134 void start_capture(std::function<void (const QString)> error_handler);
138 double get_samplerate() const;
140 void register_view(std::shared_ptr<pv::view::View> view);
142 void deregister_view(std::shared_ptr<pv::view::View> view);
144 bool has_view(std::shared_ptr<pv::view::View> view);
146 const std::unordered_set< std::shared_ptr<data::SignalBase> >
150 bool add_decoder(srd_decoder *const dec);
152 void remove_decode_signal(std::shared_ptr<data::SignalBase> signalbase);
156 void set_capture_state(capture_state state);
158 void update_signals();
160 std::shared_ptr<data::SignalBase> signalbase_from_channel(
161 std::shared_ptr<sigrok::Channel> channel) const;
164 void sample_thread_proc(std::function<void (const QString)> error_handler);
166 void feed_in_header();
168 void feed_in_meta(std::shared_ptr<sigrok::Meta> meta);
170 void feed_in_trigger();
172 void feed_in_frame_begin();
174 void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
176 void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
178 void data_feed_in(std::shared_ptr<sigrok::Device> device,
179 std::shared_ptr<sigrok::Packet> packet);
182 DeviceManager &device_manager_;
183 std::shared_ptr<devices::Device> device_;
184 QString default_name_, name_;
186 std::list< std::shared_ptr<pv::view::View> > views_;
187 std::shared_ptr<pv::view::View> main_view_;
189 std::shared_ptr<pv::toolbars::MainBar> main_bar_;
191 mutable std::mutex sampling_mutex_; //!< Protects access to capture_state_.
192 capture_state capture_state_;
194 std::unordered_set< std::shared_ptr<data::SignalBase> > signalbases_;
195 std::unordered_set< std::shared_ptr<data::SignalData> > all_signal_data_;
197 mutable std::recursive_mutex data_mutex_;
198 std::shared_ptr<data::Logic> logic_data_;
199 uint64_t cur_samplerate_;
200 std::shared_ptr<data::LogicSegment> cur_logic_segment_;
201 std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSegment> >
202 cur_analog_segments_;
204 std::thread sampling_thread_;
209 void capture_state_changed(int state);
210 void device_changed();
212 void signals_changed();
216 void trigger_event(util::Timestamp location);
220 void data_received();
224 void add_view(const QString &title, view::ViewType type,
230 #endif // PULSEVIEW_PV_SESSION_HPP