- First implementation test:

- Init + Open handlers called in DatatStruict_Open_I() API.
  - Works but too complicated...
- Second implementation should now be tested.
This commit is contained in:
Arnaud G. GIBERT 2024-06-12 12:38:48 +02:00
parent b84ae12dfa
commit 6339c66000
3 changed files with 122 additions and 85 deletions

View File

@ -758,12 +758,17 @@ typedef short NDT_DataStruct_Status;
#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 ND_DATASTRUCT_STATUS_VALUE_UNKNOWN_IS( V) ( ( V) == NDD_DATASTRUCT_STATUS_UNKNOWN)
#define ND_DATASTRUCT_STATUS_VALUE_TEMPORARY_IS( V) ( ( V) == NDD_DATASTRUCT_STATUS_TEMPORARY)
#define ND_DATASTRUCT_STATUS_VALUE_VALID_IS( V) ( ( V) == NDD_DATASTRUCT_STATUS_VALID)
#define ND_DATASTRUCT_STATUS_VALUE_INVALID_IS( V) ( ( V) == NDD_DATASTRUCT_STATUS_INVALID)
#define ND_DATASTRUCT_STATUS_UNKNOWN_IS( R) ( ND_DATASTRUCT_STATUS_VALUE_UNKNOWN_IS( ( R)->Status))
#define ND_DATASTRUCT_STATUS_TEMPORARY_IS( R) ( ND_DATASTRUCT_STATUS_VALUE_TEMPORARY_IS( ( R)->Status))
#define ND_DATASTRUCT_STATUS_VALID_IS( R) ( ND_DATASTRUCT_STATUS_VALUE_VALID_IS( ( R)->Status))
#define ND_DATASTRUCT_STATUS_INVALID_IS( R) ( ND_DATASTRUCT_STATUS_VALUE_INVALID_IS( ( R)->Status))
#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" : "???"))))
#define NDD_DATASTRUCT_STATUS_VALUE_ASCII_GET( V) ( ND_DATASTRUCT_STATUS_VALUE_UNKNOWN_IS( V) ? "UNKNOWN" : ( ND_DATASTRUCT_STATUS_VALUE_TEMPORARY_IS( V) ? "TEMPORARY" : ( ND_DATASTRUCT_STATUS_VALUE_VALID_IS( V) ? "VALID" : ( ND_DATASTRUCT_STATUS_VALUE_INVALID_IS( V) ? "INVALID" : "???"))))
#define NDD_DATASTRUCT_STATUS_ASCII_GET( R) ( NDD_DATASTRUCT_STATUS_VALUE_ASCII_GET( ( R)->Status))
@ -799,7 +804,6 @@ typedef struct NDT_Root
typedef struct NDT_DataStruct
{
NDT_Root *Root_Ptr;
NDT_Manager *Manager_Ptr; /* Manager function pointer */
@ -828,15 +832,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( 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_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_tmp_ptr_ptr, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Index_Nb Index_Nb, NDT_Index_Type *Type_Ptr, NDT_Handler *Handler_Tab, short Own_Value, 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_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);
@ -1462,6 +1466,16 @@ NDD_DLL_API NDT_Status ND_Value_Free_C( NDT_Root *, void *);
/*----------------------------------------------------------------------------*/
/* Allocate a temporary root node */
/*----------------------------------------------------------------------------*/
/* (O) Root_Tmp_Ptr_Ptr: Data structure pointer address */
/*----------------------------------------------------------------------------*/
NDT_Status ND_Root_Tmp_Alloc( NDT_Root **Root_Tmp_Ptr_Ptr, size_t Root_Extra_Size, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Index_Nb Index_Nb, NDT_Index_Type *Type_Ptr, NDT_Handler *Handler_Tab, short Own_Value, void *User_Ptr);
/*----------------------------------------------------------------------------*/
/* Execute a manager command */
/*----------------------------------------------------------------------------*/
@ -1515,8 +1529,8 @@ NDD_DLL_API NDT_Status ND_Free_C( void *, NDT_Root *, void *);
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
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);
NDT_Status ND_Handler_Init_Exec_I( NDT_Root **root_tmp_ptr_ptr, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Index_Nb Index_Nb, NDT_Index_Type *Type_Ptr, NDT_Handler *Handler_Tab, short Own_Value, void *User_Ptr, NDT_Handler_Name Handler_Init_Name, NDT_Handler_Init *Handler_Init_Ptr);
NDT_Status ND_Handler_Init_Exec_C( NDT_Root **root_tmp_ptr_ptr, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Index_Nb Index_Nb, NDT_Index_Type *Type_Ptr, NDT_Handler *Handler_Tab, short Own_Value, void *User_Ptr, NDT_Handler_Name Handler_Init_Name, NDT_Handler_Init *Handler_Init_Ptr);

