From: Corentin Lecouvey Date: Mon, 1 Sep 2014 08:05:17 +0000 (+0200) Subject: Create a "notification-display-service" daemon X-Git-Tag: accepted/tizen/ivi/20140912.193609^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2e671f2fe8c77fc9b560148f0263f26ec5b88713;p=platform%2Fcore%2Fappfw%2Fnotification-service.git Create a "notification-display-service" daemon "notification-display-service" is run by a systemd unit named "notifications-display.service" ; if we are running under a Wayland or X11 profile, it will display new notifications under the form of customized popup windows, and delete them once they are validated with "Ok". Otherwise, it will just print the messages to stderr without deleting them. Change-Id: Id33b01d67df4d731f666c2b145262642ca21cdbc Signed-off-by: Manuel Bachmann Author: Manuel Bachmann Author: Corentin Lecouvey --- diff --git a/Makefile.am b/Makefile.am index 60a8844..3ff5d19 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -bin_PROGRAMS = notification-service sample-display-client send-notification bluetooth_notification_client +bin_PROGRAMS = notification-service notification-display-service sample-display-client send-notification bluetooth_notification_client AM_CFLAGS = $(GCC_CFLAGS) AM_CPPFLAGS = $(GCC_CFLAGS) @@ -10,6 +10,10 @@ notification_service_SOURCES = \ notification_service_CFLAGS = -I. $(TIZEN_CFLAGS) notification_service_LDADD = $(TIZEN_LIBS) +notification_display_service_SOURCES = notification_display_service.c +notification_display_service_CFLAGS = -I. $(TIZEN_CFLAGS) +notification_display_service_LDADD = $(TIZEN_LIBS) + send_notification_SOURCES = send_notification.c send_notification_CFLAGS = -I. $(TIZEN_CFLAGS) send_notification_LDADD = $(TIZEN_LIBS) @@ -23,8 +27,10 @@ bluetooth_notification_client_CFLAGS = -I. $(TIZEN_CFLAGS) bluetooth_notification_client_LDADD = $(TIZEN_LIBS) SCRIPT_IN_FILES = \ - notifications.service.in + notifications.service.in \ + notifications-display.service.in install-data-hook: $(mkinstalldirs) $(DESTDIR)/usr/lib/systemd/system/ install -m 0644 notifications.service $(DESTDIR)/usr/lib/systemd/system/notifications.service + install -m 0644 notifications-display.service $(DESTDIR)/usr/lib/systemd/system/notifications-display.service diff --git a/configure.ac b/configure.ac index 194baa9..edb8edb 100644 --- a/configure.ac +++ b/configure.ac @@ -14,6 +14,6 @@ PKG_CHECK_MODULES([TIZEN], [eina ecore com-core notification dbus-1 bluetooth-ap AC_SUBST(TIZEN_CFLAGS) AC_SUBST(TIZEN_LIBS) -AC_CONFIG_FILES([Makefile notifications.service]) +AC_CONFIG_FILES([Makefile notifications.service notifications-display.service]) AC_PROG_RANLIB([ranlib]) AC_OUTPUT diff --git a/notification_display_service.c b/notification_display_service.c new file mode 100644 index 0000000..df35e42 --- /dev/null +++ b/notification_display_service.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include +#include + + +void display_notifications_cb (void *data, notification_type_e notif_type) +{ + notification_h noti = NULL; + notification_list_h notification_list = NULL; + notification_list_h get_list = NULL; + + char *pkgname = NULL; + char *title = NULL; + char *content = NULL; + char *image_path = NULL; + + notification_get_list (NOTIFICATION_TYPE_NOTI, -1, ¬ification_list); + if (notification_list) { + get_list = notification_list_get_head (notification_list); + while (get_list) { + noti = notification_list_get_data (get_list); + notification_get_pkgname (noti, &pkgname); + if (pkgname == NULL) + notification_get_application (noti, &pkgname); + notification_get_title (noti, &title, NULL); + notification_get_text (noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content); + notification_get_image (noti, NOTIFICATION_IMAGE_TYPE_ICON, &image_path); + + struct wlmessage *wlmessage = wlmessage_create (); + wlmessage_set_title (wlmessage, title); + wlmessage_set_icon (wlmessage, image_path); + wlmessage_set_message (wlmessage, content); + wlmessage_add_button (wlmessage, 0, "Ok"); + if (wlmessage_show (wlmessage, NULL) < 0) { + wlmessage_destroy (wlmessage); + return; + } + wlmessage_destroy (wlmessage); + + LOGD("\nNew Notification : %s\n", title); + LOGD("Icon : %s\n", image_path); + LOGD("Message : %s\n", content); + + get_list = notification_list_remove(get_list, noti); + notification_delete(noti); + } + } +} + +int main (int argc, char **argv) +{ + GMainLoop *mainloop = NULL; + notification_error_e error_n; + int error_s; + struct stat buf; + +retry_socket: + LOGD("Checking if the notifications server socket exists..."); + error_s = stat ("/tmp/.notification.service", &buf); + if (error_s == -1) { + LOGD("Could not find the notifications server socket"); + sleep (5); + goto retry_socket; + } + +retry_service: + LOGD("Checking if the notifications server is available..."); + error_n = notification_resister_changed_cb (display_notifications_cb, NULL); + if (error_n != NOTIFICATION_ERROR_NONE) { + LOGD("Could not register with notifications server"); + sleep (5); + goto retry_service; + } + + mainloop = g_main_loop_new (NULL, FALSE); + if (!mainloop) { + printf ("Failed to create the GLib main loop\n"); + return -1; + } + + g_main_loop_run (mainloop); + + return 0; +} diff --git a/notifications-display.service.in b/notifications-display.service.in new file mode 100644 index 0000000..11481e5 --- /dev/null +++ b/notifications-display.service.in @@ -0,0 +1,11 @@ +[Unit] +Description=Notifications Popup daemon +Requires=notifications.service display-manager-run.service +After=notifications.service display-manager-run.service + +[Service] +ExecStart=/usr/bin/notification-display-service +EnvironmentFile=/etc/sysconfig/weston + +[Install] +WantedBy=graphical.target diff --git a/packaging/notification-service.spec b/packaging/notification-service.spec index 8772d1e..cc557c6 100644 --- a/packaging/notification-service.spec +++ b/packaging/notification-service.spec @@ -41,6 +41,7 @@ make %{?_smp_mflags} %install %make_install %install_service graphical.target.wants notifications.service +%install_service graphical.target.wants notifications-display.service %post %systemd_post notifications.service @@ -54,8 +55,11 @@ make %{?_smp_mflags} %files %defattr(-,root,root,-) %{_bindir}/notification-service +%{_bindir}/notification-display-service %{_unitdir}/notifications.service +%{_unitdir}/notifications-display.service %{_unitdir}/graphical.target.wants/notifications.service +%{_unitdir}/graphical.target.wants/notifications-display.service %files test %defattr(-,root,root,-)