Compare commits

..

2 Commits

Author SHA1 Message Date
c51bb5090c - First LibNode V3 implementation test...
- Not fully implemented.
- Have to switch to the second one.
2024-06-12 12:43:26 +02:00
8e14ba08bf - Update RelaseNote with new version 3! 2024-05-21 12:06:19 +02:00
4 changed files with 558 additions and 9 deletions

View File

@ -1,3 +1,12 @@
------------------------------------------------------------------------------------------------------------------------------------
LibDataStr V 3.0.0-1 - A. GIBERT - 2024/05/xx
------------------------------------------------------------------------------------------------------------------------------------
- All:
- Working on new API...
------------------------------------------------------------------------------------------------------------------------------------
LibDataStr V 2.0.0-1 - A. GIBERT - 2024/05/21
------------------------------------------------------------------------------------------------------------------------------------

View File

@ -143,7 +143,7 @@ typedef int DST_Flags;
#define DSD_DATASTRUCT_STATUS_VALID 0x0002
#define DSD_DATASTRUCT_STATUS_INVALID 0x0003
#define DSD_DATASTRUCT_STATUS_MSK ( DSD_DATASTRUCT_STATUS_UNKNOWN | DSD_DATASTRUCT_STATUS_TEMPORARY | DSD_DATASTRUCT_STATUS_VALID | DSD_DATASTRUCT_STATUS_INVALID)
#define DSD_DATASTRUCT_STATUS_RMSK ( DSD_DATASTRUCT_STATUS_MSK
#define DSD_DATASTRUCT_STATUS_RMSK ( DSD_DATASTRUCT_STATUS_MSK ^ 0xffff)
#define DSD_DATASTRUCT_STATUS_VALUE_UNKNOWN_IS( V) ( ( V) == DSD_DATASTRUCT_STATUS_UNKNOWN)
#define DSD_DATASTRUCT_STATUS_VALUE_TEMPORARY( V) ( ( V) == DSD_DATASTRUCT_STATUS_TEMPORARY)
@ -156,12 +156,16 @@ typedef int DST_Flags;
typedef struct DST_Root
{
char Name[ DSD_NAME_SIZE];
char Heap_Name[ DSD_NAME_SIZE];
struct NDT_Root;
// char Name[ DSD_NAME_SIZE];
char Heap_Name[ DSD_NAME_SIZE];
int OpenSemId; /* Indique le nombre de processus ayant ouvert la struture */
short Heap_Owner; /* Indique si la structure est propriétaire du heap sous-jacent */
short Status; /* Indique si la structure est valide ou non */
NDT_Root ND_Root;
// short Status; /* Indique si la structure est valide ou non */
// NDT_Root ND_Root;
} DST_Root;
/*
@ -248,6 +252,36 @@ typedef struct DST_RootDescZ
/*------------------------------------------------------------------------------*/
/* DataStruct handlers */
/*------------------------------------------------------------------------------*/
NDT_Handler DSG_DataStruct_Handlers[ NDD_HANDLER_NB] =
{
{ "", /* Manager function name */
NULL}, /* Manager function pointer */
{ "DS_Handler_Init", /* Init function name */
NULL}, /* Init function pointer */
{ "SM_Base_Alloc", /* Alloc function name */
NULL}, /* Alloc function pointer */
{ "SM_Base_Free", /* Free function name */
NULL}, /* Free function pointer */
{ "DS_Handler_Open", /* Open function name */
NULL}, /* Open function pointer */
{ "", /* Close function name */
NULL}, /* Close function pointer */
{ "DS_Handler_Info", /* Info function name */
NULL}, /* Info function pointer */
{ "", /* Lock function name */
NULL}, /* Lock function pointer */
{ "", /* Unlock function name */
NULL} /* Unlock function pointer */
};
/* Définition des alias de l'API */
#ifndef DS_MODE

View File

