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