| 1 | /* |
| 2 | * Copyright © 2017 Endless Mobile, Inc. |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.0+ |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * Authors: |
| 20 | * - Philip Withnall <[email protected]> |
| 21 | */ |
| 22 | |
| 23 | #pragma once |
| 24 | |
| 25 | #include <gio/gio.h> |
| 26 | #include <glib-object.h> |
| 27 | #include <glib.h> |
| 28 | |
| 29 | #include "ostree-ref.h" |
| 30 | #include "ostree-remote.h" |
| 31 | #include "ostree-types.h" |
| 32 | |
| 33 | G_BEGIN_DECLS |
| 34 | |
| 35 | #define OSTREE_TYPE_REPO_FINDER (ostree_repo_finder_get_type ()) |
| 36 | |
| 37 | _OSTREE_PUBLIC |
| 38 | G_DECLARE_INTERFACE (OstreeRepoFinder, ostree_repo_finder, OSTREE, REPO_FINDER, GObject) |
| 39 | |
| 40 | struct _OstreeRepoFinderInterface |
| 41 | { |
| 42 | GTypeInterface g_iface; |
| 43 | |
| 44 | void (*resolve_async) (OstreeRepoFinder *self, const OstreeCollectionRef *const *refs, |
| 45 | OstreeRepo *parent_repo, GCancellable *cancellable, |
| 46 | GAsyncReadyCallback callback, gpointer user_data); |
| 47 | GPtrArray *(*resolve_finish) (OstreeRepoFinder *self, GAsyncResult *result, GError **error); |
| 48 | }; |
| 49 | |
| 50 | _OSTREE_PUBLIC |
| 51 | void ostree_repo_finder_resolve_async (OstreeRepoFinder *self, |
| 52 | const OstreeCollectionRef *const *refs, |
| 53 | OstreeRepo *parent_repo, GCancellable *cancellable, |
| 54 | GAsyncReadyCallback callback, gpointer user_data); |
| 55 | _OSTREE_PUBLIC |
| 56 | GPtrArray *ostree_repo_finder_resolve_finish (OstreeRepoFinder *self, GAsyncResult *result, |
| 57 | GError **error); |
| 58 | |
| 59 | _OSTREE_PUBLIC |
| 60 | void ostree_repo_finder_resolve_all_async (OstreeRepoFinder *const *finders, |
| 61 | const OstreeCollectionRef *const *refs, |
| 62 | OstreeRepo *parent_repo, GCancellable *cancellable, |
| 63 | GAsyncReadyCallback callback, gpointer user_data); |
| 64 | _OSTREE_PUBLIC |
| 65 | GPtrArray *ostree_repo_finder_resolve_all_finish (GAsyncResult *result, GError **error); |
| 66 | |
| 67 | /** |
| 68 | * OstreeRepoFinderResult: |
| 69 | * @remote: #OstreeRemote which contains the transport details for the result, |
| 70 | * such as its URI and GPG key |
| 71 | * @finder: the #OstreeRepoFinder instance which produced this result |
| 72 | * @priority: static priority of the result, where higher numbers indicate lower |
| 73 | * priority |
| 74 | * @ref_to_checksum: (element-type OstreeCollectionRef utf8): map of collection–ref |
| 75 | * pairs to checksums provided by this remote; values may be %NULL to |
| 76 | * indicate this remote doesn’t provide that ref |
| 77 | * @ref_to_timestamp: (element-type OstreeCollectionRef guint64) (nullable): map of |
| 78 | * collection–ref pairs to timestamps; values may be 0 for various reasons |
| 79 | * @summary_last_modified: Unix timestamp (seconds since the epoch, UTC) when |
| 80 | * the summary file on the remote was last modified, or `0` if unknown |
| 81 | * |
| 82 | * #OstreeRepoFinderResult gives a single result from an |
| 83 | * ostree_repo_finder_resolve_async() or ostree_repo_finder_resolve_all_async() |
| 84 | * operation. This represents a single remote which provides none, some or all |
| 85 | * of the refs being resolved. The structure includes various bits of metadata |
| 86 | * which allow ostree_repo_pull_from_remotes_async() (for example) to prioritise |
| 87 | * how to pull the refs. |
| 88 | * |
| 89 | * An #OstreeRepoFinderResult is immutable after construction. |
| 90 | * |
| 91 | * The @priority is used as one input of many to ordering functions like |
| 92 | * ostree_repo_finder_result_compare(). |
| 93 | * |
| 94 | * @ref_to_checksum indicates which refs (out of the ones queried for as inputs |
| 95 | * to ostree_repo_finder_resolve_async()) are provided by this remote. The refs |
| 96 | * are present as keys (of type #OstreeCollectionRef), and the corresponding values |
| 97 | * are the checksums of the commits the remote currently has for those refs. (These |
| 98 | * might not be the latest commits available out of all results.) A |
| 99 | * checksum may be %NULL if the remote does not advertise the corresponding ref. |
| 100 | * After ostree_repo_finder_resolve_async() has been called, the commit metadata |
| 101 | * should be available locally, so the details for each checksum can be looked |
| 102 | * up using ostree_repo_load_commit(). |
| 103 | * |
| 104 | * @ref_to_timestamp provides timestamps for the set of refs in |
| 105 | * @ref_to_checksum. The refs are keys (of type #OstreeCollectionRef) and the |
| 106 | * values are guint64 pointers with the timestamp associated with the checksum |
| 107 | * provided in @ref_to_checksum. @ref_to_timestamp can be %NULL, and when it's |
| 108 | * not, the timestamps are zero when any of the following conditions are met: |
| 109 | * (1) the override-commit-ids option was used on |
| 110 | * ostree_repo_find_remotes_async (2) there was an error in trying to get the |
| 111 | * commit metadata (3) the checksum for this ref is %NULL in @ref_to_checksum. |
| 112 | * |
| 113 | * Since: 2018.6 |
| 114 | */ |
| 115 | typedef struct |
| 116 | { |
| 117 | OstreeRemote *remote; |
| 118 | OstreeRepoFinder *finder; |
| 119 | gint priority; |
| 120 | GHashTable *ref_to_checksum; |
| 121 | guint64 summary_last_modified; |
| 122 | GHashTable *ref_to_timestamp; |
| 123 | |
| 124 | /*< private >*/ |
| 125 | gpointer padding[3]; |
| 126 | } OstreeRepoFinderResult; |
| 127 | |
| 128 | _OSTREE_PUBLIC |
| 129 | GType ostree_repo_finder_result_get_type (void); |
| 130 | |
| 131 | _OSTREE_PUBLIC |
| 132 | OstreeRepoFinderResult *ostree_repo_finder_result_new (OstreeRemote *remote, |
| 133 | OstreeRepoFinder *finder, gint priority, |
| 134 | GHashTable *ref_to_checksum, |
| 135 | GHashTable *ref_to_timestamp, |
| 136 | guint64 summary_last_modified); |
| 137 | _OSTREE_PUBLIC |
| 138 | OstreeRepoFinderResult *ostree_repo_finder_result_dup (OstreeRepoFinderResult *result); |
| 139 | _OSTREE_PUBLIC |
| 140 | gint ostree_repo_finder_result_compare (const OstreeRepoFinderResult *a, |
| 141 | const OstreeRepoFinderResult *b); |
| 142 | _OSTREE_PUBLIC |
| 143 | void ostree_repo_finder_result_free (OstreeRepoFinderResult *result); |
| 144 | |
| 145 | /** |
| 146 | * OstreeRepoFinderResultv: |
| 147 | * |
| 148 | * A %NULL-terminated array of #OstreeRepoFinderResult instances, designed to |
| 149 | * be used with g_auto(): |
| 150 | * |
| 151 | * |[<!-- language="C" --> |
| 152 | * g_auto(OstreeRepoFinderResultv) results = NULL; |
| 153 | * ]| |
| 154 | * |
| 155 | * Since: 2018.6 |
| 156 | */ |
| 157 | typedef OstreeRepoFinderResult **OstreeRepoFinderResultv; |
| 158 | |
| 159 | _OSTREE_PUBLIC |
| 160 | void ostree_repo_finder_result_freev (OstreeRepoFinderResult **results); |
| 161 | |
| 162 | G_END_DECLS |