e/notification: improve consistency of the API

Rename some functions and fields to have a better API. Also sanitize the
method and signal tables.



SVN revision: 82117
devs/asdfuser/comp-sounds
Lucas De Marchi 10 years ago
parent ab185d46c3
commit 8ec8c40bb7
  1. 57
      src/bin/e_notification.c
  2. 34
      src/bin/e_notification.h

@ -59,7 +59,6 @@ notify_cb(const EDBus_Service_Interface *iface EINA_UNUSED, const EDBus_Message
{
E_Notification_Notify *n;
EDBus_Message_Iter *actions_iter, *hints_iter;
unsigned id;
EDBus_Message *reply;
if (!n_data->notify_cb)
@ -83,9 +82,9 @@ notify_cb(const EDBus_Service_Interface *iface EINA_UNUSED, const EDBus_Message
n->sumary = eina_stringshare_add(n->sumary);
n->body = eina_stringshare_add(n->body);
id = n_data->notify_cb(n_data->data, n);
n->id = n_data->notify_cb(n_data->data, n);
reply = edbus_message_method_return_new(msg);
edbus_message_arguments_append(reply, "u", id);
edbus_message_arguments_append(reply, "u", n->id);
return reply;
}
@ -131,25 +130,28 @@ server_info_cb(const EDBus_Service_Interface *iface EINA_UNUSED, const EDBus_Mes
static const EDBus_Method methods[] = {
{ "Notify",
EDBUS_ARGS({"s", "app_name"}, {"u", "replaces_id"}, {"s", "app_icon"}, {"s", "summary"}, {"s", "body"}, {"as", "actions"}, {"a{sv}", "hints"}, {"i", "expire_timeout"}),
EDBUS_ARGS({"u", "id"}), notify_cb, 0
},
{
"CloseNotification", EDBUS_ARGS({"u", "id"}), NULL, close_notification_cb, 0
},
{
"GetCapabilities", NULL, EDBUS_ARGS({"as", "capabilities"}), capabilities_cb, 0
},
{
"GetServerInformation", NULL,
EDBUS_ARGS({"s", "name"}, {"s", "vendor"}, {"s", "version"}, {"s", "spec_version"}), server_info_cb, 0
},
{ NULL, NULL, NULL, NULL, 0 }
EDBUS_ARGS({"u", "id"}), notify_cb },
{ "CloseNotification", EDBUS_ARGS({"u", "id"}), NULL, close_notification_cb },
{ "GetCapabilities", NULL, EDBUS_ARGS({"as", "capabilities"}),
capabilities_cb },
{ "GetServerInformation", NULL,
EDBUS_ARGS({"s", "name"}, {"s", "vendor"}, {"s", "version"}, {"s", "spec_version"}),
server_info_cb },
{ }
};
enum
{
SIGNAL_NOTIFICATION_CLOSED = 0,
SIGNAL_ACTION_INVOKED,
};
static const EDBus_Signal signals[] = {
{"NotificationClosed", EDBUS_ARGS({"u", "id"}, {"u", "reason"}), 0},
{"ActionInvoked", EDBUS_ARGS({"u", "id"}, {"s", "action_key"}), 0},
{ NULL, NULL, 0}
[SIGNAL_NOTIFICATION_CLOSED] =
{ "NotificationClosed", EDBUS_ARGS({"u", "id"}, {"u", "reason"}) },
[SIGNAL_ACTION_INVOKED] =
{ "ActionInvoked", EDBUS_ARGS({"u", "id"}, {"s", "action_key"}) },
{ }
};
#define PATH "/org/freedesktop/Notifications"
@ -161,7 +163,7 @@ static const EDBus_Service_Interface_Desc desc = {
};
EAPI Eina_Bool
e_notification_start(E_Notification_Notify_Cb notification_cb, E_Notification_Close_Cb close_cb, const E_Notification_Server_Info *server_info, const void *data)
e_notification_server_register(const E_Notification_Server_Info *server_info, E_Notification_Notify_Cb n_cb, E_Notification_Close_Cb close_cb, const void *data)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(server_info, EINA_FALSE);
if (n_data)
@ -172,17 +174,18 @@ e_notification_start(E_Notification_Notify_Cb notification_cb, E_Notification_Cl
edbus_init();
n_data->conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SESSION);
n_data->iface = edbus_service_interface_register(n_data->conn, PATH, &desc);
n_data->notify_cb = notification_cb;
n_data->notify_cb = n_cb;
n_data->close_cb = close_cb;
n_data->data = (void *) data;
n_data->server_info = server_info;
edbus_name_request(n_data->conn, BUS,
EDBUS_NAME_REQUEST_FLAG_REPLACE_EXISTING, NULL, NULL);
return EINA_TRUE;
}
EAPI void
e_notification_stop(void)
e_notification_server_unregister(void)
{
EINA_SAFETY_ON_NULL_RETURN(n_data);
edbus_service_interface_unregister(n_data->iface);
@ -208,15 +211,17 @@ e_notification_notify_free(E_Notification_Notify *notify)
}
EAPI void
e_notification_notification_closed(unsigned id, E_Notification_Closed_Reason reason)
e_notification_notify_close(E_Notification_Notify *notify, E_Notification_Notify_Closed_Reason reason)
{
EINA_SAFETY_ON_NULL_RETURN(n_data);
EINA_SAFETY_ON_FALSE_RETURN(reason <= E_NOTIFICATION_CLOSED_REASON_UNDEFINED);
edbus_service_signal_emit(n_data->iface, 0, id, reason);
EINA_SAFETY_ON_NULL_RETURN(notify);
EINA_SAFETY_ON_FALSE_RETURN(reason <= E_NOTIFICATION_NOTIFY_CLOSED_REASON_UNDEFINED);
edbus_service_signal_emit(n_data->iface, SIGNAL_NOTIFICATION_CLOSED,
notify->id, reason);
}
EAPI Evas_Object *
e_notification_raw_image_get(Evas *evas, E_Notification_Notify *notify)
e_notification_notify_raw_image_get(E_Notification_Notify *notify, Evas *evas)
{
Evas_Object *o;
unsigned char *imgdata;

@ -11,16 +11,17 @@ typedef enum _E_Notification_Notify_Urgency
E_NOTIFICATION_NOTIFY_URGENCY_CRITICAL
} E_Notification_Notify_Urgency;
typedef enum _E_Notification_Closed_Reason
typedef enum _E_Notification_Notify_Closed_Reason
{
E_NOTIFICATION_CLOSED_REASON_EXPIRED, /** The notification expired. */
E_NOTIFICATION_CLOSED_REASON_DISMISSED, /** The notification was dismissed by the user. */
E_NOTIFICATION_CLOSED_REASON_REQUESTED, /** The notification was closed by a call to CloseNotification method. */
E_NOTIFICATION_CLOSED_REASON_UNDEFINED /** Undefined/reserved reasons. */
} E_Notification_Closed_Reason;
E_NOTIFICATION_NOTIFY_CLOSED_REASON_EXPIRED, /** The notification expired. */
E_NOTIFICATION_NOTIFY_CLOSED_REASON_DISMISSED, /** The notification was dismissed by the user. */
E_NOTIFICATION_NOTIFY_CLOSED_REASON_REQUESTED, /** The notification was closed by a call to CloseNotification method. */
E_NOTIFICATION_NOTIFY_CLOSED_REASON_UNDEFINED /** Undefined/reserved reasons. */
} E_Notification_Notify_Closed_Reason;
typedef struct _E_Notification_Notify
{
unsigned int id;
const char *app_name;
unsigned replaces_id;
const char *sumary;
@ -57,10 +58,23 @@ typedef struct _E_Notification_Server_Info
const char *capabilities[];
} E_Notification_Server_Info;
/**
* Register a notification server
*
* It's only possible to have one server registered at a time. If this function
* is called twice it will return EINA_FALSE on the second time.
*
* @return EINA_TRUE if server was registered, EINA_FALSE otherwise.
*/
EAPI Eina_Bool e_notification_server_register(const E_Notification_Server_Info *server_info, E_Notification_Notify_Cb notify_cb, E_Notification_Close_Cb close_cb, const void *data);
/**
* Unregister the sole notification server
*/
EAPI void e_notification_server_unregister(void);
EAPI void e_notification_notify_free(E_Notification_Notify *notify);
EAPI void e_notification_stop(void);
EAPI Eina_Bool e_notification_start(E_Notification_Notify_Cb notification_cb, E_Notification_Close_Cb close_cb, const E_Notification_Server_Info *server_info, const void *data);
EAPI void e_notification_notification_closed(unsigned id, E_Notification_Closed_Reason reason);
EAPI Evas_Object *e_notification_raw_image_get(Evas *evas, E_Notification_Notify *notify);
EAPI void e_notification_notify_close(E_Notification_Notify *notify, E_Notification_Notify_Closed_Reason reason);
EAPI Evas_Object *e_notification_notify_raw_image_get(E_Notification_Notify *notify, Evas *evas);
#endif

Loading…
Cancel
Save