Reviewed the queueing mechanism

This commit is contained in:
Pierre Pronchery 2011-11-03 13:35:21 +00:00
parent 594381e96d
commit f73186e74d
3 changed files with 60 additions and 42 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Phone 0.0.0\n" "Project-Id-Version: Phone 0.0.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-11-03 03:58+0100\n" "POT-Creation-Date: 2011-11-03 14:33+0100\n"
"PO-Revision-Date: 2010-04-24 02:07+0200\n" "PO-Revision-Date: 2010-04-24 02:07+0200\n"
"Last-Translator: Pierre Pronchery <khorben@defora.org>\n" "Last-Translator: Pierre Pronchery <khorben@defora.org>\n"
"Language-Team: DeforaOS development (French) <devel-fr@lists.defora.org>\n" "Language-Team: DeforaOS development (French) <devel-fr@lists.defora.org>\n"
@ -329,11 +329,11 @@ msgstr "Mauvais %s"
msgid "%s is valid" msgid "%s is valid"
msgstr "%s valide" msgstr "%s valide"
#: ../src/phone.c:3948 #: ../src/phone.c:3945
msgid "Raw data (not shown)" msgid "Raw data (not shown)"
msgstr "Données brutes (non affichées)" msgstr "Données brutes (non affichées)"
#: ../src/phone.c:3984 #: ../src/phone.c:3981
msgid "Message deleted" msgid "Message deleted"
msgstr "Message effacé" msgstr "Message effacé"

View File

