Add missing source.
[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                 while (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                         get_list = notification_list_get_head (notification_list);
55                 }
56         }
57 }
58
59 int main (int argc, char **argv)
60 {
61         char buffer[8192];
62
63          /* display notifications once, so it stays useful without inotify  */
64         display_notifications ();
65
66         fd = inotify_init ();
67         if (fd < 0) {
68                 fprintf (stderr, "ERROR: cannot initialize inotify\n");
69                 fprintf (stderr, "Verify that your kernel integrates it\n");
70                 return -1;
71         }
72
73         signal (SIGINT, sigint_handler);
74         wd = inotify_add_watch (fd, "/opt/dbspace/.notification.db", IN_MODIFY);
75         while (1) {
76                 read (fd, buffer, sizeof(buffer));
77                 display_notifications ();
78         }
79
80         return 0;
81 }