]> git.ipfire.org Git - pakfire.git/commitdiff
ctx: Create an event loop
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 15:26:46 +0000 (15:26 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 15:31:09 +0000 (15:31 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/ctx.c
src/pakfire/ctx.h

index 2d79b89273de3efff987a7db60105269054906ab..71e4d315a51d3798e2e46e63d453e824ff585bd7 100644 (file)
@@ -29,6 +29,9 @@
 #include <curl/curl.h>
 #include <magic.h>
 
+// systemd
+#include <systemd/sd-event.h>
+
 #include <pakfire/config.h>
 #include <pakfire/ctx.h>
 #include <pakfire/logging.h>
@@ -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) {
index 1e8068c233eda31037d45946df659b79841c44dd..a74c9576c514b24a37ec456567bf288eff60cc8d 100644 (file)
@@ -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 <systemd/sd-event.h>
+
+int pakfire_ctx_loop(struct pakfire_ctx* ctx, sd_event** loop);
+
 // cURL
 
 #include <curl/curl.h>