Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=74e71d285a92499b85e9a63d37e23d3484ddbdf6
commit 74e71d285a92499b85e9a63d37e23d3484ddbdf6 Author: Michel Hermier <[email protected]> Date: Tue Apr 29 11:29:31 2014 +0200 libpacman: s/pmhandle_t/libpacman::Handle/g diff --git a/lib/libpacman/db.cpp b/lib/libpacman/db.cpp index 4e12f7d..ac36e89 100644 --- a/lib/libpacman/db.cpp +++ b/lib/libpacman/db.cpp @@ -67,7 +67,7 @@ FILE *_pacman_db_fopen_lastupdate(const Database *db, const char *mode) return fopen(path, mode); } -Database::Database(pmhandle_t *handle, const char *treename, const pmdb_ops_t *_ops) +Database::Database(libpacman::Handle *handle, const char *treename, const pmdb_ops_t *_ops) : ops(_ops) { path = f_zalloc(strlen(handle->root)+strlen(handle->dbpath)+strlen(treename)+2); diff --git a/lib/libpacman/db.h b/lib/libpacman/db.h index 02563b6..79f5f58 100644 --- a/lib/libpacman/db.h +++ b/lib/libpacman/db.h @@ -40,6 +40,7 @@ namespace libpacman { class Database; +class Handle; class Package; } @@ -55,7 +56,7 @@ namespace libpacman { class Database : public libpacman::Object { - public: +public: virtual ~Database(); /* Prototypes for backends functions */ @@ -88,7 +89,7 @@ class Database pmlist_t *servers; protected: - Database(pmhandle_t *handle, const char *treename, const pmdb_ops_t *ops); + Database(libpacman::Handle *handle, const char *treename, const pmdb_ops_t *ops); virtual int open(int flags, time_t *timestamp) = 0; diff --git a/lib/libpacman/db/localdb.cpp b/lib/libpacman/db/localdb.cpp index aa5b439..767647c 100644 --- a/lib/libpacman/db/localdb.cpp +++ b/lib/libpacman/db/localdb.cpp @@ -108,7 +108,7 @@ int LocalPackage::read(unsigned int flags) return 0; } -LocalDatabase::LocalDatabase(pmhandle_t *handle, const char *treename) +LocalDatabase::LocalDatabase(libpacman::Handle *handle, const char *treename) : Database(handle, treename, &_pacman_localdb_ops) { } diff --git a/lib/libpacman/db/localdb.h b/lib/libpacman/db/localdb.h index 1af7204..d8e365a 100644 --- a/lib/libpacman/db/localdb.h +++ b/lib/libpacman/db/localdb.h @@ -44,7 +44,7 @@ class LocalDatabase : public libpacman::Database { public: - LocalDatabase(pmhandle_t *handle, const char *treename); + LocalDatabase(libpacman::Handle *handle, const char *treename); virtual ~LocalDatabase(); virtual pmlist_t *test() const; diff --git a/lib/libpacman/db/syncdb.cpp b/lib/libpacman/db/syncdb.cpp index aeb0a70..a5ff77d 100644 --- a/lib/libpacman/db/syncdb.cpp +++ b/lib/libpacman/db/syncdb.cpp @@ -109,7 +109,7 @@ int SyncPackage::read(unsigned int flags) return 0; } -SyncDatabase::SyncDatabase(pmhandle_t *handle, const char *treename) +SyncDatabase::SyncDatabase(libpacman::Handle *handle, const char *treename) : Database(handle, treename, &_pacman_syncdb_ops) { } diff --git a/lib/libpacman/db/syncdb.h b/lib/libpacman/db/syncdb.h index d3143fe..2e51596 100644 --- a/lib/libpacman/db/syncdb.h +++ b/lib/libpacman/db/syncdb.h @@ -45,7 +45,7 @@ class SyncDatabase : public libpacman::Database { public: - SyncDatabase(pmhandle_t *handle, const char *treename); + SyncDatabase(libpacman::Handle *handle, const char *treename); virtual ~SyncDatabase(); virtual int close(); diff --git a/lib/libpacman/handle.cpp b/lib/libpacman/handle.cpp index 1df9135..f164605 100644 --- a/lib/libpacman/handle.cpp +++ b/lib/libpacman/handle.cpp @@ -45,83 +45,72 @@ #include <time.h> #include <unistd.h> -pmhandle_t *_pacman_handle_new() -{ - pmhandle_t *ph = _pacman_zalloc(sizeof(pmhandle_t)); - - if(ph == NULL) { - return(NULL); - } +using namespace libpacman; - ph->maxtries = 1; +Handle::Handle() +{ + maxtries = 1; #ifndef CYGWIN /* see if we're root or not */ - ph->uid = geteuid(); + uid = geteuid(); #ifdef FAKEROOT_PROOF - if(!ph->uid && getenv("FAKEROOTKEY")) { + if(!uid && getenv("FAKEROOTKEY")) { /* fakeroot doesn't count, we're non-root */ - ph->uid = 99; + uid = 99; } #endif /* see if we're root or not (fakeroot does not count) */ #ifdef FAKEROOT_PROOF - if(ph->uid == 0 && !getenv("FAKEROOTKEY")) { + if(uid == 0 && !getenv("FAKEROOTKEY")) { #else - if(ph->uid == 0) { + if(uid == 0) { #endif - ph->access = PM_ACCESS_RW; + access = PM_ACCESS_RW; } else { - ph->access = PM_ACCESS_RO; + access = PM_ACCESS_RO; } #else - ph->access = PM_ACCESS_RW; + access = PM_ACCESS_RW; #endif - ph->dbpath = strdup(PM_DBPATH); - ph->cachedir = strdup(PM_CACHEDIR); - ph->hooksdir = strdup(PM_HOOKSDIR); - ph->triggersdir = strdup(PM_TRIGGERSDIR); - - ph->language = strdup(setlocale(LC_ALL, NULL)); + dbpath = strdup(PM_DBPATH); + cachedir = strdup(PM_CACHEDIR); + hooksdir = strdup(PM_HOOKSDIR); + triggersdir = strdup(PM_TRIGGERSDIR); - return(ph); + language = strdup(setlocale(LC_ALL, NULL)); } -int _pacman_handle_free(pmhandle_t *ph) +Handle::~Handle() { - ASSERT(ph != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); - /* close logfiles */ - if(ph->logfd) { - fclose(ph->logfd); - ph->logfd = NULL; + if(logfd) { + fclose(logfd); + logfd = NULL; } - if(ph->usesyslog) { - ph->usesyslog = 0; + if(usesyslog) { + usesyslog = 0; closelog(); } /* free memory */ - FREETRANS(ph->trans); - FREE(ph->root); - FREE(ph->dbpath); - FREE(ph->cachedir); - FREE(ph->hooksdir); - FREE(ph->language); - FREE(ph->logfile); - FREE(ph->proxyhost); - FREE(ph->xfercommand); - FREELIST(ph->dbs_sync); - FREELIST(ph->noupgrade); - FREELIST(ph->noextract); - FREELIST(ph->ignorepkg); - FREELIST(ph->holdpkg); - FREELIST(ph->needles); - free(ph); - - return(0); + FREETRANS(trans); + FREE(root); + FREE(dbpath); + FREE(cachedir); + FREE(hooksdir); + FREE(language); + FREE(logfile); + FREE(proxyhost); + FREE(xfercommand); + FREELIST(dbs_sync); + FREELIST(noupgrade); + FREELIST(noextract); + FREELIST(ignorepkg); + FREELIST(holdpkg); + FREELIST(needles); } static @@ -144,7 +133,7 @@ void _pacman_handle_set_option_stringlist(const char *option, pmlist_t **stringl } } -int _pacman_handle_set_option(pmhandle_t *ph, unsigned char val, unsigned long data) +int _pacman_handle_set_option(Handle *ph, unsigned char val, unsigned long data) { char logdir[PATH_MAX], path[PATH_MAX], *p, *q; @@ -301,7 +290,7 @@ int _pacman_handle_set_option(pmhandle_t *ph, unsigned char val, unsigned long d return(0); } -int _pacman_handle_get_option(pmhandle_t *ph, unsigned char val, long *data) +int _pacman_handle_get_option(Handle *ph, unsigned char val, long *data) { /* Sanity checks */ ASSERT(ph != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); @@ -342,7 +331,7 @@ int _pacman_handle_get_option(pmhandle_t *ph, unsigned char val, long *data) return(0); } -int _pacman_handle_lock(pmhandle_t *handle) +int _pacman_handle_lock(Handle *handle) { char lckpath[PATH_MAX]; @@ -352,7 +341,7 @@ int _pacman_handle_lock(pmhandle_t *handle) return (handle->filelock = f_filelock_aquire(lckpath, F_FILELOCK_CREATE_HOLD_DIR | F_FILELOCK_EXCLUSIVE | F_FILELOCK_UNLINK_ON_CLOSE)) != NULL ? 0: -1; } -int _pacman_handle_unlock(pmhandle_t *handle) +int _pacman_handle_unlock(Handle *handle) { int ret = 0; diff --git a/lib/libpacman/handle.h b/lib/libpacman/handle.h index be79a84..00fe235 100644 --- a/lib/libpacman/handle.h +++ b/lib/libpacman/handle.h @@ -27,8 +27,6 @@ #include "pacman.h" -typedef struct __pmhandle_t pmhandle_t; - #include "io/ffilelock.h" #include "db.h" #include "object.h" @@ -45,7 +43,15 @@ typedef enum __pmaccess_t { PM_ACCESS_RW } pmaccess_t; -struct __pmhandle_t { +namespace libpacman { + +class Handle + : public libpacman::Object +{ +public: + Handle(); + virtual ~Handle(); + pmaccess_t access; uid_t uid; libpacman::Database *db_local; @@ -81,14 +87,14 @@ struct __pmhandle_t { int sysupgrade; }; -extern pmhandle_t *handle; +} + +extern libpacman::Handle *handle; -pmhandle_t *_pacman_handle_new(void); -int _pacman_handle_free(pmhandle_t *handle); -int _pacman_handle_set_option(pmhandle_t *handle, unsigned char val, unsigned long data); -int _pacman_handle_get_option(pmhandle_t *handle, unsigned char val, long *data); -int _pacman_handle_lock(pmhandle_t *handle); -int _pacman_handle_unlock(pmhandle_t *handle); +int _pacman_handle_set_option(libpacman::Handle *handle, unsigned char val, unsigned long data); +int _pacman_handle_get_option(libpacman::Handle *handle, unsigned char val, long *data); +int _pacman_handle_lock(libpacman::Handle *handle); +int _pacman_handle_unlock(libpacman::Handle *handle); #endif /* _PACMAN_HANDLE_H */ diff --git a/lib/libpacman/pacman.cpp b/lib/libpacman/pacman.cpp index 2411cf0..ef90dd7 100644 --- a/lib/libpacman/pacman.cpp +++ b/lib/libpacman/pacman.cpp @@ -64,7 +64,7 @@ using namespace libpacman; /* Globals */ -pmhandle_t *handle = NULL; +Handle *handle = NULL; enum __pmerrno_t pm_errno; /** @defgroup pacman_interface Interface Functions @@ -83,7 +83,7 @@ int pacman_initialize(const char *root) ASSERT(handle == NULL, RET_ERR(PM_ERR_HANDLE_NOT_NULL, -1)); - handle = _pacman_handle_new(); + handle = new Handle(); if(handle == NULL) { RET_ERR(PM_ERR_MEMORY, -1); } @@ -124,7 +124,7 @@ int pacman_release(void) if(_pacman_handle_unlock(handle) != 0) { return -1; } - _pacman_handle_free(handle); + delete handle; handle = NULL; return(0); } diff --git a/lib/libpacman/pacman_p.h b/lib/libpacman/pacman_p.h index 5a4a040..2a177a4 100644 --- a/lib/libpacman/pacman_p.h +++ b/lib/libpacman/pacman_p.h @@ -34,12 +34,14 @@ namespace libpacman { class Database; class Group; +class Handle; class Package; } DEFINE_CAST(struct __pmdb_t, libpacman::Database) DEFINE_CAST(struct __pmgrp_t, libpacman::Group) +DEFINE_CAST(struct __pmhandle_t, libpacman::Handle) DEFINE_CAST(struct __pmpkg_t, libpacman::Package) #undef DEFINE_CAST diff --git a/lib/libpacman/trans.h b/lib/libpacman/trans.h index 4b06e85..f6e0ae1 100644 --- a/lib/libpacman/trans.h +++ b/lib/libpacman/trans.h @@ -30,6 +30,12 @@ typedef struct __pmtrans_t pmtrans_t; #include "util/stringlist.h" +namespace libpacman { + +class Handle; + +} + enum { STATE_IDLE = 0, STATE_INITIALIZED, @@ -56,7 +62,7 @@ typedef struct __pmtrans_cbs_t { struct __pmtrans_t { const pmtrans_ops_t *ops; int (*set_state)(pmtrans_t *trans, int new_state); - pmhandle_t *handle; + libpacman::Handle *handle; pmtranstype_t type; unsigned int flags; unsigned char state; diff --git a/lib/libpacman/trans_sysupgrade.cpp b/lib/libpacman/trans_sysupgrade.cpp index 89dcdef..51fe478 100644 --- a/lib/libpacman/trans_sysupgrade.cpp +++ b/lib/libpacman/trans_sysupgrade.cpp @@ -70,7 +70,7 @@ static int istoonew(Package *pkg) int _pacman_trans_sysupgrade(pmtrans_t *trans) { pmlist_t *i, *j, *k; - pmhandle_t *handle; + Handle *handle; Database *db_local; pmlist_t *dbs_sync; _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
