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