@ -1457,13 +1457,15 @@ static int _parse_do(ModemPlugin * modem)
: NULL; : NULL;
HayesCommandStatus status; HayesCommandStatus status;
if(command == NULL) if(command == NULL || _hayes_command_get_status(command) != HCS_ACTIVE)
/* this was most likely unsollicited */ /* this was most likely unsollicited */
return _hayes_parse_trigger(modem, line, NULL); return _hayes_parse_trigger(modem, line, NULL);
_hayes_parse_trigger(modem, line, command);
if(_hayes_command_answer_append(command, line) != 0) if(_hayes_command_answer_append(command, line) != 0)
return -1; return -1;
if((status = _hayes_command_callback(command)) == HCS_ACTIVE) if((status = _hayes_command_get_status(command)) == HCS_ACTIVE)
_hayes_parse_trigger(modem, line, command); _hayes_command_callback(command);
/* unqueue if complete */
if((status = _hayes_command_get_status(command)) == HCS_SUCCESS if((status = _hayes_command_get_status(command)) == HCS_SUCCESS
|| status == HCS_ERROR || status == HCS_TIMEOUT) || status == HCS_ERROR || status == HCS_TIMEOUT)
{ {
@ -1542,9 +1544,11 @@ static int _hayes_queue_command(ModemPlugin * modem, HayesCommand * command)
return -1; return -1;
case HAYES_MODE_COMMAND: case HAYES_MODE_COMMAND:
case HAYES_MODE_DATA: case HAYES_MODE_DATA:
_hayes_command_set_status(command, HCS_QUEUED);
if(_hayes_command_get_status(command) != HCS_QUEUED)
return -1;
queue = hayes->queue; queue = hayes->queue;
hayes->queue = g_slist_append(hayes->queue, command); hayes->queue = g_slist_append(hayes->queue, command);
_hayes_command_set_status(command, HCS_QUEUED);
if(queue == NULL) if(queue == NULL)
_hayes_queue_push(modem); _hayes_queue_push(modem);
break; break;
@ -1652,15 +1656,19 @@ static int _hayes_queue_push(ModemPlugin * modem)
if(hayes->queue == NULL) /* nothing to send */ if(hayes->queue == NULL) /* nothing to send */
return 0; return 0;
command = hayes->queue->data; command = hayes->queue->data;
attention = _hayes_command_get_attention(command);
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s() pushing \"%s\"\n", __func__, attention);
#endif
if(hayes->mode == HAYES_MODE_DATA) if(hayes->mode == HAYES_MODE_DATA)
#if 0 /* FIXME does not seem to work (see ATS2, ATS12) */ #if 0 /* FIXME does not seem to work (see ATS2, ATS12) */
prefix = "+++\r\n"; prefix = "+++\r\n";
#else #else
return 0; /* XXX ignoring commands in DATA mode */ 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)
/* no longer push the command */
return 0;
attention = _hayes_command_get_attention(command);
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s() pushing \"%s\"\n", __func__, attention);
#endif #endif
size = strlen(prefix) + strlen(attention) + sizeof(suffix); size = strlen(prefix) + strlen(attention) + sizeof(suffix);
if((p = realloc(hayes->wr_buf, hayes->wr_buf_cnt + size)) == NULL) if((p = realloc(hayes->wr_buf, hayes->wr_buf_cnt + size)) == NULL)
@ -1670,7 +1678,6 @@ static int _hayes_queue_push(ModemPlugin * modem)
snprintf(&hayes->wr_buf[hayes->wr_buf_cnt], size, "%s%s%s", prefix, snprintf(&hayes->wr_buf[hayes->wr_buf_cnt], size, "%s%s%s", prefix,
attention, suffix); attention, suffix);
hayes->wr_buf_cnt += size; hayes->wr_buf_cnt += size;
_hayes_command_set_status(command, HCS_ACTIVE);
if(hayes->channel != NULL && hayes->wr_source == 0) if(hayes->channel != NULL && hayes->wr_source == 0)
hayes->wr_source = g_io_add_watch(hayes->channel, G_IO_OUT, hayes->wr_source = g_io_add_watch(hayes->channel, G_IO_OUT,
_on_watch_can_write, modem); _on_watch_can_write, modem);
@ -1770,6 +1777,8 @@ static void _hayes_reset_stop(ModemPlugin * modem)
memset(&hayes->events, 0, sizeof(hayes->events)); memset(&hayes->events, 0, sizeof(hayes->events));
for(i = 0; i < sizeof(hayes->events) / sizeof(*hayes->events); i++) for(i = 0; i < sizeof(hayes->events) / sizeof(*hayes->events); i++)
hayes->events[i].type = i; hayes->events[i].type = i;
/* reset mode */
hayes->mode = HAYES_MODE_INIT;
} }
static void _reset_stop_channel(GIOChannel * channel) static void _reset_stop_channel(GIOChannel * channel)
@ -1962,13 +1971,7 @@ static int _hayes_command_answer_append(HayesCommand * command,
/* hayes_command_callback */ /* hayes_command_callback */
static HayesCommandStatus _hayes_command_callback(HayesCommand * command) static HayesCommandStatus _hayes_command_callback(HayesCommand * command)
{ {
if(command->callback == NULL) if(command->callback != NULL)
{
if(command->status == HCS_ACTIVE)
/* we don't expect any answer */
command->status = HCS_SUCCESS;
}
else
command->status = command->callback(command, command->status, command->status = command->callback(command, command->status,
command->priv); command->priv);
return command->status; return command->status;
@ -1991,6 +1994,9 @@ static gboolean _on_queue_timeout(gpointer data)
hayes->queue_timeout = g_slist_remove(hayes->queue_timeout, command); hayes->queue_timeout = g_slist_remove(hayes->queue_timeout, command);
if(hayes->queue_timeout != NULL) if(hayes->queue_timeout != NULL)
hayes->source = g_timeout_add(1000, _on_queue_timeout, modem); hayes->source = g_timeout_add(1000, _on_queue_timeout, modem);
else
/* XXX check the registration again to be safe */
_hayes_request_type(modem, HAYES_REQUEST_REGISTRATION);
return FALSE; return FALSE;
} }
@ -2674,17 +2680,20 @@ static HayesCommandStatus _on_request_generic(HayesCommand * command,
HayesCommandStatus status, void * priv) HayesCommandStatus status, void * priv)
{ {
char const * answer; char const * answer;
char const * p;
if(status != HCS_ACTIVE) if(status != HCS_ACTIVE)
return status; return status;
for(answer = _hayes_command_get_answer(command); answer != NULL;) if((answer = _hayes_command_get_answer(command)) == NULL)
if(strcmp(answer, "OK") == 0) return status;
return HCS_SUCCESS; /* look for the last line */
else if(strcmp(answer, "ERROR") == 0) while((p = strchr(answer, '\n')) != NULL)
return HCS_ERROR; answer = ++p;
else if((answer = strchr(answer, '\n')) != NULL) if(strcmp(answer, "OK") == 0)
answer++; return HCS_SUCCESS;
return HCS_ACTIVE; else if(strcmp(answer, "ERROR") == 0)
return HCS_ERROR;
return status;
} }
@ -2818,6 +2827,9 @@ static HayesCommandStatus _on_request_sim_pin_valid(HayesCommand * command,
ModemEvent * event = &hayes->events[MODEM_EVENT_TYPE_AUTHENTICATION]; ModemEvent * event = &hayes->events[MODEM_EVENT_TYPE_AUTHENTICATION];
ModemRequest request; ModemRequest request;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%u)\n", __func__, status);
#endif
if((status = _on_request_generic(command, status, priv)) == HCS_ERROR if((status = _on_request_generic(command, status, priv)) == HCS_ERROR
|| status == HCS_TIMEOUT) || status == HCS_TIMEOUT)
{ {
@ -2842,15 +2854,14 @@ static HayesCommandStatus _on_request_sim_pin_valid(HayesCommand * command,
_hayes_request_type(modem, _hayes_request_type(modem,
HAYES_REQUEST_CALL_WAITING_UNSOLLICITED_ENABLE); HAYES_REQUEST_CALL_WAITING_UNSOLLICITED_ENABLE);
_hayes_request_type(modem, HAYES_REQUEST_CONNECTED_LINE_ENABLE); _hayes_request_type(modem, HAYES_REQUEST_CONNECTED_LINE_ENABLE);
_hayes_request_type(modem,
HAYES_REQUEST_REGISTRATION_UNSOLLICITED_ENABLE);
/* report new messages */ /* report new messages */
_hayes_request_type(modem, HAYES_REQUEST_MESSAGE_UNSOLLICITED_ENABLE); _hayes_request_type(modem, HAYES_REQUEST_MESSAGE_UNSOLLICITED_ENABLE);
/* report new notifications */ /* report new notifications */
_hayes_request_type(modem, _hayes_request_type(modem,
HAYES_REQUEST_SUPPLEMENTARY_SERVICE_DATA_ENABLE); HAYES_REQUEST_SUPPLEMENTARY_SERVICE_DATA_ENABLE);
/* refresh the registration status */ /* refresh the registration status */
_hayes_request_type(modem, HAYES_REQUEST_REGISTRATION); _hayes_request_type(modem,
HAYES_REQUEST_REGISTRATION_UNSOLLICITED_ENABLE);
/* refresh the current call status */ /* refresh the current call status */
_hayes_trigger(modem, MODEM_EVENT_TYPE_CALL); _hayes_trigger(modem, MODEM_EVENT_TYPE_CALL);
/* refresh the contact list */ /* refresh the contact list */
@ -2879,7 +2890,7 @@ static void _on_trigger_call_error(ModemPlugin * modem, char const * answer)
if(command != NULL) if(command != NULL)
_hayes_command_set_status(command, HCS_ERROR); _hayes_command_set_status(command, HCS_ERROR);
_hayes_trigger(modem, MODEM_EVENT_TYPE_CALL); _hayes_request_type(modem, HAYES_REQUEST_PHONE_ACTIVE);
} }
@ -3080,7 +3091,11 @@ static void _on_trigger_cme_error(ModemPlugin * modem, char const * answer)
switch(u) switch(u)
{ {
case 11: /* SIM PIN required */ case 11: /* SIM PIN required */
_on_trigger_cpin(modem, "SIM PIN");
_hayes_trigger(modem, MODEM_EVENT_TYPE_AUTHENTICATION);
break;
case 12: /* SIM PUK required */ case 12: /* SIM PUK required */
_on_trigger_cpin(modem, "SIM PUK");
_hayes_trigger(modem, MODEM_EVENT_TYPE_AUTHENTICATION); _hayes_trigger(modem, MODEM_EVENT_TYPE_AUTHENTICATION);
break; break;
case 14: /* SIM busy */ case 14: /* SIM busy */
@ -3097,7 +3112,7 @@ static void _on_trigger_cme_error(ModemPlugin * modem, char const * answer)
hayes->queue_timeout = g_slist_append( hayes->queue_timeout = g_slist_append(
hayes->queue_timeout, p); hayes->queue_timeout, p);
if(hayes->source == 0) if(hayes->source == 0)
hayes->source = g_timeout_add(1000, hayes->source = g_timeout_add(5000,
_on_queue_timeout, modem); _on_queue_timeout, modem);
break; break;
case 32: /* emergency calls only */ case 32: /* emergency calls only */
@ -3504,7 +3519,11 @@ static void _on_trigger_cms_error(ModemPlugin * modem, char const * answer)
switch(u) switch(u)
{ {
case 311: /* SIM PIN required */ case 311: /* SIM PIN required */
_on_trigger_cpin(modem, "SIM PIN");
_hayes_trigger(modem, MODEM_EVENT_TYPE_AUTHENTICATION);
break;
case 316: /* SIM PUK required */ case 316: /* SIM PUK required */
_on_trigger_cpin(modem, "SIM PUK");
_hayes_trigger(modem, MODEM_EVENT_TYPE_AUTHENTICATION); _hayes_trigger(modem, MODEM_EVENT_TYPE_AUTHENTICATION);
break; break;
case 314: /* SIM busy */ case 314: /* SIM busy */
@ -3522,7 +3541,7 @@ static void _on_trigger_cms_error(ModemPlugin * modem, char const * answer)
hayes->queue_timeout = g_slist_append( hayes->queue_timeout = g_slist_append(
hayes->queue_timeout, p); hayes->queue_timeout, p);
if(hayes->source == 0) if(hayes->source == 0)
hayes->source = g_timeout_add(1000, hayes->source = g_timeout_add(5000,
_on_queue_timeout, modem); _on_queue_timeout, modem);
break; break;
case 321: /* invalid memory index */ case 321: /* invalid memory index */
@ -3768,7 +3787,10 @@ static void _on_trigger_cpin(ModemPlugin * modem, char const * answer)
ModemEvent * event = &hayes->events[MODEM_EVENT_TYPE_AUTHENTICATION]; ModemEvent * event = &hayes->events[MODEM_EVENT_TYPE_AUTHENTICATION];
char * p; char * p;
if(strcmp(answer, "READY") == 0 || strcmp(answer, "OK") == 0) #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, answer);
#endif
if(strcmp(answer, "READY") == 0)
event->authentication.status = MODEM_AUTHENTICATION_STATUS_OK; event->authentication.status = MODEM_AUTHENTICATION_STATUS_OK;
else if(strcmp(answer, "SIM PIN") == 0 else if(strcmp(answer, "SIM PIN") == 0
|| strcmp(answer, "SIM PUK") == 0) || strcmp(answer, "SIM PUK") == 0)
@ -3819,8 +3841,7 @@ static void _on_trigger_creg(ModemPlugin * modem, char const * answer)
case 2: case 2:
if(u[0] != MODEM_REGISTRATION_MODE_MANUAL) if(u[0] != MODEM_REGISTRATION_MODE_MANUAL)
u[0] = MODEM_REGISTRATION_MODE_AUTOMATIC; u[0] = MODEM_REGISTRATION_MODE_AUTOMATIC;
u[1] = (res < 3) ? MODEM_REGISTRATION_STATUS_SEARCHING u[1] = MODEM_REGISTRATION_STATUS_SEARCHING;
: MODEM_REGISTRATION_STATUS_REGISTERED;
break; break;
case 3: case 3:
u[1] = MODEM_REGISTRATION_STATUS_DENIED; u[1] = MODEM_REGISTRATION_STATUS_DENIED;
@ -3859,10 +3880,10 @@ static void _on_trigger_creg(ModemPlugin * modem, char const * answer)
hayes->registration_operator = NULL; hayes->registration_operator = NULL;
event->registration._operator = NULL; event->registration._operator = NULL;
event->registration.signal = 0.0 / 0.0; event->registration.signal = 0.0 / 0.0;
/* this is usually an unsollicited event */
modem->helper->event(modem->helper->modem, event);
break; break;
} }
/* this is usually an unsollicited event */
modem->helper->event(modem->helper->modem, event);
} }

View File

@ -3881,9 +3881,6 @@ static void _modem_event_authentication(Phone * phone, ModemEvent * event)
break; break;
snprintf(buf, sizeof(buf), _("%s is valid"), name); snprintf(buf, sizeof(buf), _("%s is valid"), name);
_phone_info(phone, phone->en_window, buf, callback); _phone_info(phone, phone->en_window, buf, callback);
/* obtain the registration status */
modem_trigger(phone->modem,
MODEM_EVENT_TYPE_REGISTRATION);
break; break;
case MODEM_AUTHENTICATION_STATUS_REQUIRED: case MODEM_AUTHENTICATION_STATUS_REQUIRED:
if(event->authentication.method if(event->authentication.method