]> sigrok.org Git - pulseview.git/blob - pv/device/devinst.cpp
Added pv::device::Device
[pulseview.git] / pv / device / devinst.cpp
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>
22
23 #include <QDebug>
24
25 #include <libsigrok/libsigrok.h>
26
27 #include "devinst.h"
28
29 namespace pv {
30 namespace device {
31
32 DevInst::DevInst(sr_dev_inst *sdi) :
33         _sdi(sdi)
34 {
35         assert(_sdi);
36 }
37
38 sr_dev_inst* DevInst::dev_inst() const
39 {
40         return _sdi;
41 }
42
43 GVariant* DevInst::get_config(const sr_probe_group *group, int key)
44 {
45         GVariant *data = NULL;
46         if (sr_config_get(_sdi->driver, _sdi, group, key, &data) != SR_OK)
47                 return NULL;
48         return data;
49 }
50
51 bool DevInst::set_config(const sr_probe_group *group, int key, GVariant *data)
52 {
53         if(sr_config_set(_sdi, group, key, data) == SR_OK) {
54                 config_changed();
55                 return true;
56         }
57         return false;
58 }
59
60 GVariant* DevInst::list_config(const sr_probe_group *group, int key)
61 {
62         GVariant *data = NULL;
63         if (sr_config_list(_sdi->driver, _sdi, group, key, &data) != SR_OK)
64                 return NULL;
65         return data;
66 }
67
68 void DevInst::enable_probe(const sr_probe *probe, bool enable)
69 {
70         for (const GSList *p = _sdi->probes; p; p = p->next)
71                 if (probe == p->data) {
72                         const_cast<sr_probe*>(probe)->enabled = enable;
73                         config_changed();
74                         return;
75                 }
76
77         // Probe was not found in the device
78         assert(0);
79 }
80
81 uint64_t DevInst::get_sample_limit()
82 {
83         uint64_t sample_limit;
84         GVariant* gvar = get_config(NULL, SR_CONF_LIMIT_SAMPLES);
85         if (gvar != NULL) {
86                 sample_limit = g_variant_get_uint64(gvar);
87                 g_variant_unref(gvar);
88         } else {
89                 sample_limit = 0U;
90         }
91         return sample_limit;
92 }
93
94 } // device
95 } // pv