All DMS opened by a program are now listed and closed with atexit system
This commit is contained in:
75
src/obidms.c
75
src/obidms.c
@ -34,6 +34,10 @@
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
|
||||
|
||||
// Initialize global list of opened DMS
|
||||
OBIDMS_p global_opened_dms_list[MAX_NB_OPENED_DMS+1] = { 0 };
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* D E C L A R A T I O N O F T H E P R I V A T E F U N C T I O N S
|
||||
@ -98,6 +102,31 @@ static char* build_infos_file_name(const char* dms_name);
|
||||
int create_dms_infos_file(int dms_file_descriptor, const char* dms_name);
|
||||
|
||||
|
||||
/**
|
||||
* Internal function adding a DMS in the global list of DMS opened by a program.
|
||||
*
|
||||
* @param dms A pointer on the DMS to add.
|
||||
*
|
||||
* @retval 0 if the operation was successfully completed.
|
||||
* @retval -1 if an error occurred.
|
||||
*
|
||||
* @since October 2017
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
static int list_dms(OBIDMS_p dms);
|
||||
|
||||
|
||||
/**
|
||||
* Internal function removing a DMS from the global list of DMS opened by a program.
|
||||
*
|
||||
* @param dms A pointer on the DMS to remove.
|
||||
*
|
||||
* @since October 2017
|
||||
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||
*/
|
||||
static void unlist_dms(OBIDMS_p dms);
|
||||
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
* D E F I N I T I O N O F T H E P R I V A T E F U N C T I O N S
|
||||
@ -202,11 +231,39 @@ int create_dms_infos_file(int dms_file_descriptor, const char* dms_name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int list_dms(OBIDMS_p dms)
|
||||
{
|
||||
int i = 0;
|
||||
while (global_opened_dms_list[i] != NULL)
|
||||
i++;
|
||||
if (i == (MAX_NB_OPENED_DMS-1))
|
||||
{
|
||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError opening a DMS: maximum number of DMS opened by a program reached");
|
||||
return -1;
|
||||
}
|
||||
global_opened_dms_list[i] = dms;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void unlist_dms(OBIDMS_p dms)
|
||||
{
|
||||
int i = 0;
|
||||
while (global_opened_dms_list[i] != dms)
|
||||
i++;
|
||||
while (global_opened_dms_list[i] != NULL)
|
||||
{
|
||||
global_opened_dms_list[i] = global_opened_dms_list[i+1];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
*
|
||||
* D E F I N I T I O N O F T H E P U B L I C F U N C T I O N S
|
||||
@ -538,6 +595,9 @@ OBIDMS_p obi_open_dms(const char* dms_path)
|
||||
dms->opened_indexers = (Opened_indexers_list_p) malloc(sizeof(Opened_indexers_list_t));
|
||||
(dms->opened_indexers)->nb_opened_indexers = 0;
|
||||
|
||||
// Add in the global list of opened DMS
|
||||
list_dms(dms);
|
||||
|
||||
return dms;
|
||||
}
|
||||
|
||||
@ -617,6 +677,10 @@ int obi_close_dms(OBIDMS_p dms)
|
||||
free(dms);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Remove DMS from global list of opened DMS
|
||||
unlist_dms(dms);
|
||||
|
||||
free(dms);
|
||||
}
|
||||
|
||||
@ -1085,5 +1149,14 @@ int obi_import_view(const char* dms_path_1, const char* dms_path_2, const char*
|
||||
}
|
||||
|
||||
|
||||
void obi_close_atexit()
|
||||
{
|
||||
int i=0;
|
||||
|
||||
while (global_opened_dms_list[i] != NULL)
|
||||
{
|
||||
obi_close_dms(global_opened_dms_list[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user