]> sigrok.org Git - pulseview.git/blame_incremental - pv/session.hpp
Move signals to views and make Session handle multiple views
[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 boost/thread namespace pollution (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
43#include "util.hpp"
44
45struct srd_decoder;
46struct srd_channel;
47
48namespace sigrok {
49class Analog;
50class Channel;
51class Device;
52class Logic;
53class Meta;
54class Packet;
55class Session;
56}
57
58namespace pv {
59
60class DeviceManager;
61
62namespace data {
63class Analog;
64class AnalogSegment;
65class Logic;
66class LogicSegment;
67class SignalBase;
68class SignalData;
69}
70
71namespace devices {
72class Device;
73}
74
75namespace view {
76class DecodeTrace;
77class View;
78}
79
80class Session : public QObject
81{
82 Q_OBJECT
83
84public:
85 enum capture_state {
86 Stopped,
87 AwaitingTrigger,
88 Running
89 };
90
91public:
92 Session(DeviceManager &device_manager);
93
94 ~Session();
95
96 DeviceManager& device_manager();
97
98 const DeviceManager& device_manager() const;
99
100 std::shared_ptr<sigrok::Session> session() const;
101
102 std::shared_ptr<devices::Device> device() const;
103
104 /**
105 * Sets device instance that will be used in the next capture session.
106 */
107 void set_device(std::shared_ptr<devices::Device> device);
108
109 void set_default_device();
110
111 capture_state get_capture_state() const;
112
113 void start_capture(std::function<void (const QString)> error_handler);
114
115 void stop_capture();
116
117 double get_samplerate() const;
118
119 void register_view(std::shared_ptr<pv::view::View> view);
120
121 void deregister_view(std::shared_ptr<pv::view::View> view);
122
123 const std::unordered_set< std::shared_ptr<data::SignalBase> >
124 signalbases() const;
125
126#ifdef ENABLE_DECODE
127 bool add_decoder(srd_decoder *const dec);
128
129 std::vector< std::shared_ptr<view::DecodeTrace> >
130 get_decode_signals() const;
131
132 void remove_decode_signal(view::DecodeTrace *signal);
133#endif
134
135private:
136 void set_capture_state(capture_state state);
137
138 void update_signals();
139
140 std::shared_ptr<data::SignalBase> signalbase_from_channel(
141 std::shared_ptr<sigrok::Channel> channel) const;
142
143private:
144 void sample_thread_proc(std::function<void (const QString)> error_handler);
145
146 void feed_in_header();
147
148 void feed_in_meta(std::shared_ptr<sigrok::Meta> meta);
149
150 void feed_in_trigger();
151
152 void feed_in_frame_begin();
153
154 void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
155
156 void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
157
158 void data_feed_in(std::shared_ptr<sigrok::Device> device,
159 std::shared_ptr<sigrok::Packet> packet);
160
161private:
162 DeviceManager &device_manager_;
163 std::shared_ptr<devices::Device> device_;
164
165 std::unordered_set< std::shared_ptr<pv::view::View> > views_;
166
167 std::vector< std::shared_ptr<view::DecodeTrace> > decode_traces_;
168
169 mutable std::mutex sampling_mutex_; //!< Protects access to capture_state_.
170 capture_state capture_state_;
171
172
173 std::unordered_set< std::shared_ptr<data::SignalBase> > signalbases_;
174 std::unordered_set< std::shared_ptr<data::SignalData> > all_signal_data_;
175
176 mutable std::recursive_mutex data_mutex_;
177 std::shared_ptr<data::Logic> logic_data_;
178 uint64_t cur_samplerate_;
179 std::shared_ptr<data::LogicSegment> cur_logic_segment_;
180 std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSegment> >
181 cur_analog_segments_;
182
183 std::thread sampling_thread_;
184
185 bool out_of_memory_;
186
187Q_SIGNALS:
188 void capture_state_changed(int state);
189 void device_selected();
190
191 void signals_changed();
192
193 void trigger_event(util::Timestamp location);
194
195 void frame_began();
196
197 void data_received();
198
199 void frame_ended();
200};
201
202} // namespace pv
203
204#endif // PULSEVIEW_PV_SESSION_HPP