From: Uwe Hermann Date: Tue, 10 Feb 2015 19:42:50 +0000 (+0100) Subject: transform: Add struct sr_transform and struct sr_transform_module. X-Git-Tag: libsigrok-0.4.0~658 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=790320f605062718115d791d2b46c1e54bc4908e transform: Add struct sr_transform and struct sr_transform_module. --- diff --git a/include/libsigrok/libsigrok.h b/include/libsigrok/libsigrok.h index 65e9da80..c0ec19ff 100644 --- a/include/libsigrok/libsigrok.h +++ b/include/libsigrok/libsigrok.h @@ -515,6 +515,8 @@ struct sr_input; struct sr_input_module; struct sr_output; struct sr_output_module; +struct sr_transform; +struct sr_transform_module; /** Constants for channel type. */ enum sr_channeltype { diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 71f65616..14320a75 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -433,6 +433,93 @@ struct sr_output_module { int (*cleanup) (struct sr_output *o); }; +/** Transform module instance. */ +struct sr_transform { + /** A pointer to this transform's module. */ + const struct sr_transform_module *module; + + /** + * The device for which this transform module is used. This + * can be used by the module to find out channel names and numbers. + */ + const struct sr_dev_inst *sdi; + + /** + * A generic pointer which can be used by the module to keep internal + * state between calls into its callback functions. + */ + void *priv; +}; + +struct sr_transform_module { + /** + * A unique ID for this transform module, suitable for use in + * command-line clients, [a-z0-9-]. Must not be NULL. + */ + char *id; + + /** + * A unique name for this transform module, suitable for use in GUI + * clients, can contain UTF-8. Must not be NULL. + */ + const char *name; + + /** + * A short description of the transform module. Must not be NULL. + * + * This can be displayed by frontends, e.g. when selecting + * which transform module(s) to add. + */ + char *desc; + + /** + * Returns a NULL-terminated list of options this transform module + * can take. Can be NULL, if the transform module has no options. + */ + const struct sr_option *(*options) (void); + + /** + * This function is called once, at the beginning of a stream. + * + * @param t Pointer to the respective 'struct sr_transform'. + * @param options Hash table of options for this transform module. + * Can be NULL if no options are to be used. + * + * @retval SR_OK Success + * @retval other Negative error code. + */ + int (*init) (struct sr_transform *t, GHashTable *options); + + /** + * This function is passed a pointer to every packet in the data feed. + * + * It can either return (in packet_out) a pointer to another packet + * (possibly the exact same packet it got as input), or NULL. + * + * @param t Pointer to the respective 'struct sr_transform'. + * @param packet_in Pointer to a datafeed packet. + * @param packet_out Pointer to the resulting datafeed packet after + * this function was run. If NULL, the transform + * module intentionally didn't output a new packet. + * + * @retval SR_OK Success + * @retval other Negative error code. + */ + int (*receive) (const struct sr_transform *t, + struct sr_datafeed_packet *packet_in, + struct sr_datafeed_packet **packet_out); + + /** + * This function is called after the caller is finished using + * the transform module, and can be used to free any internal + * resources the module may keep. + * + * @retval SR_OK Success + * @retval other Negative error code. + */ + int (*cleanup) (struct sr_transform *t); +}; + #ifdef HAVE_LIBUSB_1_0 /** USB device instance */ struct sr_usb_dev_inst {