]>
Commit | Line | Data |
---|---|---|
19adbc2c JH |
1 | /* |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2014 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> | |
19adbc2c | 22 | |
8dd44190 JH |
23 | #include <QDebug> |
24 | ||
19adbc2c JH |
25 | #include <libsigrok/libsigrok.h> |
26 | ||
27 | #include "devinst.h" | |
28 | ||
996b7c9d JH |
29 | #include <pv/sigsession.h> |
30 | ||
19adbc2c | 31 | namespace pv { |
94574501 | 32 | namespace device { |
19adbc2c JH |
33 | |
34 | DevInst::DevInst(sr_dev_inst *sdi) : | |
996b7c9d JH |
35 | _sdi(sdi), |
36 | _owner(NULL) | |
19adbc2c JH |
37 | { |
38 | assert(_sdi); | |
39 | } | |
40 | ||
41 | sr_dev_inst* DevInst::dev_inst() const | |
42 | { | |
43 | return _sdi; | |
44 | } | |
45 | ||
996b7c9d JH |
46 | void DevInst::use(SigSession *owner) |
47 | { | |
48 | assert(owner); | |
49 | assert(!_owner); | |
50 | _owner = owner; | |
51 | sr_dev_open(_sdi); | |
52 | } | |
53 | ||
54 | void DevInst::release() | |
55 | { | |
56 | if (_owner) { | |
57 | _owner->release_device(this); | |
58 | _owner = NULL; | |
59 | sr_dev_close(_sdi); | |
60 | } | |
61 | } | |
62 | ||
63 | SigSession* DevInst::owner() const | |
64 | { | |
65 | return _owner; | |
66 | } | |
67 | ||
8dd44190 JH |
68 | GVariant* DevInst::get_config(const sr_probe_group *group, int key) |
69 | { | |
70 | GVariant *data = NULL; | |
71 | if (sr_config_get(_sdi->driver, _sdi, group, key, &data) != SR_OK) | |
72 | return NULL; | |
73 | return data; | |
74 | } | |
75 | ||
76 | bool DevInst::set_config(const sr_probe_group *group, int key, GVariant *data) | |
77 | { | |
42e634cf JH |
78 | if(sr_config_set(_sdi, group, key, data) == SR_OK) { |
79 | config_changed(); | |
80 | return true; | |
81 | } | |
82 | return false; | |
8dd44190 JH |
83 | } |
84 | ||
85 | GVariant* DevInst::list_config(const sr_probe_group *group, int key) | |
86 | { | |
87 | GVariant *data = NULL; | |
88 | if (sr_config_list(_sdi->driver, _sdi, group, key, &data) != SR_OK) | |
89 | return NULL; | |
90 | return data; | |
91 | } | |
92 | ||
e183f4e3 JH |
93 | void DevInst::enable_probe(const sr_probe *probe, bool enable) |
94 | { | |
95 | for (const GSList *p = _sdi->probes; p; p = p->next) | |
96 | if (probe == p->data) { | |
97 | const_cast<sr_probe*>(probe)->enabled = enable; | |
8283c116 | 98 | config_changed(); |
e183f4e3 JH |
99 | return; |
100 | } | |
101 | ||
102 | // Probe was not found in the device | |
103 | assert(0); | |
104 | } | |
105 | ||
27d7c96b DK |
106 | uint64_t DevInst::get_sample_limit() |
107 | { | |
108 | uint64_t sample_limit; | |
109 | GVariant* gvar = get_config(NULL, SR_CONF_LIMIT_SAMPLES); | |
110 | if (gvar != NULL) { | |
111 | sample_limit = g_variant_get_uint64(gvar); | |
112 | g_variant_unref(gvar); | |
113 | } else { | |
114 | sample_limit = 0U; | |
115 | } | |
116 | return sample_limit; | |
117 | } | |
118 | ||
94574501 | 119 | } // device |
19adbc2c | 120 | } // pv |