- Remove ND_Node_Root_Alloc(),

- Update init handler API.
This commit is contained in:
Arnaud G. GIBERT 2024-05-31 12:11:56 +02:00
parent 4756903ac3
commit b84ae12dfa
3 changed files with 150 additions and 188 deletions

View File

@ -75,7 +75,7 @@
# define NDD_MIN(A,B) ( ( A > B) ? B : A)
# define NDD_MAX(A,B) ( ( A < B) ? B : A)
# define ND_STRCPY( dest, src, size) strncpy( (dest), (src), (size)); \
# define ND_STR_CPY( dest, src, size) strncpy( (dest), (src), (size)); \
(dest)[ (size) - 1] = '\0'
@ -727,7 +727,7 @@ typedef struct NDT_Handler
# define NDD_HANDLER_TAB_SIZE ( sizeof( NDT_Handler) * NDD_HANDLER_NB)
# define NDD_HANDLER_SET( Handler_Ptr, Function_Name, Function_Ptr) ND_STRCPY( ( Handler_Ptr).Name, (Function_Name), NDD_HANDLER_NAME_SIZE); \
# define NDD_HANDLER_SET( Handler_Ptr, Function_Name, Function_Ptr) ND_STR_CPY( ( Handler_Ptr).Name, (Function_Name), NDD_HANDLER_NAME_SIZE); \
( Handler_Ptr).Ptr = (NDT_Handler_Function *)(Function_Ptr);
# ifndef _LIBNODE_C_
@ -749,14 +749,32 @@ typedef char *NDT_DataStruct_Name;
typedef short NDT_DataStruct_Status;
#define NDD_DATASTRUCT_STATUS_UNKNOWN 0x0000
#define NDD_DATASTRUCT_STATUS_TEMPORARY 0x0001
#define NDD_DATASTRUCT_STATUS_VALID 0x0002
#define NDD_DATASTRUCT_STATUS_INVALID 0x0003
#define NDD_DATASTRUCT_STATUS_MSK ( NDD_DATASTRUCT_STATUS_UNKNOWN | NDD_DATASTRUCT_STATUS_TEMPORARY | NDD_DATASTRUCT_STATUS_VALID | NDD_DATASTRUCT_STATUS_INVALID)
#define NDD_DATASTRUCT_STATUS_RMSK ( NDD_DATASTRUCT_STATUS_MSK ^ 0xffff)
#define NDD_DATASTRUCT_STATUS_VALUE_UNKNOWN_IS( V) ( ( V) == NDD_DATASTRUCT_STATUS_UNKNOWN)
#define NDD_DATASTRUCT_STATUS_VALUE_TEMPORARY( V) ( ( V) == NDD_DATASTRUCT_STATUS_TEMPORARY)
#define NDD_DATASTRUCT_STATUS_VALUE_VALID( V) ( ( V) == NDD_DATASTRUCT_STATUS_VALID)
#define NDD_DATASTRUCT_STATUS_VALUE_INVALID( V) ( ( V) == NDD_DATASTRUCT_STATUS_INVALID)
#define NDD_DATASTRUCT_STATUS_VALUE_ASCII_GET( V) ( NDD_DATASTRUCT_STATUS_VALUE_UNKNOWN_IS( V) ? "UNKNOWN" : ( NDD_DATASTRUCT_STATUS_VALUE_TEMPORARY( V) ? "TEMPORARY" : ( NDD_DATASTRUCT_STATUS_VALUE_VALID( V) ? "VALID" : ( NDD_DATASTRUCT_STATUS_VALUE_INVALID( V) ? "INVALID" : "???"))))
typedef struct NDT_Root
{
char Name[ NDD_DATASTRUCT_NAME_SIZE];
char Name[ NDD_DATASTRUCT_NAME_SIZE];
long Root_Size; /* Root node total size */
size_t Root_Size; /* Root node total size */
NDT_DataStruct_Status Status;
// NDT_DataStruct_Handlers Handlers;
NDT_Handler Handler_Tab[ NDD_HANDLER_ID_NB];
NDT_Handler Handler_Tab[ NDD_HANDLER_ID_NB];
/* Deprecated Start */
NDT_Manager *Manager_Ptr; /* Manager function pointer */
@ -767,13 +785,13 @@ typedef struct NDT_Root
char Deallocator_Name[ NDD_DEALLOCATOR_NAME_SIZE_MAX]; /* Value deallocator function name */
/* Deprecated End */
short Own_Value; /* Flag indicating if the structure is the node owner */
short Own_Value; /* Flag indicating if the structure is the node owner */
void *User_Ptr; /* User pointer */
void *User_Ptr; /* User pointer */
NDT_Index_Nb Index_Nb;
NDT_Index_Nb Index_Open_Count;
NDT_Index Index_Tab[ 1];
NDT_Index_Nb Index_Nb;
NDT_Index_Nb Index_Open_Count;
NDT_Index Index_Tab[ 1];
} NDT_Root;
@ -810,15 +828,15 @@ typedef struct NDT_Node
/* Handler protypes */
/*----------------------------------------------------------------------------*/
typedef NDT_Status NDT_Handler_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node *Node_Ptr, NDT_Command Cmd, va_list *);
typedef NDT_Status NDT_Handler_Init( NDT_Root **Root_Ptr_Ptr, size_t *Root_Extra_Size, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Handler *Handler_Tab, void *User_Ptr);
typedef NDT_Status NDT_Handler_Alloc( void **Memory_Ptr_Ptr, NDT_Root *Root_Ptr, size_t Size, void *User_Ptr);
typedef NDT_Status NDT_Handler_Free( void *Memory_Ptr, NDT_Root *Root_Ptr, void *User_Ptr);
typedef NDT_Status NDT_Handler_Open( NDT_Root *Root_Ptr, NDT_Open_Flag Open_Mode, void *User_Ptr);
typedef NDT_Status NDT_Handler_Close( NDT_Root *Root_Ptr, NDT_Close_Flag Close_Mode, void *User_Ptr);
typedef NDT_Status NDT_Handler_Info( NDT_Root *Root_Ptr, NDT_Recursive_Offset Recursive_Offset);
typedef NDT_Status NDT_Handler_Lock( NDT_Root *Root_Ptr, NDT_Lock_Flag Lock_Mode, bool *Locked_Ptr, void *User_Ptr);
typedef NDT_Status NDT_Handler_Unlock( NDT_Root *Root_Ptr, void *User_Ptr);
typedef NDT_Status NDT_Handler_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node *Node_Ptr, NDT_Command Cmd, va_list *);
typedef NDT_Status NDT_Handler_Init( size_t *Root_Extra_Size_Ptr, void *User_Ptr);
typedef NDT_Status NDT_Handler_Alloc( void **Memory_Ptr_Ptr, NDT_Root *Root_Ptr, size_t Size, void *User_Ptr);
typedef NDT_Status NDT_Handler_Free( void *Memory_Ptr, NDT_Root *Root_Ptr, void *User_Ptr);
typedef NDT_Status NDT_Handler_Open( NDT_Root *Root_Ptr, NDT_Open_Flag Open_Mode, void *User_Ptr);
typedef NDT_Status NDT_Handler_Close( NDT_Root *Root_Ptr, NDT_Close_Flag Close_Mode, void *User_Ptr);
typedef NDT_Status NDT_Handler_Info( NDT_Root *Root_Ptr, NDT_Recursive_Offset Recursive_Offset);
typedef NDT_Status NDT_Handler_Lock( NDT_Root *Root_Ptr, NDT_Lock_Flag Lock_Mode, bool *Locked_Ptr, void *User_Ptr);
typedef NDT_Status NDT_Handler_Unlock( NDT_Root *Root_Ptr, void *User_Ptr);
@ -1491,18 +1509,14 @@ NDD_DLL_API NDT_Status ND_Free_C( void *, NDT_Root *, void *);
/*----------------------------------------------------------------------------*/
/* Execute an init handler function */
/*----------------------------------------------------------------------------*/
/* (O) Root_Ptr_Ptr: Pointer adress of the new data structure */
/* (O) Root_Extra_Size: Pointer on the extra root size */
/* (I) DataStruct_Name: Name of the data structure */
/* (I) Open_Mode: Open mode */
/* (I) Handler_Tab: Pointer on the handler tab */
/* (I) Handler_Init_Name: Init handler function name */
/* (I) Handler_Init_Ptr: Init handler function pointer */
/* (I) User_Ptr: User pointer */
/* (O) Root_Extra_Size_Ptr: Pointer on the extra root size */
/* (I) Handler_Init_Name: Init handler function name */
/* (I) Handler_Init_Ptr: Init handler function pointer */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status ND_Handler_Init_Exec_I( NDT_Root **Root_Ptr_Ptr, size_t *Root_Extra_Size, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Handler *Handler_Tab, NDT_Handler_Name Handler_Init_Name, NDT_Handler_Init *Handler_Init_Ptr, void *User_Ptr);
NDT_Status ND_Handler_Init_Exec_C( NDT_Root **Root_Ptr_Ptr, size_t *Root_Extra_Size, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Handler *Handler_Tab, NDT_Handler_Name Handler_Init_Name, NDT_Handler_Init *Handler_Init_Ptr, void *User_Ptr);
NDT_Status ND_Handler_Init_Exec_I( size_t *Root_Extra_Size_Ptr, NDT_Handler_Name Handler_Init_Name, NDT_Handler_Init *Handler_Init_Ptr, void *User_Ptr);
NDT_Status ND_Handler_Init_Exec_C( size_t *Root_Extra_Size_Ptr, NDT_Handler_Name Handler_Init_Name, NDT_Handler_Init *Handler_Init_Ptr, void *User_Ptr);

