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