From ce93087febcc6823ad7fbe6d8c15e309d08a51ed Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Thu, 8 Nov 2012 13:29:13 +0100 Subject: [PATCH] Supporting generic notifications (through plug-ins) --- include/Phone/phone.h | 15 +++++++++++++++ src/phone.c | 13 ++++++++++++- src/plugins/debug.c | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/Phone/phone.h b/include/Phone/phone.h index ff01332..24b026c 100644 --- a/include/Phone/phone.h +++ b/include/Phone/phone.h @@ -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 { diff --git a/src/phone.c b/src/phone.c index 7eeb129..e10c635 100644 --- a/src/phone.c +++ b/src/phone.c @@ -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; diff --git a/src/plugins/debug.c b/src/plugins/debug.c index a56b868..5864090 100644 --- a/src/plugins/debug.c +++ b/src/plugins/debug.c @@ -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" },