5 #include <notification.h>
10 void load_plugins (char *path, int (**fct)(notification_h))
13 struct dirent *plugins_dir;
16 int (*plugin_fct)(notification_h);
22 while ((plugins_dir = readdir(dir)) != NULL) {
23 if (g_str_has_suffix (plugins_dir->d_name, ".so")) {
24 plugin_path = g_strconcat (path, G_DIR_SEPARATOR_S, plugins_dir->d_name, NULL);
25 plugin = dlopen (plugin_path, RTLD_NOW | RTLD_LOCAL);
26 plugin_fct = dlsym (plugin, "display_notification");
29 LOGD("\"%s\" is not a plugin, continuing", plugins_dir->d_name);
31 } else if (!plugin_fct) {
32 LOGD("Plugin \"%s\" incompatible, continuing", plugins_dir->d_name);
33 dlclose (plugins_dir->d_name);
36 /* use the first working plugin, if not configured otherwise */
37 LOGD("Plugin \"%s\" compatible, loading...", plugins_dir->d_name);
47 int display_notification_text (notification_h noti)
52 char *image_path = NULL;
54 notification_get_pkgname (noti, &pkgname);
56 notification_get_application (noti, &pkgname);
57 notification_get_title (noti, &title, NULL);
58 notification_get_text (noti, NOTIFICATION_TEXT_TYPE_CONTENT, &content);
59 notification_get_image (noti, NOTIFICATION_IMAGE_TYPE_ICON, &image_path);
61 LOGD("\nNew Notification : %s", title);
62 LOGD("Icon : %s", image_path);
63 LOGD("Message : %s", content);
68 void display_notifications_cb (void *data, notification_type_e notif_type)
70 int (*fct)(notification_h) = data;
71 notification_h noti = NULL;
72 notification_list_h notification_list = NULL;
73 notification_list_h get_list = NULL;
75 notification_get_list (NOTIFICATION_TYPE_NOTI, -1, ¬ification_list);
76 if (notification_list) {
77 get_list = notification_list_get_head (notification_list);
79 noti = notification_list_get_data (get_list);
81 /* if the display function was successful, delete the notification */
83 get_list = notification_list_remove(get_list, noti);
84 notification_delete(noti);
91 int main (int argc, char **argv)
93 GMainLoop *mainloop = NULL;
95 notification_error_e error_n;
96 int (*disp_fct)(notification_h);
98 /* fall back to pure text notification if no plugin works */
99 disp_fct = &display_notification_text;
100 LOGD("Checking for display plugins...");
101 if (g_file_test (PLUGINSDIR, G_FILE_TEST_IS_DIR))
102 load_plugins (PLUGINSDIR, &disp_fct);
105 LOGD("Checking if the notifications server socket exists...");
106 error_s = g_file_test ("/tmp/.notification.service", G_FILE_TEST_EXISTS);
108 LOGD("Could not find the notifications server socket");
114 LOGD("Checking if the notifications server is available...");
115 error_n = notification_resister_changed_cb (display_notifications_cb, (*disp_fct));
116 if (error_n != NOTIFICATION_ERROR_NONE) {
117 LOGD("Could not register with notifications server");
122 mainloop = g_main_loop_new (NULL, FALSE);
124 printf ("Failed to create the GLib main loop\n");
128 g_main_loop_run (mainloop);