From 0bba88736755a8d2d71c01c5e737155e80021954 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Mon, 28 Dec 2015 17:30:12 +0100 Subject: [PATCH] Code cleanup --- src/modems/hayes.c | 29 +---------------------- src/modems/hayes/channel.c | 48 ++++++++++++++++++++++++++++++++++++++ src/modems/hayes/channel.h | 3 +++ src/modems/project.conf | 2 +- 4 files changed, 53 insertions(+), 29 deletions(-) diff --git a/src/modems/hayes.c b/src/modems/hayes.c index 9f9be05..859ccb4 100644 --- a/src/modems/hayes.c +++ b/src/modems/hayes.c @@ -187,7 +187,6 @@ static int _hayes_queue_command(Hayes * hayes, HayesChannel * channel, static int _hayes_queue_command_full(Hayes * hayes, char const * attention, HayesCommandCallback callback); #endif -static void _hayes_queue_flush(Hayes * hayes, HayesChannel * channel); static int _hayes_queue_pop(Hayes * hayes, HayesChannel * channel); static int _hayes_queue_push(Hayes * hayes, HayesChannel * channel); @@ -614,7 +613,7 @@ static void _stop_channel(Hayes * hayes, HayesChannel * channel) if(channel->fp != NULL) fclose(channel->fp); channel->fp = NULL; - _hayes_queue_flush(hayes, channel); + hayeschannel_queue_flush(channel); _stop_giochannel(channel->channel); channel->channel = NULL; _stop_giochannel(channel->rd_ppp_channel); @@ -1178,32 +1177,6 @@ static int _hayes_queue_command_full(Hayes * hayes, #endif -/* hayes_queue_flush */ -static void _hayes_queue_flush(Hayes * hayes, HayesChannel * channel) -{ - g_slist_foreach(channel->queue_timeout, (GFunc)hayes_command_delete, - NULL); - g_slist_free(channel->queue_timeout); - channel->queue_timeout = NULL; - g_slist_foreach(channel->queue, (GFunc)hayes_command_delete, NULL); - g_slist_free(channel->queue); - channel->queue = NULL; - free(channel->rd_buf); - channel->rd_buf = NULL; - channel->rd_buf_cnt = 0; - _hayes_reset_source(&channel->rd_source); - free(channel->wr_buf); - channel->wr_buf = NULL; - channel->wr_buf_cnt = 0; - _hayes_reset_source(&channel->wr_source); - _hayes_reset_source(&channel->rd_ppp_source); - _hayes_reset_source(&channel->wr_ppp_source); - channel->authenticate_count = 0; - _hayes_reset_source(&channel->authenticate_source); - _hayes_reset_source(&channel->timeout); -} - - /* hayes_queue_pop */ static int _hayes_queue_pop(Hayes * hayes, HayesChannel * channel) { diff --git a/src/modems/hayes/channel.c b/src/modems/hayes/channel.c index c4211ca..2d35675 100644 --- a/src/modems/hayes/channel.c +++ b/src/modems/hayes/channel.c @@ -15,10 +15,17 @@ +#include +#include "command.h" #include "channel.h" /* HayesChannel */ +/* private */ +/* prototypes */ +static void _hayeschannel_reset_source(guint * source); + + /* public */ /* functions */ /* hayeschannel_init */ @@ -40,3 +47,44 @@ void hayeschannel_destroy(HayesChannel * channel) { (void) channel; } + + +/* useful */ +/* queue management */ +/* hayeschannel_queue_flush */ +void hayeschannel_queue_flush(HayesChannel * channel) +{ + g_slist_foreach(channel->queue_timeout, (GFunc)hayes_command_delete, + NULL); + g_slist_free(channel->queue_timeout); + channel->queue_timeout = NULL; + g_slist_foreach(channel->queue, (GFunc)hayes_command_delete, NULL); + g_slist_free(channel->queue); + channel->queue = NULL; + free(channel->rd_buf); + channel->rd_buf = NULL; + channel->rd_buf_cnt = 0; + _hayeschannel_reset_source(&channel->rd_source); + free(channel->wr_buf); + channel->wr_buf = NULL; + channel->wr_buf_cnt = 0; + _hayeschannel_reset_source(&channel->wr_source); + _hayeschannel_reset_source(&channel->rd_ppp_source); + _hayeschannel_reset_source(&channel->wr_ppp_source); + channel->authenticate_count = 0; + _hayeschannel_reset_source(&channel->authenticate_source); + _hayeschannel_reset_source(&channel->timeout); +} + + +/* private */ +/* functions */ +/* hayeschannel_reset_source */ +static void _hayeschannel_reset_source(guint * source) +{ + /* XXX duplicated from _hayes_reset_source() */ + if(*source == 0) + return; + g_source_remove(*source); + *source = 0; +} diff --git a/src/modems/hayes/channel.h b/src/modems/hayes/channel.h index e4c8015..0872a14 100644 --- a/src/modems/hayes/channel.h +++ b/src/modems/hayes/channel.h @@ -88,4 +88,7 @@ typedef struct _HayesChannel void hayeschannel_init(HayesChannel * channel, ModemPlugin * modem); void hayeschannel_destroy(HayesChannel * channel); +/* queue management */ +void hayeschannel_queue_flush(HayesChannel * channel); + #endif /* PHONE_MODEM_HAYES_CHANNEL_H */ diff --git a/src/modems/project.conf b/src/modems/project.conf index b1a38e6..ca7896b 100644 --- a/src/modems/project.conf +++ b/src/modems/project.conf @@ -30,7 +30,7 @@ install=$(LIBDIR)/Phone/modem depends=hayes/channel.h,hayes/command.h,hayes/quirks.h,hayes.h [hayes/channel.c] -depends=hayes/channel.h +depends=hayes/channel.h,hayes/command.h [hayes/command.c] depends=hayes/command.h