Supporting generic notifications (through plug-ins)

This commit is contained in:
Pierre Pronchery 2012-11-08 13:29:13 +01:00
parent dd545af274
commit ce93087feb
3 changed files with 28 additions and 1 deletions

View File

@ -45,6 +45,13 @@ typedef enum _PhoneEncoding
PHONE_ENCODING_DATA
} PhoneEncoding;
typedef enum _PhoneNotificationType
{
PHONE_NOTIFICATION_TYPE_INFO = 0,
PHONE_NOTIFICATION_TYPE_ERROR,
PHONE_NOTIFICATION_TYPE_WARNING
} PhoneNotificationType;
typedef enum _PhoneEventType
{
PHONE_EVENT_TYPE_KEY_TONE,
@ -55,6 +62,7 @@ typedef enum _PhoneEventType
char **, size_t * */
PHONE_EVENT_TYPE_MESSAGE_SENT,
PHONE_EVENT_TYPE_MODEM_EVENT, /* ModemEvent * event */
PHONE_EVENT_TYPE_NOTIFICATION,
PHONE_EVENT_TYPE_NOTIFICATION_OFF,
PHONE_EVENT_TYPE_NOTIFICATION_ON, /* char const * message? */
PHONE_EVENT_TYPE_OFFLINE,
@ -85,6 +93,13 @@ typedef union _PhoneEvent
ModemEvent * event;
} modem_event;
/* PHONE_EVENT_TYPE_NOTIFICATION */
struct
{
PhoneEventType type;
char const * message;
} notification;
/* PHONE_EVENT_TYPE_VOLUME_GET, PHONE_EVENT_TYPE_VOLUME_SET */
struct
{

View File

@ -619,6 +619,9 @@ int phone_error(Phone * phone, char const * message, int ret)
{
if(phone == NULL)
return _error_text(message, ret);
if(phone_event_type(phone, PHONE_EVENT_TYPE_NOTIFICATION,
PHONE_NOTIFICATION_TYPE_ERROR, message) != 0)
return ret;
return _phone_error(NULL, message, ret);
}
@ -1001,6 +1004,11 @@ int phone_event_type(Phone * phone, PhoneEventType type, ...)
event.modem_event.event = va_arg(ap, ModemEvent *);
va_end(ap);
break;
case PHONE_EVENT_TYPE_NOTIFICATION:
event.notification.type = va_arg(ap,
PhoneNotificationType);
event.notification.message = va_arg(ap, char const *);
break;
case PHONE_EVENT_TYPE_VOLUME_GET:
level = va_arg(ap, double *);
va_end(ap);
@ -1027,7 +1035,9 @@ int phone_event_type(Phone * phone, PhoneEventType type, ...)
/* phone_info */
void phone_info(Phone * phone, char const * message)
{
_phone_info(phone, NULL, message, NULL);
if(phone_event_type(phone, PHONE_EVENT_TYPE_NOTIFICATION,
PHONE_NOTIFICATION_TYPE_INFO, message) == 0)
_phone_info(phone, NULL, message, NULL);
}
@ -4053,6 +4063,7 @@ static void _modem_event_authentication(Phone * phone, ModemEvent * event)
phone_code_clear(phone);
if(name == NULL)
break;
/* FIXME turn this into a simple notification */
snprintf(buf, sizeof(buf), _("%s is valid"), name);
_phone_info(phone, phone->en_window, buf, callback);
break;

View File

@ -103,6 +103,7 @@ static DebugPhoneEvent _debug_phone_events[] =
{
{ PHONE_EVENT_TYPE_KEY_TONE, "KEY_TONE" },
{ PHONE_EVENT_TYPE_MODEM_EVENT, "MODEM_EVENT" },
{ PHONE_EVENT_TYPE_NOTIFICATION, "NOTIFICATION" },
{ PHONE_EVENT_TYPE_NOTIFICATION_OFF, "NOTIFICATION_OFF" },
{ PHONE_EVENT_TYPE_NOTIFICATION_ON, "NOTIFICATION_ON" },
{ PHONE_EVENT_TYPE_ONLINE, "ONLINE" },