mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 22:50:08 +01:00
cloud-setup: add register-object callback to nmcs_utils_poll()
nmcs_utils_poll() calls nmcs_wait_for_objects_register(), which is specific to nm-cloud-setup. nmcs_utils_poll() should move to libnm-glib-aux, so it should not have a direct dependency on nm-cloud-setup code. Add instead a hook that the caller can use for registering the object.
This commit is contained in:
parent
1ee35cb638
commit
90f7d7d77b
3 changed files with 37 additions and 20 deletions
|
|
@ -309,6 +309,11 @@ _poll_cancelled_cb(GObject *object, gpointer user_data)
|
|||
* before the next. Together with @ratelimit_timeout_ms this determines how
|
||||
* frequently we probe. We will wait at least this time between the end of the
|
||||
* previous poll and the next one.
|
||||
* @probe_register_object_fcn: (allow-none): called by nmcs_utils_poll()
|
||||
* synchronously, with the new, internal GTask instance. The purpose of this
|
||||
* callback is a bit obscure, you may want to pass NULL here. It's used by some
|
||||
* caller to register a weak pointer on the internal GTask instance to track
|
||||
* the lifetime of the operation.
|
||||
* @probe_start_fcn: used to start a (asynchronous) probe. A probe must be
|
||||
* completed by calling the provided callback. While a probe is in progress, we
|
||||
* will not start another. The function is called the first time on an idle
|
||||
|
|
@ -325,15 +330,16 @@ _poll_cancelled_cb(GObject *object, gpointer user_data)
|
|||
* actions.
|
||||
*/
|
||||
void
|
||||
nmcs_utils_poll(int poll_timeout_ms,
|
||||
int ratelimit_timeout_ms,
|
||||
int sleep_timeout_ms,
|
||||
NMCSUtilsPollProbeStartFcn probe_start_fcn,
|
||||
NMCSUtilsPollProbeFinishFcn probe_finish_fcn,
|
||||
gpointer probe_user_data,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
nmcs_utils_poll(int poll_timeout_ms,
|
||||
int ratelimit_timeout_ms,
|
||||
int sleep_timeout_ms,
|
||||
NMCSUtilsPollProbeRegisterObjectFcn probe_register_object_fcn,
|
||||
NMCSUtilsPollProbeStartFcn probe_start_fcn,
|
||||
NMCSUtilsPollProbeFinishFcn probe_finish_fcn,
|
||||
gpointer probe_user_data,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
PollTaskData *poll_task_data;
|
||||
|
||||
|
|
@ -350,10 +356,11 @@ nmcs_utils_poll(int poll_timeout_ms,
|
|||
.internal_cancellable = g_cancellable_new(),
|
||||
};
|
||||
|
||||
nmcs_wait_for_objects_register(poll_task_data->task);
|
||||
|
||||
g_task_set_task_data(poll_task_data->task, poll_task_data, _poll_task_data_free);
|
||||
|
||||
if (probe_register_object_fcn)
|
||||
probe_register_object_fcn((GObject *) poll_task_data->task, probe_user_data);
|
||||
|
||||
if (poll_timeout_ms >= 0) {
|
||||
poll_task_data->source_timeout =
|
||||
nm_g_source_attach(nm_g_timeout_source_new(poll_timeout_ms,
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ gboolean nmcs_wait_for_objects_iterate_until_done(GMainContext *context, int tim
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef void (*NMCSUtilsPollProbeRegisterObjectFcn)(GObject *object, gpointer user_data);
|
||||
|
||||
typedef void (*NMCSUtilsPollProbeStartFcn)(GCancellable *cancellable,
|
||||
gpointer probe_user_data,
|
||||
GAsyncReadyCallback callback,
|
||||
|
|
@ -50,15 +52,16 @@ typedef gboolean (*NMCSUtilsPollProbeFinishFcn)(GObject *source,
|
|||
gpointer probe_user_data,
|
||||
GError **error);
|
||||
|
||||
void nmcs_utils_poll(int poll_timeout_ms,
|
||||
int ratelimit_timeout_ms,
|
||||
int sleep_timeout_ms,
|
||||
NMCSUtilsPollProbeStartFcn probe_start_fcn,
|
||||
NMCSUtilsPollProbeFinishFcn probe_finish_fcn,
|
||||
gpointer probe_user_data,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
void nmcs_utils_poll(int poll_timeout_ms,
|
||||
int ratelimit_timeout_ms,
|
||||
int sleep_timeout_ms,
|
||||
NMCSUtilsPollProbeRegisterObjectFcn probe_register_object_fcn,
|
||||
NMCSUtilsPollProbeStartFcn probe_start_fcn,
|
||||
NMCSUtilsPollProbeFinishFcn probe_finish_fcn,
|
||||
gpointer probe_user_data,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
gboolean nmcs_utils_poll_finish(GAsyncResult *result, gpointer *probe_user_data, GError **error);
|
||||
|
||||
|
|
|
|||
|
|
@ -429,6 +429,12 @@ _poll_req_data_free(gpointer data)
|
|||
nm_g_slice_free(poll_req_data);
|
||||
}
|
||||
|
||||
static void
|
||||
_poll_reg_probe_register_object_fcn(GObject *object, gpointer user_data)
|
||||
{
|
||||
nmcs_wait_for_objects_register(object);
|
||||
}
|
||||
|
||||
static void
|
||||
_poll_req_probe_start_fcn(GCancellable *cancellable,
|
||||
gpointer probe_user_data,
|
||||
|
|
@ -578,6 +584,7 @@ nm_http_client_poll_req(NMHttpClient *self,
|
|||
nmcs_utils_poll(poll_timeout_ms,
|
||||
ratelimit_timeout_ms,
|
||||
0,
|
||||
_poll_reg_probe_register_object_fcn,
|
||||
_poll_req_probe_start_fcn,
|
||||
_poll_req_probe_finish_fcn,
|
||||
poll_req_data,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue