Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=c5a20299c787b5066e1cffb0219e2fb95672131c

commit c5a20299c787b5066e1cffb0219e2fb95672131c
Author: Michel Hermier <[email protected]>
Date:   Wed Apr 23 08:39:39 2014 +0200

libpacman: Objectify __pmpkg_t.

diff --git a/lib/libpacman/db/localdb.c b/lib/libpacman/db/localdb.c
index 04bcab5..16efae6 100644
--- a/lib/libpacman/db/localdb.c
+++ b/lib/libpacman/db/localdb.c
@@ -124,8 +124,13 @@ _pacman_localpkg_remove(pmpkg_t *pkg)
}

static const
-pmpkg_ops_t _pacman_localpkg_operations = {
-       .destroy = NULL,
+struct __pmpkg_operations_t _pacman_localpkg_operations = {
+       .as_pmobject_operations_t = {
+               .fini = NULL,
+
+               .get = NULL,
+               .set = NULL,
+       },

.read = _pacman_localpkg_read,
.write = _pacman_localpkg_write,
@@ -136,9 +141,9 @@ static
int _pacman_localpkg_init(pmpkg_t *pkg, pmdb_t *db)
{
ASSERT(pkg != NULL, RET_ERR(PM_ERR_PKG_INVALID, -1));
+       _pacman_object_init(&pkg->as_pmobject_t, 
&_pacman_localpkg_operations.as_pmobject_operations_t);
ASSERT(_pacman_pkg_init(pkg, db) == 0, return -1);

-       pkg->operations = &_pacman_localpkg_operations;
return 0;
}

diff --git a/lib/libpacman/db/syncdb.c b/lib/libpacman/db/syncdb.c
index e60a970..7dab363 100644
--- a/lib/libpacman/db/syncdb.c
+++ b/lib/libpacman/db/syncdb.c
@@ -107,8 +107,13 @@ int _pacman_syncpkg_read(pmpkg_t *pkg, unsigned int flags)
}

static const
-pmpkg_ops_t _pacman_syncpkg_operations = {
-       .destroy = NULL,
+struct __pmpkg_operations_t _pacman_syncpkg_operations = {
+       .as_pmobject_operations_t = {
+               .fini = NULL,
+
+               .get = NULL,
+               .set = NULL,
+       },

.read = _pacman_syncpkg_read,
.write = NULL,
@@ -119,9 +124,9 @@ static
int _pacman_syncpkg_init(pmpkg_t *pkg, pmdb_t *db)
{
ASSERT(pkg != NULL, RET_ERR(PM_ERR_PKG_INVALID, -1));
+       _pacman_object_init(&pkg->as_pmobject_t, 
&_pacman_syncpkg_operations.as_pmobject_operations_t);
ASSERT(_pacman_pkg_init(pkg, db) == 0, return -1);

-       pkg->operations = &_pacman_syncpkg_operations;
return 0;
}

diff --git a/lib/libpacman/object.c b/lib/libpacman/object.c
index 7e905f5..a6cc411 100644
--- a/lib/libpacman/object.c
+++ b/lib/libpacman/object.c
@@ -57,22 +57,32 @@ int _pacman_object_fini(struct __pmobject_t *self)
return 0;
}

+const struct __pmobject_operations_t *_pacman_object_operations(struct 
__pmobject_t *self)
+{
+       ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL));
+       ASSERT(self->operations != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL));
+
+       return self->operations;
+}
+
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));
+       const struct __pmobject_operations_t *object_operations;
+
+       ASSERT((object_operations = _pacman_object_operations(self)) != NULL, 
return -1);
+       ASSERT(object_operations->get != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));

-       return self->operations->get(self, val, data);
+       return object_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));
+       const struct __pmobject_operations_t *object_operations;
+
+       ASSERT((object_operations = _pacman_object_operations(self)) != NULL, 
return -1);
+       ASSERT(object_operations->set != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));

-       return self->operations->set(self, val, data);
+       return object_operations->set(self, val, data);
}

/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/object.h b/lib/libpacman/object.h
index d77e922..23fcf65 100644
--- a/lib/libpacman/object.h
+++ b/lib/libpacman/object.h
@@ -43,6 +43,8 @@ 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);

+const struct __pmobject_operations_t *_pacman_object_operations(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);

diff --git a/lib/libpacman/package.c b/lib/libpacman/package.c
index 4024429..46d9d24 100644
--- a/lib/libpacman/package.c
+++ b/lib/libpacman/package.c
@@ -539,6 +539,19 @@ char *_pacman_pkg_fileneedbackup(const pmpkg_t *pkg, const 
char *file)
return(NULL);
}

+const struct __pmpkg_operations_t pmpkg_operations = {
+       .as_pmobject_operations_t = {
+               .fini = NULL,
+
+               .get = NULL,
+               .set = NULL,
+       },
+
+       .read = NULL,
+       .write = NULL,
+       .remove = NULL
+};
+
typedef struct FPackageStrMatcher FPackageStrMatcher;

struct FPackageStrMatcher
diff --git a/lib/libpacman/package.h b/lib/libpacman/package.h
index 253261d..505c261 100644
--- a/lib/libpacman/package.h
+++ b/lib/libpacman/package.h
@@ -31,6 +31,7 @@

#include "pacman.h"

+#include "object.h"
#include "trans.h"

enum {
@@ -77,10 +78,8 @@ enum {
#define PM_PACKAGE_FLAG_SCRIPTLET             (1<<24)
#define PM_PACKAGE_FLAG_STICKY                (1<<25)

-typedef struct pmpkg_ops_t pmpkg_ops_t;
-
-struct pmpkg_ops_t {
-       int (*destroy)(pmpkg_t *pkg);
+struct __pmpkg_operations_t {
+       struct __pmobject_operations_t as_pmobject_operations_t;

int (*read)(pmpkg_t *pkg, unsigned int flags);
int (*write)(pmpkg_t *pkg, unsigned int flags); /* Optional */
@@ -89,7 +88,7 @@ struct pmpkg_ops_t {

/* IMPROVEMENT: Add a dirty_flags to know what flags needs to be written */
struct __pmpkg_t {
-       const pmpkg_ops_t *operations;
+       struct __pmobject_t as_pmobject_t;
pmdb_t *database;

unsigned int flags;
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to