View File

@ -973,10 +973,13 @@ NDT_Status ND_Index_Open_C( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_I
NDT_Status ND_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Index_Nb Index_Nb, NDT_Index_Type *Type_Ptr,
NDT_Manager_Name Manager_Name, NDT_Manager *Manager_Ptr, NDT_Handler *Handler_Tab, short Own_Value, void *User_Ptr)
{
NDT_Status status;
NDT_Handler handler_target_tab[ NDD_HANDLER_NB];
NDT_Handler_Id handler_id;
size_t root_extra_size;
NDT_Status status;
NDT_Handler_Id handler_id;
NDT_Handler handler_target_tab[ NDD_HANDLER_NB];
NDT_Root *root_tmp_ptr;
size_t root_size, root_extra_size;
NDT_Index_Id index_id;
if( Handler_Tab == NULL)
@ -984,10 +987,11 @@ NDT_Status ND_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, NDT_DataStruct_Name
Handler_Tab = NDG_Handler_Tab_Default;
}
memcpy( &handler_target_tab, Handler_Tab, NDD_HANDLER_TAB_SIZE);
/* Valeurs par défaut des fonctions d'allocation et de désallocation */
/* Init Manager handler */
if( Manager_Name != NULL)
{
@ -1017,21 +1021,89 @@ NDT_Status ND_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, NDT_DataStruct_Name
*Root_Ptr_Ptr = NULL;
if( ( status = ND_Handler_Init_Exec_I( Root_Ptr_Ptr, &root_extra_size, Name, Open_Mode, handler_target_tab, handler_target_tab[ NDD_HANDLER_ID_INIT].Name, ( NDT_Handler_Init *)handler_target_tab[ NDD_HANDLER_ID_INIT].Ptr, User_Ptr)) != NDS_OK)
if( ( status = ND_Handler_Init_Exec_I( &root_extra_size, handler_target_tab[ NDD_HANDLER_ID_INIT].Name, ( NDT_Handler_Init *)handler_target_tab[ NDD_HANDLER_ID_INIT].Ptr, User_Ptr)) != NDS_OK)
{
return( status);
}
if( ( *Root_Ptr_Ptr != NULL) && ( status = ND_Node_Root_Alloc( Root_Ptr_Ptr, Name, Index_Nb, Type_Ptr, handler_target_tab, root_extra_size, Own_Value, User_Ptr)) != NDS_OK)
/* Root Tmp Alloc */
root_size = sizeof( NDT_Root) + sizeof(NDT_Index) * (Index_Nb - 1) + root_extra_size;
if( ( root_tmp_ptr = malloc( root_size)) == NULL)
{
LG_LOG_ERROR_1( "Can't allocate memory for data structure: [%s]", Name);
return( NDS_ERRMEM);
}
ND_STR_CPY( root_tmp_ptr->Name, Name, NDD_DATASTRUCT_NAME_SIZE);
root_tmp_ptr->Root_Size = root_size;
root_tmp_ptr->Status = NDD_DATASTRUCT_STATUS_TEMPORARY;
memcpy( root_tmp_ptr->Handler_Tab, handler_target_tab, NDD_HANDLER_TAB_SIZE);
root_tmp_ptr->Own_Value = Own_Value;
root_tmp_ptr->User_Ptr = User_Ptr;
root_tmp_ptr->Index_Nb = Index_Nb;
root_tmp_ptr->Index_Open_Count = 0;
/* Index init */
for( index_id = 0; index_id < Index_Nb; index_id++)
{
if( ( Type_Ptr[ index_id] & NDD_INDEX_STATUS_MSK) == NDD_INDEX_STATUS_OPENED)
{
if( ( status = ND_Index_Open_I( root_tmp_ptr, index_id, Type_Ptr[ index_id])) != NDS_OK)
{
LG_LOG_ERROR_0( "Index open error");
return( status);
}
}
else
{
if( ( status = ND_Index_Clear( root_tmp_ptr, index_id)) != NDS_OK)
{
LG_LOG_ERROR_0( "Index cleaning error");
return( status);
}
root_tmp_ptr->Index_Tab[ index_id].Type = NDD_INDEX_STATUS_CLOSED;
}
}
/* Root Alloc */
if( ( status = ND_Allocator_Exec_I( (void **)Root_Ptr_Ptr, root_tmp_ptr, root_tmp_ptr->Root_Size, root_tmp_ptr->Handler_Tab[ NDD_HANDLER_ID_ALLOC].Name, (NDT_Allocator *)root_tmp_ptr->Handler_Tab[ NDD_HANDLER_ID_ALLOC].Ptr, User_Ptr)) != NDS_OK)
{
return( status);
}
/* Root Tmp copy and free */
memcpy( *Root_Ptr_Ptr, root_tmp_ptr, root_tmp_ptr->Root_Size);
( *Root_Ptr_Ptr)->Status = NDD_DATASTRUCT_STATUS_VALID;
/* To be removed... */
ND_STR_CPY( ( *Root_Ptr_Ptr)->Manager_Name, ( *Root_Ptr_Ptr)->Handler_Tab[ NDD_HANDLER_ID_MANAGER].Name, NDD_HANDLER_NAME_SIZE);
( *Root_Ptr_Ptr)->Manager_Ptr = (NDT_Manager *)( *Root_Ptr_Ptr)->Handler_Tab[ NDD_HANDLER_ID_MANAGER].Ptr;
ND_STR_CPY( ( *Root_Ptr_Ptr)->Allocator_Name, ( *Root_Ptr_Ptr)->Handler_Tab[ NDD_HANDLER_ID_ALLOC].Name, NDD_HANDLER_NAME_SIZE);
( *Root_Ptr_Ptr)->Allocator_Ptr = (NDT_Allocator *)( *Root_Ptr_Ptr)->Handler_Tab[ NDD_HANDLER_ID_ALLOC].Ptr;
ND_STR_CPY( ( *Root_Ptr_Ptr)->Deallocator_Name, ( *Root_Ptr_Ptr)->Handler_Tab[ NDD_HANDLER_ID_FREE].Name, NDD_HANDLER_NAME_SIZE);
( *Root_Ptr_Ptr)->Deallocator_Ptr = (NDT_Deallocator *)( *Root_Ptr_Ptr)->Handler_Tab[ NDD_HANDLER_ID_FREE].Ptr;
free( root_tmp_ptr);
/* Call Open function */
if( ( status = ND_Handler_Open_Exec_I( *Root_Ptr_Ptr, Open_Mode, handler_target_tab[ NDD_HANDLER_ID_OPEN].Name, ( NDT_Handler_Open *)handler_target_tab[ NDD_HANDLER_ID_OPEN].Ptr, User_Ptr)) != NDS_OK)
if( ( status = ND_Handler_Open_Exec_I( *Root_Ptr_Ptr, Open_Mode, ( *Root_Ptr_Ptr)->Handler_Tab[ NDD_HANDLER_ID_OPEN].Name, ( NDT_Handler_Open *)( *Root_Ptr_Ptr)->Handler_Tab[ NDD_HANDLER_ID_OPEN].Ptr, User_Ptr)) != NDS_OK)
{
return( status);
}
@ -2140,8 +2212,8 @@ NDT_Status ND_DataStruct_Info_Print_I( FILE *Out, NDT_Root *Root_Ptr, NDT_Recu
offset, version_name);
*/
LG_LOG_INFO_7( "%sRoot: (%s%p)\tName: [%s]\tIndex Nb: (%d)\tIndex Open Count: (%d)\tRoot_Size: (%ld)",
offset, NDD_PRINTF_PTR_PREFIX, Root_Ptr, Root_Ptr->Name, Root_Ptr->Index_Nb, Root_Ptr->Index_Open_Count, Root_Ptr->Root_Size);
LG_LOG_INFO_8( "%sRoot: (%s%p)\tName: [%s]\tIndex Nb: (%d)\tIndex Open Count: (%d)\tRoot_Size: (%ld)\tStatus: [%s]",
offset, NDD_PRINTF_PTR_PREFIX, Root_Ptr, Root_Ptr->Name, Root_Ptr->Index_Nb, Root_Ptr->Index_Open_Count, Root_Ptr->Root_Size, NDD_DATASTRUCT_STATUS_VALUE_ASCII_GET( Root_Ptr->Status));
LG_LOG_INFO_13( "%sManager: (%s%p) [%s]\tInit: (%s%p) [%s]\tAlloc: (%s%p) [%s]\tFree: (%s%p) [%s]", offset,
NDD_PRINTF_PTR_PREFIX, Root_Ptr->Handler_Tab[ NDD_HANDLER_ID_MANAGER].Ptr, Root_Ptr->Handler_Tab[ NDD_HANDLER_ID_MANAGER].Name,
@ -3622,24 +3694,20 @@ NDT_Status ND_Manager_Exec_C( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_
/*----------------------------------------------------------------------------*/
/* Execute an init handler function */
/*----------------------------------------------------------------------------*/
/* (O) Root_Ptr_Ptr: Pointer adress of the new data structure */
/* (O) Root_Extra_Size: Pointer on the extra root size */
/* (I) DataStruct_Name: Name of the data structure */
/* (I) Open_Mode: Open mode */
/* (I) Handler_Tab: Pointer on the handler tab */
/* (I) Handler_Init_Name: Init handler function name */
/* (I) Handler_Init_Ptr: Init handler function pointer */
/* (I) User_Ptr: User pointer */
/* (O) Root_Extra_Size_Ptr: Pointer on the extra root size */
/* (I) Handler_Init_Name: Init handler function name */
/* (I) Handler_Init_Ptr: Init handler function pointer */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status ND_Handler_Init_Exec_I( NDT_Root **Root_Ptr_Ptr, size_t *Root_Extra_Size, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Handler *Handler_Tab, NDT_Handler_Name Handler_Init_Name, NDT_Handler_Init *Handler_Init_Ptr, void *User_Ptr)
NDT_Status ND_Handler_Init_Exec_I( size_t *Root_Extra_Size_Ptr, NDT_Handler_Name Handler_Init_Name, NDT_Handler_Init *Handler_Init_Ptr, void *User_Ptr)
{
NDT_Handler_Init *handler_init_ptr;
ND_HANDLER_SYMBOL_FIND( handler_init_ptr, Handler_Init_Name, Handler_Init_Ptr);
return( handler_init_ptr( Root_Ptr_Ptr, Root_Extra_Size, Name, Open_Mode, Handler_Tab, User_Ptr));
return( handler_init_ptr( Root_Extra_Size_Ptr, User_Ptr));
}
@ -3649,23 +3717,19 @@ NDT_Status ND_Handler_Init_Exec_I( NDT_Root **Root_Ptr_Ptr, size_t *Root_Extr
/*----------------------------------------------------------------------------*/
/* Execute an init handler function */
/*----------------------------------------------------------------------------*/
/* (O) Root_Ptr_Ptr: Pointer adress of the new data structure */
/* (O) Root_Extra_Size: Pointer on the extra root size */
/* (I) DataStruct_Name: Name of the data structure */
/* (I) Open_Mode: Open mode */
/* (I) Handler_Tab: Pointer on the handler tab */
/* (I) Handler_Init_Name: Init handler function name */
/* (I) Handler_Init_Ptr: Init handler function pointer */
/* (I) User_Ptr: User pointer */
/* (O) Root_Extra_Size_Ptr: Pointer on the extra root size */
/* (I) Handler_Init_Name: Init handler function name */
/* (I) Handler_Init_Ptr: Init handler function pointer */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status ND_Handler_Init_Exec_C( NDT_Root **Root_Ptr_Ptr, size_t *Root_Extra_Size, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Handler *Handler_Tab, NDT_Handler_Name Handler_Init_Name, NDT_Handler_Init *Handler_Init_Ptr, void *User_Ptr)
NDT_Status ND_Handler_Init_Exec_C( size_t *Root_Extra_Size_Ptr, NDT_Handler_Name Handler_Init_Name, NDT_Handler_Init *Handler_Init_Ptr, void *User_Ptr)
{
ND_LIBNODE_OPEN_CHECK();
ND_HANDLER_NOT_NULL_CHECK( Handler_Init_Name, Handler_Init_Ptr);
return( ND_Handler_Init_Exec_I( Root_Ptr_Ptr, Root_Extra_Size, Name, Open_Mode, Handler_Tab, Handler_Init_Name, Handler_Init_Ptr, User_Ptr));
return( ND_Handler_Init_Exec_I( Root_Extra_Size_Ptr, Handler_Init_Name, Handler_Init_Ptr, User_Ptr));
}
@ -4139,17 +4203,13 @@ NDT_Status ND_Deallocator_Exec_C( void *Ptr, NDT_Root *Root_Ptr, NDT_Deallocat
/* - Return extra root size */
/* - Update handler tab */
/*----------------------------------------------------------------------------*/
/* (O) Root_Ptr_Ptr: Pointer adress of the new data structure */
/* (O) Root_Extra_Size: Pointer on the extra root size */
/* (I) DataStruct_Name: Name of the data structure */
/* (I) Open_Mode: Open mode */
/* (I) Handler_Tab: Pointer on the handler tab */
/* (I) User_Ptr: User pointer */
/* (O) Root_Extra_Size_Ptr: Pointer on the extra root size */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status ND_Handler_Init_Default( NDT_Root **Root_Ptr_Ptr, size_t *Root_Extra_Size, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Handler *Handler_Tab, void *User_Ptr)
NDT_Status ND_Handler_Init_Default( size_t *Root_Extra_Size_Ptr, void *User_Ptr)
{
*Root_Extra_Size = 0L;
*Root_Extra_Size_Ptr = 0L;
return( NDS_OK);
}
@ -4433,97 +4493,6 @@ NDT_Status ND_Index_Clear( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id)
/*----------------------------------------------------------------------------*/
/* Allocation d'une racine de structure de données */
/*----------------------------------------------------------------------------*/
/* (O) New_Root: adresse du pointeur sur la nouvelle racine */
/* (I) Type: type de la structure de données */
/* (I) Allocator: pointeur vers la fonction d'allocation */
/* (I) Deallocator: pointeur vers la fonction de désallocation */
/* (I) Data : pointeur de données utiles à l'allocateur */
/*----------------------------------------------------------------------------*/
// NDT_Status ND_Node_Root_Alloc( NDT_Root **Root_Ptr_Ptr, NDT_Index_Nb Index_Nb, NDT_Index_Type *Type_Ptr, char *Manager_Name, NDT_Manager *Manager_Ptr, char *Allocator_Name, NDT_Allocator *Allocator_Ptr, char *Deallocator_Name, NDT_Deallocator *Deallocator_Ptr, short Own_Value, void *Data_Ptr)
NDT_Status ND_Node_Root_Alloc( NDT_Root **Root_Ptr_Ptr, NDT_DataStruct_Name Name, NDT_Index_Nb Index_Nb, NDT_Index_Type *Type_Ptr, NDT_Handler *Handler_Tab, size_t Root_Extra_Size, short Own_Value, void *User_Ptr)
{
NDT_Status status;
size_t root_size;
NDT_Index_Id index_id;
root_size = sizeof( NDT_Root) + sizeof(NDT_Index) * (Index_Nb - 1) + Root_Extra_Size;
if( ( status = ND_Allocator_Exec_I( (void **)Root_Ptr_Ptr, NULL, root_size, Handler_Tab[ NDD_HANDLER_ID_ALLOC].Name, (NDT_Allocator *)Handler_Tab[ NDD_HANDLER_ID_ALLOC].Ptr, User_Ptr)) != NDS_OK)
{
return( status);
}
ND_STRCPY( ( *Root_Ptr_Ptr)->Name, Name, NDD_DATASTRUCT_NAME_SIZE);
( *Root_Ptr_Ptr)->Root_Size = root_size;
memcpy( &( ( *Root_Ptr_Ptr)->Handler_Tab), Handler_Tab, NDD_HANDLER_TAB_SIZE);
/* To be removed... */
ND_STRCPY( ( *Root_Ptr_Ptr)->Manager_Name, ( *Root_Ptr_Ptr)->Handler_Tab[ NDD_HANDLER_ID_MANAGER].Name, NDD_HANDLER_NAME_SIZE);
( *Root_Ptr_Ptr)->Manager_Ptr = (NDT_Manager *)( *Root_Ptr_Ptr)->Handler_Tab[ NDD_HANDLER_ID_MANAGER].Ptr;
ND_STRCPY( ( *Root_Ptr_Ptr)->Allocator_Name, ( *Root_Ptr_Ptr)->Handler_Tab[ NDD_HANDLER_ID_ALLOC].Name, NDD_HANDLER_NAME_SIZE);
( *Root_Ptr_Ptr)->Allocator_Ptr = (NDT_Allocator *)( *Root_Ptr_Ptr)->Handler_Tab[ NDD_HANDLER_ID_ALLOC].Ptr;
ND_STRCPY( ( *Root_Ptr_Ptr)->Deallocator_Name, ( *Root_Ptr_Ptr)->Handler_Tab[ NDD_HANDLER_ID_FREE].Name, NDD_HANDLER_NAME_SIZE);
( *Root_Ptr_Ptr)->Deallocator_Ptr = (NDT_Deallocator *)( *Root_Ptr_Ptr)->Handler_Tab[ NDD_HANDLER_ID_FREE].Ptr;
/*
if( strlen( Manager_Name) > NDD_MANAGER_NAME_LEN_MAX) return( NDS_ERRAPI);
strcpy( ( *Root_Ptr_Ptr)->Manager_Name, Manager_Name);
( *Root_Ptr_Ptr)->Manager_Ptr = Manager_Ptr;
if( strlen( Allocator_Name) > NDD_ALLOCATOR_NAME_LEN_MAX) return( NDS_ERRAPI);
strcpy( ( *Root_Ptr_Ptr)->Allocator_Name, Allocator_Name);
( *Root_Ptr_Ptr)->Allocator_Ptr = Allocator_Ptr;
if( strlen( Deallocator_Name) > NDD_DEALLOCATOR_NAME_LEN_MAX) return( NDS_ERRAPI);
strcpy( ( *Root_Ptr_Ptr)->Deallocator_Name, Deallocator_Name);
( *Root_Ptr_Ptr)->Deallocator_Ptr = Deallocator_Ptr;
*/
( *Root_Ptr_Ptr)->Own_Value = Own_Value;
( *Root_Ptr_Ptr)->User_Ptr = User_Ptr;
( *Root_Ptr_Ptr)->Index_Nb = Index_Nb;
( *Root_Ptr_Ptr)->Index_Open_Count = 0;
for( index_id = 0; index_id < Index_Nb; index_id++)
{
if( ( Type_Ptr[index_id] & NDD_INDEX_STATUS_MSK) == NDD_INDEX_STATUS_OPENED)
{
status = ND_Index_Open_I( *Root_Ptr_Ptr, index_id, Type_Ptr[index_id]);
if( ND_ERROR( status)) return( status);
}
else
{
if( ( status = ND_Index_Clear( *Root_Ptr_Ptr, index_id)) != NDS_OK)
{
LG_LOG_ERROR_0( "Index cleaning error");
return( NDS_KO);
}
( *Root_Ptr_Ptr)->Index_Tab[index_id].Type = NDD_INDEX_STATUS_CLOSED;
}
}
return( NDS_OK);
}
/*----------------------------------------------------------------------------*/
/* Désallocation de la racine d'une structure de donnée */
/*----------------------------------------------------------------------------*/

View File

@ -194,23 +194,6 @@ NDT_Status ND_Node_Free( NDT_Root *, NDT_Node *);
/*----------------------------------------------------------------------------*/
NDT_Status ND_Index_Clear( NDT_Root *, NDT_Index_Id);
/*----------------------------------------------------------------------------*/
/* Alocate and initialize a new data structure root node */
/*----------------------------------------------------------------------------*/
/* (O) Root_Ptr_Ptr: Pointer adress of the new sata structure */
/* (I) DataStruct_Name: Name of the data structure */
/* (I) Index_Nb: Number of index */
/* (I) Index_Type_Ptr: Array of Index type (List, tree, ...) */
/* (I) Handlers_Ptr: Pointer to the data structure handlers */
/* (I) Root_Extra_Size: Additional size to be allocated with root node */
/* (I) Own_Value: Flag indicating if the structure is the node owner */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status ND_Node_Root_Alloc( NDT_Root **Root_Ptr_Ptr, NDT_DataStruct_Name Name, NDT_Index_Nb Index_Nb, NDT_Index_Type *Type_Ptr, NDT_Handler *Handler_Tab, size_t Root_Extra_Size, short Own_Value, void *User_Ptr);
/*----------------------------------------------------------------------------*/
/* Destruction d'une racine */
/*----------------------------------------------------------------------------*/
@ -338,15 +321,11 @@ NDT_Status ND_List_Sort( NDT_Root *, NDT_Index_Id);
/* - Return extra root size */
/* - Update handler tab */
/*----------------------------------------------------------------------------*/
/* (O) Root_Ptr_Ptr: Pointer adress of the new data structure */
/* (O) Root_Extra_Size: Pointer on the extra root size */
/* (I) DataStruct_Name: Name of the data structure */
/* (I) Open_Mode: Open mode */
/* (I) Handler_Tab: Pointer on the handler tab */
/* (I) User_Ptr: User pointer */
/* (O) Root_Extra_Size_Ptr: Pointer on the extra root size */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status ND_Handler_Init_Default( NDT_Root **Root_Ptr_Ptr, size_t *Root_Extra_Size, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Handler *Handler_Tab, void *User_Ptr);
NDT_Status ND_Handler_Init_Default( size_t *Root_Extra_Size_Ptr, void *User_Ptr);