]> sigrok.org Git - pulseview.git/blob - pv/device/devinst.cpp
Moved SigSession::is_trigger_enabled into DevInst
[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 #include <pv/sigsession.h>
30
31 namespace pv {
32 namespace device {
33
34 DevInst::DevInst() :
35         _owner(NULL)
36 {
37 }
38
39 void DevInst::use(SigSession *owner)
40 {
41         assert(owner);
42         assert(!_owner);
43         _owner = owner;
44         sr_dev_open(dev_inst());
45 }
46
47 void DevInst::release()
48 {
49         if (_owner) {
50                 _owner->release_device(this);
51                 _owner = NULL;
52                 sr_dev_close(dev_inst());
53         }
54 }
55
56 SigSession* DevInst::owner() const
57 {
58         return _owner;
59 }
60
61 GVariant* DevInst::get_config(const sr_probe_group *group, int key)
62 {
63         GVariant *data = NULL;
64         sr_dev_inst *const sdi = dev_inst();
65         assert(sdi);
66         if (sr_config_get(sdi->driver, sdi, group, key, &data) != SR_OK)
67                 return NULL;
68         return data;
69 }
70
71 bool DevInst::set_config(const sr_probe_group *group, int key, GVariant *data)
72 {
73         sr_dev_inst *const sdi = dev_inst();
74         assert(sdi);
75         if(sr_config_set(sdi, group, key, data) == SR_OK) {
76                 config_changed();
77                 return true;
78         }
79         return false;
80 }
81
82 GVariant* DevInst::list_config(const sr_probe_group *group, int key)
83 {
84         GVariant *data = NULL;
85         sr_dev_inst *const sdi = dev_inst();
86         assert(sdi);
87         if (sr_config_list(sdi->driver, sdi, group, key, &data) != SR_OK)
88                 return NULL;
89         return data;
90 }
91
92 void DevInst::enable_probe(const sr_probe *probe, bool enable)
93 {
94         sr_dev_inst *const sdi = dev_inst();
95         assert(sdi);
96         for (const GSList *p = sdi->probes; p; p = p->next)
97                 if (probe == p->data) {
98                         const_cast<sr_probe*>(probe)->enabled = enable;
99                         config_changed();
100                         return;
101                 }
102
103         // Probe was not found in the device
104         assert(0);
105 }
106
107 uint64_t DevInst::get_sample_limit()
108 {
109         uint64_t sample_limit;
110         GVariant* gvar = get_config(NULL, SR_CONF_LIMIT_SAMPLES);
111         if (gvar != NULL) {
112                 sample_limit = g_variant_get_uint64(gvar);
113                 g_variant_unref(gvar);
114         } else {
115                 sample_limit = 0U;
116         }
117         return sample_limit;
118 }
119
120 bool DevInst::is_trigger_enabled() const
121 {
122         return false;
123 }
124
125 } // device
126 } // pv