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_gnuplot;
63 extern SR_PRIV struct sr_output_module output_chronovu_la8;
64 extern SR_PRIV struct sr_output_module output_csv;
65 extern SR_PRIV struct sr_output_module output_analog;
66 extern SR_PRIV struct sr_output_module output_srzip;
67 extern SR_PRIV struct sr_output_module output_wav;
70 static const struct sr_output_module *output_module_list[] = {
93 return output_module_list;
104 sr_err(
"Invalid output module NULL!");
119 sr_err(
"Invalid output module NULL!");
134 sr_err(
"Invalid output module NULL!");
150 const struct sr_output_module *omod)
153 sr_err(
"Invalid output module NULL!");
169 return (flag & omod->flags);
182 for (i = 0; output_module_list[i]; i++) {
183 if (!strcmp(output_module_list[i]->
id,
id))
184 return output_module_list[i];
201 const struct sr_option *mod_opts, **opts;
204 if (!omod || !omod->options)
207 mod_opts = omod->options();
209 for (size = 0; mod_opts[size].
id; size++)
211 opts = g_malloc((size + 1) *
sizeof(
struct sr_option *));
213 for (i = 0; i < size; i++)
214 opts[i] = &mod_opts[i];
233 for (i = 0; options[i]; i++) {
234 if (options[i]->
def) {
235 g_variant_unref(options[i]->
def);
236 ((
struct sr_option *)options[i])->def = NULL;
240 g_slist_free_full(options[i]->
values, (GDestroyNotify)g_variant_unref);
241 ((
struct sr_option *)options[i])->values = NULL;
261 GHashTable *options,
const struct sr_dev_inst *sdi,
262 const char *filename)
264 struct sr_output *op;
266 const GVariantType *gvt;
267 GHashTable *new_opts;
272 op = g_malloc(
sizeof(
struct sr_output));
275 op->filename = g_strdup(filename);
277 new_opts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
278 (GDestroyNotify)g_variant_unref);
280 mod_opts = omod->options();
281 for (i = 0; mod_opts[i].
id; i++) {
282 if (options && g_hash_table_lookup_extended(options,
283 mod_opts[i].
id, &key, &value)) {
285 gvt = g_variant_get_type(mod_opts[i].
def);
286 if (!g_variant_is_of_type(value, gvt)) {
287 sr_err(
"Invalid type for '%s' option.",
292 g_hash_table_insert(new_opts, g_strdup(mod_opts[i].
id),
293 g_variant_ref(value));
296 g_hash_table_insert(new_opts, g_strdup(mod_opts[i].
id),
297 g_variant_ref(mod_opts[i].
def));
303 g_hash_table_iter_init(&iter, options);
304 while (g_hash_table_iter_next(&iter, &key, &value)) {
305 if (!g_hash_table_lookup(new_opts, key)) {
306 sr_err(
"Output module '%s' has no option '%s'",
307 omod->id, (
char *)key);
308 g_hash_table_destroy(new_opts);
316 if (op->module->init && op->module->init(op, new_opts) !=
SR_OK) {
321 g_hash_table_destroy(new_opts);
337 return o->module->receive(o, packet, out);
353 if (o->module->cleanup)
354 ret = o->module->cleanup((
struct sr_output *)o);
355 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 * sr_output_name_get(const struct sr_output_module *omod)
Returns the specified output module's name.
The public libsigrok header file to be used by frontends.
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...
const char * sr_output_id_get(const struct sr_output_module *omod)
Returns the specified output module's ID.
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.
Generic option struct used by various subsystems.
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 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 * 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 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...