Code cleanup

This commit is contained in:
Pierre Pronchery 2015-12-28 17:30:12 +01:00
parent 324ceb9f0d
commit 0bba887367
4 changed files with 53 additions and 29 deletions

View File

@ -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)
{

View File

@ -15,10 +15,17 @@
#include <stdlib.h>
#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;
}

View File

@ -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 */

View File

@ -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