]>
Commit | Line | Data |
---|---|---|
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 |
26 | using std::map; |
27 | using std::set; | |
28 | ||
29 | using sigrok::ConfigKey; | |
7bb0fbf4 | 30 | using sigrok::Capability; |
b48daed6 JH |
31 | using sigrok::Error; |
32 | ||
33 | using Glib::VariantBase; | |
34 | using Glib::Variant; | |
35 | ||
da30ecb7 JH |
36 | namespace pv { |
37 | namespace devices { | |
38 | ||
2ad82c2e UH |
39 | Device::~Device() |
40 | { | |
da30ecb7 JH |
41 | if (session_) |
42 | session_->remove_datafeed_callbacks(); | |
43 | } | |
44 | ||
2ad82c2e UH |
45 | std::shared_ptr<sigrok::Session> Device::session() const |
46 | { | |
da30ecb7 JH |
47 | return session_; |
48 | } | |
49 | ||
2ad82c2e UH |
50 | std::shared_ptr<sigrok::Device> Device::device() const |
51 | { | |
da30ecb7 JH |
52 | return device_; |
53 | } | |
54 | ||
b48daed6 JH |
55 | template |
56 | uint64_t Device::read_config(const sigrok::ConfigKey*, | |
57 | const uint64_t); | |
58 | ||
59 | template<typename T> | |
60 | T Device::read_config(const ConfigKey *key, const T default_value) | |
61 | { | |
62 | assert(key); | |
b48daed6 JH |
63 | |
64 | if (!device_) | |
65 | return default_value; | |
66 | ||
7bb0fbf4 | 67 | if (!device_->config_check(key, Capability::GET)) |
b48daed6 JH |
68 | return default_value; |
69 | ||
05b22769 | 70 | return VariantBase::cast_dynamic<Glib::Variant<guint64>>( |
b48daed6 JH |
71 | device_->config_get(ConfigKey::SAMPLERATE)).get(); |
72 | } | |
73 | ||
2ad82c2e UH |
74 | void Device::start() |
75 | { | |
5237f0c5 JH |
76 | assert(session_); |
77 | session_->start(); | |
78 | } | |
79 | ||
2ad82c2e UH |
80 | void Device::run() |
81 | { | |
da30ecb7 JH |
82 | assert(device_); |
83 | assert(session_); | |
84 | session_->run(); | |
85 | } | |
86 | ||
2ad82c2e UH |
87 | void Device::stop() |
88 | { | |
da30ecb7 JH |
89 | assert(session_); |
90 | session_->stop(); | |
91 | } | |
92 | ||
93 | } // namespace devices | |
94 | } // namespace pv |