e03908843ed170a71fc10c6f06337510744740d1
[platform/core/appfw/notification-service.git] / notification_display_service.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <signal.h>
4 #include <sys/inotify.h>
5 #include <notification.h>
6 #ifdef HAVE_WAYLAND
7 #include <libwlmessage.h>
8 #endif
9
10
11 int fd, wd;
12
13 void sigint_handler (int s)
14 {
15         inotify_rm_watch (fd, wd);
16         close (fd);
17         exit (0);
18 }
19
20 void display_notifications ()
21 {
22         notification_h noti = NULL;
23         notification_list_h notification_list = NULL;
24         notification_list_h get_list = NULL;
25
26         char *pkgname = NULL;
27         char *title = NULL;
28         char *content = NULL;
29         char *image_path = NULL;
30
31         notification_get_list (NOTIFICATION_TYPE_NOTI, -1, &notification_list);
32         if (notification_list) {
33                 get_list = notification_list_get_head (notification_list);
34                 if (get_list) {
35                         noti = notification_list_get_data (get_list);
36                         notification_get_pkgname (noti, &pkgname);
37                         if (pkgname == NULL)
38                                 notification_get_application (noti, &pkgname);
39                         notification_get_title (noti, &title, NULL);
40                         notification_get_text (noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content);
41                         notification_get_image (noti, NOTIFICATION_IMAGE_TYPE_ICON, &image_path);
42
43 #                       ifdef HAVE_WAYLAND
44                         struct wlmessage *wlmessage = wlmessage_create ();
45                         wlmessage_set_title (wlmessage, title);
46                         wlmessage_set_icon (wlmessage, image_path);
47                         wlmessage_set_message (wlmessage, content);
48                         wlmessage_add_button (wlmessage, 0, "Ok");
49                         wlmessage_show (wlmessage, NULL);
50                         wlmessage_destroy (wlmessage);
51 #                       endif
52
53                         notification_delete (noti);
54                 }
55         }
56 }
57
58 int main (int argc, char **argv)
59 {
60         char buffer[8192];
61
62          /* display notifications once, so it stays useful without inotify  */
63         display_notifications ();
64
65         fd = inotify_init ();
66         if (fd < 0) {
67                 fprintf (stderr, "ERROR: cannot initialize inotify\n");
68                 fprintf (stderr, "Verify that your kernel integrates it\n");
69                 return -1;
70         }
71
72         signal (SIGINT, sigint_handler);
73         wd = inotify_add_watch (fd, "/usr/dbspace/.notification.db", IN_MODIFY);
74         while (1) {
75                 read (fd, buffer, sizeof(buffer));
76                 display_notifications ();
77         }
78
79         return 0;
80 }