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 "views/viewbase.hpp"
87 class Session : public QObject
99 Session(DeviceManager &device_manager, QString name);
103 DeviceManager& device_manager();
105 const DeviceManager& device_manager() const;
107 std::shared_ptr<sigrok::Session> session() const;
109 std::shared_ptr<devices::Device> device() const;
111 QString name() const;
113 void set_name(QString name);
115 const std::list< std::shared_ptr<views::ViewBase> > views() const;
117 std::shared_ptr<views::ViewBase> main_view() const;
119 std::shared_ptr<pv::toolbars::MainBar> main_bar() const;
121 void set_main_bar(std::shared_ptr<pv::toolbars::MainBar> main_bar);
123 void save_settings(QSettings &settings) const;
125 void restore_settings(QSettings &settings);
128 * Attempts to set device instance, may fall back to demo if needed
130 void select_device(std::shared_ptr<devices::Device> device);
133 * Sets device instance that will be used in the next capture session.
135 void set_device(std::shared_ptr<devices::Device> device);
137 void set_default_device();
139 void load_init_file(const std::string &file_name,
140 const std::string &format);
142 void load_file(QString file_name,
143 std::shared_ptr<sigrok::InputFormat> format = nullptr,
144 const std::map<std::string, Glib::VariantBase> &options =
145 std::map<std::string, Glib::VariantBase>());
147 capture_state get_capture_state() const;
149 void start_capture(std::function<void (const QString)> error_handler);
153 double get_samplerate() const;
155 void register_view(std::shared_ptr<views::ViewBase> view);
157 void deregister_view(std::shared_ptr<views::ViewBase> view);
159 bool has_view(std::shared_ptr<views::ViewBase> view);
161 const std::unordered_set< std::shared_ptr<data::SignalBase> >
165 bool add_decoder(srd_decoder *const dec);
167 void remove_decode_signal(std::shared_ptr<data::SignalBase> signalbase);
171 void set_capture_state(capture_state state);
173 void update_signals();
175 std::shared_ptr<data::SignalBase> signalbase_from_channel(
176 std::shared_ptr<sigrok::Channel> channel) const;
179 void sample_thread_proc(std::function<void (const QString)> error_handler);
181 void feed_in_header();
183 void feed_in_meta(std::shared_ptr<sigrok::Meta> meta);
185 void feed_in_trigger();
187 void feed_in_frame_begin();
189 void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
191 void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
193 void data_feed_in(std::shared_ptr<sigrok::Device> device,
194 std::shared_ptr<sigrok::Packet> packet);
197 DeviceManager &device_manager_;
198 std::shared_ptr<devices::Device> device_;
199 QString default_name_, name_;
201 std::list< std::shared_ptr<views::ViewBase> > views_;
202 std::shared_ptr<pv::views::ViewBase> main_view_;
204 std::shared_ptr<pv::toolbars::MainBar> main_bar_;
206 mutable std::mutex sampling_mutex_; //!< Protects access to capture_state_.
207 capture_state capture_state_;
209 std::unordered_set< std::shared_ptr<data::SignalBase> > signalbases_;
210 std::unordered_set< std::shared_ptr<data::SignalData> > all_signal_data_;
212 mutable std::recursive_mutex data_mutex_;
213 std::shared_ptr<data::Logic> logic_data_;
214 uint64_t cur_samplerate_;
215 std::shared_ptr<data::LogicSegment> cur_logic_segment_;
216 std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSegment> >
217 cur_analog_segments_;
219 std::thread sampling_thread_;
224 void capture_state_changed(int state);
225 void device_changed();
227 void signals_changed();
231 void trigger_event(util::Timestamp location);
235 void data_received();
239 void add_view(const QString &title, views::ViewType type,
245 #endif // PULSEVIEW_PV_SESSION_HPP