From: Michael Tremer Date: Fri, 5 Mar 2021 17:18:11 +0000 (+0000) Subject: packager: Add scaffolding X-Git-Tag: 0.9.28~1285^2~623 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6aeb48e6465c9795b4f70b9a2cc45985bd512f4b;p=pakfire.git packager: Add scaffolding Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 3e6cb8ce2..79a581b57 100644 --- a/Makefile.am +++ b/Makefile.am @@ -272,6 +272,7 @@ libpakfire_la_SOURCES = \ src/libpakfire/key.c \ src/libpakfire/logging.c \ src/libpakfire/package.c \ + src/libpakfire/packager.c \ src/libpakfire/packagelist.c \ src/libpakfire/pakfire.c \ src/libpakfire/parser.c \ @@ -301,6 +302,7 @@ pkginclude_HEADERS += \ src/libpakfire/include/pakfire/key.h \ src/libpakfire/include/pakfire/logging.h \ src/libpakfire/include/pakfire/package.h \ + src/libpakfire/include/pakfire/packager.h \ src/libpakfire/include/pakfire/packagelist.h \ src/libpakfire/include/pakfire/pakfire.h \ src/libpakfire/include/pakfire/parser.h \ diff --git a/src/libpakfire/include/pakfire/packager.h b/src/libpakfire/include/pakfire/packager.h new file mode 100644 index 000000000..139b87b4b --- /dev/null +++ b/src/libpakfire/include/pakfire/packager.h @@ -0,0 +1,33 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2021 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_PACKAGER_H +#define PAKFIRE_PACKAGER_H + +#include + +struct pakfire_packager; + +int pakfire_packager_create(struct pakfire_packager** packager, PakfirePackage pkg); + +struct pakfire_packager* pakfire_packager_ref(struct pakfire_packager* packager); +struct pakfire_packager* pakfire_packager_unref(struct pakfire_packager* packager); + +#endif /* PAKFIRE_PACKAGER_H */ diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 40df6d125..9e9c73041 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -247,6 +247,12 @@ global: pakfire_packagelist_sort; pakfire_packagelist_unref; + # packager + + pakfire_packager_create; + pakfire_packager_ref; + pakfire_packager_unref; + # parser pakfire_parser_append; pakfire_parser_create; diff --git a/src/libpakfire/packager.c b/src/libpakfire/packager.c new file mode 100644 index 000000000..fd91f061b --- /dev/null +++ b/src/libpakfire/packager.c @@ -0,0 +1,77 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2021 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 +#include +#include +#include + +struct pakfire_packager { + Pakfire pakfire; + int nrefs; + + PakfirePackage pkg; +}; + +PAKFIRE_EXPORT int pakfire_packager_create(struct pakfire_packager** packager, + PakfirePackage pkg) { + struct pakfire_packager* p = calloc(1, sizeof(*p)); + if (!p) + return ENOMEM; + + // Initialize reference counting + p->nrefs = 1; + + // Store a reference to Pakfire + p->pakfire = pakfire_package_get_pakfire(pkg); + + // Store a reference to the package + p->pkg = pakfire_package_ref(pkg); + + *packager = p; + + return 0; +} + +static void pakfire_packager_free(struct pakfire_packager* packager) { + pakfire_package_unref(packager->pkg); + pakfire_unref(packager->pakfire); +} + +PAKFIRE_EXPORT struct pakfire_packager* pakfire_packager_ref( + struct pakfire_packager* packager) { + ++packager->nrefs; + + return packager; +} + +PAKFIRE_EXPORT struct pakfire_packager* pakfire_packager_unref( + struct pakfire_packager* packager) { + if (--packager->nrefs > 0) + return packager; + + pakfire_packager_free(packager); + + return NULL; +}