[tepl] MetadataStore: make lots of functions private
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] MetadataStore: make lots of functions private
- Date: Sat, 18 Apr 2020 17:18:26 +0000 (UTC)
commit 96277d77039179e6e40da0c97660b202102c41dd
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Apr 15 19:24:22 2020 +0200
MetadataStore: make lots of functions private
Since there is TeplFileMetadata and the _tepl_metadata_*() functions.
Loading the TeplMetadataStore will be done lazily by the
_tepl_metadata_*() functions.
docs/reference/tepl-sections.txt | 5 ---
tepl/tepl-metadata-store.c | 90 ++++++++++++++++++----------------------
tepl/tepl-metadata-store.h | 29 +++++++------
testsuite/test-metadata-store.c | 28 ++++++-------
4 files changed, 71 insertions(+), 81 deletions(-)
---
diff --git a/docs/reference/tepl-sections.txt b/docs/reference/tepl-sections.txt
index 1e3e816..9321509 100644
--- a/docs/reference/tepl-sections.txt
+++ b/docs/reference/tepl-sections.txt
@@ -311,12 +311,7 @@ TeplMetadataStore
tepl_metadata_store_get_singleton
tepl_metadata_store_set_store_file
tepl_metadata_store_set_max_number_of_locations
-tepl_metadata_store_load_async
-tepl_metadata_store_load_finish
-tepl_metadata_store_is_loaded
tepl_metadata_store_save
-tepl_metadata_store_get_metadata_for_location
-tepl_metadata_store_set_metadata_for_location
<SUBSECTION Standard>
TEPL_IS_METADATA_STORE
TEPL_IS_METADATA_STORE_CLASS
diff --git a/tepl/tepl-metadata-store.c b/tepl/tepl-metadata-store.c
index ad9e6a2..bf02984 100644
--- a/tepl/tepl-metadata-store.c
+++ b/tepl/tepl-metadata-store.c
@@ -219,7 +219,7 @@ tepl_metadata_store_get_property (GObject *object,
switch (prop_id)
{
case PROP_LOADED:
- g_value_set_boolean (value, tepl_metadata_store_is_loaded (store));
+ g_value_set_boolean (value, _tepl_metadata_store_is_loaded (store));
break;
default:
@@ -255,13 +255,14 @@ tepl_metadata_store_class_init (TeplMetadataStoreClass *klass)
/**
* TeplMetadataStore:loaded:
*
+ * Warning: this property is intended to be used only privately by Tepl,
+ * don't use it in application code.
+ *
* %TRUE when the metadata has been loaded, or when there has been at
* least an attempt to load it (i.e. when
- * tepl_metadata_store_load_finish() has been called).
+ * _tepl_metadata_store_load_finish() has been called).
*
* %FALSE otherwise.
- *
- * Since: 5.0
*/
properties[PROP_LOADED] =
g_param_spec_boolean ("loaded",
@@ -329,9 +330,10 @@ _tepl_metadata_store_unref_singleton (void)
* A good place to store the metadata is in a sub-directory of the user data
* directory. See g_get_user_data_dir().
*
- * Note that this function does no I/O. To load the metadata from the
- * @store_file, call tepl_metadata_store_load_async(). To save the metadata,
- * call tepl_metadata_store_save().
+ * Note that this function does no I/O. The metadata will be loaded
+ * asynchronously and lazily by using the #TeplFileMetadata API; as a result
+ * this function needs to be called before using any of the #TeplFileMetadata
+ * API. To save the metadata, call tepl_metadata_store_save().
*
* Since: 5.0
*/
@@ -357,12 +359,8 @@ tepl_metadata_store_set_store_file (TeplMetadataStore *store,
* tepl_metadata_store_set_store_file()) to grow indefinitely.
*
* @max_number_of_locations is the maximum number of #GFile locations for which
- * metadata are written to the store file. See
- * tepl_metadata_store_set_metadata_for_location() (this sets the metadata for
- * _one_ location).
- *
- * Upon saving, the #TeplMetadataStore discards the least recently accessed
- * metadata if needed.
+ * metadata are written to the store file. Upon saving, the #TeplMetadataStore
+ * discards the least recently accessed metadata if needed.
*
* Since: 5.0
*/
@@ -714,8 +712,8 @@ out:
g_bytes_unref (xml_file_bytes);
}
-/**
- * tepl_metadata_store_load_async:
+/*
+ * _tepl_metadata_store_load_async:
* @store: the #TeplMetadataStore.
* @io_priority: the I/O priority of the request. E.g. %G_PRIORITY_LOW,
* %G_PRIORITY_DEFAULT or %G_PRIORITY_HIGH.
@@ -728,25 +726,22 @@ out:
* tepl_metadata_store_set_store_file() before.
*
* You can call this function only once. Once the #TeplMetadataStore is loaded
- * it cannot be loaded a second time. A good moment to call this function is on
- * application startup, see the #GApplication::startup signal.
+ * it cannot be loaded a second time.
*
* See the #GAsyncResult documentation to know how to use this function.
- *
- * Since: 5.0
*/
void
-tepl_metadata_store_load_async (TeplMetadataStore *store,
- gint io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+_tepl_metadata_store_load_async (TeplMetadataStore *store,
+ gint io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
GTask *task;
g_return_if_fail (TEPL_IS_METADATA_STORE (store));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- g_return_if_fail (!tepl_metadata_store_is_loaded (store));
+ g_return_if_fail (!_tepl_metadata_store_is_loaded (store));
g_return_if_fail (store->priv->xml_file != NULL);
task = g_task_new (store, cancellable, callback, user_data);
@@ -761,29 +756,28 @@ tepl_metadata_store_load_async (TeplMetadataStore *store,
task);
}
-/**
- * tepl_metadata_store_load_finish:
+/*
+ * _tepl_metadata_store_load_finish:
* @store: the #TeplMetadataStore.
* @result: a #GAsyncResult.
* @error: location to a %NULL #GError, or %NULL.
*
- * Finishes the metadata loading started with tepl_metadata_store_load_async().
+ * Finishes the metadata loading started with _tepl_metadata_store_load_async().
*
* Regardless of whether the operation was successful or not, calling this
* function sets the #TeplMetadataStore:loaded property to %TRUE.
*
* Returns: whether the metadata was loaded successfully.
- * Since: 5.0
*/
gboolean
-tepl_metadata_store_load_finish (TeplMetadataStore *store,
- GAsyncResult *result,
- GError **error)
+_tepl_metadata_store_load_finish (TeplMetadataStore *store,
+ GAsyncResult *result,
+ GError **error)
{
g_return_val_if_fail (TEPL_IS_METADATA_STORE (store), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
g_return_val_if_fail (g_task_is_valid (result, store), FALSE);
- g_return_val_if_fail (!tepl_metadata_store_is_loaded (store), FALSE);
+ g_return_val_if_fail (!_tepl_metadata_store_is_loaded (store), FALSE);
store->priv->is_loaded = TRUE;
g_object_notify_by_pspec (G_OBJECT (store), properties[PROP_LOADED]);
@@ -791,15 +785,14 @@ tepl_metadata_store_load_finish (TeplMetadataStore *store,
return g_task_propagate_boolean (G_TASK (result), error);
}
-/**
- * tepl_metadata_store_is_loaded:
+/*
+ * _tepl_metadata_store_is_loaded:
* @store: the #TeplMetadataStore.
*
* Returns: the value of the #TeplMetadataStore:loaded property.
- * Since: 5.0
*/
gboolean
-tepl_metadata_store_is_loaded (TeplMetadataStore *store)
+_tepl_metadata_store_is_loaded (TeplMetadataStore *store)
{
g_return_val_if_fail (TEPL_IS_METADATA_STORE (store), FALSE);
@@ -1013,19 +1006,18 @@ tepl_metadata_store_save (TeplMetadataStore *store,
return ok;
}
-/**
- * tepl_metadata_store_get_metadata_for_location:
+/*
+ * _tepl_metadata_store_get_metadata_for_location:
* @store: the #TeplMetadataStore.
* @location: a #GFile.
*
* Returns: (transfer full) (nullable): a #GFileInfo containing the metadata,
* under the "metadata" namespace. Or %NULL if there is no metadata for
* @location.
- * Since: 5.0
*/
GFileInfo *
-tepl_metadata_store_get_metadata_for_location (TeplMetadataStore *store,
- GFile *location)
+_tepl_metadata_store_get_metadata_for_location (TeplMetadataStore *store,
+ GFile *location)
{
DocumentMetadata *document_metadata;
@@ -1045,19 +1037,17 @@ tepl_metadata_store_get_metadata_for_location (TeplMetadataStore *store,
return g_object_ref (document_metadata->entries);
}
-/**
- * tepl_metadata_store_set_metadata_for_location:
+/*
+ * _tepl_metadata_store_set_metadata_for_location:
* @store: the #TeplMetadataStore.
* @location: a #GFile.
* @metadata: (nullable): a #GFileInfo containing the metadata, or %NULL to
- * remove the metadata for @location.
- *
- * Since: 5.0
+ * remove the metadata for @location.
*/
void
-tepl_metadata_store_set_metadata_for_location (TeplMetadataStore *store,
- GFile *location,
- GFileInfo *metadata)
+_tepl_metadata_store_set_metadata_for_location (TeplMetadataStore *store,
+ GFile *location,
+ GFileInfo *metadata)
{
g_return_if_fail (TEPL_IS_METADATA_STORE (store));
g_return_if_fail (G_IS_FILE (location));
diff --git a/tepl/tepl-metadata-store.h b/tepl/tepl-metadata-store.h
index 3b57e46..0bed587 100644
--- a/tepl/tepl-metadata-store.h
+++ b/tepl/tepl-metadata-store.h
@@ -53,35 +53,40 @@ GType tepl_metadata_store_get_type (void);
TeplMetadataStore * tepl_metadata_store_get_singleton (void);
-G_GNUC_INTERNAL
-void _tepl_metadata_store_unref_singleton (void);
-
void tepl_metadata_store_set_store_file (TeplMetadataStore *store,
GFile *store_file);
void tepl_metadata_store_set_max_number_of_locations (TeplMetadataStore *store,
guint
max_number_of_locations);
-void tepl_metadata_store_load_async (TeplMetadataStore *store,
+gboolean tepl_metadata_store_save (TeplMetadataStore *store,
+ GCancellable *cancellable,
+ GError **error);
+
+G_GNUC_INTERNAL
+void _tepl_metadata_store_unref_singleton (void);
+
+G_GNUC_INTERNAL
+void _tepl_metadata_store_load_async (TeplMetadataStore *store,
gint io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
-gboolean tepl_metadata_store_load_finish (TeplMetadataStore *store,
+G_GNUC_INTERNAL
+gboolean _tepl_metadata_store_load_finish (TeplMetadataStore *store,
GAsyncResult *result,
GError **error);
-gboolean tepl_metadata_store_is_loaded (TeplMetadataStore *store);
-
-gboolean tepl_metadata_store_save (TeplMetadataStore *store,
- GCancellable *cancellable,
- GError **error);
+G_GNUC_INTERNAL
+gboolean _tepl_metadata_store_is_loaded (TeplMetadataStore *store);
-GFileInfo * tepl_metadata_store_get_metadata_for_location (TeplMetadataStore *store,
+G_GNUC_INTERNAL
+GFileInfo * _tepl_metadata_store_get_metadata_for_location (TeplMetadataStore *store,
GFile *location);
-void tepl_metadata_store_set_metadata_for_location (TeplMetadataStore *store,
+G_GNUC_INTERNAL
+void _tepl_metadata_store_set_metadata_for_location (TeplMetadataStore *store,
GFile *location,
GFileInfo *metadata);
diff --git a/testsuite/test-metadata-store.c b/testsuite/test-metadata-store.c
index 4c7fada..0663b2f 100644
--- a/testsuite/test-metadata-store.c
+++ b/testsuite/test-metadata-store.c
@@ -69,7 +69,7 @@ load_store_file_cb (GObject *source_object,
TeplMetadataStore *store = TEPL_METADATA_STORE (source_object);
GError **error = user_data;
- tepl_metadata_store_load_finish (store, result, error);
+ _tepl_metadata_store_load_finish (store, result, error);
gtk_main_quit ();
}
@@ -81,11 +81,11 @@ load_store_file (GFile *store_file,
GError *error = NULL;
tepl_metadata_store_set_store_file (store, store_file);
- tepl_metadata_store_load_async (store,
- G_PRIORITY_DEFAULT,
- NULL,
- load_store_file_cb,
- &error);
+ _tepl_metadata_store_load_async (store,
+ G_PRIORITY_DEFAULT,
+ NULL,
+ load_store_file_cb,
+ &error);
gtk_main ();
if (expect_no_error)
@@ -149,9 +149,9 @@ mark_metadata_store_as_modified (void)
location = g_file_new_for_path ("foo");
metadata = g_file_info_new ();
- g_assert_true (tepl_metadata_store_get_metadata_for_location (store, location) == NULL);
- tepl_metadata_store_set_metadata_for_location (store, location, metadata);
- tepl_metadata_store_set_metadata_for_location (store, location, NULL);
+ g_assert_true (_tepl_metadata_store_get_metadata_for_location (store, location) == NULL);
+ _tepl_metadata_store_set_metadata_for_location (store, location, metadata);
+ _tepl_metadata_store_set_metadata_for_location (store, location, NULL);
g_object_unref (location);
g_object_unref (metadata);
@@ -169,7 +169,7 @@ check_metadata_exists (const gchar *uri,
const gchar *received_value;
location = g_file_new_for_uri (uri);
- metadata = tepl_metadata_store_get_metadata_for_location (store, location);
+ metadata = _tepl_metadata_store_get_metadata_for_location (store, location);
g_assert_true (metadata != NULL);
complete_key = g_strconcat ("metadata::", key, NULL);
@@ -307,7 +307,7 @@ test_load_xml_from_old_metadata_manager (void)
* Do not modify the atime of the other <document>.
*/
location = g_file_new_for_uri ("file:///home/seb/test-header.csv");
- tepl_metadata_store_set_metadata_for_location (store, location, NULL);
+ _tepl_metadata_store_set_metadata_for_location (store, location, NULL);
g_clear_object (&location);
tmp_file = save_store ();
@@ -354,7 +354,7 @@ test_generate_new_store_file_simple (void)
location = g_file_new_for_path ("/my_absolute_file_absolutely");
metadata = g_file_info_new ();
g_file_info_set_attribute_string (metadata, "metadata::my_key", "my_value");
- tepl_metadata_store_set_metadata_for_location (store, location, metadata);
+ _tepl_metadata_store_set_metadata_for_location (store, location, metadata);
g_object_unref (location);
g_object_unref (metadata);
@@ -362,7 +362,7 @@ test_generate_new_store_file_simple (void)
metadata = g_file_info_new ();
g_file_info_set_attribute_string (metadata, "metadata::a_key", "a_value");
g_file_info_set_attribute_string (metadata, "metadata::another_key", "another_value");
- tepl_metadata_store_set_metadata_for_location (store, location, metadata);
+ _tepl_metadata_store_set_metadata_for_location (store, location, metadata);
g_object_unref (location);
g_object_unref (metadata);
@@ -398,7 +398,7 @@ test_generate_new_store_file (void)
location = g_file_new_for_path ("/home/seb/santé/pandémie-coronavirus-stats.csv");
metadata = g_file_info_new ();
g_file_info_set_attribute_string (metadata, "metadata::CLÉ", "Évolution \"<=>\"");
- tepl_metadata_store_set_metadata_for_location (store, location, metadata);
+ _tepl_metadata_store_set_metadata_for_location (store, location, metadata);
g_object_unref (location);
g_object_unref (metadata);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]