From: Michael Tremer Date: Sun, 15 Oct 2023 13:31:27 +0000 (+0000) Subject: libpakfire: Create scaffolding for a new Pakfire context X-Git-Tag: 0.9.30~1504 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8d26fe6a234c57ca41adfa2e0054bc31db491ff;p=pakfire.git libpakfire: Create scaffolding for a new Pakfire context Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 6a1f0136b..c75aa91e5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -217,6 +217,7 @@ libpakfire_la_SOURCES = \ src/libpakfire/cgroup.c \ src/libpakfire/compress.c \ src/libpakfire/config.c \ + src/libpakfire/ctx.c \ src/libpakfire/db.c \ src/libpakfire/dependencies.c \ src/libpakfire/digest.c \ @@ -256,6 +257,7 @@ pkginclude_HEADERS += \ src/libpakfire/include/pakfire/compress.h \ src/libpakfire/include/pakfire/config.h \ src/libpakfire/include/pakfire/constants.h \ + src/libpakfire/include/pakfire/ctx.h \ src/libpakfire/include/pakfire/db.h \ src/libpakfire/include/pakfire/dependencies.h \ src/libpakfire/include/pakfire/digest.h \ diff --git a/src/libpakfire/ctx.c b/src/libpakfire/ctx.c new file mode 100644 index 000000000..c557313a5 --- /dev/null +++ b/src/libpakfire/ctx.c @@ -0,0 +1,65 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2023 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#include +#include + +#include +#include + +struct pakfire_ctx { + // Reference counter + int nrefs; +}; + +static void pakfire_ctx_free(struct pakfire_ctx* ctx) { + free(ctx); +} + +PAKFIRE_EXPORT int pakfire_ctx_create(struct pakfire_ctx** ctx) { + struct pakfire_ctx* c = NULL; + + // Allocate the context + c = calloc(1, sizeof(*c)); + if (!c) + return -errno; + + // Initialize the reference counter + c->nrefs = 1; + + // Return the pointer + *ctx = c; + + return 0; +} + +PAKFIRE_EXPORT struct pakfire_ctx* pakfire_ctx_ref(struct pakfire_ctx* ctx) { + ctx->nrefs++; + + return ctx; +} + +PAKFIRE_EXPORT struct pakfire_ctx* pakfire_ctx_unref(struct pakfire_ctx* ctx) { + if (--ctx->nrefs > 0) + return ctx; + + pakfire_ctx_free(ctx); + return NULL; +} diff --git a/src/libpakfire/include/pakfire/ctx.h b/src/libpakfire/include/pakfire/ctx.h new file mode 100644 index 000000000..acdd1b205 --- /dev/null +++ b/src/libpakfire/include/pakfire/ctx.h @@ -0,0 +1,31 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2023 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#ifndef PAKFIRE_CTX_H +#define PAKFIRE_CTX_H + +struct pakfire_ctx; + +int pakfire_ctx_create(struct pakfire_ctx** ctx); + +struct pakfire_ctx* pakfire_ctx_ref(struct pakfire_ctx* ctx); +struct pakfire_ctx* pakfire_ctx_unref(struct pakfire_ctx* ctx); + +#endif /* PAKFIRE_CTX_H */ diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 563f60f4a..e877a0cd9 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -20,6 +20,11 @@ LIBPAKFIRE_0 { global: + # pakfire ctx + pakfire_ctx_create; + pakfire_ctx_ref; + pakfire_ctx_unref; + # pakfire pakfire_check; pakfire_clean;