]> sigrok.org Git - pulseview.git/blame - pv/devinst.cpp
Moved all sr_probe modification into pv::DevInst
[pulseview.git] / pv / 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 {
34
35DevInst::DevInst(sr_dev_inst *sdi) :
36 _sdi(sdi)
37{
38 assert(_sdi);
39}
40
41sr_dev_inst* DevInst::dev_inst() const
42{
43 return _sdi;
44}
45
46string DevInst::format_device_title() const
47{
48 ostringstream s;
49
50 assert(_sdi);
51
52 if (_sdi->vendor && _sdi->vendor[0]) {
53 s << _sdi->vendor;
54 if ((_sdi->model && _sdi->model[0]) ||
55 (_sdi->version && _sdi->version[0]))
56 s << ' ';
57 }
58
59 if (_sdi->model && _sdi->model[0]) {
60 s << _sdi->model;
61 if (_sdi->version && _sdi->version[0])
62 s << ' ';
63 }
64
65 if (_sdi->version && _sdi->version[0])
66 s << _sdi->version;
67
68 return s.str();
69}
70
8dd44190
JH
71GVariant* DevInst::get_config(const sr_probe_group *group, int key)
72{
73 GVariant *data = NULL;
74 if (sr_config_get(_sdi->driver, _sdi, group, key, &data) != SR_OK)
75 return NULL;
76 return data;
77}
78
79bool DevInst::set_config(const sr_probe_group *group, int key, GVariant *data)
80{
42e634cf
JH
81 if(sr_config_set(_sdi, group, key, data) == SR_OK) {
82 config_changed();
83 return true;
84 }
85 return false;
8dd44190
JH
86}
87
88GVariant* DevInst::list_config(const sr_probe_group *group, int key)
89{
90 GVariant *data = NULL;
91 if (sr_config_list(_sdi->driver, _sdi, group, key, &data) != SR_OK)
92 return NULL;
93 return data;
94}
95
e183f4e3
JH
96void DevInst::enable_probe(const sr_probe *probe, bool enable)
97{
98 for (const GSList *p = _sdi->probes; p; p = p->next)
99 if (probe == p->data) {
100 const_cast<sr_probe*>(probe)->enabled = enable;
101 return;
102 }
103
104 // Probe was not found in the device
105 assert(0);
106}
107
19adbc2c 108} // pv