]>
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 | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #include <cassert> | |
22 | ||
23 | #include <libsigrokcxx/libsigrokcxx.hpp> | |
24 | ||
25 | #include "device.hpp" | |
26 | ||
b48daed6 JH |
27 | using std::map; |
28 | using std::set; | |
29 | ||
30 | using sigrok::ConfigKey; | |
7bb0fbf4 | 31 | using sigrok::Capability; |
b48daed6 JH |
32 | using sigrok::Error; |
33 | ||
34 | using Glib::VariantBase; | |
35 | using Glib::Variant; | |
36 | ||
da30ecb7 JH |
37 | namespace pv { |
38 | namespace devices { | |
39 | ||
2ad82c2e UH |
40 | Device::Device() |
41 | { | |
da30ecb7 JH |
42 | } |
43 | ||
2ad82c2e UH |
44 | Device::~Device() |
45 | { | |
da30ecb7 JH |
46 | if (session_) |
47 | session_->remove_datafeed_callbacks(); | |
48 | } | |
49 | ||
2ad82c2e UH |
50 | std::shared_ptr<sigrok::Session> Device::session() const |
51 | { | |
da30ecb7 JH |
52 | return session_; |
53 | } | |
54 | ||
2ad82c2e UH |
55 | std::shared_ptr<sigrok::Device> Device::device() const |
56 | { | |
da30ecb7 JH |
57 | return device_; |
58 | } | |
59 | ||
b48daed6 JH |
60 | template |
61 | uint64_t Device::read_config(const sigrok::ConfigKey*, | |
62 | const uint64_t); | |
63 | ||
64 | template<typename T> | |
65 | T Device::read_config(const ConfigKey *key, const T default_value) | |
66 | { | |
67 | assert(key); | |
b48daed6 JH |
68 | |
69 | if (!device_) | |
70 | return default_value; | |
71 | ||
7bb0fbf4 | 72 | if (!device_->config_check(key, Capability::GET)) |
b48daed6 JH |
73 | return default_value; |
74 | ||
05b22769 | 75 | return VariantBase::cast_dynamic<Glib::Variant<guint64>>( |
b48daed6 JH |
76 | device_->config_get(ConfigKey::SAMPLERATE)).get(); |
77 | } | |
78 | ||
2ad82c2e UH |
79 | void Device::start() |
80 | { | |
5237f0c5 JH |
81 | assert(session_); |
82 | session_->start(); | |
83 | } | |
84 | ||
2ad82c2e UH |
85 | void Device::run() |
86 | { | |
da30ecb7 JH |
87 | assert(device_); |
88 | assert(session_); | |
89 | session_->run(); | |
90 | } | |
91 | ||
2ad82c2e UH |
92 | void Device::stop() |
93 | { | |
da30ecb7 JH |
94 | assert(session_); |
95 | session_->stop(); | |
96 | } | |
97 | ||
98 | } // namespace devices | |
99 | } // namespace pv |