]> sigrok.org Git - sigrok-util.git/blob - source/drv-api.c
new-driver: Update to latest API changes.
[sigrok-util.git] / source / drv-api.c
1 /*
2  * This file is part of the libsigrok project.
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
20 #include <glib.h>
21 #include "libsigrok.h"
22 #include "libsigrok-internal.h"
23 #include "protocol.h"
24
25 SR_PRIV struct sr_dev_driver ${lib}_driver_info;
26 static struct sr_dev_driver *di = &${lib}_driver_info;
27
28 /* Properly close and free all devices. */
29 static int clear_instances(void)
30 {
31         struct sr_dev_inst *sdi;
32         struct drv_context *drvc;
33         struct dev_context *devc;
34         GSList *l;
35
36         if (!(drvc = di->priv))
37                 return SR_OK;
38
39         for (l = drvc->instances; l; l = l->next) {
40                 if (!(sdi = l->data))
41                         continue;
42                 if (!(devc = sdi->priv))
43                         continue;
44
45                 /* TODO */
46
47                 sr_dev_inst_free(sdi);
48         }
49
50         g_slist_free(drvc->instances);
51         drvc->instances = NULL;
52
53         return SR_OK;
54 }
55
56 static int hw_init(struct sr_context *sr_ctx)
57 {
58         return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN);
59 }
60
61 static GSList *hw_scan(GSList *options)
62 {
63         struct drv_context *drvc;
64         GSList *devices;
65
66         (void)options;
67
68         devices = NULL;
69         drvc = di->priv;
70         drvc->instances = NULL;
71
72         /* TODO */
73
74         return devices;
75 }
76
77 static GSList *hw_dev_list(void)
78 {
79         struct drv_context *drvc;
80
81         drvc = di->priv;
82
83         return drvc->instances;
84 }
85
86 static int hw_dev_open(struct sr_dev_inst *sdi)
87 {
88         (void)sdi;
89
90         /* TODO */
91
92         return SR_OK;
93 }
94
95 static int hw_dev_close(struct sr_dev_inst *sdi)
96 {
97         (void)sdi;
98
99         /* TODO */
100
101         return SR_OK;
102 }
103
104 static int hw_cleanup(void)
105 {
106         clear_instances();
107
108         /* TODO */
109
110         return SR_OK;
111 }
112
113 static int hw_config_get(int id, const void **value,
114                          const struct sr_dev_inst *sdi)
115 {
116         (void)sdi;
117         (void)value;
118
119         switch (id) {
120         /* TODO */
121         default:
122                 return SR_ERR_ARG;
123         }
124
125         return SR_OK;
126 }
127
128 static int hw_config_set(int id, const void *value,
129                          const struct sr_dev_inst *sdi)
130 {
131         (void)value;
132
133         int ret;
134
135         if (sdi->status != SR_ST_ACTIVE) {
136                 sr_err("Device inactive, can't set config options.");
137                 return SR_ERR;
138         }
139
140         ret = SR_OK;
141         switch (id) {
142         /* TODO */
143         default:
144                 sr_err("Unknown hardware capability: %d.", id);
145                 ret = SR_ERR_ARG;
146         }
147
148         return ret;
149 }
150
151 static int hw_config_list(int key, const void **data,
152                           const struct sr_dev_inst *sdi)
153 {
154         (void)sdi;
155         (void)data;
156
157         switch (key) {
158         default:
159                 return SR_ERR_ARG;
160         }
161
162         return SR_OK;
163 }
164
165 static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
166                                     void *cb_data)
167 {
168         (void)sdi;
169         (void)cb_data;
170
171         /* TODO */
172
173         return SR_OK;
174 }
175
176 static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
177 {
178         (void)cb_data;
179
180         if (sdi->status != SR_ST_ACTIVE) {
181                 sr_err("Device inactive, can't stop acquisition.");
182                 return SR_ERR;
183         }
184
185         /* TODO */
186
187         return SR_OK;
188 }
189
190 SR_PRIV struct sr_dev_driver ${lib}_driver_info = {
191         .name = "${short}",
192         .longname = "${name}",
193         .api_version = 1,
194         .init = hw_init,
195         .cleanup = hw_cleanup,
196         .scan = hw_scan,
197         .dev_list = hw_dev_list,
198         .dev_clear = clear_instances,
199         .config_get = hw_config_get,
200         .config_set = hw_config_set,
201         .config_list = hw_config_list,
202         .dev_open = hw_dev_open,
203         .dev_close = hw_dev_close,
204         .dev_acquisition_start = hw_dev_acquisition_start,
205         .dev_acquisition_stop = hw_dev_acquisition_stop,
206         .priv = NULL,
207 };