Code cleanup

This commit is contained in:
Pierre Pronchery 2014-08-12 19:14:00 +02:00
parent 8e14b7bf7a
commit 318b495c67
3 changed files with 21 additions and 9 deletions

View File

@ -1027,8 +1027,7 @@ static int _parse_do(Hayes * hayes, HayesChannel * channel)
if((status = hayes_command_get_status(command)) == HCS_ACTIVE)
hayes_command_callback(command);
/* unqueue if complete */
if((status = hayes_command_get_status(command)) == HCS_SUCCESS
|| status == HCS_ERROR || status == HCS_TIMEOUT)
if(hayes_command_is_complete(command))
{
_hayes_queue_pop(hayes, channel);
_hayes_queue_push(hayes, channel);
@ -1105,8 +1104,8 @@ static int _hayes_queue_command(Hayes * hayes, HayesChannel * channel,
return -1;
case HAYES_MODE_COMMAND:
case HAYES_MODE_DATA:
hayes_command_set_status(command, HCS_QUEUED);
if(hayes_command_get_status(command) != HCS_QUEUED)
if(hayes_command_set_status(command, HCS_QUEUED)
!= HCS_QUEUED)
return -1;
queue = channel->queue;
channel->queue = g_slist_append(channel->queue,
@ -1217,8 +1216,7 @@ static int _hayes_queue_push(Hayes * hayes, HayesChannel * channel)
#else
return 0; /* XXX keep commands in the queue in DATA mode */
#endif
hayes_command_set_status(command, HCS_ACTIVE);
if(hayes_command_get_status(command) != HCS_ACTIVE)
if(hayes_command_set_status(command, HCS_ACTIVE) != HCS_ACTIVE)
/* no longer push the command */
return 0;
attention = hayes_command_get_attention(command);

View File

@ -94,6 +94,7 @@ void hayes_command_delete(HayesCommand * command)
}
/* accessors */
/* hayes_command_get_answer */
char const * hayes_command_get_answer(HayesCommand * command)
{
@ -166,6 +167,15 @@ unsigned int hayes_command_get_timeout(HayesCommand * command)
}
/* hayes_command_is_complete */
int hayes_command_is_complete(HayesCommand * command)
{
return command->status == HCS_SUCCESS
|| command->status == HCS_ERROR
|| command->status == HCS_TIMEOUT;
}
/* hayes_command_set_callback */
void hayes_command_set_callback(HayesCommand * command,
HayesCommandCallback callback, void * priv)
@ -191,11 +201,11 @@ void hayes_command_set_priority(HayesCommand * command,
/* hayes_command_set_status */
void hayes_command_set_status(HayesCommand * command,
HayesCommandStatus hayes_command_set_status(HayesCommand * command,
HayesCommandStatus status)
{
command->status = status;
hayes_command_callback(command);
return hayes_command_callback(command);
}
@ -207,6 +217,7 @@ void hayes_command_set_timeout(HayesCommand * command,
}
/* useful */
/* hayes_command_answer_append */
int hayes_command_answer_append(HayesCommand * command,
char const * answer)

View File

@ -64,15 +64,18 @@ char * hayes_command_get_line(HayesCommand * command,
HayesCommandPriority hayes_command_get_priority(HayesCommand * command);
HayesCommandStatus hayes_command_get_status(HayesCommand * command);
unsigned int hayes_command_get_timeout(HayesCommand * command);
int hayes_command_is_complete(HayesCommand * command);
void hayes_command_set_callback(HayesCommand * command,
HayesCommandCallback callback, void * priv);
void hayes_command_set_data(HayesCommand * command, void * data);
void hayes_command_set_priority(HayesCommand * command,
HayesCommandPriority priority);
void hayes_command_set_status(HayesCommand * command,
HayesCommandStatus hayes_command_set_status(HayesCommand * command,
HayesCommandStatus status);
void hayes_command_set_timeout(HayesCommand * command,
unsigned int timeout);
/* useful */
int hayes_command_answer_append(HayesCommand * command,
char const * answer);
HayesCommandStatus hayes_command_callback(HayesCommand * command);