From: Soeren Apel Date: Wed, 29 Jul 2015 19:19:49 +0000 (+0200) Subject: Add filename field to sr_output and make it accessible X-Git-Tag: libsigrok-0.4.0~456 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=81b3ce374c3b6d48e5ed321ac7a871ce4248a0bb Add filename field to sr_output and make it accessible This fixes parts of bug #570. --- diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index a08def8e..357c9d6f 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -1565,10 +1565,28 @@ shared_ptr OutputFormat::create_output( Output::Deleter()); } +shared_ptr OutputFormat::create_output(string filename, + shared_ptr device, map options) +{ + return shared_ptr( + new Output(filename, shared_from_this(), device, options), + Output::Deleter()); +} + Output::Output(shared_ptr format, shared_ptr device, map options) : UserOwned(sr_output_new(format->_structure, - map_to_hash_variant(options), device->_structure)), + map_to_hash_variant(options), device->_structure, NULL)), + _format(format), + _device(device), + _options(options) +{ +} + +Output::Output(string filename, shared_ptr format, + shared_ptr device, map options) : + UserOwned(sr_output_new(format->_structure, + map_to_hash_variant(options), device->_structure, filename.c_str())), _format(format), _device(device), _options(options) diff --git a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp index 54be95df..9bc9cdaa 100644 --- a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp +++ b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp @@ -957,7 +957,16 @@ public: /** Create an output using this format. * @param device Device to output for. * @param options Mapping of (option name, value) pairs. */ - shared_ptr create_output(shared_ptr device, + shared_ptr create_output( + shared_ptr device, + map options = + map()); + /** Create an output using this format. + * @param filename Name of destination file. + * @param device Device to output for. + * @param options Mapping of (option name, value) pairs. */ + shared_ptr create_output(string filename, + shared_ptr device, map options = map()); protected: @@ -978,6 +987,8 @@ protected: Output(shared_ptr format, shared_ptr device); Output(shared_ptr format, shared_ptr device, map options); + Output(string filename, shared_ptr format, + shared_ptr device, map options); ~Output(); const shared_ptr _format; const shared_ptr _device; diff --git a/include/libsigrok/proto.h b/include/libsigrok/proto.h index 3d07694d..788f80de 100644 --- a/include/libsigrok/proto.h +++ b/include/libsigrok/proto.h @@ -177,7 +177,8 @@ SR_API const struct sr_output_module *sr_output_find(char *id); SR_API const struct sr_option **sr_output_options_get(const struct sr_output_module *omod); SR_API void sr_output_options_free(const struct sr_option **opts); SR_API const struct sr_output *sr_output_new(const struct sr_output_module *omod, - GHashTable *params, const struct sr_dev_inst *sdi); + GHashTable *params, const struct sr_dev_inst *sdi, + const char *filename); SR_API int sr_output_send(const struct sr_output *o, const struct sr_datafeed_packet *packet, GString **out); SR_API int sr_output_free(const struct sr_output *o); diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 627e243c..3ab181b3 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -368,6 +368,11 @@ struct sr_output { */ const struct sr_dev_inst *sdi; + /** + * The name of the file that the data should be written to. + */ + const char *filename; + /** * A generic pointer which can be used by the module to keep internal * state between calls into its callback functions. diff --git a/src/output/output.c b/src/output/output.c index 5e2d409d..04f3054c 100644 --- a/src/output/output.c +++ b/src/output/output.c @@ -245,7 +245,8 @@ SR_API void sr_output_options_free(const struct sr_option **options) * @since 0.4.0 */ SR_API const struct sr_output *sr_output_new(const struct sr_output_module *omod, - GHashTable *options, const struct sr_dev_inst *sdi) + GHashTable *options, const struct sr_dev_inst *sdi, + const char *filename) { struct sr_output *op; const struct sr_option *mod_opts; @@ -258,6 +259,7 @@ SR_API const struct sr_output *sr_output_new(const struct sr_output_module *omod op = g_malloc(sizeof(struct sr_output)); op->module = omod; op->sdi = sdi; + op->filename = g_strdup(filename); new_opts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_variant_unref); @@ -335,6 +337,7 @@ SR_API int sr_output_free(const struct sr_output *o) ret = SR_OK; if (o->module->cleanup) ret = o->module->cleanup((struct sr_output *)o); + g_free((char *)o->filename); g_free((gpointer)o); return ret;