All DMS opened by a program are now listed and closed with atexit system
This commit is contained in:
@ -17,6 +17,7 @@ cdef extern from "obidms.h" nogil:
|
|||||||
int obi_close_dms(OBIDMS_p dms)
|
int obi_close_dms(OBIDMS_p dms)
|
||||||
char* obi_dms_get_dms_path(OBIDMS_p dms)
|
char* obi_dms_get_dms_path(OBIDMS_p dms)
|
||||||
char* obi_dms_get_full_path(OBIDMS_p dms, const_char_p path_name)
|
char* obi_dms_get_full_path(OBIDMS_p dms, const_char_p path_name)
|
||||||
|
void obi_close_atexit()
|
||||||
|
|
||||||
obiversion_t obi_import_column(const char* dms_path_1, const char* dms_path_2, const char* column_name, obiversion_t version_number)
|
obiversion_t obi_import_column(const char* dms_path_1, const char* dms_path_2, const char* column_name, obiversion_t version_number)
|
||||||
int obi_import_view(const char* dms_path_1, const char* dms_path_2, const char* view_name_1, const char* view_name_2)
|
int obi_import_view(const char* dms_path_1, const char* dms_path_2, const char* view_name_1, const char* view_name_2)
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
#cython: language_level=3
|
#cython: language_level=3
|
||||||
|
|
||||||
|
|
||||||
from libc.stdlib cimport free
|
from libc.stdlib cimport free, atexit
|
||||||
from cpython.list cimport PyList_Size
|
from cpython.list cimport PyList_Size
|
||||||
|
|
||||||
from .capi.obidms cimport obi_open_dms, \
|
from .capi.obidms cimport obi_open_dms, \
|
||||||
obi_create_dms, \
|
obi_create_dms, \
|
||||||
obi_close_dms, \
|
obi_close_dms, \
|
||||||
obi_dms_exists, \
|
obi_dms_exists, \
|
||||||
obi_dms_get_full_path
|
obi_dms_get_full_path, \
|
||||||
|
obi_close_atexit
|
||||||
|
|
||||||
from .capi.obitypes cimport const_char_p
|
from .capi.obitypes cimport const_char_p
|
||||||
|
|
||||||
@ -30,6 +31,10 @@ cdef class DMS(OBIWrapper):
|
|||||||
cdef inline OBIDMS_p pointer(self):
|
cdef inline OBIDMS_p pointer(self):
|
||||||
return <OBIDMS_p>(self._pointer)
|
return <OBIDMS_p>(self._pointer)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def obi_atexit():
|
||||||
|
atexit(obi_close_atexit)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def open_or_new(object dms_name) :
|
def open_or_new(object dms_name) :
|
||||||
cdef OBIDMS_p pointer
|
cdef OBIDMS_p pointer
|
||||||
|
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?)
|
#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
|
* 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);
|
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
|
* 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 -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
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
|
* 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 = (Opened_indexers_list_p) malloc(sizeof(Opened_indexers_list_t));
|
||||||
(dms->opened_indexers)->nb_opened_indexers = 0;
|
(dms->opened_indexers)->nb_opened_indexers = 0;
|
||||||
|
|
||||||
|
// Add in the global list of opened DMS
|
||||||
|
list_dms(dms);
|
||||||
|
|
||||||
return dms;
|
return dms;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,6 +677,10 @@ int obi_close_dms(OBIDMS_p dms)
|
|||||||
free(dms);
|
free(dms);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove DMS from global list of opened DMS
|
||||||
|
unlist_dms(dms);
|
||||||
|
|
||||||
free(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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
18
src/obidms.h
18
src/obidms.h
@ -36,6 +36,8 @@
|
|||||||
*/
|
*/
|
||||||
#define MAX_NB_OPENED_COLUMNS (1000) /**< The maximum number of columns open at the same time.
|
#define MAX_NB_OPENED_COLUMNS (1000) /**< The maximum number of columns open at the same time.
|
||||||
*/
|
*/
|
||||||
|
#define MAX_NB_OPENED_DMS (1000) /**< The maximum number of DMS open at the same time for a given program.
|
||||||
|
*/
|
||||||
#define MAX_NB_OPENED_INDEXERS (1000) /**< The maximum number of indexers open at the same time.
|
#define MAX_NB_OPENED_INDEXERS (1000) /**< The maximum number of indexers open at the same time.
|
||||||
*/
|
*/
|
||||||
#define MAX_PATH_LEN (1024) /**< Maximum length for the character string defining a
|
#define MAX_PATH_LEN (1024) /**< Maximum length for the character string defining a
|
||||||
@ -121,6 +123,12 @@ typedef struct OBIDMS {
|
|||||||
} OBIDMS_t, *OBIDMS_p;
|
} OBIDMS_t, *OBIDMS_p;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Global Array of DMS pointers listing all the DMS opened by a program.
|
||||||
|
*/
|
||||||
|
extern OBIDMS_p global_opened_dms_list[MAX_NB_OPENED_DMS+1];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if an OBIDMS exists.
|
* @brief Checks if an OBIDMS exists.
|
||||||
*
|
*
|
||||||
@ -403,4 +411,14 @@ obiversion_t obi_import_column(const char* dms_path_1, const char* dms_path_2, c
|
|||||||
int obi_import_view(const char* dms_path_1, const char* dms_path_2, const char* view_name_1, const char* view_name_2);
|
int obi_import_view(const char* dms_path_1, const char* dms_path_2, const char* view_name_1, const char* view_name_2);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Closes all DMS in the global list of opened DMS.
|
||||||
|
* To be executed 'at exit' of programs.
|
||||||
|
*
|
||||||
|
* @since October 2017
|
||||||
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
|
*/
|
||||||
|
void obi_close_atexit();
|
||||||
|
|
||||||
|
|
||||||
#endif /* OBIDMS_H_ */
|
#endif /* OBIDMS_H_ */
|
||||||
|
Reference in New Issue
Block a user