Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=72af9c41992091b167a609fe2d2ae5bda3b477fc
commit 72af9c41992091b167a609fe2d2ae5bda3b477fc Author: Michel Hermier <[email protected]> Date: Tue Apr 22 18:03:35 2014 +0200 libpacman: Add a basic object infrastructure for pacman. diff --git a/lib/libpacman/CMakeLists.txt b/lib/libpacman/CMakeLists.txt index b5c6f28..c783ccf 100644 --- a/lib/libpacman/CMakeLists.txt +++ b/lib/libpacman/CMakeLists.txt @@ -54,6 +54,7 @@ set(LIBPACMAN_SOURCES error.c group.c handle.c + object.c package.c packages_transaction.c pacman.c diff --git a/lib/libpacman/object.c b/lib/libpacman/object.c new file mode 100644 index 0000000..7e905f5 --- /dev/null +++ b/lib/libpacman/object.c @@ -0,0 +1,78 @@ +/* + * object.c + * + * Copyright (c) 2014 by Michel Hermier <[email protected]> + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ + +#include "config.h" + +#include "object.h" + +#include "util.h" + +#include <fstdlib.h> + +int _pacman_object_delete(struct __pmobject_t *self) +{ + ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + ASSERT(self->operations == NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + + if(self->operations->fini != NULL) { + self->operations->fini(self); + } + f_free(self); + return 0; +} + +int _pacman_object_init(struct __pmobject_t *self, const struct __pmobject_operations_t *operations) +{ + ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + ASSERT(self->operations == NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + + self->operations = NULL; + return 0; +} + +int _pacman_object_fini(struct __pmobject_t *self) +{ + ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + ASSERT(self->operations != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + + self->operations = NULL; + return 0; +} + +int _pacman_object_get(struct __pmobject_t *self, unsigned val, unsigned long *data) +{ + ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + ASSERT(self->operations != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + ASSERT(self->operations->get != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + + return self->operations->get(self, val, data); +} + +int _pacman_object_set(struct __pmobject_t *self, unsigned val, unsigned long data) +{ + ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + ASSERT(self->operations != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + ASSERT(self->operations->set != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + + return self->operations->set(self, val, data); +} + +/* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/object.h b/lib/libpacman/object.h new file mode 100644 index 0000000..d77e922 --- /dev/null +++ b/lib/libpacman/object.h @@ -0,0 +1,51 @@ +/* + * object.h + * + * Copyright (c) 2014 by Michel Hermier <[email protected]> + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ +#ifndef _PACMAN_OBJECT_H +#define _PACMAN_OBJECT_H + +#include <stddef.h> + +struct __pmobject_t; + +struct __pmobject_operations_t +{ + int (*fini)(struct __pmobject_t *object); + + int (*get)(struct __pmobject_t *object, unsigned val, unsigned long *data); + int (*set)(struct __pmobject_t *object, unsigned val, unsigned long data); +}; + +struct __pmobject_t +{ + const struct __pmobject_operations_t *operations; +}; + +int _pacman_object_delete(struct __pmobject_t *self); + +int _pacman_object_init(struct __pmobject_t *self, const struct __pmobject_operations_t *operations); +int _pacman_object_fini(struct __pmobject_t *self); + +int _pacman_object_get(struct __pmobject_t *self, unsigned val, unsigned long *data); +int _pacman_object_set(struct __pmobject_t *self, unsigned val, unsigned long data); + +#endif /* _PACMAN__OBJECT_H */ + +/* vim: set ts=2 sw=2 noet: */ _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
