23 #include "libsigrok-internal.h" 26 #define LOG_PREFIX "output" 56 extern SR_PRIV struct sr_output_module output_bits;
57 extern SR_PRIV struct sr_output_module output_hex;
58 extern SR_PRIV struct sr_output_module output_ascii;
59 extern SR_PRIV struct sr_output_module output_binary;
60 extern SR_PRIV struct sr_output_module output_vcd;
61 extern SR_PRIV struct sr_output_module output_ols;
62 extern SR_PRIV struct sr_output_module output_chronovu_la8;
63 extern SR_PRIV struct sr_output_module output_csv;
64 extern SR_PRIV struct sr_output_module output_analog;
65 extern SR_PRIV struct sr_output_module output_srzip;
66 extern SR_PRIV struct sr_output_module output_wav;
67 extern SR_PRIV struct sr_output_module output_wavedrom;
68 extern SR_PRIV struct sr_output_module output_null;
71 static const struct sr_output_module *output_module_list[] = {
95 return output_module_list;
106 sr_err(
"Invalid output module NULL!");
121 sr_err(
"Invalid output module NULL!");
136 sr_err(
"Invalid output module NULL!");
152 const struct sr_output_module *omod)
155 sr_err(
"Invalid output module NULL!");
171 return (flag & omod->flags);
184 for (i = 0; output_module_list[i]; i++) {
185 if (!strcmp(output_module_list[i]->
id,
id))
186 return output_module_list[i];
203 const struct sr_option *mod_opts, **opts;
206 if (!omod || !omod->options)
209 mod_opts = omod->options();
211 for (size = 0; mod_opts[
size].
id; size++)
213 opts = g_malloc((size + 1) *
sizeof(
struct sr_option *));
215 for (i = 0; i <
size; i++)
216 opts[i] = &mod_opts[i];
235 for (i = 0; options[i]; i++) {
236 if (options[i]->
def) {
237 g_variant_unref(options[i]->
def);
238 ((
struct sr_option *)options[i])->def = NULL;
242 g_slist_free_full(options[i]->
values, (GDestroyNotify)g_variant_unref);
243 ((
struct sr_option *)options[i])->values = NULL;
263 GHashTable *options,
const struct sr_dev_inst *sdi,
264 const char *filename)
266 struct sr_output *op;
268 const GVariantType *gvt;
269 GHashTable *new_opts;
274 op = g_malloc(
sizeof(
struct sr_output));
277 op->filename = g_strdup(filename);
279 new_opts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
280 (GDestroyNotify)g_variant_unref);
282 mod_opts = omod->options();
283 for (i = 0; mod_opts[i].
id; i++) {
284 if (options && g_hash_table_lookup_extended(options,
285 mod_opts[i].
id, &key, &value)) {
287 gvt = g_variant_get_type(mod_opts[i].
def);
288 if (!g_variant_is_of_type(value, gvt)) {
289 sr_err(
"Invalid type for '%s' option.",
294 g_hash_table_insert(new_opts, g_strdup(mod_opts[i].
id),
295 g_variant_ref(value));
298 g_hash_table_insert(new_opts, g_strdup(mod_opts[i].
id),
299 g_variant_ref(mod_opts[i].
def));
305 g_hash_table_iter_init(&iter, options);
306 while (g_hash_table_iter_next(&iter, &key, &value)) {
307 if (!g_hash_table_lookup(new_opts, key)) {
308 sr_err(
"Output module '%s' has no option '%s'",
309 omod->id, (
char *)key);
310 g_hash_table_destroy(new_opts);
318 if (op->module->init && op->module->init(op, new_opts) !=
SR_OK) {
323 g_hash_table_destroy(new_opts);
339 return o->module->receive(o, packet, out);
355 if (o->module->cleanup)
356 ret = o->module->cleanup((
struct sr_output *)o);
357 g_free((
char *)o->filename);
int sr_output_send(const struct sr_output *o, const struct sr_datafeed_packet *packet, GString **out)
Send a packet to the specified output instance.
const char *const * sr_output_extensions_get(const struct sr_output_module *omod)
Returns the specified output module's file extensions typical for the file format, as a NULL terminated array, or returns a NULL pointer if there is no preferred extension.
const struct sr_output_module ** sr_output_list(void)
Returns a NULL-terminated list of all available output modules.
const struct sr_option ** sr_output_options_get(const struct sr_output_module *omod)
Returns a NULL-terminated array of struct sr_option, or NULL if the module takes no options...
Generic option struct used by various subsystems.
Packet in a sigrok data feed.
int sr_output_free(const struct sr_output *o)
Free the specified output instance and all associated resources.
const char * sr_output_name_get(const struct sr_output_module *omod)
Returns the specified output module's name.
const struct sr_output_module * sr_output_find(char *id)
Return the output module with the specified ID, or NULL if no module with that id is found...
gboolean sr_output_test_flag(const struct sr_output_module *omod, uint64_t flag)
const char * sr_output_id_get(const struct sr_output_module *omod)
Returns the specified output module's ID.
The public libsigrok header file to be used by frontends.
const char * sr_output_description_get(const struct sr_output_module *omod)
Returns the specified output module's description.
const struct sr_output * sr_output_new(const struct sr_output_module *omod, GHashTable *options, const struct sr_dev_inst *sdi, const char *filename)
Create a new output instance using the specified output module.
void sr_output_options_free(const struct sr_option **options)
After a call to sr_output_options_get(), this function cleans up all resources returned by that call...