]> sigrok.org Git - libsigrok.git/commitdiff
Add filename field to sr_output and make it accessible
authorSoeren Apel <redacted>
Wed, 29 Jul 2015 19:19:49 +0000 (21:19 +0200)
committerUwe Hermann <redacted>
Thu, 30 Jul 2015 17:21:42 +0000 (19:21 +0200)
This fixes parts of bug #570.

bindings/cxx/classes.cpp
bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp
include/libsigrok/proto.h
src/libsigrok-internal.h
src/output/output.c

index a08def8eebaed63d6482ffc17c5d6970da3bf2c5..357c9d6f3cbccac46f24a7d1c74025c525b40324 100644 (file)
@@ -1565,10 +1565,28 @@ shared_ptr<Output> OutputFormat::create_output(
                Output::Deleter());
 }
 
+shared_ptr<Output> OutputFormat::create_output(string filename,
+       shared_ptr<Device> device, map<string, Glib::VariantBase> options)
+{
+       return shared_ptr<Output>(
+               new Output(filename, shared_from_this(), device, options),
+               Output::Deleter());
+}
+
 Output::Output(shared_ptr<OutputFormat> format,
                shared_ptr<Device> device, map<string, Glib::VariantBase> 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<OutputFormat> format,
+               shared_ptr<Device> device, map<string, Glib::VariantBase> options) :
+       UserOwned(sr_output_new(format->_structure,
+               map_to_hash_variant(options), device->_structure, filename.c_str())),
        _format(format),
        _device(device),
        _options(options)
index 54be95df2d3f180ce36fe53178208ac882695aa2..9bc9cdaa11282ae4352839527d13c8b44900d286 100644 (file)
@@ -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<Output> create_output(shared_ptr<Device> device,
+       shared_ptr<Output> create_output(
+               shared_ptr<Device> device,
+               map<string, Glib::VariantBase> options =
+                       map<string, Glib::VariantBase>());
+       /** 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<Output> create_output(string filename,
+               shared_ptr<Device> device,
                map<string, Glib::VariantBase> options =
                        map<string, Glib::VariantBase>());
 protected:
@@ -978,6 +987,8 @@ protected:
        Output(shared_ptr<OutputFormat> format, shared_ptr<Device> device);
        Output(shared_ptr<OutputFormat> format,
                shared_ptr<Device> device, map<string, Glib::VariantBase> options);
+       Output(string filename, shared_ptr<OutputFormat> format,
+               shared_ptr<Device> device, map<string, Glib::VariantBase> options);
        ~Output();
        const shared_ptr<OutputFormat> _format;
        const shared_ptr<Device> _device;
index 3d07694d5f140b009842566d1f0ffb4c8eb897c8..788f80de1087601f751457cbdddb545fa2c6bdb2 100644 (file)
@@ -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);
index 627e243cc8348652d5c321fd9664bf6e578b8708..3ab181b3f87c80e2eb6a8d60e634aee8368b08bc 100644 (file)
@@ -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.
index 5e2d409d525ddc0c9fee24eab8392504548124ba..04f3054cf1deafeb7674e2fda07adc5c7a926fbb 100644 (file)
@@ -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;