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