]> code.delx.au - pulseaudio/commitdiff
split out save trigger function
authorLennart Poettering <lennart@poettering.net>
Mon, 4 Aug 2008 16:56:12 +0000 (18:56 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 4 Aug 2008 16:56:12 +0000 (18:56 +0200)
src/modules/module-device-restore.c

index d93b9e6398ff9aa8f7b8237d9a8b75f3456c79d7..fcd40219ff06bb02b157c99e7de5c151464cec7f 100644 (file)
@@ -143,6 +143,17 @@ fail:
     return NULL;
 }
 
+static void trigger_save(struct userdata *u) {
+    struct timeval tv;
+
+    if (u->save_time_event)
+        return;
+
+    pa_gettimeofday(&tv);
+    tv.tv_sec += SAVE_INTERVAL;
+    u->save_time_event = u->core->mainloop->time_new(u->core->mainloop, &tv, save_time_callback, u);
+}
+
 static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
     struct userdata *u = userdata;
     struct entry entry, *old;
@@ -158,6 +169,8 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
         t != (PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE))
         return;
 
+    memset(&entry, 0, sizeof(entry));
+
     if ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SINK) {
         pa_sink *sink;
 
@@ -206,14 +219,9 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
 
     gdbm_store(u->gdbm_file, key, data, GDBM_REPLACE);
 
-    if (!u->save_time_event) {
-        struct timeval tv;
-        pa_gettimeofday(&tv);
-        tv.tv_sec += SAVE_INTERVAL;
-        u->save_time_event = u->core->mainloop->time_new(u->core->mainloop, &tv, save_time_callback, u);
-    }
-
     pa_xfree(name);
+
+    trigger_save(u);
 }
 
 static pa_hook_result_t sink_fixate_hook_callback(pa_core *c, pa_sink_new_data *new_data, struct userdata *u) {