]> sigrok.org Git - sigrok-util.git/blame - source/drv-api.c
new-driver: Shorten dev_list().
[sigrok-util.git] / source / drv-api.c
CommitLineData
a65d66c0 1/*
4b527a01 2 * This file is part of the libsigrok project.
a65d66c0
BV
3 *
4 * Copyright (C) ${year} ${author} <${email}>
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 3 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, see <http://www.gnu.org/licenses/>.
18 */
19
a65d66c0
BV
20#include "protocol.h"
21
2ef7b331 22SR_PRIV struct sr_dev_driver ${lib}_driver_info;
a65d66c0
BV
23static struct sr_dev_driver *di = &${lib}_driver_info;
24
87c5b243 25static int init(struct sr_context *sr_ctx)
a65d66c0 26{
5b10d8fd 27 return std_init(sr_ctx, di, LOG_PREFIX);
a65d66c0
BV
28}
29
87c5b243 30static GSList *scan(GSList *options)
a65d66c0
BV
31{
32 struct drv_context *drvc;
33 GSList *devices;
34
35 (void)options;
126eded0 36
a65d66c0
BV
37 devices = NULL;
38 drvc = di->priv;
39 drvc->instances = NULL;
40
87c5b243
BV
41 /* TODO: scan for devices, either based on a SR_CONF_CONN option
42 * or on a USB scan. */
a65d66c0
BV
43
44 return devices;
45}
46
87c5b243 47static GSList *dev_list(void)
a65d66c0 48{
28fca3a8 49 return ((struct drv_context *)(di->priv))->instances;
a65d66c0
BV
50}
51
87c5b243
BV
52static int dev_clear(void)
53{
54 return std_dev_clear(di, NULL);
55}
56
57static int dev_open(struct sr_dev_inst *sdi)
a65d66c0 58{
3aef82b3
UH
59 (void)sdi;
60
87c5b243
BV
61 /* TODO: get handle from sdi->conn and open it. */
62
63 sdi->status = SR_ST_ACTIVE;
a65d66c0
BV
64
65 return SR_OK;
66}
67
87c5b243 68static int dev_close(struct sr_dev_inst *sdi)
a65d66c0 69{
3aef82b3
UH
70 (void)sdi;
71
87c5b243
BV
72 /* TODO: get handle from sdi->conn and close it. */
73
74 sdi->status = SR_ST_INACTIVE;
a65d66c0
BV
75
76 return SR_OK;
77}
78
87c5b243 79static int cleanup(void)
a65d66c0 80{
87c5b243 81 dev_clear();
a65d66c0 82
87c5b243 83 /* TODO: free other driver resources, if any. */
a65d66c0
BV
84
85 return SR_OK;
86}
87
87c5b243 88static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
a65d66c0 89{
87c5b243
BV
90 int ret;
91
3aef82b3 92 (void)sdi;
87c5b243 93 (void)data;
3aef82b3 94
87c5b243
BV
95 ret = SR_OK;
96 switch (key) {
a65d66c0
BV
97 /* TODO */
98 default:
87c5b243 99 return SR_ERR_NA;
a65d66c0
BV
100 }
101
87c5b243 102 return ret;
a65d66c0
BV
103}
104
87c5b243 105static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
a65d66c0
BV
106{
107 int ret;
108
87c5b243
BV
109 (void)data;
110
111 if (sdi->status != SR_ST_ACTIVE)
112 return SR_ERR_DEV_CLOSED;
a65d66c0
BV
113
114 ret = SR_OK;
87c5b243 115 switch (key) {
a65d66c0
BV
116 /* TODO */
117 default:
87c5b243 118 ret = SR_ERR_NA;
a65d66c0
BV
119 }
120
121 return ret;
122}
123
87c5b243 124static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
3aef82b3 125{
87c5b243
BV
126 int ret;
127
3aef82b3
UH
128 (void)sdi;
129 (void)data;
130
87c5b243 131 ret = SR_OK;
3aef82b3 132 switch (key) {
87c5b243 133 /* TODO */
3aef82b3 134 default:
87c5b243 135 return SR_ERR_NA;
3aef82b3
UH
136 }
137
87c5b243 138 return ret;
3aef82b3
UH
139}
140
87c5b243 141static int dev_acquisition_start(const struct sr_dev_inst *sdi,
126eded0 142 void *cb_data)
a65d66c0 143{
3aef82b3
UH
144 (void)sdi;
145 (void)cb_data;
146
87c5b243
BV
147 if (sdi->status != SR_ST_ACTIVE)
148 return SR_ERR_DEV_CLOSED;
149
150 /* TODO: configure hardware, reset acquisition state, set up
151 * callbacks and send header packet. */
a65d66c0
BV
152
153 return SR_OK;
154}
155
87c5b243 156static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
a65d66c0 157{
a65d66c0
BV
158 (void)cb_data;
159
87c5b243
BV
160 if (sdi->status != SR_ST_ACTIVE)
161 return SR_ERR_DEV_CLOSED;
a65d66c0 162
87c5b243 163 /* TODO: stop acquisition. */
a65d66c0
BV
164
165 return SR_OK;
166}
167
168SR_PRIV struct sr_dev_driver ${lib}_driver_info = {
169 .name = "${short}",
170 .longname = "${name}",
171 .api_version = 1,
87c5b243
BV
172 .init = init,
173 .cleanup = cleanup,
174 .scan = scan,
175 .dev_list = dev_list,
176 .dev_clear = dev_clear,
177 .config_get = config_get,
178 .config_set = config_set,
179 .config_list = config_list,
180 .dev_open = dev_open,
181 .dev_close = dev_close,
182 .dev_acquisition_start = dev_acquisition_start,
183 .dev_acquisition_stop = dev_acquisition_stop,
a65d66c0
BV
184 .priv = NULL,
185};