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, see <http://www.gnu.org/licenses/>.
20 #ifndef PULSEVIEW_PV_SESSION_HPP
21 #define PULSEVIEW_PV_SESSION_HPP
29 #include <unordered_set>
33 // Windows: Avoid boost/thread namespace pollution (which includes windows.h).
37 #include <boost/thread/shared_mutex.hpp>
44 #include "views/viewbase.hpp"
86 class Session : public QObject
98 Session(DeviceManager &device_manager, QString name);
102 DeviceManager& device_manager();
104 const DeviceManager& device_manager() const;
106 std::shared_ptr<sigrok::Session> session() const;
108 std::shared_ptr<devices::Device> device() const;
110 QString name() const;
112 void set_name(QString name);
114 const std::list< std::shared_ptr<views::ViewBase> > views() const;
116 std::shared_ptr<views::ViewBase> main_view() const;
118 std::shared_ptr<pv::toolbars::MainBar> main_bar() const;
120 void set_main_bar(std::shared_ptr<pv::toolbars::MainBar> main_bar);
123 * Indicates whether the captured data was saved to disk already or not
125 bool data_saved() const;
127 void save_settings(QSettings &settings) const;
129 void restore_settings(QSettings &settings);
132 * Attempts to set device instance, may fall back to demo if needed
134 void select_device(std::shared_ptr<devices::Device> device);
137 * Sets device instance that will be used in the next capture session.
139 void set_device(std::shared_ptr<devices::Device> device);
141 void set_default_device();
143 void load_init_file(const std::string &file_name,
144 const std::string &format);
146 void load_file(QString file_name,
147 std::shared_ptr<sigrok::InputFormat> format = nullptr,
148 const std::map<std::string, Glib::VariantBase> &options =
149 std::map<std::string, Glib::VariantBase>());
151 capture_state get_capture_state() const;
153 void start_capture(std::function<void (const QString)> error_handler);
157 double get_samplerate() const;
159 void register_view(std::shared_ptr<views::ViewBase> view);
161 void deregister_view(std::shared_ptr<views::ViewBase> view);
163 bool has_view(std::shared_ptr<views::ViewBase> view);
165 const std::unordered_set< std::shared_ptr<data::SignalBase> >
169 bool add_decoder(srd_decoder *const dec);
171 void remove_decode_signal(std::shared_ptr<data::SignalBase> signalbase);
175 void set_capture_state(capture_state state);
177 void update_signals();
179 std::shared_ptr<data::SignalBase> signalbase_from_channel(
180 std::shared_ptr<sigrok::Channel> channel) const;
183 void sample_thread_proc(std::function<void (const QString)> error_handler);
185 void free_unused_memory();
187 void feed_in_header();
189 void feed_in_meta(std::shared_ptr<sigrok::Meta> meta);
191 void feed_in_trigger();
193 void feed_in_frame_begin();
195 void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
197 void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
199 void data_feed_in(std::shared_ptr<sigrok::Device> device,
200 std::shared_ptr<sigrok::Packet> packet);
203 DeviceManager &device_manager_;
204 std::shared_ptr<devices::Device> device_;
205 QString default_name_, name_;
207 std::list< std::shared_ptr<views::ViewBase> > views_;
208 std::shared_ptr<pv::views::ViewBase> main_view_;
210 std::shared_ptr<pv::toolbars::MainBar> main_bar_;
212 mutable std::mutex sampling_mutex_; //!< Protects access to capture_state_.
213 capture_state capture_state_;
215 std::unordered_set< std::shared_ptr<data::SignalBase> > signalbases_;
216 std::unordered_set< std::shared_ptr<data::SignalData> > all_signal_data_;
218 mutable std::recursive_mutex data_mutex_;
219 std::shared_ptr<data::Logic> logic_data_;
220 uint64_t cur_samplerate_;
221 std::shared_ptr<data::LogicSegment> cur_logic_segment_;
222 std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSegment> >
223 cur_analog_segments_;
225 std::thread sampling_thread_;
231 void capture_state_changed(int state);
232 void device_changed();
234 void signals_changed();
238 void trigger_event(util::Timestamp location);
242 void data_received();
246 void add_view(const QString &title, views::ViewType type,
250 void on_data_saved();
255 #endif // PULSEVIEW_PV_SESSION_HPP