#include <errno.h>
#include <dirent.h>
#include <fcntl.h>
+#include <glib.h>
#include "stickerd_dbus.h"
#include "stickerd_data_manager.h"
#define LOG_TAG "STICKERD_DATA_MANAGER"
#define MAX_ERROR_BUFFER 256
+#define TERMINATE_TIMER_INTERVAL 3000
enum {
STICKER_URI_TYPE_NONE,
static GHashTable *_monitoring_hash = NULL;
static char error_buffer[MAX_ERROR_BUFFER];
static GList *consumer_list = NULL;
+static guint _terminate_timer_id = 0;
extern GMainLoop *main_loop;
+static void _terminate_daemon()
+{
+ LOGD("Terminate sticker daemon");
+ g_hash_table_destroy(_monitoring_hash);
+ _monitoring_hash = NULL;
+ g_list_free_full(consumer_list, free);
+ consumer_list = NULL;
+ g_main_loop_quit(main_loop);
+}
+
+static gboolean _terminate_timer_handler(gpointer user_data)
+{
+ _terminate_daemon();
+ return TRUE;
+}
+
static void _check_watcher_exist()
{
if (_monitoring_hash != NULL && g_hash_table_size(_monitoring_hash) == 0) {
- LOGD("Terminate sticker daemon");
- g_hash_table_destroy(_monitoring_hash);
- _monitoring_hash = NULL;
- g_list_free_full(consumer_list, free);
- consumer_list = NULL;
- g_main_loop_quit(main_loop);
+ if (_terminate_timer_id != 0) {
+ g_source_remove(_terminate_timer_id);
+ _terminate_timer_id = 0;
+ }
+
+ _terminate_timer_id = g_timeout_add(TERMINATE_TIMER_INTERVAL, _terminate_timer_handler, NULL);
+ if (_terminate_timer_id <= 0)
+ _terminate_daemon();
}
}
gpointer user_data)
{
LOGD("name: %s", name);
+ if (_terminate_timer_id != 0) {
+ g_source_remove(_terminate_timer_id);
+ _terminate_timer_id = 0;
+ }
}
static void _on_name_vanished(GDBusConnection *connection,