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