record-store: Track async operations
We need to be able to tell when all async operations finished. Otherwise we might shut down the daemon with in flight operations leaving a open database around. Signed-off-by: Guido Günther <agx@sigxcpu.org> Part-of: <https://gitlab.gnome.org/GNOME/calls/-/merge_requests/795>
This commit is contained in:
@@ -97,6 +97,7 @@ struct _CallsRecordStore {
|
|||||||
gchar *filename;
|
gchar *filename;
|
||||||
GomAdapter *adapter;
|
GomAdapter *adapter;
|
||||||
GomRepository *repository;
|
GomRepository *repository;
|
||||||
|
int busy;
|
||||||
|
|
||||||
GListStore *list_store;
|
GListStore *list_store;
|
||||||
};
|
};
|
||||||
@@ -202,6 +203,7 @@ load_calls_fetch_cb (GomResourceGroup *group,
|
|||||||
g_free (records);
|
g_free (records);
|
||||||
g_object_unref (group);
|
g_object_unref (group);
|
||||||
exit:
|
exit:
|
||||||
|
self->busy--;
|
||||||
g_object_unref (self);
|
g_object_unref (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,12 +236,14 @@ load_calls_find_cb (GomRepository *repository,
|
|||||||
|
|
||||||
g_debug ("Found %u call records in database `%s', fetching",
|
g_debug ("Found %u call records in database `%s', fetching",
|
||||||
count, self->filename);
|
count, self->filename);
|
||||||
|
self->busy++;
|
||||||
gom_resource_group_fetch_async (group,
|
gom_resource_group_fetch_async (group,
|
||||||
0,
|
0,
|
||||||
count,
|
count,
|
||||||
(GAsyncReadyCallback) load_calls_fetch_cb,
|
(GAsyncReadyCallback) load_calls_fetch_cb,
|
||||||
g_object_ref (self));
|
g_object_ref (self));
|
||||||
exit:
|
exit:
|
||||||
|
self->busy--;
|
||||||
g_object_unref (self);
|
g_object_unref (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,6 +264,7 @@ load_calls (CallsRecordStore *self)
|
|||||||
|
|
||||||
g_debug ("Finding records in call record database `%s'",
|
g_debug ("Finding records in call record database `%s'",
|
||||||
self->filename);
|
self->filename);
|
||||||
|
self->busy++;
|
||||||
gom_repository_find_sorted_async (self->repository,
|
gom_repository_find_sorted_async (self->repository,
|
||||||
CALLS_TYPE_CALL_RECORD,
|
CALLS_TYPE_CALL_RECORD,
|
||||||
filter,
|
filter,
|
||||||
@@ -297,6 +302,7 @@ set_up_repo_migrate_cb (GomRepository *repo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_signal_emit (self, signals[SIGNAL_DB_DONE], 0, ok);
|
g_signal_emit (self, signals[SIGNAL_DB_DONE], 0, ok);
|
||||||
|
self->busy--;
|
||||||
g_object_unref (self);
|
g_object_unref (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,6 +326,7 @@ set_up_repo (CallsRecordStore *self)
|
|||||||
" record database `%s'",
|
" record database `%s'",
|
||||||
self->filename);
|
self->filename);
|
||||||
types = g_list_append (types, (gpointer) CALLS_TYPE_CALL_RECORD);
|
types = g_list_append (types, (gpointer) CALLS_TYPE_CALL_RECORD);
|
||||||
|
self->busy++;
|
||||||
gom_repository_automatic_migrate_async
|
gom_repository_automatic_migrate_async
|
||||||
(repo,
|
(repo,
|
||||||
RECORD_STORE_VERSION,
|
RECORD_STORE_VERSION,
|
||||||
@@ -380,6 +387,7 @@ open_repo_adapter_open_cb (GomAdapter *adapter,
|
|||||||
set_up_repo (self);
|
set_up_repo (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self->busy--;
|
||||||
g_object_unref (self);
|
g_object_unref (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,6 +414,7 @@ open_repo (CallsRecordStore *self)
|
|||||||
uri = g_strdup_printf ("file:%s", self->filename);
|
uri = g_strdup_printf ("file:%s", self->filename);
|
||||||
g_debug ("Opening call record database using URI `%s'", uri);
|
g_debug ("Opening call record database using URI `%s'", uri);
|
||||||
self->adapter = gom_adapter_new ();
|
self->adapter = gom_adapter_new ();
|
||||||
|
self->busy++;
|
||||||
gom_adapter_open_async
|
gom_adapter_open_async
|
||||||
(self->adapter,
|
(self->adapter,
|
||||||
uri,
|
uri,
|
||||||
@@ -794,3 +803,23 @@ calls_record_store_get_list_model (CallsRecordStore *self)
|
|||||||
{
|
{
|
||||||
return G_LIST_MODEL (self->list_store);
|
return G_LIST_MODEL (self->list_store);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* calls_record_store_is_busy:
|
||||||
|
* @self: The record store
|
||||||
|
*
|
||||||
|
* Check whether there are async database operations in flight. It
|
||||||
|
* is only save to dispose the record store when this function returns
|
||||||
|
* `FALSE`.
|
||||||
|
*
|
||||||
|
* Returns: `TRUE` when there are async db operations, otherwise
|
||||||
|
* `FALSE`.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
calls_record_store_is_busy (CallsRecordStore *self)
|
||||||
|
{
|
||||||
|
g_assert (CALLS_IS_RECORD_STORE (self));
|
||||||
|
g_assert (self->busy >= 0);
|
||||||
|
|
||||||
|
return !!self->busy;
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ G_DECLARE_FINAL_TYPE (CallsRecordStore, calls_record_store, CALLS, RECORD_STORE,
|
|||||||
|
|
||||||
CallsRecordStore *calls_record_store_new (void);
|
CallsRecordStore *calls_record_store_new (void);
|
||||||
GListModel *calls_record_store_get_list_model (CallsRecordStore *);
|
GListModel *calls_record_store_get_list_model (CallsRecordStore *);
|
||||||
|
gboolean calls_record_store_is_busy (CallsRecordStore *self);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user