]> sigrok.org Git - sigrok-util.git/blob - source/drv-api.c
new-driver: Adapt to recent driver 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 <config.h>
21 #include "protocol.h"
22
23 SR_PRIV struct sr_dev_driver {lib}_driver_info;
24
25 static GSList *scan(struct sr_dev_driver *di, GSList *options)
26 {{
27         struct drv_context *drvc;
28         GSList *devices;
29
30         (void)options;
31
32         devices = NULL;
33         drvc = di->context;
34         drvc->instances = NULL;
35
36         /* TODO: scan for devices, either based on a SR_CONF_CONN option
37          * or on a USB scan. */
38
39         return devices;
40 }}
41
42 static int dev_clear(const struct sr_dev_driver *di)
43 {{
44         return std_dev_clear(di, NULL);
45 }}
46
47 static int dev_open(struct sr_dev_inst *sdi)
48 {{
49         (void)sdi;
50
51         /* TODO: get handle from sdi->conn and open it. */
52
53         sdi->status = SR_ST_ACTIVE;
54
55         return SR_OK;
56 }}
57
58 static int dev_close(struct sr_dev_inst *sdi)
59 {{
60         (void)sdi;
61
62         /* TODO: get handle from sdi->conn and close it. */
63
64         sdi->status = SR_ST_INACTIVE;
65
66         return SR_OK;
67 }}
68
69 static int config_get(uint32_t key, GVariant **data,
70         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
71 {{
72         int ret;
73
74         (void)sdi;
75         (void)data;
76         (void)cg;
77
78         ret = SR_OK;
79         switch (key) {{
80         /* TODO */
81         default:
82                 return SR_ERR_NA;
83         }}
84
85         return ret;
86 }}
87
88 static int config_set(uint32_t key, GVariant *data,
89         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
90 {{
91         int ret;
92
93         (void)data;
94         (void)cg;
95
96         if (sdi->status != SR_ST_ACTIVE)
97                 return SR_ERR_DEV_CLOSED;
98
99         ret = SR_OK;
100         switch (key) {{
101         /* TODO */
102         default:
103                 ret = SR_ERR_NA;
104         }}
105
106         return ret;
107 }}
108
109 static int config_list(uint32_t key, GVariant **data,
110         const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
111 {{
112         int ret;
113
114         (void)sdi;
115         (void)data;
116         (void)cg;
117
118         ret = SR_OK;
119         switch (key) {{
120         /* TODO */
121         default:
122                 return SR_ERR_NA;
123         }}
124
125         return ret;
126 }}
127
128 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
129 {{
130         if (sdi->status != SR_ST_ACTIVE)
131                 return SR_ERR_DEV_CLOSED;
132
133         /* TODO: configure hardware, reset acquisition state, set up
134          * callbacks and send header packet. */
135
136         return SR_OK;
137 }}
138
139 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
140 {{
141         if (sdi->status != SR_ST_ACTIVE)
142                 return SR_ERR_DEV_CLOSED;
143
144         /* TODO: stop acquisition. */
145
146         return SR_OK;
147 }}
148
149 SR_PRIV struct sr_dev_driver {lib}_driver_info = {{
150         .name = "{short}",
151         .longname = "{name}",
152         .api_version = 1,
153         .init = std_init,
154         .cleanup = std_cleanup,
155         .scan = scan,
156         .dev_list = std_dev_list,
157         .dev_clear = dev_clear,
158         .config_get = config_get,
159         .config_set = config_set,
160         .config_list = config_list,
161         .dev_open = dev_open,
162         .dev_close = dev_close,
163         .dev_acquisition_start = dev_acquisition_start,
164         .dev_acquisition_stop = dev_acquisition_stop,
165         .context = NULL,
166 }};
167
168 SR_REGISTER_DEV_DRIVER({lib}_driver_info);