From d3ac0d253e35c3d40dbc952becaec37b952e4eb4 Mon Sep 17 00:00:00 2001 From: Christian Spielberger Date: Mon, 19 Sep 2022 16:23:38 +0200 Subject: [PATCH 1/2] telev: add telev_is_empty() --- include/re_telev.h | 1 + src/telev/telev.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/re_telev.h b/include/re_telev.h index ed22a5d7a..ba0730a96 100644 --- a/include/re_telev.h +++ b/include/re_telev.h @@ -18,6 +18,7 @@ int telev_set_srate(struct telev *tel, uint32_t srate); int telev_send(struct telev *tel, int event, bool end); int telev_recv(struct telev *tel, struct mbuf *mb, int *event, bool *end); int telev_poll(struct telev *tel, bool *marker, struct mbuf *mb); +bool telev_is_empty(struct telev *tel); int telev_digit2code(int digit); int telev_code2digit(int code); diff --git a/src/telev/telev.c b/src/telev/telev.c index 4e4d71f70..344f66e0b 100644 --- a/src/telev/telev.c +++ b/src/telev/telev.c @@ -341,6 +341,12 @@ int telev_poll(struct telev *tel, bool *marker, struct mbuf *mb) } +bool telev_is_empty(struct telev *tel) +{ + return tel->state == IDLE && !mbuf_get_left(tel->mb); +} + + /** * Convert DTMF digit to Event code * From 9162e9c0e7e784120b316163ec8b477312117dd9 Mon Sep 17 00:00:00 2001 From: Christian Spielberger Date: Tue, 20 Sep 2022 11:47:05 +0200 Subject: [PATCH 2/2] telev: make parameter const and add NULL pointer check --- include/re_telev.h | 2 +- src/telev/telev.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/re_telev.h b/include/re_telev.h index ba0730a96..f9b9700c7 100644 --- a/include/re_telev.h +++ b/include/re_telev.h @@ -18,7 +18,7 @@ int telev_set_srate(struct telev *tel, uint32_t srate); int telev_send(struct telev *tel, int event, bool end); int telev_recv(struct telev *tel, struct mbuf *mb, int *event, bool *end); int telev_poll(struct telev *tel, bool *marker, struct mbuf *mb); -bool telev_is_empty(struct telev *tel); +bool telev_is_empty(const struct telev *tel); int telev_digit2code(int digit); int telev_code2digit(int code); diff --git a/src/telev/telev.c b/src/telev/telev.c index 344f66e0b..19faaa046 100644 --- a/src/telev/telev.c +++ b/src/telev/telev.c @@ -341,8 +341,11 @@ int telev_poll(struct telev *tel, bool *marker, struct mbuf *mb) } -bool telev_is_empty(struct telev *tel) +bool telev_is_empty(const struct telev *tel) { + if (!tel) + return true; + return tel->state == IDLE && !mbuf_get_left(tel->mb); }