24 #include "libsigrok-internal.h"
27 #define LOG_PREFIX "transform"
45 extern SR_PRIV struct sr_transform_module transform_nop;
46 extern SR_PRIV struct sr_transform_module transform_scale;
47 extern SR_PRIV struct sr_transform_module transform_invert;
50 static const struct sr_transform_module *transform_module_list[] = {
64 return transform_module_list;
75 sr_err(
"Invalid transform module NULL!");
90 sr_err(
"Invalid transform module NULL!");
105 sr_err(
"Invalid transform module NULL!");
122 for (i = 0; transform_module_list[i]; i++) {
123 if (!strcmp(transform_module_list[i]->
id,
id))
124 return transform_module_list[i];
141 const struct sr_option *mod_opts, **opts;
144 if (!tmod || !tmod->options)
147 mod_opts = tmod->options();
149 for (size = 0; mod_opts[size].
id; size++)
151 opts = g_malloc((size + 1) *
sizeof(
struct sr_option *));
153 for (i = 0; i < size; i++)
154 opts[i] = &mod_opts[i];
173 for (i = 0; options[i]; i++) {
174 if (options[i]->
def) {
175 g_variant_unref(options[i]->
def);
176 ((
struct sr_option *)options[i])->def = NULL;
180 g_slist_free_full(options[i]->
values, (GDestroyNotify)g_variant_unref);
181 ((
struct sr_option *)options[i])->values = NULL;
201 GHashTable *options,
const struct sr_dev_inst *sdi)
203 struct sr_transform *t;
205 const GVariantType *gvt;
206 GHashTable *new_opts;
211 t = g_malloc(
sizeof(
struct sr_transform));
215 new_opts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
216 (GDestroyNotify)g_variant_unref);
218 mod_opts = tmod->options();
219 for (i = 0; mod_opts[i].
id; i++) {
220 if (options && g_hash_table_lookup_extended(options,
221 mod_opts[i].
id, &key, &value)) {
223 gvt = g_variant_get_type(mod_opts[i].
def);
224 if (!g_variant_is_of_type(value, gvt)) {
225 sr_err(
"Invalid type for '%s' option.",
230 g_hash_table_insert(new_opts, g_strdup(mod_opts[i].
id),
231 g_variant_ref(value));
234 g_hash_table_insert(new_opts, g_strdup(mod_opts[i].
id),
235 g_variant_ref(mod_opts[i].
def));
241 g_hash_table_iter_init(&iter, options);
242 while (g_hash_table_iter_next(&iter, &key, &value)) {
243 if (!g_hash_table_lookup(new_opts, key)) {
244 sr_err(
"Transform module '%s' has no option '%s'.",
245 tmod->id, (
char *)key);
246 g_hash_table_destroy(new_opts);
254 if (t->module->init && t->module->init(t, new_opts) !=
SR_OK) {
259 g_hash_table_destroy(new_opts);
262 sdi->session->transforms = g_slist_append(sdi->session->transforms, t);
280 if (t->module->cleanup)
281 ret = t->module->cleanup((
struct sr_transform *)t);
The public libsigrok header file to be used by frontends.
const struct sr_transform_module ** sr_transform_list(void)
Returns a NULL-terminated list of all available transform modules.
const struct sr_option ** sr_transform_options_get(const struct sr_transform_module *tmod)
Returns a NULL-terminated array of struct sr_option, or NULL if the module takes no options...
void sr_transform_options_free(const struct sr_option **options)
After a call to sr_transform_options_get(), this function cleans up all resources returned by that ca...
const char * sr_transform_name_get(const struct sr_transform_module *tmod)
Returns the specified transform module's name.
const char * sr_transform_description_get(const struct sr_transform_module *tmod)
Returns the specified transform module's description.
Generic option struct used by various subsystems.
const struct sr_transform * sr_transform_new(const struct sr_transform_module *tmod, GHashTable *options, const struct sr_dev_inst *sdi)
Create a new transform instance using the specified transform module.
const char * sr_transform_id_get(const struct sr_transform_module *tmod)
Returns the specified transform module's ID.
const struct sr_transform_module * sr_transform_find(const char *id)
Return the transform module with the specified ID, or NULL if no module with that ID is found...
int sr_transform_free(const struct sr_transform *t)
Free the specified transform instance and all associated resources.