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