From: <ny...@us...> - 2007-01-07 17:31:11
|
Revision: 245 http://svn.sourceforge.net/pmplib/?rev=245&view=rev Author: nyaochi Date: 2007-01-07 09:31:09 -0800 (Sun, 07 Jan 2007) Log Message: ----------- - Removed pmp_music_t::read() and pmp_music_t::write() member functions. - Introduced pmp_t::open() and pmp_t::close() member functions instead. Please don't use the SVN version for the time being. Modified Paths: -------------- trunk/pmplib/frontend/easypmp/common/database.c trunk/pmplib/frontend/easypmp/common/easypmp.h trunk/pmplib/frontend/easypmp/cui/main.c trunk/pmplib/include/pmp.h trunk/pmplib/lib/pmp_iriverplus2/pmp_iriverplus2.c trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.c trunk/pmplib/lib/pmp_irivnavi/pmp_irivnavi.c trunk/pmplib/lib/pmp_portalplayer1/pmp_portalplayer1.c Modified: trunk/pmplib/frontend/easypmp/common/database.c =================================================================== --- trunk/pmplib/frontend/easypmp/common/database.c 2007-01-07 15:17:10 UTC (rev 244) +++ trunk/pmplib/frontend/easypmp/common/database.c 2007-01-07 17:31:09 UTC (rev 245) @@ -111,7 +111,7 @@ int result = 0; uint32_t i; result_t res = 0; - pmp_music_t* pmpdb = NULL; + pmp_music_t* pmpdb = pmp->music; pmp_record_t* records = NULL; pmp_record_t* old_records = NULL; uint32_t num_old_records = 0, num_obtained = 0; @@ -125,8 +125,38 @@ * Read the existing database for update processing mode. */ if (opt->verb & MODE_DATABASE_UPDATE) { - // - easypmp_database_read(pmp, opt, &old_records, &num_old_records, progress, instance); + /* + * Read the existing database for update processing mode. + */ + // Start reading a database. + if (progress(instance, EASYPMPDBP_READ | EASYPMPSP_START, 0, 0, NULL) != 0) { + result = EASYPMPE_CANCEL; + goto error_exit; + } + + // Obtain the number of records in the database. + res = pmpdb->get(pmpdb, NULL, &num_old_records); + if (res != 0) { + result = MAKE_PMP_ERROR(res); + goto error_exit; + } + + // Allocate an array for the records. + old_records = malloc(sizeof(pmp_record_t) * num_old_records); + if (!old_records) { + result = EASYPMPE_INSUFFICIENT_MEMORY; + goto error_exit; + } + + // Obtain the records from the database. + res = pmpdb->get(pmpdb, old_records, &num_old_records); + if (res != 0) { + result = MAKE_PMP_ERROR(res); + goto error_exit; + } + + // Sort the records for binary search. + qsort(old_records, num_old_records, sizeof(pmp_record_t), comp_filename); } else { if (progress(instance, EASYPMPDBP_READ | EASYPMPSP_SKIPPED, 0, 0, NULL) != 0) { result = EASYPMPE_CANCEL; @@ -135,15 +165,6 @@ } /* - * Create a database engine for database construction. - */ - res = pmp->create_instance_db(pmp, &pmpdb); - if (!pmpdb) { - result = MAKE_PMP_ERROR(res); - goto error_exit; - } - - /* * Allocate an array for the new records. */ records = calloc(fl->num_elements, sizeof(pmp_record_t)); @@ -235,11 +256,6 @@ result = EASYPMPE_CANCEL; goto error_exit; } - res = pmpdb->write(pmpdb); - if (res != 0) { - result = MAKE_PMP_ERROR(res); - goto error_exit; - } if (progress(instance, EASYPMPDBP_WRITE | EASYPMPSP_END, 0, 0, NULL) != 0) { result = EASYPMPE_CANCEL; goto error_exit; @@ -274,108 +290,11 @@ } } - /* - * Release the database engine. - */ - if (pmpdb) { - pmpdb->release(pmpdb); - pmpdb = NULL; - } return result; } -int -easypmp_database_read( - pmp_t* pmp, - const option_t* opt, - pmp_record_t** ptr_records, - uint32_t* ptr_num_records, - easypmp_progress_t progress, - void *instance -) -{ - int result = 0; - result_t res = 0; - pmp_music_t* pmpdb = NULL; - - /* - * Read the existing database for update processing mode. - */ - // Create a database engine. - res = pmp->create_instance_db(pmp, &pmpdb); - if (!pmpdb) { - result = MAKE_PMP_ERROR(res); - goto error_exit; - } - - // Start reading a database. - if (progress(instance, EASYPMPDBP_READ | EASYPMPSP_START, 0, 0, NULL) != 0) { - result = EASYPMPE_CANCEL; - goto error_exit; - } - - // Read the existing database. - res = pmpdb->read(pmpdb); - if (res != 0) { - result = MAKE_PMP_ERROR(res); - goto error_exit; - } - - // Obtain the number of records in the database. - res = pmpdb->get(pmpdb, NULL, ptr_num_records); - if (res != 0) { - result = MAKE_PMP_ERROR(res); - goto error_exit; - } - - // Allocate an array for the records. - (*ptr_records) = malloc(sizeof(pmp_record_t) * (*ptr_num_records)); - if (!(*ptr_records)) { - result = EASYPMPE_INSUFFICIENT_MEMORY; - goto error_exit; - } - - // Obtain the records from the database. - res = pmpdb->get(pmpdb, *ptr_records, ptr_num_records); - if (res != 0) { - result = MAKE_PMP_ERROR(res); - goto error_exit; - } - - // Sort the records for binary search. - qsort(*ptr_records, *ptr_num_records, sizeof(pmp_record_t), comp_filename); - - // Release the database instance. - if (pmpdb) { - pmpdb->release(pmpdb); - pmpdb = NULL; - } - - if (progress(instance, EASYPMPDBP_READ | EASYPMPSP_END, *ptr_num_records, 0, NULL) != 0) { - result = EASYPMPE_CANCEL; - goto error_exit; - } - - return result; - -error_exit: - /* - * Free allocated memory. - */ - if ((*ptr_records)) { - uint32_t i; - for (i = 0;i < *ptr_num_records;++i) { - pmp_record_finish(&((*ptr_records)[i])); - } - free((*ptr_records)); - } - return result; -} - - - int database_dump(pmp_t* pmp, FILE *fp, int level) { pmp_music_t* pmpdb = NULL; @@ -383,7 +302,6 @@ if (!pmpdb) { return 1; } - pmpdb->read(pmpdb); pmpdb->dump(pmpdb, fp, level); pmpdb->release(pmpdb); return 0; Modified: trunk/pmplib/frontend/easypmp/common/easypmp.h =================================================================== --- trunk/pmplib/frontend/easypmp/common/easypmp.h 2007-01-07 15:17:10 UTC (rev 244) +++ trunk/pmplib/frontend/easypmp/common/easypmp.h 2007-01-07 17:31:09 UTC (rev 245) @@ -151,16 +151,6 @@ ); int -easypmp_database_read( - pmp_t* pmp, - const option_t* opt, - pmp_record_t** ptr_records, - uint32_t* ptr_num_records, - easypmp_progress_t progress, - void *instance -); - -int easypmp_set_strip_words( option_t* opt, const ucs2char_t* str Modified: trunk/pmplib/frontend/easypmp/cui/main.c =================================================================== --- trunk/pmplib/frontend/easypmp/cui/main.c 2007-01-07 15:17:10 UTC (rev 244) +++ trunk/pmplib/frontend/easypmp/cui/main.c 2007-01-07 17:31:09 UTC (rev 245) @@ -212,6 +212,7 @@ easypmp_filelist_t musics, playlists; pmp_record_t* records = NULL; uint32_t num_records = 0; + uint32_t openflag = 0; FILE *fpi = stdin, *fpo = stdout, *fpe = stderr; option_t opt; @@ -325,6 +326,20 @@ goto exit_main; } + // Open flag. + if (opt.verb & MODE_DATABASE) { + if (opt.verb & MODE_DATABASE_UPDATE) { + openflag |= PMPOF_MUSIC_DB_READ; + } + openflag |= PMPOF_MUSIC_DB_WRITE; + } + if (opt.verb & MODE_DATABASE_REPR) { + openflag |= PMPOF_MUSIC_DB_READ; + } + + // Open the PMP. + ret = pmp->open(pmp, openflag); + // Show player information. device_show_information(pmp, fpo); fprintf(fpo, "\n"); @@ -353,10 +368,12 @@ easypmp_database(&musics, pmp, &opt, &records, &num_records, easypmp_progress, NULL); } if (opt.verb & MODE_PLAYLIST) { + /* // Read the database for JSPL. if ((opt.verb & MODE_PLAYLIST_JSPL) && (!records)) { easypmp_database_read(pmp, &opt, &records, &num_records, easypmp_progress, NULL); } + */ #ifndef HAVE_JSAPI_H if(opt.verb & MODE_PLAYLIST_JSPL) { fprintf(fpe, "Warning: Ignoring -j/--jspl option. This version of easypmp\n"); @@ -378,6 +395,7 @@ free(records); } + pmp->close(pmp, 0); pmp->release(pmp); pmphelp_finish(pmphelp); option_finish(&opt); Modified: trunk/pmplib/include/pmp.h =================================================================== --- trunk/pmplib/include/pmp.h 2007-01-07 15:17:10 UTC (rev 244) +++ trunk/pmplib/include/pmp.h 2007-01-07 17:31:09 UTC (rev 245) @@ -42,6 +42,26 @@ struct tag_pmp_playlist_t; typedef struct tag_pmp_playlist_t pmp_playlist_t; /** + * Interface IDs. + */ +enum { + PMPIID_NONE = 0, + PMPIID_MUSIC, + PMPIID_TUNER, + PMPIID_PHOTO, +}; + +/** + * Open flags. + */ +enum { + PMPOF_MUSIC_DB_READ = 0x0001, + PMPOF_MUSIC_DB_WRITE = 0x0002, + PMPOF_MUSIC_PL_READ = 0x0004, + PMPOF_MUSIC_PL_WRITE = 0x0008, +}; + +/** * Error codes. */ enum { @@ -83,11 +103,11 @@ } pmp_pathenv_t; typedef struct { - char id[128]; - char name[128]; - char mode[128]; - char language[128]; - char version[128]; + char id[128]; /**< Device identifier. */ + char name[128]; /**< Device name. */ + char mode[128]; /**< Firmware mode. */ + char language[128]; /**< Firmware language. */ + char version[128]; /**< Firmware version. */ pmp_pathenv_t path_to_root; /**< Path to the root directory */ pmp_pathenv_t path_to_music; /**< Path to the music files */ @@ -125,10 +145,15 @@ uint32_t ref_count; void* instance; pmp_environment_t env; + pmp_music_t* music; + uint32_t flag; uint32_t (*add_ref)(pmp_t* pmp); uint32_t (*release)(pmp_t* pmp); + result_t (*open)(pmp_t* pmp, uint32_t flag); + result_t (*close)(pmp_t* pmp, uint32_t flag); + result_t (*create_instance_db)(pmp_t* pmp, pmp_music_t** pmpdb); result_t (*create_instance_pl)(pmp_t* pmp, pmp_playlist_t** pmppl); @@ -146,9 +171,6 @@ uint32_t (*add_ref)(pmp_music_t* pmpdb); uint32_t (*release)(pmp_music_t* pmpdb); - result_t (*read)(pmp_music_t* pmpdb); - result_t (*write)(pmp_music_t* pmpdb); - result_t (*set)(pmp_music_t* pmpdb, const pmp_record_t* records, uint32_t num_records); result_t (*get)(pmp_music_t* pmpdb, pmp_record_t* records, uint32_t* num_records); Modified: trunk/pmplib/lib/pmp_iriverplus2/pmp_iriverplus2.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus2/pmp_iriverplus2.c 2007-01-07 15:17:10 UTC (rev 244) +++ trunk/pmplib/lib/pmp_iriverplus2/pmp_iriverplus2.c 2007-01-07 17:31:09 UTC (rev 245) @@ -115,6 +115,8 @@ static uint32_t pmp_add_ref(pmp_t* pmp); static uint32_t pmp_release(pmp_t* pmp); +static result_t pmp_open(pmp_t* pmp, uint32_t flag); +static result_t pmp_close(pmp_t* pmp, uint32_t flag); static result_t pmp_create_instance_db(pmp_t* pmp, pmp_music_t** ptr_pmpdb); static result_t pmp_create_instance_pl(pmp_t* pmp, pmp_playlist_t** ptr_pmppl); static result_t pmp_is_supported_codec(pmp_t* pmp, uint32_t codec); @@ -328,15 +330,18 @@ pmp->add_ref = pmp_add_ref; pmp->release = pmp_release; + pmp->open = pmp_open; + pmp->close = pmp_close; pmp->create_instance_db = pmp_create_instance_db; pmp->create_instance_pl = pmp_create_instance_pl; pmp->is_supported_codec = pmp_is_supported_codec; pmp->is_supported_ext = pmp_is_supported_ext; + pmp->add_ref(pmp); // Allocate the internal variables. pmpi = (pmp_internal_t*)calloc(1, sizeof(pmp_internal_t)); if (!pmpi) { - free(pmp); + pmp_release(pmp); return PMPDBE_OUTOFMEMORY; } pmp->instance = pmpi; @@ -359,8 +364,14 @@ ucs2cpy(pmpenv->path_to_playlist.path, pmpi->env.path_to_playlist); ucs2cpy(pmpenv->playlist_ext, pmpi->env.playlist_ext); + // Create music instance. + ret = pmp_create_instance_db(pmp, &pmp->music); + if (ret != 0) { + pmp_release(pmp); + return ret; + } + // Prepare - pmp->add_ref(pmp); *ptr_pmp = pmp; return 0; } @@ -374,12 +385,39 @@ { uint32_t count = interlocked_decrement(&pmp->ref_count); if (count == 0) { + pmpdb_release(pmp->music); free(pmp->instance); free(pmp); } return count; } +static result_t pmp_open(pmp_t* pmp, uint32_t flag) +{ + result_t ret = 0; + pmp->flag = flag; + + if (pmp->flag & PMPOF_MUSIC_DB_READ) { + ret = pmpdb_read(pmp->music); + if (ret != 0) { + return ret; + } + } + return 0; +} + +static result_t pmp_close(pmp_t* pmp, uint32_t flag) +{ + result_t ret = 0; + if (pmp->flag & PMPOF_MUSIC_DB_WRITE) { + ret = pmpdb_write(pmp->music); + if (ret != 0) { + return ret; + } + } + return 0; +} + static result_t pmp_create_instance_db(pmp_t* pmp, pmp_music_t** ptr_pmpdb) { pmp_music_t* pmpdb = NULL; @@ -395,8 +433,6 @@ pmpdb->add_ref = pmpdb_add_ref; pmpdb->release = pmpdb_release; - pmpdb->read = pmpdb_read; - pmpdb->write = pmpdb_write; pmpdb->set = pmpdb_set; pmpdb->get = pmpdb_get; pmpdb->dump = pmpdb_dump; Modified: trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.c 2007-01-07 15:17:10 UTC (rev 244) +++ trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.c 2007-01-07 17:31:09 UTC (rev 245) @@ -111,6 +111,8 @@ static uint32_t pmp_add_ref(pmp_t* pmp); static uint32_t pmp_release(pmp_t* pmp); +static result_t pmp_open(pmp_t* pmp, uint32_t flag); +static result_t pmp_close(pmp_t* pmp, uint32_t flag); static result_t pmp_create_instance_db(pmp_t* pmp, pmp_music_t** ptr_pmpdb); static result_t pmp_create_instance_pl(pmp_t* pmp, pmp_playlist_t** ptr_pmppl); static result_t pmp_is_supported_codec(pmp_t* pmp, uint32_t codec); @@ -339,10 +341,13 @@ pmp->add_ref = pmp_add_ref; pmp->release = pmp_release; + pmp->open = pmp_open; + pmp->close = pmp_close; pmp->create_instance_db = pmp_create_instance_db; pmp->create_instance_pl = pmp_create_instance_pl; pmp->is_supported_codec = pmp_is_supported_codec; pmp->is_supported_ext = pmp_is_supported_ext; + pmp->add_ref(pmp); // Allocate the internal variables. pmpi = (pmp_internal_t*)calloc(1, sizeof(pmp_internal_t)); @@ -370,8 +375,14 @@ ucs2cpy(pmpenv->path_to_playlist.path, pmpi->env.path_to_playlist); ucs2cpy(pmpenv->playlist_ext, pmpi->env.playlist_ext); + // Create music instance. + ret = pmp_create_instance_db(pmp, &pmp->music); + if (ret != 0) { + pmp_release(pmp); + return ret; + } + // Prepare - pmp->add_ref(pmp); *ptr_pmp = pmp; return 0; } @@ -385,12 +396,39 @@ { uint32_t count = interlocked_decrement(&pmp->ref_count); if (count == 0) { + pmpdb_release(pmp->music); free(pmp->instance); free(pmp); } return count; } +static result_t pmp_open(pmp_t* pmp, uint32_t flag) +{ + result_t ret = 0; + pmp->flag = flag; + + if (pmp->flag & PMPOF_MUSIC_DB_READ) { + ret = pmpdb_read(pmp->music); + if (ret != 0) { + return ret; + } + } + return 0; +} + +static result_t pmp_close(pmp_t* pmp, uint32_t flag) +{ + result_t ret = 0; + if (pmp->flag & PMPOF_MUSIC_DB_WRITE) { + ret = pmpdb_write(pmp->music); + if (ret != 0) { + return ret; + } + } + return 0; +} + static result_t pmp_create_instance_db(pmp_t* pmp, pmp_music_t** ptr_pmpdb) { pmp_music_t* pmpdb = NULL; @@ -406,8 +444,6 @@ pmpdb->add_ref = pmpdb_add_ref; pmpdb->release = pmpdb_release; - pmpdb->read = pmpdb_read; - pmpdb->write = pmpdb_write; pmpdb->set = pmpdb_set; pmpdb->get = pmpdb_get; pmpdb->dump = pmpdb_dump; Modified: trunk/pmplib/lib/pmp_irivnavi/pmp_irivnavi.c =================================================================== --- trunk/pmplib/lib/pmp_irivnavi/pmp_irivnavi.c 2007-01-07 15:17:10 UTC (rev 244) +++ trunk/pmplib/lib/pmp_irivnavi/pmp_irivnavi.c 2007-01-07 17:31:09 UTC (rev 245) @@ -24,14 +24,14 @@ #ifdef HAVE_CONFIG_H #include <config.h> #endif/*HAVE_CONFIG_H*/ + +#include <os.h> #ifdef HAVE_STRING_H #include <string.h> #endif/*HAVE_STRING_H*/ #ifdef HAVE_STDLIB_H #include <stdlib.h> #endif/*HAVE_STDLIB_H*/ - -#include <os.h> #include <stddef.h> #include <ucs2char.h> #include <filepath.h> @@ -87,6 +87,8 @@ static uint32_t pmp_add_ref(pmp_t* pmp); static uint32_t pmp_release(pmp_t* pmp); +static result_t pmp_open(pmp_t* pmp, uint32_t flag); +static result_t pmp_close(pmp_t* pmp, uint32_t flag); static result_t pmp_create_instance_db(pmp_t* pmp, pmp_music_t** ptr_pmpdb); static result_t pmp_create_instance_pl(pmp_t* pmp, pmp_playlist_t** ptr_pmppl); static result_t pmp_is_supported_codec(pmp_t* pmp, uint32_t codec); @@ -104,7 +106,7 @@ static uint32_t pmppl_release(pmp_playlist_t* pmppl); static result_t pmppl_write(pmp_playlist_t* pmppl, const ucs2char_t* filename, ucs2char_t* const files[], uint32_t num_files); -int exists_sysfile(const ucs2char_t* path_to_device, const ucs2char_t* sysfilename) +static int exists_sysfile(const ucs2char_t* path_to_device, const ucs2char_t* sysfilename) { ucs2char_t filename[MAX_PATH]; @@ -133,6 +135,7 @@ // Check the model of the player. if (id && *id) { + // A device identifier is specified. if (strcmp(id, MODELID_H100) == 0) { model = MODEL_IRIVER_H100; } @@ -140,6 +143,7 @@ model = MODEL_IRIVER_H300; } } else { + // Try automatic device recognition. if (exists_sysfile(path_to_device, ucs2cs_h100_sys)) { model = MODEL_IRIVER_H100; } @@ -168,15 +172,18 @@ // Set member methods. pmp->add_ref = pmp_add_ref; pmp->release = pmp_release; + pmp->open = pmp_open; + pmp->close = pmp_close; pmp->create_instance_db = pmp_create_instance_db; pmp->create_instance_pl = pmp_create_instance_pl; pmp->is_supported_codec = pmp_is_supported_codec; pmp->is_supported_ext = pmp_is_supported_ext; + pmp->add_ref(pmp); // Allocate the internal variables. pmpi = (pmp_internal_t*)calloc(1, sizeof(pmp_internal_t)); if (!pmpi) { - free(pmp); + pmp_release(pmp); return PMPDBE_OUTOFMEMORY; } pmp->instance = pmpi; @@ -216,7 +223,14 @@ ucs2cpy(pmpenv->path_to_playlist.path, pmpi->env.path_to_playlist); ucs2cpy(pmpenv->playlist_ext, pmpi->env.playlist_ext); - pmp->add_ref(pmp); + // Create music instance. + ret = pmp_create_instance_db(pmp, &pmp->music); + if (ret != 0) { + pmp_release(pmp); + return ret; + } + + // Return this instance to the caller. *ptr_pmp = pmp; return 0; } @@ -230,11 +244,38 @@ { uint32_t count = interlocked_decrement(&pmp->ref_count); if (count == 0) { + pmpdb_release(pmp->music); free(pmp); } return count; } +static result_t pmp_open(pmp_t* pmp, uint32_t flag) +{ + result_t ret = 0; + pmp->flag = flag; + + if (pmp->flag & PMPOF_MUSIC_DB_READ) { + ret = pmpdb_read(pmp->music); + if (ret != 0) { + return ret; + } + } + return 0; +} + +static result_t pmp_close(pmp_t* pmp, uint32_t flag) +{ + result_t ret = 0; + if (pmp->flag & PMPOF_MUSIC_DB_WRITE) { + ret = pmpdb_write(pmp->music); + if (ret != 0) { + return ret; + } + } + return 0; +} + static int pmp_is_supported_codec(pmp_t* pmp, uint32_t codec) { return ( @@ -276,8 +317,6 @@ // Set member methods. pmpdb->add_ref = pmpdb_add_ref; pmpdb->release = pmpdb_release; - pmpdb->read = pmpdb_read; - pmpdb->write = pmpdb_write; pmpdb->set = pmpdb_set; pmpdb->get = pmpdb_get; pmpdb->dump = pmpdb_dump; Modified: trunk/pmplib/lib/pmp_portalplayer1/pmp_portalplayer1.c =================================================================== --- trunk/pmplib/lib/pmp_portalplayer1/pmp_portalplayer1.c 2007-01-07 15:17:10 UTC (rev 244) +++ trunk/pmplib/lib/pmp_portalplayer1/pmp_portalplayer1.c 2007-01-07 17:31:09 UTC (rev 245) @@ -24,13 +24,13 @@ #ifdef HAVE_CONFIG_H #include <config.h> #endif/*HAVE_CONFIG_H*/ -#ifdef HAVE_STRING_H -#include <string.h> -#endif/*HAVE_STRING_H*/ #include <os.h> #include <stdio.h> #include <stdlib.h> +#ifdef HAVE_STRING_H +#include <string.h> +#endif/*HAVE_STRING_H*/ #include <ucs2char.h> #include <filepath.h> #include <pmp.h> @@ -218,6 +218,8 @@ static uint32_t pmp_add_ref(pmp_t* pmp); static uint32_t pmp_release(pmp_t* pmp); +static result_t pmp_open(pmp_t* pmp, uint32_t flag); +static result_t pmp_close(pmp_t* pmp, uint32_t flag); static result_t pmp_create_instance_db(pmp_t* pmp, pmp_music_t** ptr_pmpdb); static result_t pmp_create_instance_pl(pmp_t* pmp, pmp_playlist_t** ptr_pmppl); static result_t pmp_is_supported_codec(pmp_t* pmp, uint32_t codec); @@ -387,13 +389,16 @@ pmp->release = pmp_release; pmp->create_instance_db = pmp_create_instance_db; pmp->create_instance_pl = pmp_create_instance_pl; + pmp->open = pmp_open; + pmp->close = pmp_close; pmp->is_supported_codec = pmp_is_supported_codec; pmp->is_supported_ext = pmp_is_supported_ext; + pmp->add_ref(pmp); // Allocate the internal variables. pmpi = (pmp_internal_t*)calloc(1, sizeof(pmp_internal_t)); if (!pmpi) { - free(pmp); + pmp_release(pmp); return PMPDBE_OUTOFMEMORY; } pmp->instance = pmpi; @@ -416,8 +421,14 @@ ucs2cpy(pmpenv->path_to_playlist.path, pmpi->env.path_to_playlist); ucs2cpy(pmpenv->playlist_ext, pmpi->env.playlist_ext); + // Create music instance. + ret = pmp_create_instance_db(pmp, &pmp->music); + if (ret != 0) { + pmp_release(pmp); + return ret; + } + // Prepare - pmp->add_ref(pmp); *ptr_pmp = pmp; return 0; } @@ -431,12 +442,39 @@ { uint32_t count = interlocked_decrement(&pmp->ref_count); if (count == 0) { + pmpdb_release(pmp->music); free(pmp->instance); free(pmp); } return count; } +static result_t pmp_open(pmp_t* pmp, uint32_t flag) +{ + result_t ret = 0; + pmp->flag = flag; + + if (pmp->flag & PMPOF_MUSIC_DB_READ) { + ret = pmpdb_read(pmp->music); + if (ret != 0) { + return ret; + } + } + return 0; +} + +static result_t pmp_close(pmp_t* pmp, uint32_t flag) +{ + result_t ret = 0; + if (pmp->flag & PMPOF_MUSIC_DB_WRITE) { + ret = pmpdb_write(pmp->music); + if (ret != 0) { + return ret; + } + } + return 0; +} + static result_t pmp_create_instance_db(pmp_t* pmp, pmp_music_t** ptr_pmpdb) { pmp_music_t* pmpdb = NULL; @@ -452,8 +490,6 @@ pmpdb->add_ref = pmpdb_add_ref; pmpdb->release = pmpdb_release; - pmpdb->read = pmpdb_read; - pmpdb->write = pmpdb_write; pmpdb->set = pmpdb_set; pmpdb->get = pmpdb_get; pmpdb->dump = pmpdb_dump; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |