]> sigrok.org Git - pulseview.git/blame_incremental - pv/session.hpp
ViewItem: Make select virtual
[pulseview.git] / pv / session.hpp
... / ...
CommitLineData
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2012-14 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
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.
10 *
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.
15 *
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
19 */
20
21#ifndef PULSEVIEW_PV_SESSION_HPP
22#define PULSEVIEW_PV_SESSION_HPP
23
24#include <map>
25#include <memory>
26#include <mutex>
27#include <set>
28#include <string>
29#include <thread>
30#include <unordered_set>
31#include <vector>
32
33#ifdef _WIN32
34// Windows: Avoid namespace pollution by thread.hpp (which includes windows.h).
35#define NOGDI
36#define NORESOURCE
37#endif
38#include <boost/thread/shared_mutex.hpp>
39
40#include <QObject>
41#include <QString>
42
43struct srd_decoder;
44struct srd_channel;
45
46namespace sigrok {
47class Analog;
48class Channel;
49class Device;
50class Logic;
51class Meta;
52class Packet;
53class Session;
54}
55
56namespace pv {
57
58class DeviceManager;
59
60namespace data {
61class Analog;
62class AnalogSegment;
63class Logic;
64class LogicSegment;
65class SignalData;
66}
67
68namespace devices {
69class Device;
70}
71
72namespace view {
73class DecodeTrace;
74class LogicSignal;
75class Signal;
76}
77
78class Session : public QObject
79{
80 Q_OBJECT
81
82public:
83 enum capture_state {
84 Stopped,
85 AwaitingTrigger,
86 Running
87 };
88
89public:
90 Session(DeviceManager &device_manager);
91
92 ~Session();
93
94 DeviceManager& device_manager();
95
96 const DeviceManager& device_manager() const;
97
98 std::shared_ptr<sigrok::Session> session() const;
99
100 std::shared_ptr<devices::Device> device() const;
101
102 /**
103 * Sets device instance that will be used in the next capture session.
104 */
105 void set_device(std::shared_ptr<devices::Device> device);
106
107 void set_default_device();
108
109 capture_state get_capture_state() const;
110
111 void start_capture(std::function<void (const QString)> error_handler);
112
113 void stop_capture();
114
115 std::set< std::shared_ptr<data::SignalData> > get_data() const;
116
117 const std::unordered_set< std::shared_ptr<view::Signal> >
118 signals() const;
119
120#ifdef ENABLE_DECODE
121 bool add_decoder(srd_decoder *const dec);
122
123 std::vector< std::shared_ptr<view::DecodeTrace> >
124 get_decode_signals() const;
125
126 void remove_decode_signal(view::DecodeTrace *signal);
127#endif
128
129private:
130 void set_capture_state(capture_state state);
131
132 void update_signals();
133
134 std::shared_ptr<view::Signal> signal_from_channel(
135 std::shared_ptr<sigrok::Channel> channel) const;
136
137private:
138 void sample_thread_proc(std::shared_ptr<devices::Device> device,
139 std::function<void (const QString)> error_handler);
140
141 void feed_in_header();
142
143 void feed_in_meta(std::shared_ptr<sigrok::Meta> meta);
144
145 void feed_in_frame_begin();
146
147 void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
148
149 void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
150
151 void data_feed_in(std::shared_ptr<sigrok::Device> device,
152 std::shared_ptr<sigrok::Packet> packet);
153
154private:
155 DeviceManager &device_manager_;
156 std::shared_ptr<devices::Device> device_;
157
158 std::vector< std::shared_ptr<view::DecodeTrace> > decode_traces_;
159
160 mutable std::mutex sampling_mutex_;
161 capture_state capture_state_;
162
163 mutable boost::shared_mutex signals_mutex_;
164 std::unordered_set< std::shared_ptr<view::Signal> > signals_;
165
166 mutable std::recursive_mutex data_mutex_;
167 std::shared_ptr<data::Logic> logic_data_;
168 uint64_t cur_samplerate_;
169 std::shared_ptr<data::LogicSegment> cur_logic_segment_;
170 std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSegment> >
171 cur_analog_segments_;
172
173 std::thread sampling_thread_;
174
175 bool out_of_memory_;
176
177Q_SIGNALS:
178 void capture_state_changed(int state);
179 void device_selected();
180
181 void signals_changed();
182
183 void frame_began();
184
185 void data_received();
186
187 void frame_ended();
188};
189
190} // namespace pv
191
192#endif // PULSEVIEW_PV_SESSION_HPP