View File

@ -958,7 +958,7 @@ NDT_Status ND_Index_Open_C( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_I
/*----------------------------------------------------------------------------*/
/* Create a new data structure */
/*----------------------------------------------------------------------------*/
/* (O) Root_Ptr_Ptr: Pointer adress of the new sata structure */
/* (O) Root_Ptr_Ptr: Pointer adress of the new data structure */
/* (I) DataStruct_Name: Name of the data structure */
/* (I) Open_Mode: Open mode */
/* (I) Index_Nb: Number of index */
@ -978,10 +978,10 @@ NDT_Status ND_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, NDT_DataStruct_Name
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;
*Root_Ptr_Ptr = NULL;
if( Handler_Tab == NULL)
{
Handler_Tab = NDG_Handler_Tab_Default;
@ -1018,77 +1018,37 @@ NDT_Status ND_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, NDT_DataStruct_Name
/* Call init function */
*Root_Ptr_Ptr = NULL;
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)
if( ( status = ND_Handler_Init_Exec_I( &root_tmp_ptr, Name, Open_Mode, Index_Nb, Type_Ptr, handler_target_tab, Own_Value, User_Ptr, handler_target_tab[ NDD_HANDLER_ID_INIT].Name, ( NDT_Handler_Init *)handler_target_tab[ NDD_HANDLER_ID_INIT].Ptr)) != NDS_OK)
{
return( status);
}
/* 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)
if( ND_DATASTRUCT_STATUS_TEMPORARY_IS( root_tmp_ptr))
{
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 Alloc */
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_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)
{
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;
}
}
return( status);
}
/* Root Alloc */
/* Root Tmp copy and free */
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)
memcpy( *Root_Ptr_Ptr, root_tmp_ptr, root_tmp_ptr->Root_Size);
( *Root_Ptr_Ptr)->Status = NDD_DATASTRUCT_STATUS_VALID;
free( root_tmp_ptr);
}
else
{
return( status);
*Root_Ptr_Ptr = root_tmp_ptr;
}
/* 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;
@ -1097,8 +1057,6 @@ NDT_Status ND_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, NDT_DataStruct_Name
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 */
@ -3536,6 +3494,73 @@ NDT_Status ND_Value_Free_C( NDT_Root *Root_Ptr, void *Value_Ptr)
/*----------------------------------------------------------------------------*/
/* Allocate a temporary root node */
/*----------------------------------------------------------------------------*/
/* (O) Root_Tmp_Ptr_Ptr: Data structure pointer address */
/*----------------------------------------------------------------------------*/
NDT_Status ND_Root_Tmp_Alloc( NDT_Root **Root_Tmp_Ptr_Ptr, size_t Root_Extra_Size, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Index_Nb Index_Nb, NDT_Index_Type *Type_Ptr, NDT_Handler *Handler_Tab, short Own_Value, void *User_Ptr)
{
NDT_Status status;
size_t root_size;
NDT_Index_Id index_id;
/* Root Tmp Alloc */
root_size = sizeof( NDT_Root) + sizeof( NDT_Index) * (Index_Nb - 1) + Root_Extra_Size;
if( ( *Root_Tmp_Ptr_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_Ptr)->Name, Name, NDD_DATASTRUCT_NAME_SIZE);
( *Root_Tmp_Ptr_Ptr)->Root_Size = root_size;
( *Root_Tmp_Ptr_Ptr)->Status = NDD_DATASTRUCT_STATUS_TEMPORARY;
memcpy( ( *Root_Tmp_Ptr_Ptr)->Handler_Tab, Handler_Tab, NDD_HANDLER_TAB_SIZE);
( *Root_Tmp_Ptr_Ptr)->Own_Value = Own_Value;
( *Root_Tmp_Ptr_Ptr)->User_Ptr = User_Ptr;
( *Root_Tmp_Ptr_Ptr)->Index_Nb = Index_Nb;
( *Root_Tmp_Ptr_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_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_Ptr), index_id)) != NDS_OK)
{
LG_LOG_ERROR_0( "Index cleaning error");
return( status);
}
( *Root_Tmp_Ptr_Ptr)->Index_Tab[ index_id].Type = NDD_INDEX_STATUS_CLOSED;
}
}
return( NDS_OK);
}
/*----------------------------------------------------------------------------*/
/* Execute a manager command */
/*----------------------------------------------------------------------------*/
@ -3700,14 +3725,14 @@ NDT_Status ND_Manager_Exec_C( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
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_I( NDT_Root **Root_Tmp_Ptr_Ptr, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Index_Nb Index_Nb, NDT_Index_Type *Type_Ptr, NDT_Handler *Handler_Tab, short Own_Value, void *User_Ptr, NDT_Handler_Name Handler_Init_Name, NDT_Handler_Init *Handler_Init_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_Extra_Size_Ptr, User_Ptr));
return( handler_init_ptr( Root_Tmp_Ptr_Ptr, Name, Open_Mode, Index_Nb, Type_Ptr, Handler_Tab, Own_Value, User_Ptr));
}
@ -3723,13 +3748,13 @@ NDT_Status ND_Handler_Init_Exec_I( size_t *Root_Extra_Size_Ptr, NDT_Handler_Na
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
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)
NDT_Status ND_Handler_Init_Exec_C( NDT_Root **Root_Tmp_Ptr_Ptr, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Index_Nb Index_Nb, NDT_Index_Type *Type_Ptr, NDT_Handler *Handler_Tab, short Own_Value, void *User_Ptr, NDT_Handler_Name Handler_Init_Name, NDT_Handler_Init *Handler_Init_Ptr)
{
ND_LIBNODE_OPEN_CHECK();
ND_HANDLER_NOT_NULL_CHECK( Handler_Init_Name, Handler_Init_Ptr);
return( ND_Handler_Init_Exec_I( Root_Extra_Size_Ptr, Handler_Init_Name, Handler_Init_Ptr, User_Ptr));
return( ND_Handler_Init_Exec_I( Root_Tmp_Ptr_Ptr, Name, Open_Mode, Index_Nb, Type_Ptr, Handler_Tab, Own_Value, User_Ptr, Handler_Init_Name, Handler_Init_Ptr));
}
@ -4207,11 +4232,9 @@ NDT_Status ND_Deallocator_Exec_C( void *Ptr, NDT_Root *Root_Ptr, NDT_Deallocat
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status ND_Handler_Init_Default( size_t *Root_Extra_Size_Ptr, void *User_Ptr)
NDT_Status ND_Handler_Init_Default( NDT_Root **Root_Tmp_Ptr_Ptr, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Index_Nb Index_Nb, NDT_Index_Type *Type_Ptr, NDT_Handler *Handler_Tab, short Own_Value, void *User_Ptr)
{
*Root_Extra_Size_Ptr = 0L;
return( NDS_OK);
return( ND_Root_Tmp_Alloc( Root_Tmp_Ptr_Ptr, 0L, Name, Open_Mode, Index_Nb, Type_Ptr, Handler_Tab, Own_Value, User_Ptr));
}

View File

@ -325,7 +325,7 @@ NDT_Status ND_List_Sort( NDT_Root *, NDT_Index_Id);
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status ND_Handler_Init_Default( size_t *Root_Extra_Size_Ptr, void *User_Ptr);
NDT_Status ND_Handler_Init_Default( NDT_Root **root_tmp_ptr_ptr, NDT_DataStruct_Name Name, NDT_Open_Flag Open_Mode, NDT_Index_Nb Index_Nb, NDT_Index_Type *Type_Ptr, NDT_Handler *Handler_Tab, short Own_Value, void *User_Ptr);