]> sigrok.org Git - pulseview.git/blob - pv/devices/device.cpp
Don't use std:: in the code directly (where possible).
[pulseview.git] / pv / devices / device.cpp
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
26 using std::map;
27 using std::set;
28 using std::shared_ptr;
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
40 Device::~Device()
41 {
42         if (session_)
43                 session_->remove_datafeed_callbacks();
44 }
45
46 shared_ptr<sigrok::Session> Device::session() const
47 {
48         return session_;
49 }
50
51 shared_ptr<sigrok::Device> Device::device() const
52 {
53         return device_;
54 }
55
56 template
57 uint64_t Device::read_config(const sigrok::ConfigKey*,
58         const uint64_t);
59
60 template<typename T>
61 T 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
75 void Device::start()
76 {
77         assert(session_);
78         session_->start();
79 }
80
81 void Device::run()
82 {
83         assert(device_);
84         assert(session_);
85         session_->run();
86 }
87
88 void Device::stop()
89 {
90         assert(session_);
91         session_->stop();
92 }
93
94 } // namespace devices
95 } // namespace pv