@ -108,7 +108,9 @@ DST_Status DS_Library_Open_I ( int Instance, const char *Context, DST_Flags D
if( DS_Open_Counter == 0)
{
if( ( nd_status = ND_DataStruct_Open( &OpenedDS_List, 1, &index_type, "DS_OpenedDS_List_Manager", NULL, NULL, NULL, NULL, NULL, TRUE, NULL)) != NDS_OK)
// if( ( nd_status = ND_DataStruct_Open( &OpenedDS_List, 1, &index_type, "DS_OpenedDS_List_Manager", NULL, NULL, NULL, NULL, NULL, TRUE, NULL)) != NDS_OK)
if( ( nd_status = ND_DataStruct_Open( &OpenedDS_List, "DS-Opened_DataStruct", 1, &index_type, "DS_OpenedDS_List_Manager", NULL, NULL, TRUE, NULL)) != NDS_OK)
{
LG_LOG_ERROR_1( "Unable to create the opened data structure list: (%d)", nd_status);
SM_Library_Close (SMD_CLOSE);
@ -612,8 +614,8 @@ DST_Status DS_DataStruct_Open_I( DST_Root **Root_Ptr_Ptr, char *DS_Name, NDT
/*----------------------------------------------------------------------------*/
/* Fermeture d'une structure de données */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à fermer */
/* (I) Close_Mode : mode de fermeture de la structure (destruction ou non) */
/* (I) Root : pointeur sur la racine de la structure de données à fermer */
/* (I) Close_Mode : mode de fermeture de la structure (destruction ou non) */
/*----------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Close_I( DST_Root *Root_Ptr, DST_Flags Close_Mode)
@ -3807,7 +3809,6 @@ DST_Status DS_Semaphore_Create ( DST_Root *Root_Ptr)
/*----------------------------------------------------------------------------*/
/* Opération sur un sémaphore */
/*----------------------------------------------------------------------------*/
@ -3885,6 +3886,405 @@ DST_Status DS_Semaphore_Operate( int SemId, struct sembuf *Operations, unsign
/*----------------------------------------------------------------------------*/
/* Init handler: */
/* - Return extra root size */
/* - Update handler tab */
/*----------------------------------------------------------------------------*/
/* (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) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Init( NDT_Root **ND_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)
{
DST_Root **Root_Ptr_Ptr = (DSD_Root *)( ND_Root_Tmp_Ptr_Ptr)
DST_Status status;
SMT_Status sm_status;
size_t root_extra_size;
char prefixed_name[ DSD_NAME_SIZE];
short mode, locked;
short segment_size = 1024; /* to be fixed */
SMT_Heap *heap_ptr;
SMT_DSH *dsh_ptr;
DST_DataStruct *opened_datastruct_ptr;
DS_Name_Prefix( prefixed_name, Name);
/* Evaluate the use case depending on Open_Mode */
if( SM_Heap_Exist( prefixed_name) == SMS_YES)
{
if( DSD_MSK_OPEN( Open_Mode))
{
mode = 1;
}
else
{
if( DSD_MSK_NEW( Open_Mode))
{
mode = 2;
}
else
{
LG_LOG_ERROR_1( "The data structure: [%s] already exists and (Flags & DSD_OPEN & DSD_NEW) is false", Name);
return( DSS_ERRAPI);
}
}
}
else
{
if( DSD_MSK_CREATE( Open_Mode))
{
mode = 3;
}
else
{
LG_LOG_ERROR_1( "The data structure: [%s] does no exist and (Flags & DSD_CREATE) is false", DS_Name);
return( DSS_ERRAPI);
}
}
LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Creation Mode:(%d)", mode);
if( ( mode > 1))
{
root_extra_size = sizeof( DST_Root) - sizeof( NDT_Root);
if( ( status = ND_Root_Tmp_Alloc( ND_Root_Tmp_Ptr_Ptr, root_extra_size, Name, Open_Mode, Index_Nb, Type_Ptr, Handler_Tab, Own_Value, User_Ptr)) != NDS_OK)
{
return( status);
}
}
switch( mode)
{
/*--------------- Open existing DataStruct in existing heap -----------------*/
case 1:
{
/* If DataStruct is allready open, return */
if( ( status = DS_DataStruct_IsOpen( Root_Ptr_Ptr, Name)) != DSS_OK)
{
LG_LOG_ERROR_2( "Unable test data structure: [%s] state, status: (%d)", Name, status);
return( status);
}
else
{
return( DSS_OK);
}
/* Open heap in read mode */
if( ( sm_status = SM_Heap_Open( prefixed_name, &heap_ptr, 0, ( SMD_OPEN | SMD_READ), &locked)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to open the data structure heap: [%s] for reading, status: (%d)", prefixed_name, sm_status);
if( locked == TRUE)
{
if( ( sm_status = SM_Heap_Unlock( heap_ptr)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to unlock the data structure heap: [%s], status: (%d)", heap_ptr->Name, sm_status);
}
}
*Root_Ptr_Ptr = NULL;
return( SMS_KO);
}
dsh_ptr = heap_ptr->MHH->DSR->Index_Tab[ NDD_INDEX_PRIMARY].Head->Value;
/* La racine de la structure se trouve dans le premier chunk du premier segment du heap */
*Root_Tmp_Ptr_Ptr = ( DST_Root *)( ( size_t)( dsh_ptr->Start) + sizeof( NDT_Node) + sizeof( SMT_Chunk));
break;
}
/*--------------- New DataStruct in existing heap -----------------*/
case 2:
{
/* Open heap in write mode */
if( ( sm_status = SM_Heap_Open( prefixed_name, &heap_ptr, 0, ( SMD_OPEN | SMD_WRITE), &locked)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to open the data structure heap: [%s] for writing, status: (%d)", prefixed_name, sm_status);
return( SMS_KO);
}
break;
}
/*--------------- New DataStruct in new heap -----------------*/
case 3:
{
/* New heap creation */
if( ( sm_status = SM_Heap_Open( prefixed_name, &heap_ptr, segment_size, ( SMD_CREATE | SMD_WRITE), &locked)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to create a heap for the data structure [%s], status: (%d)", Name, sm_status);
return( DSS_KO);
}
break;
}
default:
{
LG_LOG_ERROR_1( "Internal error, mode: (%d)", mode);
return( DSS_KO);
break;
}
}
/* Update Tmp Root structure */
ND_STR_CPY( ( *Root_Ptr_Ptr)->Heap_Name, prefixed_name);
return( DSS_OK);
}
/*----------------------------------------------------------------------------*/
/* Alloc handler: */
/* malloc() function wrapper with NDT_Status return status */
/*----------------------------------------------------------------------------*/
/* (O) Memory_Ptr_Ptr: Memory pointer address */
/* (I) Root_Ptr: Data structure pointer */
/* (I) Size: Allocation size */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Alloc( void **Memory_Ptr_Ptr, NDT_Root *Root_Ptr, size_t Size, void *User_Ptr)
{
DST_Status status;
SMT_Status sm_status;
SMT_Heap *heap_ptr;
int locked;
size_t nd_root_offset;
if( ND_DATASTRUCT_STATUS_TEMPORARY_IS( Root_Ptr))
{
/* Root node allocation case */
Root_Ptr = User_Ptr;
nd_root_offset = offsetof( DST_Root, ND_Root);
Size += nd_root_offset;
}
else
{
/* Default allocation case */
Root_Ptr = DSD_DS_ROOT_GET( ND_Root_Ptr);
nd_root_offset = 0;
}
if( ( sm_status = SM_Heap_IsOpen( Root_Ptr->Heap_Name, &heap_ptr)) != SMS_YES)
{
LG_LOG_ERROR_1( "The data structure heap: [%s] is not open", Root_Ptr->Heap_Name);
return( DSS_KO);
}
/* Verrouillage du heap en écriture */
if( ( sm_status = SM_Heap_Lock( heap_ptr, SMD_WRITE, &locked)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to lock the data structure heap: [%s] for writing, status: (%d)", Root_Ptr->Heap_Name, sm_status);
return( DSS_OK);
}
/* Allocate the chunk */
if( ( sm_status = SM_Chunk_Alloc( heap_ptr, Size, Ptr_Ptr)) != SMS_OK)
{
LG_LOG_ERROR_3( "Unable to alloc size: (%d) in the heap: [%s] for writing, status: (%d)", Size, Root_Ptr->Heap_Name, sm_status);
status = DSS_KO;
}
else
{
status = DSS_OK;
LG_LOG_TRACE_3( LGD_LOG_LEVEL_DEFAULT, "New alloc: DS Root: (%p) ND Root: (%p) Offset: (%d)", *Ptr_Ptr, (*Ptr_Ptr + nd_root_offset), nd_root_offset);
*Ptr_Ptr += nd_root_offset;
}
/* Déverrouillage de la data structure si besoin */
if( locked == TRUE)
{
if( ( sm_status = SM_Heap_Unlock( heap_ptr)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to unlock the data structure heap: [%s], status: (%d)", heap_ptr->Name, sm_status);
status = DSS_KO;
}
}
return( status);
}
/*----------------------------------------------------------------------------*/
/* Free handler: */
/* free() function wrapper with NDT_Status return status */
/*----------------------------------------------------------------------------*/
/* (I) Memory_Ptr: Memory pointer */
/* (I) Root_Ptr: Data structure pointer */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Free( void *Memory_Ptr, NDT_Root *Root_Ptr, void *User_Ptr)
{
}
/*----------------------------------------------------------------------------*/
/* Open handler */
/*----------------------------------------------------------------------------*/
/* (I) Root_Ptr: Data structure pointer */
/* (I) Open_Mode: Open mode */
/* (I) Handler_Open_Name: Free handler function name */
/* (I) Handler_Open_Ptr: Free handler function pointer */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Open( NDT_Root *ND_Root_Ptr, NDT_Open_Flag Open_Mode, void *User_Ptr)
{
DST_Root **Root_Ptr = (DSD_Root *)( ND_Root_Ptr_Ptr)
DST_Status status;
SMT_Status sm_status;
/* Update Root structure */
// ND_Root_Ptr_->Status = NDD_DATASTRUCT_STATUS_VALID;
return( DSS_OK);
}
/*----------------------------------------------------------------------------*/
/* Close handler */
/*----------------------------------------------------------------------------*/
/* (I) Root_Ptr: Data structure pointer */
/* (I) Close_Mode: Close mode */
/* (I) Handler_Close_Name: Free handler function name */
/* (I) Handler_Close_Ptr: Free handler function pointer */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Close( NDT_Root *Root_Ptr, NDT_Close_Flag Close_Mode, void *User_Ptr)
{
}
/*----------------------------------------------------------------------------*/
/* Info handler */
/*----------------------------------------------------------------------------*/
/* (I) Root_Ptr: Data structure pointer */
/* (I) Recursive_Offset: Print line offset */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Info( NDT_Root *Root_Ptr, NDT_Recursive_Offset Recursive_Offset)
{
}
/*----------------------------------------------------------------------------*/
/* Lock handler */
/*----------------------------------------------------------------------------*/
/* (I) Root_Ptr: Data structure pointer */
/* (I) Open_Mode: Lock mode */
/* (O) Locked_Ptr: Locked flag */
/* (I) Handler_Lock_Name: Free handler function name */
/* (I) Handler_Lock_Ptr: Free handler function pointer */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Lock( NDT_Root *Root_Ptr, NDT_Lock_Flag Lock_Mode, bool *Locked_Ptr, void *User_Ptr)
{
}
/*----------------------------------------------------------------------------*/
/* Unlock handler */
/*----------------------------------------------------------------------------*/
/* (I) Root_Ptr: Data structure pointer */
/* (I) Handler_Unlock_Name: Free handler function name */
/* (I) Handler_Unlock_Ptr: Free handler function pointer */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Unlock( NDT_Root *Root_Ptr, void *User_Ptr)
{
}
/*----------------------------------------------------------------------------*/
/* Fonction manager de la liste des DS ouvertes */
/*----------------------------------------------------------------------------*/

View File

@ -161,6 +161,112 @@ DST_Status DS_DataStruct_IsOpen( DST_Root **Root_Ptr_Ptr, char *DS_Name);
/*----------------------------------------------------------------------------*/
/* Init handler: */
/* - Return extra root size */
/* - Update handler tab */
/*----------------------------------------------------------------------------*/
/* (O) Root_Extra_Size_Ptr: Pointer on the extra root size */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Init( size_t *Root_Extra_Size_Ptr, void *User_Ptr);
/*----------------------------------------------------------------------------*/
/* Alloc handler: */
/* malloc() function wrapper with NDT_Status return status */
/*----------------------------------------------------------------------------*/
/* (O) Memory_Ptr_Ptr: Memory pointer address */
/* (I) Root_Ptr: Data structure pointer */
/* (I) Size: Allocation size */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Alloc( void **Memory_Ptr_Ptr, NDT_Root *Root_Ptr, size_t Size, void *User_Ptr);
/*----------------------------------------------------------------------------*/
/* Free handler: */
/* free() function wrapper with NDT_Status return status */
/*----------------------------------------------------------------------------*/
/* (I) Memory_Ptr: Memory pointer */
/* (I) Root_Ptr: Data structure pointer */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Free( void *Memory_Ptr, NDT_Root *Root_Ptr, void *User_Ptr);
/*----------------------------------------------------------------------------*/
/* Open handler */
/*----------------------------------------------------------------------------*/
/* (I) Root_Ptr: Data structure pointer */
/* (I) Open_Mode: Open mode */
/* (I) Handler_Open_Name: Free handler function name */
/* (I) Handler_Open_Ptr: Free handler function pointer */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Open( NDT_Root *Root_Ptr, NDT_Open_Flag Open_Mode, void *User_Ptr);
/*----------------------------------------------------------------------------*/
/* Close handler */
/*----------------------------------------------------------------------------*/
/* (I) Root_Ptr: Data structure pointer */
/* (I) Close_Mode: Close mode */
/* (I) Handler_Close_Name: Free handler function name */
/* (I) Handler_Close_Ptr: Free handler function pointer */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Close( NDT_Root *Root_Ptr, NDT_Close_Flag Close_Mode, void *User_Ptr);
/*----------------------------------------------------------------------------*/
/* Info handler */
/*----------------------------------------------------------------------------*/
/* (I) Root_Ptr: Data structure pointer */
/* (I) Recursive_Offset: Print line offset */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Info( NDT_Root *Root_Ptr, NDT_Recursive_Offset Recursive_Offset);
/*----------------------------------------------------------------------------*/
/* Lock handler */
/*----------------------------------------------------------------------------*/
/* (I) Root_Ptr: Data structure pointer */
/* (I) Open_Mode: Lock mode */
/* (O) Locked_Ptr: Locked flag */
/* (I) Handler_Lock_Name: Free handler function name */
/* (I) Handler_Lock_Ptr: Free handler function pointer */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Lock( NDT_Root *Root_Ptr, NDT_Lock_Flag Lock_Mode, bool *Locked_Ptr, void *User_Ptr);
/*----------------------------------------------------------------------------*/
/* Unlock handler */
/*----------------------------------------------------------------------------*/
/* (I) Root_Ptr: Data structure pointer */
/* (I) Handler_Unlock_Name: Free handler function name */
/* (I) Handler_Unlock_Ptr: Free handler function pointer */
/* (I) User_Ptr: User pointer */
/*----------------------------------------------------------------------------*/
NDT_Status DS_Handler_Unlock( NDT_Root *Root_Ptr, void *User_Ptr);
/*----------------------------------------------------------------------------*/
/* Fonction manager de la liste des DS ouvertes */
/*----------------------------------------------------------------------------*/