- Add DS_STRUCT_LOCK() & DS_STRUCT_UNLOCK() macros,

- Implement DS_DataStruct_Traverse_I() & DS_DataStruct_Convert_L() API,
- code cleanup...
This commit is contained in:
Arnaud G. GIBERT 2024-05-11 22:43:25 +02:00
parent 32d95032b0
commit d110799f8e
2 changed files with 199 additions and 322 deletions

View File

@ -191,20 +191,58 @@ typedef struct DST_RootDescZ
/* */ /* */
/*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/
#define DS_STRUCT_VALID_CHECK( Root_Ptr) \ #define DS_STRUCT_VALID_CHECK( Root_Ptr) \
if( !DSD_DATASTRUCT_STATUS_VALUE_VALID( (Root_Ptr)->Status)) \ if( !DSD_DATASTRUCT_STATUS_VALUE_VALID( (Root_Ptr)->Status)) \
{ \ { \
DST_Status status; \ DST_Status status; \
int nb_detected = 0, nb_corrected = 0; \ int nb_detected = 0, nb_corrected = 0; \
\ \
\ \
if( ( status = DS_DataStruct_Check_I( Root_Ptr, &nb_detected, &nb_corrected, DS_stderr)) != DSS_OK) \ if( ( status = DS_DataStruct_Check_I( (Root_Ptr), &nb_detected, &nb_corrected, DS_stderr)) != DSS_OK) \
{ \ { \
LG_LOG_ERROR_0( "Unable to check the data structure"); \ LG_LOG_ERROR_0( "Unable to check the data structure"); \
\ \
return( status); \ return( status); \
} \ } \
} \ }
/*------------------------------------------------------------------------------*/
/* */
/*------------------------------------------------------------------------------*/
#define DS_STRUCT_LOCK( Root_Ptr, Lock_Mode, Lock_Flag_Ptr) \
{ \
DST_Status status; \
\
\
if( ( status = DS_DataStruct_Lock_I( (Root_Ptr), (Lock_Mode), (Lock_Flag_Ptr))) != DSS_OK) \
{ \
LG_LOG_ERROR_0( "Unable to lock the data structure"); \
\
return( status); \
} \
}
/*------------------------------------------------------------------------------*/
/* */
/*------------------------------------------------------------------------------*/
#define DS_STRUCT_UNLOCK( Root_Ptr, Lock_Flag) \
{ \
DST_Status status; \
\
\
if( (Lock_Flag) && ( ( status = DS_DataStruct_Unlock_I( (Root_Ptr))) != DSS_OK)) \
{ \
LG_LOG_ERROR_0( "Unable to unlock the data structure"); \
\
return( status); \
} \
}
@ -235,7 +273,6 @@ typedef struct DST_RootDescZ
# define DS_DataStruct_Open DS_DataStruct_Open_I # define DS_DataStruct_Open DS_DataStruct_Open_I
# define DS_DataStruct_Close DS_DataStruct_Close_I # define DS_DataStruct_Close DS_DataStruct_Close_I
# define DS_DataStruct_Flush DS_DataStruct_Flush_I # define DS_DataStruct_Flush DS_DataStruct_Flush_I
# define DS_DataStruct_Reorg DS_DataStruct_Reorg_I
# define DS_DataStruct_Check DS_DataStruct_Check_I # define DS_DataStruct_Check DS_DataStruct_Check_I
# define DS_DataStruct_Convert DS_DataStruct_Convert_I # define DS_DataStruct_Convert DS_DataStruct_Convert_I
# define DS_DataStruct_Reorg DS_DataStruct_Reorg_I # define DS_DataStruct_Reorg DS_DataStruct_Reorg_I
@ -618,17 +655,16 @@ DSD_API DST_Status SD_DataStruct_Value_Find_CL( void **Value_Ptr_Ptr, DST_Roo
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Parcours de tous les noeuds d'une structure de données et exécution d'une */ /* Traverse a data structure & execute a command on each node */
/* commande sur chacun d'eux */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données */ /* (I) Root_Ptr: Data structure pointer */
/* (I) Command : Commande à exécuter sur chaque noeud traversé */ /* (I) Command: Manager command */
/* (I) Data : pointeur de données utilisateur */ /* (I) ...: User args */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/*
DSD_API DST_Status DS_DataStruct_Traverse_I( NDT_Root * Root, NDT_Command Command, void * Data); DSD_API DST_Status DS_DataStruct_Traverse_I( DST_Root *Root_Ptr, NDT_Command Command, ...);
DSD_API DST_Status DS_DataStruct_Traverse_L( NDT_Root * Root, NDT_Command Command, void * Data); DSD_API DST_Status DS_DataStruct_Traverse_L( DST_Root *Root_Ptr, NDT_Command Command, ...);
DSD_API DST_Status DS_DataStruct_Traverse_CL( NDT_Root * Root, NDT_Command Command, void * Data); DSD_API DST_Status DS_DataStruct_Traverse_CL( DST_Root *Root_Ptr, NDT_Command Command, ...);

View File

@ -272,11 +272,7 @@ DST_Status DS_DataStruct_Open_I( DST_Root **Root_Ptr_Ptr, char *DS_Name, NDT
/* Création de la node structure */ /* Création de la node structure */
/*
strncpy( rootdesc_tmp.Heap_Name, prefixed_name, DSD_NAME_LEN);
rootdesc_tmp.Heap_Name[ DSD_NAME_LEN] = '\0';
*/
// if( ( nd_status = ND_DataStruct_Open( Root_Ptr_Ptr, Index_Nb, Index_Type_Tab, Manager_Name, NULL, "DS_DataStruct_Alloc", NULL, "DS_DataStruct_Free", NULL, Own_Value, &rootdesc_tmp)) != NDS_OK)
if( ( nd_status = ND_DataStruct_Open( &nd_root_ptr, Index_Nb, Index_Type_Tab, Manager_Name, NULL, "DS_Allocator", NULL, "DS_Deallocator", NULL, Own_Value, &root_tmp)) != NDS_OK) if( ( nd_status = ND_DataStruct_Open( &nd_root_ptr, Index_Nb, Index_Type_Tab, Manager_Name, NULL, "DS_Allocator", NULL, "DS_Deallocator", NULL, Own_Value, &root_tmp)) != NDS_OK)
{ {
LG_LOG_ERROR_2( "Unable to create a new node structure in the existing heap: [%s], status: (%d)", heap_ptr->Name, nd_status); LG_LOG_ERROR_2( "Unable to create a new node structure in the existing heap: [%s], status: (%d)", heap_ptr->Name, nd_status);
@ -295,34 +291,6 @@ DST_Status DS_DataStruct_Open_I( DST_Root **Root_Ptr_Ptr, char *DS_Name, NDT
} }
/* Allocation de mémoire pour la description de la nouvelle data structure */
/*
if( ( status = DS_DataStruct_Alloc( (void **)( &rootdesc_ptr), sizeof( DST_RootDesc), &rootdesc_tmp)) != DSS_OK)
{
LG_LOG_ERROR_2( "Unable to allocate memory for the data structure description for new heap: [%s], status: (%d)", heap_ptr->Name, status);
/*
Strange: why end the heap here ?
if( ( sm_status = SM_Heap_End( prefixed_name)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to remove the heap: [%s], 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( status);
}
*/
/* Initialise root */ /* Initialise root */
*Root_Ptr_Ptr = DSD_DS_ROOT_GET( nd_root_ptr); *Root_Ptr_Ptr = DSD_DS_ROOT_GET( nd_root_ptr);
@ -338,29 +306,6 @@ Strange: why end the heap here ?
( *Root_Ptr_Ptr)->ND_Root.User_Ptr = NULL; ( *Root_Ptr_Ptr)->ND_Root.User_Ptr = NULL;
// ( *Root_Ptr_Ptr)->Manager_Name = ( *Root_Ptr_Ptr)->Manager_Name;
/*
strncpy( rootdesc_ptr->Heap_Name, prefixed_name, DSD_NAME_LEN);
rootdesc_ptr->Heap_Name[ DSD_NAME_LEN] = '\0';
rootdesc_ptr->Manager_Name = ( *Root_Ptr_Ptr)->Manager_Name;
/* On indique que la structure n'est pas propriétaire de son heap */
/*
rootdesc_ptr->Heap_Owner = FALSE;
/* On indique que la structure est valide */
/*
rootdesc_ptr->Valid = TRUE;
/* On rattache la desription de la data structure à la racine */
/*
( *Root_Ptr_Ptr)->User_Ptr = rootdesc_ptr;
/* Déverrouillage du heap */ /* Déverrouillage du heap */
@ -423,41 +368,8 @@ Strange: why end the heap here ?
/* La racine de la structure se trouve dans le premier chunk du premier segment du heap */ /* La racine de la structure se trouve dans le premier chunk du premier segment du heap */
*Root_Ptr_Ptr = ( DST_Root *)( ( size_t)( dsh_ptr->Start) + sizeof( NDT_Node) + sizeof( SMT_Chunk)); *Root_Ptr_Ptr = ( DST_Root *)( ( size_t)( dsh_ptr->Start) + sizeof( NDT_Node) + sizeof( SMT_Chunk));
// *Root_Ptr_Ptr = (NDT_Root *)( ( size_t)( dsh_ptr->Start) + sizeof( NDT_Node) + sizeof( SMT_Chunk));
/* Chargement des fonctions manager de la structure */
/*
rootdesc_ptr = (*Root_Ptr_Ptr)->User_Ptr;
if( !rootdesc_ptr)
{
LG_LOG_ERROR_1( "Data structure [%s] has no description defined", DS_Name);
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( DSS_ERRAPI);
}
/*
if( !RootDesc->Manager_Name || !dlopen (( const char *)(RootDesc->Manager_FileName), RTLD_LAZY | RTLD_GLOBAL))
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to load the manager file %s of data structure \"%s\" (%s)", RootDesc->Manager_FileName == NULL ? "undefined" : (char *)(RootDesc->Manager_FileName), DS_Name, dlerror ());
DS_Error_Print ();
if (Locked == TRUE) SM_Heap_Unlock (Heap);
*Root = NULL;
return DSS_ERRDLL;
}
*/
break; break;
} }
@ -490,11 +402,7 @@ Strange: why end the heap here ?
/* Création de la structure de données dans le heap */ /* Création de la structure de données dans le heap */
/*
strncpy( rootdesc_tmp.Heap_Name, prefixed_name, DSD_NAME_LEN);
rootdesc_tmp.Heap_Name[ DSD_NAME_LEN] = '\0';
*/
// if( ( nd_status = ND_DataStruct_Open( Root_Ptr_Ptr, Index_Nb, Index_Type_Tab, Manager_Name, NULL, "DS_DataStruct_Alloc", NULL, "DS_DataStruct_Free", NULL, Own_Value, &rootdesc_tmp)) != NDS_OK)
if( ( nd_status = ND_DataStruct_Open( &nd_root_ptr, Index_Nb, Index_Type_Tab, Manager_Name, NULL, "DS_Allocator", NULL, "DS_Deallocator", NULL, Own_Value, &root_tmp)) != NDS_OK) if( ( nd_status = ND_DataStruct_Open( &nd_root_ptr, Index_Nb, Index_Type_Tab, Manager_Name, NULL, "DS_Allocator", NULL, "DS_Deallocator", NULL, Own_Value, &root_tmp)) != NDS_OK)
{ {
LG_LOG_ERROR_2( "Unable to create a new node structure in new heap: [%s], status: (%d)", heap_ptr->Name, nd_status); LG_LOG_ERROR_2( "Unable to create a new node structure in new heap: [%s], status: (%d)", heap_ptr->Name, nd_status);
@ -510,42 +418,6 @@ Strange: why end the heap here ?
} }
/* Allocation de mémoire pour la description de la structure */
/*
if( ( status = DS_DataStruct_Alloc( (void **)( &rootdesc_ptr), sizeof( DST_RootDesc), &rootdesc_tmp)) != DSS_OK)
{
LG_LOG_ERROR_2( "Unable to allocate memory for the data structure description for new heap: [%s], status: (%d)", heap_ptr->Name, status);
if( ( sm_status = SM_Heap_End( prefixed_name)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to remove the heap: [%s], status: (%d)", prefixed_name, sm_status);
}
*Root_Ptr_Ptr = NULL;
return( status);
}
strncpy( rootdesc_ptr->Heap_Name, prefixed_name, DSD_NAME_LEN);
rootdesc_ptr->Heap_Name[ DSD_NAME_LEN] = '\0';
rootdesc_ptr->Manager_Name = ( *Root_Ptr_Ptr)->Manager_Name;
/* On indique que la structure est propriétaire du heap */
/*
rootdesc_ptr->Heap_Owner = TRUE;
/* On indique que la structure est valide */
/*
rootdesc_ptr->Valid = TRUE;
/* On rattache la desription de la data structure à la racine */
/*
( *Root_Ptr_Ptr)->User_Ptr = rootdesc_ptr;
/* Initialise root */ /* Initialise root */
*Root_Ptr_Ptr = DSD_DS_ROOT_GET( nd_root_ptr); *Root_Ptr_Ptr = DSD_DS_ROOT_GET( nd_root_ptr);
@ -590,7 +462,6 @@ Strange: why end the heap here ?
/* On incrémente le sémaphore qui compte le nombre de processus qui ouvrent la structure */ /* On incrémente le sémaphore qui compte le nombre de processus qui ouvrent la structure */
// if( ( status = DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Open, 1)) != DSS_OK)
if( ( status = DS_Semaphore_Operate( ( *Root_Ptr_Ptr)->OpenSemId, DS_SemOp_Open, 1)) != DSS_OK) if( ( status = DS_Semaphore_Operate( ( *Root_Ptr_Ptr)->OpenSemId, DS_SemOp_Open, 1)) != DSS_OK)
{ {
LG_LOG_ERROR_2( "Unable to incremente the semaphore of data structure: [%s], status: (%d)", DS_Name, status); LG_LOG_ERROR_2( "Unable to incremente the semaphore of data structure: [%s], status: (%d)", DS_Name, status);
@ -605,7 +476,6 @@ Strange: why end the heap here ?
if( mode == 3) if( mode == 3)
{ {
// semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
semctl( ( *Root_Ptr_Ptr)->OpenSemId, 0, IPC_RMID, Sem_Ctl); semctl( ( *Root_Ptr_Ptr)->OpenSemId, 0, IPC_RMID, Sem_Ctl);
if( ( sm_status = SM_Heap_End( prefixed_name)) != SMS_OK) if( ( sm_status = SM_Heap_End( prefixed_name)) != SMS_OK)
@ -615,7 +485,6 @@ Strange: why end the heap here ?
} }
else else
{ {
// DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1);
DS_Semaphore_Operate( ( *Root_Ptr_Ptr)->OpenSemId, DS_SemOp_Close, 1); DS_Semaphore_Operate( ( *Root_Ptr_Ptr)->OpenSemId, DS_SemOp_Close, 1);
} }
@ -641,7 +510,6 @@ Strange: why end the heap here ?
if( mode == 3) if( mode == 3)
{ {
// semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
semctl( ( *Root_Ptr_Ptr)->OpenSemId, 0, IPC_RMID, Sem_Ctl); semctl( ( *Root_Ptr_Ptr)->OpenSemId, 0, IPC_RMID, Sem_Ctl);
if( ( sm_status = SM_Heap_End( prefixed_name)) != SMS_OK) if( ( sm_status = SM_Heap_End( prefixed_name)) != SMS_OK)
@ -651,7 +519,6 @@ Strange: why end the heap here ?
} }
else else
{ {
// DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1);
DS_Semaphore_Operate( ( *Root_Ptr_Ptr)->OpenSemId, DS_SemOp_Close, 1); DS_Semaphore_Operate( ( *Root_Ptr_Ptr)->OpenSemId, DS_SemOp_Close, 1);
} }
@ -679,7 +546,6 @@ Strange: why end the heap here ?
if( mode == 3) if( mode == 3)
{ {
// semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
semctl( ( *Root_Ptr_Ptr)->OpenSemId, 0, IPC_RMID, Sem_Ctl); semctl( ( *Root_Ptr_Ptr)->OpenSemId, 0, IPC_RMID, Sem_Ctl);
if( ( sm_status = SM_Heap_End( prefixed_name)) != SMS_OK) if( ( sm_status = SM_Heap_End( prefixed_name)) != SMS_OK)
@ -689,7 +555,6 @@ Strange: why end the heap here ?
} }
else else
{ {
// DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1);
DS_Semaphore_Operate( ( *Root_Ptr_Ptr)->OpenSemId, DS_SemOp_Close, 1); DS_Semaphore_Operate( ( *Root_Ptr_Ptr)->OpenSemId, DS_SemOp_Close, 1);
} }
@ -719,7 +584,6 @@ Strange: why end the heap here ?
if( mode == 3) if( mode == 3)
{ {
// semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
semctl( ( *Root_Ptr_Ptr)->OpenSemId, 0, IPC_RMID, Sem_Ctl); semctl( ( *Root_Ptr_Ptr)->OpenSemId, 0, IPC_RMID, Sem_Ctl);
if( ( sm_status = SM_Heap_End( prefixed_name)) != SMS_OK) if( ( sm_status = SM_Heap_End( prefixed_name)) != SMS_OK)
@ -729,7 +593,6 @@ Strange: why end the heap here ?
} }
else else
{ {
// DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1);
DS_Semaphore_Operate( ( *Root_Ptr_Ptr)->OpenSemId, DS_SemOp_Close, 1); DS_Semaphore_Operate( ( *Root_Ptr_Ptr)->OpenSemId, DS_SemOp_Close, 1);
} }
@ -746,83 +609,6 @@ Strange: why end the heap here ?
/*----------------------------------------------------------------------------*/
/* Verrouillage d'une structure de données */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/* (I) Lock_Mode : type de verrou à poser sur la structure */
/* (O) Locked : verrou effectif (TRUE ou FALSE) */
/*----------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Lock_I( DST_Root *Root_Ptr, DST_Flags Lock_Mode, int *Locked )
{
// char *Heap_Name = ( (DST_RootDesc *)( Root_Ptr->User_Ptr))->Heap_Name;
SMT_Status sm_status;
SMT_Heap *heap_ptr;
/* Réouverture du heap sous-jacent (rafraîchissement des segments) + verrouillage */
if( ( sm_status = SM_Heap_Open( Root_Ptr->Heap_Name, &heap_ptr, 0, ( SMD_OPEN | Lock_Mode), Locked)) != SMS_OK)
{
LG_LOG_ERROR_3( "Unable to reopen the data structure heap: [%s] for [%s], status: (%d)",
Root_Ptr->Heap_Name, (DSD_MSK_READ( Lock_Mode) ? "reading" : "writing"), sm_status);
return( DSS_KO);
}
return( DSS_OK);
}
/*----------------------------------------------------------------------------*/
/* Déverrouillage d'une structure de données */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/*----------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Unlock_I( DST_Root *Root_Ptr)
{
// char *Heap_Name = ( (DST_RootDesc *)( Root_Ptr->User_Ptr))->Heap_Name;
SMT_Status sm_status;
SMT_Heap *heap_ptr;
if( ( sm_status = SM_Heap_IsOpen( Root_Ptr->Heap_Name, &heap_ptr)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to check if heap: [%s] is open, status: (%d)", Root_Ptr->Heap_Name, sm_status);
return( DSS_KO);
}
else
{
if( heap_ptr == NULL)
{
LG_LOG_ERROR_1( "Data structure heap: [%s] is not open", Root_Ptr->Heap_Name);
return( DSS_KO);
}
}
if( ( sm_status = SM_Heap_Unlock( heap_ptr)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to unlock the data structure heap: [%s], status: (%d)", Root_Ptr->Heap_Name, sm_status);
return( DSS_KO);
}
return( DSS_OK);
}
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Fermeture d'une structure de données */ /* Fermeture d'une structure de données */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -1166,8 +952,6 @@ DST_Status DS_DataStruct_Check_I( DST_Root *Root_Ptr, int *Error_Detected_Nb
DST_Status DS_DataStruct_Convert_I( DST_Root *Root_Ptr, NDT_Index_Type *Index_Type_Ptr) DST_Status DS_DataStruct_Convert_I( DST_Root *Root_Ptr, NDT_Index_Type *Index_Type_Ptr)
{ {
// DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr);
DST_Status status; DST_Status status;
NDT_Status nd_status; NDT_Status nd_status;
@ -1251,6 +1035,71 @@ DST_Status DS_DataStruct_Reorg_I( DST_Root *Root_Ptr)
/*----------------------------------------------------------------------------*/
/* Traverse a data structure & execute a command on each node */
/*----------------------------------------------------------------------------*/
/* (I) Root_Ptr: Data structure pointer */
/* (I) Command: Manager command */
/* (I) ...: User args */
/*----------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Traverse_I( DST_Root *Root_Ptr, NDT_Command Command, ...)
{
DST_Status status;
NDT_Status nd_status;
va_list user_args;
/* On vérifie que la data structure est valide */
DS_STRUCT_VALID_CHECK( Root_Ptr);
/* Récupération des arguments pour l'allocation de la valeur */
va_start( user_args, Command);
/* On rend éventuellement la structure invalide le temps de sa traversée */
switch( Command)
{
case NDD_CMD_VALUE_PRINT:
break;
default:
Root_Ptr->Status = DSD_DATASTRUCT_STATUS_INVALID;
break;
}
/* Traversée de la node structure */
if( ( nd_status = ND_DataStruct_Traverse_VI( &( Root_Ptr->ND_Root), Command, &user_args)) != NDS_OK)
{
LG_LOG_ERROR_1( "Unable to traverse the node structure, status: (%d)", nd_status);
status = DSS_KO;
}
else
{
status = DSS_OK;
}
/* On rend la structure valide */
Root_Ptr->Status = DSD_DATASTRUCT_STATUS_VALID;
va_end( user_args);
return( status);
}
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Print data structure information */ /* Print data structure information */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -1263,8 +1112,6 @@ DST_Status DS_DataStruct_Reorg_I( DST_Root *Root_Ptr)
DST_Status DS_DataStruct_Info_Print_I( FILE *Out, DST_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset) DST_Status DS_DataStruct_Info_Print_I( FILE *Out, DST_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset)
{ {
// DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr);
DST_Status status; DST_Status status;
NDT_Status nd_status; NDT_Status nd_status;
@ -1275,7 +1122,7 @@ DST_Status DS_DataStruct_Info_Print_I( FILE *Out, DST_Root *Root_Ptr, NDT_Recu
/* On vérifie que la data structure est valide */ /* On vérifie que la data structure est valide */
// DS_STRUCT_VALID_CHECK( Root_Ptr->ND_Root, RootDesc_Ptr); DS_STRUCT_VALID_CHECK( Root_Ptr);
/* Affichage des informations sur la structure */ /* Affichage des informations sur la structure */
@ -1316,79 +1163,76 @@ DST_Status DS_DataStruct_Info_Print_I( FILE *Out, DST_Root *Root_Ptr, NDT_Recu
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Parcours de tous les noeuds d'une structure de données et exécution d'une */ /* Verrouillage d'une structure de données */
/* commande sur chacun d'eux */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à parcourir*/ /* (I) Root : pointeur sur la racine de la structure */
/* (I) Command : commande à exécuter sur chaque noeud traversé */ /* (I) Lock_Mode : type de verrou à poser sur la structure */
/* (I) Data : pointeur de données utilisateur */ /* (O) Locked : verrou effectif (TRUE ou FALSE) */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/*
DST_Status DS_DataStruct_Traverse_I ( NDT_Root * Root, NDT_Command Command, void * Data ) DST_Status DS_DataStruct_Lock_I( DST_Root *Root_Ptr, DST_Flags Lock_Mode, int *Locked )
{ {
DST_Status rc; // char *Heap_Name = ( (DST_RootDesc *)( Root_Ptr->User_Ptr))->Heap_Name;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
/* On vérifie que la data structure est valide */ SMT_Status sm_status;
/* SMT_Heap *heap_ptr;
if (RootDesc->Valid == FALSE)
/* Réouverture du heap sous-jacent (rafraîchissement des segments) + verrouillage */
if( ( sm_status = SM_Heap_Open( Root_Ptr->Heap_Name, &heap_ptr, 0, ( SMD_OPEN | Lock_Mode), Locked)) != SMS_OK)
{ {
int nb_detected, nb_corrected; LG_LOG_ERROR_3( "Unable to reopen the data structure heap: [%s] for [%s], status: (%d)",
Root_Ptr->Heap_Name, (DSD_MSK_READ( Lock_Mode) ? "reading" : "writing"), sm_status);
/* On vérifie la structure */ return( DSS_KO);
/* }
nb_detected = nb_corrected = 0;
if( ( status = DS_DataStruct_Check_L( Root_Ptr, &nb_detected, &nb_corrected, DS_stderr)) != DSS_OK) return( DSS_OK);
}
/*----------------------------------------------------------------------------*/
/* Déverrouillage d'une structure de données */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure */
/*----------------------------------------------------------------------------*/
DST_Status DS_DataStruct_Unlock_I( DST_Root *Root_Ptr)
{
// char *Heap_Name = ( (DST_RootDesc *)( Root_Ptr->User_Ptr))->Heap_Name;
SMT_Status sm_status;
SMT_Heap *heap_ptr;
if( ( sm_status = SM_Heap_IsOpen( Root_Ptr->Heap_Name, &heap_ptr)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to check if heap: [%s] is open, status: (%d)", Root_Ptr->Heap_Name, sm_status);
return( DSS_KO);
}
else
{
if( heap_ptr == NULL)
{ {
LG_LOG_ERROR_0( "Unable to check the data structure"); LG_LOG_ERROR_1( "Data structure heap: [%s] is not open", Root_Ptr->Heap_Name);
return( status); return( DSS_KO);
} }
} }
/* On rend éventuellement la structure invalide le temps de sa traversée */ if( ( sm_status = SM_Heap_Unlock( heap_ptr)) != SMS_OK)
/*
switch ((int)Command)
{ {
case NDD_CMD_PRINT_VALUE: LG_LOG_ERROR_2( "Unable to unlock the data structure heap: [%s], status: (%d)", Root_Ptr->Heap_Name, sm_status);
break;
default: return( DSS_KO);
RootDesc->Valid = FALSE;
break;
} }
/* Traversée de la node structure */ return( DSS_OK);
/*
rc = ND_DataStruct_Traverse (Root, Command, Data);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Traverse : unable to traverse the node structure ");
DS_Error_Print ();
if (!DS_ERROR(rc)) RootDesc->Valid = TRUE;
return rc;
}
/* On rend la structure valide */
/*
RootDesc->Valid = TRUE;
return DSS_OK;
}
/*----------------------------------------------------------------------------*/
/* Affichage d'une structure de données */
/*----------------------------------------------------------------------------*/
/* (I) Root : pointeur sur la racine de la structure de données à afficher */
/* (I) Out : flux de sortie */
/*----------------------------------------------------------------------------*/
/*
DST_Status DS_DataStruct_Print_I ( NDT_Root * Root, FILE * Out )
{
return DS_DataStruct_Traverse_I (Root, NDD_CMD_PRINT_VALUE, Out);
} }
@ -2092,7 +1936,7 @@ DST_Status DS_Value_Alloc_I( void **Value_Ptr_Ptr, DST_Root *Root_Ptr, ... )
if( ( nd_status = ND_Manager_Exec( &( Root_Ptr->ND_Root), NDD_INDEX_UNKNOWN, NULL, NDD_CMD_VALUE_ALLOC, Value_Ptr_Ptr, &user_args)) != NDS_OK) if( ( nd_status = ND_Manager_Exec( &( Root_Ptr->ND_Root), NDD_INDEX_UNKNOWN, NULL, NDD_CMD_VALUE_ALLOC, Value_Ptr_Ptr, &user_args)) != NDS_OK)
{ {
LG_LOG_ERROR_1( "Unnable to alloc a new value: (%d)", nd_status); LG_LOG_ERROR_1( "Unable to alloc a new value, status: (%d)", nd_status);
status = DSS_KO; status = DSS_KO;
} }
@ -2304,30 +2148,27 @@ DST_Status DS_DataStruct_Check_L( DST_Root *Root_Ptr, int *Error_Detected_Nb
/* (I) Root_Ptr: Data structure pointer */ /* (I) Root_Ptr: Data structure pointer */
/* (I) Index_Type_Ptr: Array of index type (List, tree, ...) */ /* (I) Index_Type_Ptr: Array of index type (List, tree, ...) */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/*
DST_Status DS_DataStruct_Convert_L ( NDT_Root * Root, NDT_DataStruct_Type Target_Type ) DST_Status DS_DataStruct_Convert_L( DST_Root *Root_Ptr, NDT_Index_Type *Index_Type_Ptr)
{ {
DST_Status rc; DST_Status status;
int Locked; int lock_flag;
/* Verrouillage de la data structure en écriture */
/*
rc = DS_DataStruct_Lock_I (Root, SMD_WRITE, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Convert : unable to lock the data structure for writing");
DS_Error_Print ();
return rc; /* Lock the data structure in write mode */
}
rc = DS_DataStruct_Convert_I (Root, Target_Type); DS_STRUCT_LOCK( Root_Ptr, SMD_WRITE, &lock_flag);
/* Déverrouillage de la data structure si besoin */
/*
if (Locked == TRUE) DS_DataStruct_Unlock_I (Root);
return rc; status = DS_DataStruct_Convert_I( Root_Ptr, Index_Type_Ptr);
/* Unlock if needed Lock the data structure */
DS_STRUCT_UNLOCK( Root_Ptr, lock_flag);
return( status);
} }