PulseView  0.3.0
A Qt-based sigrok GUI
session.hpp
Go to the documentation of this file.
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 
45 struct srd_decoder;
46 struct srd_channel;
47 
48 namespace sigrok {
49 class Analog;
50 class Channel;
51 class Device;
52 class Logic;
53 class Meta;
54 class Packet;
55 class Session;
56 }
57 
58 namespace pv {
59 
60 class DeviceManager;
61 
62 namespace data {
63 class Analog;
64 class AnalogSegment;
65 class Logic;
66 class LogicSegment;
67 class SignalData;
68 }
69 
70 namespace devices {
71 class Device;
72 }
73 
74 namespace view {
75 class DecodeTrace;
76 class LogicSignal;
77 class Signal;
78 }
79 
80 class Session : public QObject
81 {
82  Q_OBJECT
83 
84 public:
89  };
90 
91 public:
93 
94  ~Session();
95 
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 
107  void set_device(std::shared_ptr<devices::Device> device);
108 
109  void set_default_device();
110 
112 
113  void start_capture(std::function<void (const QString)> error_handler);
114 
115  void stop_capture();
116 
117  std::set< std::shared_ptr<data::SignalData> > get_data() const;
118 
119  double get_samplerate() const;
120 
121  const std::unordered_set< std::shared_ptr<view::Signal> >
122  signals() const;
123 
124 #ifdef ENABLE_DECODE
125  bool add_decoder(srd_decoder *const dec);
126 
127  std::vector< std::shared_ptr<view::DecodeTrace> >
128  get_decode_signals() const;
129 
130  void remove_decode_signal(view::DecodeTrace *signal);
131 #endif
132 
133 private:
134  void set_capture_state(capture_state state);
135 
136  void update_signals();
137 
138  std::shared_ptr<view::Signal> signal_from_channel(
139  std::shared_ptr<sigrok::Channel> channel) const;
140 
141 private:
142  void sample_thread_proc(std::shared_ptr<devices::Device> device,
143  std::function<void (const QString)> error_handler);
144 
145  void feed_in_header();
146 
147  void feed_in_meta(std::shared_ptr<sigrok::Meta> meta);
148 
149  void feed_in_trigger();
150 
151  void feed_in_frame_begin();
152 
153  void feed_in_logic(std::shared_ptr<sigrok::Logic> logic);
154 
155  void feed_in_analog(std::shared_ptr<sigrok::Analog> analog);
156 
157  void data_feed_in(std::shared_ptr<sigrok::Device> device,
158  std::shared_ptr<sigrok::Packet> packet);
159 
160 private:
162  std::shared_ptr<devices::Device> device_;
163 
164  std::vector< std::shared_ptr<view::DecodeTrace> > decode_traces_;
165 
166  mutable std::mutex sampling_mutex_;
168 
169  mutable boost::shared_mutex signals_mutex_;
170  std::unordered_set< std::shared_ptr<view::Signal> > signals_;
171 
172  mutable std::recursive_mutex data_mutex_;
173  std::shared_ptr<data::Logic> logic_data_;
174  uint64_t cur_samplerate_;
175  std::shared_ptr<data::LogicSegment> cur_logic_segment_;
176  std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSegment> >
178 
179  std::thread sampling_thread_;
180 
182 
183 Q_SIGNALS:
184  void capture_state_changed(int state);
185  void device_selected();
186 
187  void signals_changed();
188 
189  void trigger_event(util::Timestamp location);
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_SESSION_HPP
void data_received()
void frame_began()
void update_signals()
Definition: session.cpp:334
void feed_in_trigger()
Definition: session.cpp:499
void feed_in_logic(std::shared_ptr< sigrok::Logic > logic)
Definition: session.cpp:526
uint64_t cur_samplerate_
Definition: session.hpp:174
std::shared_ptr< data::LogicSegment > cur_logic_segment_
Definition: session.hpp:175
void signals_changed()
void feed_in_header()
Definition: session.cpp:473
std::thread sampling_thread_
Definition: session.hpp:179
std::mutex sampling_mutex_
Protects access to capture_state_.
Definition: session.hpp:166
void sample_thread_proc(std::shared_ptr< devices::Device > device, std::function< void(const QString)> error_handler)
Definition: session.cpp:438
bool out_of_memory_
Definition: session.hpp:181
void capture_state_changed(int state)
void stop_capture()
Definition: session.cpp:203
std::recursive_mutex data_mutex_
Definition: session.hpp:172
std::shared_ptr< sigrok::Session > session() const
Definition: session.cpp:119
std::map< std::shared_ptr< sigrok::Channel >, std::shared_ptr< data::AnalogSegment > > cur_analog_segments_
Definition: session.hpp:177
std::shared_ptr< view::Signal > signal_from_channel(std::shared_ptr< sigrok::Channel > channel) const
Definition: session.cpp:426
const std::unordered_set< std::shared_ptr< view::Signal > > signals() const
Definition: session.cpp:244
void set_device(std::shared_ptr< devices::Device > device)
Definition: session.cpp:131
std::shared_ptr< data::Logic > logic_data_
Definition: session.hpp:173
std::shared_ptr< devices::Device > device() const
Definition: session.cpp:126
void feed_in_meta(std::shared_ptr< sigrok::Meta > meta)
Definition: session.cpp:478
void feed_in_frame_begin()
Definition: session.cpp:520
double get_samplerate() const
Definition: session.cpp:225
DeviceManager & device_manager()
Definition: session.cpp:109
capture_state get_capture_state() const
Definition: session.cpp:170
DeviceManager & device_manager_
Definition: session.hpp:161
boost::shared_mutex signals_mutex_
Definition: session.hpp:169
void data_feed_in(std::shared_ptr< sigrok::Device > device, std::shared_ptr< sigrok::Packet > packet)
Definition: session.cpp:623
void frame_ended()
void device_selected()
void feed_in_analog(std::shared_ptr< sigrok::Analog > analog)
Definition: session.cpp:562
void set_default_device()
Definition: session.cpp:154
std::unordered_set< std::shared_ptr< view::Signal > > signals_
Definition: session.hpp:170
Session(DeviceManager &device_manager)
Definition: session.cpp:96
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 24 >, boost::multiprecision::et_off > Timestamp
Timestamp type providing yoctosecond resolution.
Definition: util.hpp:58
void set_capture_state(capture_state state)
Definition: session.cpp:320
capture_state capture_state_
Definition: session.hpp:167
std::vector< std::shared_ptr< view::DecodeTrace > > decode_traces_
Definition: session.hpp:164
std::shared_ptr< devices::Device > device_
Definition: session.hpp:162
void start_capture(std::function< void(const QString)> error_handler)
Definition: session.cpp:176
void trigger_event(util::Timestamp location)
std::set< std::shared_ptr< data::SignalData > > get_data() const
Definition: session.cpp:213