Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=cfpm.git;a=commitdiff;h=a1bf818710ef27daed5f4fce3222ac79a6b06e00
commit a1bf818710ef27daed5f4fce3222ac79a6b06e00 Author: Priyank <priy...@frugalware.org> Date: Fri Jun 5 15:08:19 2009 +0530 Added another constructor to the Database class * A database object can directly be instantiated by providing the name of the pacman-g2 database to the constructor * new method: isRegistered() to check whether the database object is registered or not. * minor fixes diff --git a/main.cc b/main.cc index ee031d1..f221d9d 100644 --- a/main.cc +++ b/main.cc @@ -19,7 +19,7 @@ int main(int argc,char **argv) /* initialize libpacman */ if( !initialize("/") ) cerr<<"Error initializing libpacman"<<endl; - + /* register a new database */ if ( db.registerDb("local") ) cout<<"database registered"<<endl; @@ -28,7 +28,7 @@ int main(int argc,char **argv) /* unregister database */ db.unregisterDb(); - + /* release libpacman */ release(); diff --git a/pm.cc b/pm.cc index 211635c..169b772 100644 --- a/pm.cc +++ b/pm.cc @@ -28,13 +28,20 @@ void Shared::setStatus() { en = pm_errno; } Database::Database() { db = NULL; + registered = false; +} + +Database::Database(const string dbname) +{ + Database(); + registerDb(dbname); } Database::~Database() { - if ( db!=NULL ) + if ( db!=NULL && registered ) { - pacman_db_unregister(db); + unregisterDb(); } } @@ -45,19 +52,34 @@ bool Database::registerDb(const string dbname) { setStatus(); ret = false; + registered = false; } + else + { + registered = true; + } + return ret; } bool Database::unregisterDb() { bool ret = true; - if ( !pacman_db_unregister(db) ) + if ( pacman_db_unregister(db) == -1 ) { setStatus(); ret = false; } - db = NULL; + else + { + db = NULL; + registered = false; + } return ret; } +bool Database::isRegistered() +{ + return registered; +} + diff --git a/pm.hh b/pm.hh index bd7596d..6273ea7 100644 --- a/pm.hh +++ b/pm.hh @@ -2,10 +2,12 @@ #define _PM_HEADER_ #include <pacman.h> #include <string> + namespace PM { bool initialize(const std::string &root); bool release(); + class Shared { public: @@ -21,12 +23,15 @@ namespace PM class Database : public Shared { PM_DB *db; + bool registered; public: Database(); + Database(const std::string dbname); ~Database(); bool registerDb(const std::string dbname); bool unregisterDb(); + bool isRegistered(); }; } #endif _______________________________________________ Frugalware-git mailing list Frugalware-git@frugalware.org http://frugalware.org/mailman/listinfo/frugalware-git