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