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>
81 class Session : public QObject
93 Session(DeviceManager &device_manager);
97 DeviceManager& device_manager();
99 const DeviceManager& device_manager() const;
101 std::shared_ptr<sigrok::Session> session() const;
103 std::shared_ptr<devices::Device> device() const;
106 * Sets device instance that will be used in the next capture session.
108 void set_device(std::shared_ptr<devices::Device> device);
110 void set_default_device();
112 capture_state get_capture_state() const;
114 void start_capture(std::function<void (const QString)> error_handler);
118 double get_samplerate() const;
120 const std::unordered_set< std::shared_ptr<view::Signal> >
124 bool add_decoder(srd_decoder *const dec);
126 std::vector< std::shared_ptr<view::DecodeTrace> >
127 get_decode_signals() const;
129 void remove_decode_signal(view::DecodeTrace *signal);
133 void set_capture_state(capture_state state);
135 void update_signals();
137 std::shared_ptr<data::SignalBase> signal_from_channel(
138 std::shared_ptr<sigrok::Channel> channel) const;
141 void sample_thread_proc(std::function<void (const QString)> error_handler);
143 void feed_in_header();
145 void feed_in_meta(std::shared_ptr<sigrok::Meta> meta);
147 void feed_in_trigger();
149 void feed_in_frame_begin();
151 void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
153 void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
155 void data_feed_in(std::shared_ptr<sigrok::Device> device,
156 std::shared_ptr<sigrok::Packet> packet);
159 DeviceManager &device_manager_;
160 std::shared_ptr<devices::Device> device_;
162 std::vector< std::shared_ptr<view::DecodeTrace> > decode_traces_;
164 mutable std::mutex sampling_mutex_; //!< Protects access to capture_state_.
165 capture_state capture_state_;
167 mutable boost::shared_mutex signals_mutex_;
168 std::unordered_set< std::shared_ptr<view::Signal> > signals_;
170 std::set< std::shared_ptr<data::SignalBase> > signalbases_;
171 std::set< std::shared_ptr<data::SignalData> > all_signal_data_;
173 mutable std::recursive_mutex data_mutex_;
174 std::shared_ptr<data::Logic> logic_data_;
175 uint64_t cur_samplerate_;
176 std::shared_ptr<data::LogicSegment> cur_logic_segment_;
177 std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSegment> >
178 cur_analog_segments_;
180 std::thread sampling_thread_;
185 void capture_state_changed(int state);
186 void device_selected();
188 void signals_changed();
190 void trigger_event(util::Timestamp location);
194 void data_received();
201 #endif // PULSEVIEW_PV_SESSION_HPP