From owner-p4-projects@FreeBSD.ORG Wed Aug 15 06:43:29 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id AC74416A421; Wed, 15 Aug 2007 06:43:29 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 40DCD16A41A for ; Wed, 15 Aug 2007 06:43:29 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 267FE13C4B3 for ; Wed, 15 Aug 2007 06:43:29 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l7F6hSVC072112 for ; Wed, 15 Aug 2007 06:43:29 GMT (envelope-from gcooper@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l7F6hS7O072109 for perforce@freebsd.org; Wed, 15 Aug 2007 06:43:28 GMT (envelope-from gcooper@FreeBSD.org) Date: Wed, 15 Aug 2007 06:43:28 GMT Message-Id: <200708150643.l7F6hS7O072109@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gcooper@FreeBSD.org using -f From: Garrett Cooper To: Perforce Change Reviews Cc: Subject: PERFORCE change 125165 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Aug 2007 06:43:30 -0000 http://perforce.freebsd.org/chv.cgi?CH=125165 Change 125165 by gcooper@optimus-revised_pkgtools on 2007/08/15 06:43:07 - Fill in more DB API blanks, in particular a 'constructor' and 'destructor'. - Convert all DB arguments to db arguments. Need to pass in the database object to all called 'methods' (currently it doesn't do much, but just in case..). Affected files ... .. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/lib/db/api.c#3 edit .. //depot/projects/soc2007/revised_fbsd_pkgtools/v2/lib/db/api.h#3 edit Differences ... ==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/lib/db/api.c#3 (text+ko) ==== @@ -6,7 +6,7 @@ * @return 1 on failure */ int -build_filedb(DB *database, const char *filedb_filename, const char **file_manifest_filenames) +build_filedb(db *database, const char *filedb_filename, const char **file_manifest_filenames) { int build_db_exit_status; @@ -32,7 +32,7 @@ * @return 1 on failure */ int -build_pkgdb(DB *database, const char *pkgdb_filename, const char **index_filenames) +build_pkgdb(db *database, const char *pkgdb_filename, const char **index_filenames) { int build_db_exit_status; @@ -59,18 +59,18 @@ * @return 1 on failure */ int -build_db(DB *database, const char *db_filename, const char *data) +build_db(db *database, const char *db_filename, const char *data) { int build_db_exit_status; - build_db_exit_status = + database->bdb_obj = dbopen(db_filename, O_CREAT | O_EXLOCK | O_EXCL | O_WRLOCK, 0644, DB_HASH, NULL); /** * dbopen was successful. */ - if(0 == build_db_exit_status) { + if(NULL != build_db_exit_status) { /** * Try initializing the database header. @@ -91,6 +91,8 @@ } + } else { + build_db_exit_status = 1; } /** @@ -108,7 +110,7 @@ * @return 1 on failure */ int -cache_file_entry(DB *database, const void *entry, const size_t entry_size) +cache_file_entry(db *database, const void *entry, const size_t entry_size) { int cache_exit_status; @@ -128,7 +130,7 @@ * @return 1 on failure */ int -cache_pkg_entry(DB *database, const void *entry, const size_t entry_size) +cache_pkg_entry(db *database, const void *entry, const size_t entry_size) { int cache_exit_status; @@ -149,7 +151,7 @@ * @return 1 on failure */ int -remove_lru_cache_entry(DB *database, const size_t entry_size) +remove_lru_cache_entry(db *database, const size_t entry_size) { DBT @@ -174,7 +176,7 @@ header_query = { __HEADER_TITLE, sizeof(__HEADER_TITLE) }, header_retrieved; - int db_exit_status = database->get(, 0); +// int db_exit_status = database->bdb_obj->get(, 0); /** * Ok, there is a cache. Let's proceed. @@ -196,7 +198,7 @@ * @return 1 on failure */ int -initialize_database_header(DB *database) +initialize_database_header(db *database) { @@ -210,7 +212,7 @@ * @return 1 on failure */ int -initialize_entry_cache(DB *database) +initialize_entry_cache(db *database) { @@ -223,7 +225,7 @@ * @return 1 on failure */ int -flush_changes(DB *database, const void **entry_list, const size_t entry_size) +flush_changes(db *database, const void **entry_list, const size_t entry_size) { @@ -237,12 +239,12 @@ * @return NULL if not found. */ void* -file_search(DB *database, const char *key) +file_search(db *database, const char *key) { file_entry *entry; - db_search(entry, sizeof(file_entry), DB, key); + db_search(entry, sizeof(file_entry), database, key); return entry; @@ -254,12 +256,12 @@ * @return NULL if not found. */ void* -pkg_search(DB *database, const char *key) +pkg_search(db *database, const char *key) { pkg_entry *entry; - db_search(entry, sizeof(pkg_entry), DB, key); + db_search(entry, sizeof(pkg_entry), db, key); return entry; @@ -281,7 +283,7 @@ * be returned than just 1. */ int -db_search(void *found_entry, const size_t found_entry_size, DB *database, const char *key) +db_search(void *found_entry, const size_t found_entry_size, db *database, const char *key) { DBT search_key = { key, sizeof(key) }; @@ -292,13 +294,14 @@ /** * The search subroutine. */ - int db_get_exit_status = database->get(database, &search_key, &db_found_entry, 0); + exit_status = + database->bdb_obj->get(database->bdb_obj, &search_key, &db_found_entry, 0); /** * Success! We found it and everything passed in * creating the DBT objects. */ - if(0 == db_get_exit_status) { + if(0 == exit_status) { assert(found_entry_size == db_found_entry->size); @@ -325,20 +328,50 @@ } } - /** - * Else if the key's positive, there was an - * unknown BDB error. - */ - else if(0 < db_get_exit_status) { - exit_status = 1; + + return exit_status; + +} + +void* +initialize_db(const char *filename, __DB_TYPE_e db_type) { + + db *database; + + switch(db_type) { + + case FILEDB: + + database->__build = build_filedb; + database->__cache_entry = cache_file_entry; + database->__flush = flush_changes; + database->__free = free_db; + database->__search = file_search; + + break; + + case PKGDB: + + database->__build = build_pkgdb; + database->__cache_entry = cache_pkg_entry; + database->__flush = flush_changes; + database->__free = free_db; + database->__search = pkg_search; + + break; + + default: + errx(-1, "Unknown package database type\n"); + } - /** - * Else, the key wasn't found. - */ - else { - exit_status = -1; - } + + return database; + +} + +int +free_db(db* db_obj) +{ - return exit_status; } ==== //depot/projects/soc2007/revised_fbsd_pkgtools/v2/lib/db/api.h#3 (text+ko) ==== @@ -1,6 +1,6 @@ -#ifndef __DB_API_H +#ifndef __db_API_H -#define __DB_API_H +#define __db_API_H #include #include @@ -9,6 +9,10 @@ #include +typedef enum { + FILEDB, PKGDB +} __DB_TYPE_e; + /** * The database will appear something like this (abstractly): * @@ -32,39 +36,61 @@ */ #define __HEADER_FIELD_TITLE "__HEADER" +/** + * The generalized database object. Used for the file and pkg + * databases. + */ typedef struct { - DB bdb_obj; + /** 'OBJECTS' **/ + /** The base database store object **/ + DB *bdb_obj; + /** End 'OBJECTS' **/ + + + /** 'METHODS' **/ + /** Build the database **/ + int (*__build) (db*, const char*, const char**); + /** Cache an entry**/ + int (*__cache_entry)(db*, const void*, const size_t); + /** Flush all changes **/ + int (*__flush) (db*, const void*, const size_t); + + int (*__free) (db*); + /** Query the database **/ + void* (*__search) (db*, const char*); - int (*build_db) (DB*, const char*, const char**); - int (*cache_entry) (DB*, const void*, const size_t); - int (*flush_changes)(DB*, const void*, const size_t); - int (*init_db) (DB*, const char*); - void* (*search) (DB*, const char*); + /** End 'METHODS' **/ } db; /** Database building functions **/ -int build_filedb(DB*, const char*, const char**); -int build_pkgdb(DB*, const char*, const char**); +int build_filedb(db*, const char*, const char**); +int build_pkgdb(db*, const char*, const char**); + +int build_db(db*, const char*, const char *); /** Cache maintenance functions **/ -int cache_file_entry(DB*, const void* const size_t); -int cache_pkg_entry(DB*, const void*, const size_t); +int cache_file_entry(db*, const void* const size_t); +int cache_pkg_entry(db*, const void*, const size_t); -int remove_lru_cache_entry(DB*, const size_t); +int remove_lru_cache_entry(db*, const size_t); /** For initializing required fields in the databases **/ -int initialize_database_header(DB*); -int initialize_entry_cache(DB*); +int initialize_database_header(db*); +int initialize_entry_cache(db*); /** Functions for flushing changes **/ -int flush_changes(DB*, const void*, const size_t); +int flush_changes(db*, const void*, const size_t); /** Functions for search databases **/ -void* file_search(DB*, const char*); -void* pkg_search(DB*, const char*); +void* file_search(db*, const char*); +void* pkg_search(db*, const char*); + +int db_search(void*, const size_t, db*, const char *); + +void* initialize_db(const char*, __DB_TYPE_e); -int db_search(void*, const size_t, DB*, const char *); +int free_db(db*); #endif