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