]> sigrok.org Git - pulseview.git/blame - pv/devices/device.cpp
Don't use std:: in the code directly (where possible).
[pulseview.git] / pv / devices / device.cpp
CommitLineData
da30ecb7
JH
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
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
da30ecb7
JH
18 */
19
20#include <cassert>
21
22#include <libsigrokcxx/libsigrokcxx.hpp>
23
24#include "device.hpp"
25
b48daed6
JH
26using std::map;
27using std::set;
6f925ba9 28using std::shared_ptr;
b48daed6
JH
29
30using sigrok::ConfigKey;
7bb0fbf4 31using sigrok::Capability;
b48daed6
JH
32using sigrok::Error;
33
34using Glib::VariantBase;
35using Glib::Variant;
36
da30ecb7
JH
37namespace pv {
38namespace devices {
39
2ad82c2e
UH
40Device::~Device()
41{
da30ecb7
JH
42 if (session_)
43 session_->remove_datafeed_callbacks();
44}
45
6f925ba9 46shared_ptr<sigrok::Session> Device::session() const
2ad82c2e 47{
da30ecb7
JH
48 return session_;
49}
50
6f925ba9 51shared_ptr<sigrok::Device> Device::device() const
2ad82c2e 52{
da30ecb7
JH
53 return device_;
54}
55
b48daed6
JH
56template
57uint64_t Device::read_config(const sigrok::ConfigKey*,
58 const uint64_t);
59
60template<typename T>
61T Device::read_config(const ConfigKey *key, const T default_value)
62{
63 assert(key);
b48daed6
JH
64
65 if (!device_)
66 return default_value;
67
7bb0fbf4 68 if (!device_->config_check(key, Capability::GET))
b48daed6
JH
69 return default_value;
70
05b22769 71 return VariantBase::cast_dynamic<Glib::Variant<guint64>>(
b48daed6
JH
72 device_->config_get(ConfigKey::SAMPLERATE)).get();
73}
74
2ad82c2e
UH
75void Device::start()
76{
5237f0c5
JH
77 assert(session_);
78 session_->start();
79}
80
2ad82c2e
UH
81void Device::run()
82{
da30ecb7
JH
83 assert(device_);
84 assert(session_);
85 session_->run();
86}
87
2ad82c2e
UH
88void Device::stop()
89{
da30ecb7
JH
90 assert(session_);
91 session_->stop();
92}
93
94} // namespace devices
95} // namespace pv