diff --git a/include/Phone/modem.h b/include/Phone/modem.h index 5c949d8..5c7a430 100644 --- a/include/Phone/modem.h +++ b/include/Phone/modem.h @@ -146,6 +146,7 @@ typedef enum _ModemEventType MODEM_EVENT_TYPE_CALL, MODEM_EVENT_TYPE_CONNECTION, MODEM_EVENT_TYPE_CONTACT, + MODEM_EVENT_TYPE_CONTACT_DELETED, MODEM_EVENT_TYPE_MESSAGE, MODEM_EVENT_TYPE_MESSAGE_DELETED, MODEM_EVENT_TYPE_MESSAGE_SENT, @@ -214,6 +215,13 @@ typedef union _ModemEvent char const * number; } contact; + /* MODEM_EVENT_TYPE_CONTACT_DELETED */ + struct + { + ModemEventType type; + unsigned int id; + } contact_deleted; + /* MODEM_EVENT_TYPE_MESSAGE */ struct { @@ -337,7 +345,6 @@ typedef union _ModemRequest struct { ModemRequestType type; - unsigned int id; char const * name; char const * number; } contact_new; diff --git a/src/modem.c b/src/modem.c index c3fe535..1db7acd 100644 --- a/src/modem.c +++ b/src/modem.c @@ -205,7 +205,6 @@ int modem_request_type(Modem * modem, ModemRequestType type, ...) request.contact.id = va_arg(ap, unsigned int); break; case MODEM_REQUEST_CONTACT_NEW: - request.contact_new.id = va_arg(ap, unsigned int); request.contact_new.name = va_arg(ap, char const *); request.contact_new.number = va_arg(ap, char const *); break; diff --git a/src/modems/debug.c b/src/modems/debug.c index c7d1c35..1e27c6e 100644 --- a/src/modems/debug.c +++ b/src/modems/debug.c @@ -230,6 +230,11 @@ static int _debug_request(ModemPlugin * modem, ModemRequest * request) memset(&event, 0, sizeof(event)); switch(request->type) { + case MODEM_REQUEST_CONTACT_DELETE: + event.type = MODEM_EVENT_TYPE_CONTACT_DELETED; + event.contact_deleted.id = request->contact_delete.id; + helper->event(helper->modem, &event); + break; case MODEM_REQUEST_CONTACT_NEW: debug->event_contact.type = MODEM_EVENT_TYPE_CONTACT; debug->event_contact.contact.id++; diff --git a/src/modems/hayes.c b/src/modems/hayes.c index d66cd33..2678a91 100644 --- a/src/modems/hayes.c +++ b/src/modems/hayes.c @@ -273,6 +273,8 @@ static HayesCommandStatus _on_request_call_outgoing(HayesCommand * command, HayesCommandStatus status, void * priv); static HayesCommandStatus _on_request_call_status(HayesCommand * command, HayesCommandStatus status, void * priv); +static HayesCommandStatus _on_request_contact_delete(HayesCommand * command, + HayesCommandStatus status, void * priv); static HayesCommandStatus _on_request_contact_list(HayesCommand * command, HayesCommandStatus status, void * priv); static HayesCommandStatus _on_request_functional(HayesCommand * command, @@ -492,6 +494,8 @@ static HayesRequestHandler _hayes_request_handlers[] = _on_request_call_status }, { MODEM_REQUEST_CALL_PRESENTATION, NULL, _on_request_generic }, + { MODEM_REQUEST_CONTACT_DELETE, NULL, + _on_request_contact_delete }, { MODEM_REQUEST_CONTACT_LIST, "AT+CPBR=?", _on_request_contact_list }, { MODEM_REQUEST_MESSAGE, NULL, @@ -609,6 +613,8 @@ static char * _request_attention_apn(char const * protocol, char const * apn); static char * _request_attention_call(ModemPlugin * modem, ModemRequest * request); static char * _request_attention_call_hangup(ModemPlugin * modem); +static char * _request_attention_contact_delete(ModemPlugin * modem, + unsigned int id); static char * _request_attention_contact_list(ModemRequest * request); static char * _request_attention_gprs(ModemPlugin * modem, char const * username, char const * password); @@ -700,12 +706,15 @@ static char * _request_attention(ModemPlugin * modem, ModemRequest * request) request->call_presentation.enabled ? 1 : 0); return strdup(buf); + case MODEM_REQUEST_CONTACT_DELETE: + return _request_attention_contact_delete(modem, + request->contact_delete.id); case MODEM_REQUEST_MESSAGE: return _request_attention_message(modem, request->message.id); case MODEM_REQUEST_MESSAGE_DELETE: return _request_attention_message_delete(modem, - request->message.id); + request->message_delete.id); case MODEM_REQUEST_MESSAGE_SEND: return _request_attention_message_send(modem, request->message_send.number, @@ -793,6 +802,19 @@ static char * _request_attention_call_hangup(ModemPlugin * modem) return NULL; } +static char * _request_attention_contact_delete(ModemPlugin * modem, + unsigned int id) +{ + Hayes * hayes = modem->priv; + char const cmd[] = "AT+CPBW="; + char buf[32]; + + /* FIXME store in the command itself */ + hayes->events[MODEM_EVENT_TYPE_CONTACT_DELETED].contact_deleted.id = id; + snprintf(buf, sizeof(buf), "%s%u%s", cmd, id, ",\"\""); + return strdup(buf); +} + static char * _request_attention_contact_list(ModemRequest * request) { HayesRequestContactList * list = request->plugin.data; @@ -1069,7 +1091,8 @@ static int _hayes_trigger(ModemPlugin * modem, ModemEventType event) e = &hayes->events[MODEM_EVENT_TYPE_STATUS]; modem->helper->event(modem->helper->modem, e); break; - case MODEM_EVENT_TYPE_ERROR: /* do not make sense */ + case MODEM_EVENT_TYPE_CONTACT_DELETED: /* do not make sense */ + case MODEM_EVENT_TYPE_ERROR: case MODEM_EVENT_TYPE_MESSAGE: case MODEM_EVENT_TYPE_MESSAGE_DELETED: case MODEM_EVENT_TYPE_MESSAGE_SENT: @@ -2293,6 +2316,21 @@ static HayesCommandStatus _on_request_call_status(HayesCommand * command, } +/* on_request_contact_delete */ +static HayesCommandStatus _on_request_contact_delete(HayesCommand * command, + HayesCommandStatus status, void * priv) +{ + ModemPlugin * modem = priv; + Hayes * hayes = modem->priv; + ModemEvent * event = &hayes->events[MODEM_EVENT_TYPE_CONTACT_DELETED]; + + if((status = _on_request_generic(command, status, priv)) != HCS_SUCCESS) + return status; + modem->helper->event(modem->helper->modem, event); + return status; +} + + /* on_request_contact_list */ static HayesCommandStatus _on_request_contact_list(HayesCommand * command, HayesCommandStatus status, void * priv)