+static void trigger_save(struct userdata *u) {
+ if (u->save_time_event)
+ return;
+
+ u->save_time_event = pa_core_rttime_new(u->core, pa_rtclock_now() + SAVE_INTERVAL, save_time_callback, u);
+}
+
+static void port_info_free(struct port_info *p_info) {
+ pa_assert(p_info);
+
+ pa_xfree(p_info->name);
+ pa_xfree(p_info);
+}
+
+static struct entry* entry_new(void) {
+ struct entry *r = pa_xnew0(struct entry, 1);
+ r->version = ENTRY_VERSION;
+ r->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) port_info_free);
+ return r;
+}
+
+static struct port_info *port_info_new(pa_device_port *port) {
+ struct port_info *p_info;
+
+ if (port) {
+ p_info = pa_xnew(struct port_info, 1);
+ p_info->name = pa_xstrdup(port->name);
+ p_info->offset = port->latency_offset;
+ } else
+ p_info = pa_xnew0(struct port_info, 1);
+
+ return p_info;
+}
+
+static void entry_free(struct entry* e) {
+ pa_assert(e);
+
+ pa_xfree(e->profile);
+ pa_hashmap_free(e->ports);
+
+ pa_xfree(e);
+}
+
+static struct entry *entry_from_card(pa_card *card) {
+ struct port_info *p_info;
+ struct entry *entry;
+ pa_device_port *port;
+ void *state;
+
+ pa_assert(card);
+
+ entry = entry_new();
+ if (card->save_profile)
+ entry->profile = pa_xstrdup(card->active_profile->name);
+
+ PA_HASHMAP_FOREACH(port, card->ports, state) {
+ p_info = port_info_new(port);
+ pa_assert_se(pa_hashmap_put(entry->ports, p_info->name, p_info) >= 0);
+ }
+
+ return entry;
+}
+
+static bool entrys_equal(struct entry *a, struct entry *b) {
+ struct port_info *Ap_info, *Bp_info;
+ void *state;
+
+ pa_assert(a);
+ pa_assert(b);
+
+ if (!pa_streq(a->profile, b->profile) ||
+ pa_hashmap_size(a->ports) != pa_hashmap_size(b->ports))
+ return false;
+
+ PA_HASHMAP_FOREACH(Ap_info, a->ports, state) {
+ if ((Bp_info = pa_hashmap_get(b->ports, Ap_info->name))) {
+ if (Ap_info->offset != Bp_info->offset)
+ return false;
+ } else
+ return false;
+ }
+
+ return true;
+}
+
+static bool entry_write(struct userdata *u, const char *name, const struct entry *e) {
+ pa_tagstruct *t;