From: Michael Tremer Date: Wed, 25 Jun 2025 15:26:46 +0000 (+0000) Subject: ctx: Create an event loop X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c825269dc8530e95d70135f7dd7d9854905f5da3;p=pakfire.git ctx: Create an event loop Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/ctx.c b/src/pakfire/ctx.c index 2d79b892..71e4d315 100644 --- a/src/pakfire/ctx.c +++ b/src/pakfire/ctx.c @@ -29,6 +29,9 @@ #include #include +// systemd +#include + #include #include #include @@ -49,6 +52,9 @@ struct pakfire_ctx { // Distro struct pakfire_distro distro; + // Event Loop + sd_event* loop; + // Logging struct pakfire_ctx_log { int level; @@ -170,6 +176,10 @@ static int pakfire_ctx_load_config(struct pakfire_ctx* ctx, const char* path) { } static void pakfire_ctx_free(struct pakfire_ctx* ctx) { + // Release event loop + if (ctx->loop) + sd_event_unref(ctx->loop); + // Release cURL Share Handle if (ctx->share) curl_share_cleanup(ctx->share); @@ -364,6 +374,24 @@ int pakfire_ctx_pick_solution(struct pakfire_ctx* ctx, struct pakfire* pakfire, return ctx->pick_solution.callback(ctx, pakfire, ctx->pick_solution.data, transaction); } +// Event Loop + +int pakfire_ctx_loop(struct pakfire_ctx* ctx, sd_event** loop) { + int r; + + // Initialize the loop whenever we need it + if (!ctx->loop) { + r = sd_event_new(&ctx->loop); + if (r < 0) + return r; + } + + // Return the loop + *loop = sd_event_ref(ctx->loop); + + return 0; +} + // cURL CURLSH* pakfire_ctx_curl_share(struct pakfire_ctx* ctx) { diff --git a/src/pakfire/ctx.h b/src/pakfire/ctx.h index 1e8068c2..a74c9576 100644 --- a/src/pakfire/ctx.h +++ b/src/pakfire/ctx.h @@ -108,6 +108,12 @@ int pakfire_ctx_setup_progress(struct pakfire_ctx* ctx, struct pakfire_progress* int pakfire_ctx_pick_solution(struct pakfire_ctx* ctx, struct pakfire* pakfire, struct pakfire_transaction* transaction); +// Event Loop + +#include + +int pakfire_ctx_loop(struct pakfire_ctx* ctx, sd_event** loop); + // cURL #include