PulseView  0.3.0
A Qt-based sigrok GUI
device.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2015 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 #include <cassert>
22 
23 #include <libsigrokcxx/libsigrokcxx.hpp>
24 
25 #include "device.hpp"
26 
27 using std::map;
28 using std::set;
29 
30 using sigrok::ConfigKey;
31 using sigrok::Capability;
32 using sigrok::Error;
33 
34 using Glib::VariantBase;
35 using Glib::Variant;
36 
37 namespace pv {
38 namespace devices {
39 
41 {
42 }
43 
45 {
46  if (session_)
47  session_->remove_datafeed_callbacks();
48 }
49 
50 std::shared_ptr<sigrok::Session> Device::session() const
51 {
52  return session_;
53 }
54 
55 std::shared_ptr<sigrok::Device> Device::device() const
56 {
57  return device_;
58 }
59 
60 template
61 uint64_t Device::read_config(const sigrok::ConfigKey*,
62  const uint64_t);
63 
64 template<typename T>
65 T Device::read_config(const ConfigKey *key, const T default_value)
66 {
67  assert(key);
68 
69  if (!device_)
70  return default_value;
71 
72  if (!device_->config_check(key, Capability::GET))
73  return default_value;
74 
75  return VariantBase::cast_dynamic<Glib::Variant<guint64>>(
76  device_->config_get(ConfigKey::SAMPLERATE)).get();
77 }
78 
80 {
81  assert(session_);
82  session_->start();
83 }
84 
86 {
87  assert(device_);
88  assert(session_);
89  session_->run();
90 }
91 
93 {
94  assert(session_);
95  session_->stop();
96 }
97 
98 } // namespace devices
99 } // namespace pv
virtual void stop()
Definition: device.cpp:92
virtual void run()
Definition: device.cpp:85
std::shared_ptr< sigrok::Device > device() const
Definition: device.cpp:55
virtual ~Device()
Definition: device.cpp:44
T read_config(const sigrok::ConfigKey *key, const T default_value=0)
std::shared_ptr< sigrok::Session > session_
Definition: device.hpp:78
std::shared_ptr< sigrok::Session > session() const
Definition: device.cpp:50
std::shared_ptr< sigrok::Device > device_
Definition: device.hpp:79
virtual void start()
Definition: device.cpp:79