]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Create scaffolding for a new Pakfire context
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Oct 2023 13:31:27 +0000 (13:31 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 15 Oct 2023 13:42:41 +0000 (13:42 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/libpakfire/ctx.c [new file with mode: 0644]
src/libpakfire/include/pakfire/ctx.h [new file with mode: 0644]
src/libpakfire/libpakfire.sym

index 6a1f0136baafe0217f5bb2ceb5425daaa6226af2..c75aa91e5abe537146cd13f6e45eca6cf5172ff6 100644 (file)
@@ -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 (file)
index 0000000..c557313
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include <pakfire/ctx.h>
+#include <pakfire/private.h>
+
+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 (file)
index 0000000..acdd1b2
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#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 */
index 563f60f4ad553618b87d23ac459668623b471870..e877a0cd97766f314efc1b4e5ae51e8006334965 100644 (file)
 
 LIBPAKFIRE_0 {
 global:
+       # pakfire ctx
+       pakfire_ctx_create;
+       pakfire_ctx_ref;
+       pakfire_ctx_unref;
+
        # pakfire
        pakfire_check;
        pakfire_clean;