]> sigrok.org Git - pulseview.git/blob - pv/devinst.cpp
Moved config getting/setting into DevInst
[pulseview.git] / pv / 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 #include <sstream>
23
24 #include <QDebug>
25
26 #include <libsigrok/libsigrok.h>
27
28 #include "devinst.h"
29
30 using std::ostringstream;
31 using std::string;
32
33 namespace pv {
34
35 DevInst::DevInst(sr_dev_inst *sdi) :
36         _sdi(sdi)
37 {
38         assert(_sdi);
39 }
40
41 sr_dev_inst* DevInst::dev_inst() const
42 {
43         return _sdi;
44 }
45
46 string 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
71 GVariant* 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
79 bool DevInst::set_config(const sr_probe_group *group, int key, GVariant *data)
80 {
81         return sr_config_set(_sdi, group, key, data) == SR_OK;
82 }
83
84 GVariant* DevInst::list_config(const sr_probe_group *group, int key)
85 {
86         GVariant *data = NULL;
87         if (sr_config_list(_sdi->driver, _sdi, group, key, &data) != SR_OK)
88                 return NULL;
89         return data;
90 }
91
92 } // pv