From: Soeren Apel Date: Thu, 28 Apr 2016 06:13:17 +0000 (+0200) Subject: Input: Add reset() function X-Git-Tag: libsigrok-0.5.0~437 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b6b4f03e404e06430eca810ad2bf7ccc84262b6e;p=libsigrok.git Input: Add reset() function --- diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index 1c5b97b0..5e07c2c6 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -1329,6 +1329,11 @@ void Input::end() check(sr_input_end(_structure)); } +void Input::reset() +{ + check(sr_input_reset(_structure)); +} + Input::~Input() { sr_input_free(_structure); diff --git a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp index eb7957e5..ad59f5b9 100644 --- a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp +++ b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp @@ -828,6 +828,7 @@ public: void send(void *data, size_t length); /** Signal end of input data. */ void end(); + void reset(); private: Input(shared_ptr context, const struct sr_input *structure); ~Input(); diff --git a/include/libsigrok/proto.h b/include/libsigrok/proto.h index 6ae3be8f..caa8407e 100644 --- a/include/libsigrok/proto.h +++ b/include/libsigrok/proto.h @@ -154,6 +154,7 @@ SR_API int sr_input_scan_file(const char *filename, const struct sr_input **in); SR_API struct sr_dev_inst *sr_input_dev_inst_get(const struct sr_input *in); SR_API int sr_input_send(const struct sr_input *in, GString *buf); SR_API int sr_input_end(const struct sr_input *in); +SR_API int sr_input_reset(const struct sr_input *in); SR_API void sr_input_free(const struct sr_input *in); /*--- output/output.c -------------------------------------------------------*/ diff --git a/src/input/input.c b/src/input/input.c index f2cc9769..f99902d3 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -559,6 +559,27 @@ SR_API int sr_input_end(const struct sr_input *in) return in->module->end((struct sr_input *)in); } +/** + * Reset the input module's input handling structures. + * + * Causes the input module to reset its internal state so that we can re-send + * the input data from the beginning without having to re-create the entire + * input module. + * + * @since 0.5.0 + */ +SR_API int sr_input_reset(const struct sr_input *in) +{ + if (!in->module->reset) { + sr_spew("Tried to reset %s module but no reset handler found.", + in->module->id); + return SR_OK; + } + + sr_spew("Resetting %s module.", in->module->id); + return in->module->reset((struct sr_input *)in); +} + /** * Free the specified input instance and all associated resources. * diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 0d6e0dab..589d0a4d 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -401,6 +401,18 @@ struct sr_input_module { */ int (*end) (struct sr_input *in); + /** + * Reset the input module's input handling structures. + * + * Causes the input module to reset its internal state so that we can + * re-send the input data from the beginning without having to + * re-create the entire input module. + * + * @retval SR_OK Success. + * @retval other Negative error code. + */ + int (*reset) (struct sr_input *in); + /** * This function is called after the caller is finished using * the input module, and can be used to free any internal