]> sigrok.org Git - pulseview.git/blame - pv/device/devinst.cpp
Moved DevInst into the pv::device namespace
[pulseview.git] / pv / device / devinst.cpp
CommitLineData
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>
22#include <sstream>
23
8dd44190
JH
24#include <QDebug>
25
19adbc2c
JH
26#include <libsigrok/libsigrok.h>
27
28#include "devinst.h"
29
30using std::ostringstream;
31using std::string;
32
33namespace pv {
94574501 34namespace device {
19adbc2c
JH
35
36DevInst::DevInst(sr_dev_inst *sdi) :
37 _sdi(sdi)
38{
39 assert(_sdi);
40}
41
42sr_dev_inst* DevInst::dev_inst() const
43{
44 return _sdi;
45}
46
47string DevInst::format_device_title() const
48{
49 ostringstream s;
50
51 assert(_sdi);
52
53 if (_sdi->vendor && _sdi->vendor[0]) {
54 s << _sdi->vendor;
55 if ((_sdi->model && _sdi->model[0]) ||
56 (_sdi->version && _sdi->version[0]))
57 s << ' ';
58 }
59
60 if (_sdi->model && _sdi->model[0]) {
61 s << _sdi->model;
62 if (_sdi->version && _sdi->version[0])
63 s << ' ';
64 }
65
66 if (_sdi->version && _sdi->version[0])
67 s << _sdi->version;
68
69 return s.str();
70}
71
8dd44190
JH
72GVariant* DevInst::get_config(const sr_probe_group *group, int key)
73{
74 GVariant *data = NULL;
75 if (sr_config_get(_sdi->driver, _sdi, group, key, &data) != SR_OK)
76 return NULL;
77 return data;
78}
79
80bool DevInst::set_config(const sr_probe_group *group, int key, GVariant *data)
81{
42e634cf
JH
82 if(sr_config_set(_sdi, group, key, data) == SR_OK) {
83 config_changed();
84 return true;
85 }
86 return false;
8dd44190
JH
87}
88
89GVariant* DevInst::list_config(const sr_probe_group *group, int key)
90{
91 GVariant *data = NULL;
92 if (sr_config_list(_sdi->driver, _sdi, group, key, &data) != SR_OK)
93 return NULL;
94 return data;
95}
96
e183f4e3
JH
97void DevInst::enable_probe(const sr_probe *probe, bool enable)
98{
99 for (const GSList *p = _sdi->probes; p; p = p->next)
100 if (probe == p->data) {
101 const_cast<sr_probe*>(probe)->enabled = enable;
8283c116 102 config_changed();
e183f4e3
JH
103 return;
104 }
105
106 // Probe was not found in the device
107 assert(0);
108}
109
27d7c96b
DK
110uint64_t DevInst::get_sample_limit()
111{
112 uint64_t sample_limit;
113 GVariant* gvar = get_config(NULL, SR_CONF_LIMIT_SAMPLES);
114 if (gvar != NULL) {
115 sample_limit = g_variant_get_uint64(gvar);
116 g_variant_unref(gvar);
117 } else {
118 sample_limit = 0U;
119 }
120 return sample_limit;
121}
122
94574501 123} // device
19adbc2c 124} // pv