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;
69 static const struct sr_output_module *output_module_list[] = {
91 return output_module_list;
102 sr_err(
"Invalid output module NULL!");
117 sr_err(
"Invalid output module NULL!");
132 sr_err(
"Invalid output module NULL!");
148 const struct sr_output_module *omod)
151 sr_err(
"Invalid output module NULL!");
167 return (flag & omod->flags);
180 for (i = 0; output_module_list[i]; i++) {
181 if (!strcmp(output_module_list[i]->
id,
id))
182 return output_module_list[i];
199 const struct sr_option *mod_opts, **opts;
202 if (!omod || !omod->options)
205 mod_opts = omod->options();
207 for (size = 0; mod_opts[size].
id; size++)
209 opts = g_malloc((size + 1) *
sizeof(
struct sr_option *));
211 for (i = 0; i < size; i++)
212 opts[i] = &mod_opts[i];
231 for (i = 0; options[i]; i++) {
232 if (options[i]->
def) {
233 g_variant_unref(options[i]->
def);
234 ((
struct sr_option *)options[i])->def = NULL;
238 g_slist_free_full(options[i]->
values, (GDestroyNotify)g_variant_unref);
239 ((
struct sr_option *)options[i])->values = NULL;
259 GHashTable *options,
const struct sr_dev_inst *sdi,
260 const char *filename)
262 struct sr_output *op;
264 const GVariantType *gvt;
265 GHashTable *new_opts;
270 op = g_malloc(
sizeof(
struct sr_output));
273 op->filename = g_strdup(filename);
275 new_opts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
276 (GDestroyNotify)g_variant_unref);
278 mod_opts = omod->options();
279 for (i = 0; mod_opts[i].
id; i++) {
280 if (options && g_hash_table_lookup_extended(options,
281 mod_opts[i].
id, &key, &value)) {
283 gvt = g_variant_get_type(mod_opts[i].
def);
284 if (!g_variant_is_of_type(value, gvt)) {
285 sr_err(
"Invalid type for '%s' option.",
290 g_hash_table_insert(new_opts, g_strdup(mod_opts[i].
id),
291 g_variant_ref(value));
294 g_hash_table_insert(new_opts, g_strdup(mod_opts[i].
id),
295 g_variant_ref(mod_opts[i].
def));
301 g_hash_table_iter_init(&iter, options);
302 while (g_hash_table_iter_next(&iter, &key, &value)) {
303 if (!g_hash_table_lookup(new_opts, key)) {
304 sr_err(
"Output module '%s' has no option '%s'",
305 omod->id, (
char *)key);
306 g_hash_table_destroy(new_opts);
314 if (op->module->init && op->module->init(op, new_opts) !=
SR_OK) {
319 g_hash_table_destroy(new_opts);
335 return o->module->receive(o, packet, out);
351 if (o->module->cleanup)
352 ret = o->module->cleanup((
struct sr_output *)o);
353 g_free((
char *)o->filename);
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...
Generic option struct used by various subsystems.
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 * sr_output_name_get(const struct sr_output_module *omod)
Returns the specified output module's name.
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 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...
const char * sr_output_description_get(const struct sr_output_module *omod)
Returns the specified output module's description.
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 struct sr_output_module ** sr_output_list(void)
Returns a NULL-terminated list of all available output modules.
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.
gboolean sr_output_test_flag(const struct sr_output_module *omod, uint64_t flag)
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_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...