diff options
author | Gerhard Sittig <gerhard.sittig@gmx.net> | 2021-12-26 07:42:27 +0100 |
---|---|---|
committer | Gerhard Sittig <gerhard.sittig@gmx.net> | 2021-12-26 13:45:09 +0100 |
commit | 819e508972da02a0dcff7f81178f0283546a9afd (patch) | |
tree | 5a48cb02cf7b712e2d152e547b7fab6ab969c8dd /session.c | |
parent | 487890c822762d9886dfd022ed599c9909ceaab9 (diff) | |
download | libsigrokdecode-819e508972da02a0dcff7f81178f0283546a9afd.tar.gz libsigrokdecode-819e508972da02a0dcff7f81178f0283546a9afd.zip |
session: introduce the public "send EOF" API routine
Introduce the public srd_session_send_eof() routine which is backed by
the internal srd_inst_send_eof() helper. Applications can tell decoders
when the input stream of sample data is exhausted, so that decoders can
optionally "flush" their previously accumulated information when
desired. Previous implementations just kept decoders in blocking .wait()
calls and somehow terminated them at arbitrary times afterwards.
When EOF is sent to the decoder session, then calls to the .wait()
method which typically are done from .decode() or its descendents will
end with an EOFError Python exception. Termination of .decode() with the
EOFError exception is non-fatal for backwards compatibility and to keep
the convenience for current decoder implementations. Decoders can either
catch the exception, or use context managers, or do nothing.
This API extension is motivated by research for bug #1581 and provides
the infrastructure to address bug #292. Decoders need to remain careful,
and should not claim that protocol activities would have completed when
their end condition was not even seen in the capture. Marking incomplete
activities with warnings is the most appropriate reaction.
Diffstat (limited to 'session.c')
-rw-r--r-- | session.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -279,6 +279,32 @@ SRD_API int srd_session_send(struct srd_session *sess, } /** + * Communicate the end of the stream of sample data to the session. + * + * @param[in] sess The session. Must not be NULL. + * + * @return SRD_OK upon success. A (negative) error code otherwise. + * + * @since 0.6.0 + */ +SRD_API int srd_session_send_eof(struct srd_session *sess) +{ + GSList *d; + int ret; + + if (!sess) + return SRD_ERR_ARG; + + for (d = sess->di_list; d; d = d->next) { + ret = srd_inst_send_eof(d->data); + if (ret != SRD_OK) + return ret; + } + + return SRD_OK; +} + +/** * Terminate currently executing decoders in a session, reset internal state. * * All decoder instances have their .wait() method terminated, which |