diff --git a/include/datastr.h b/include/datastr.h index 451e92d..59ee7c2 100644 --- a/include/datastr.h +++ b/include/datastr.h @@ -33,6 +33,7 @@ //extern "C" { #endif +#include #include @@ -137,19 +138,50 @@ typedef int DST_Flags; #define DSD_NAME_LEN ( short)SMD_NAME_LEN #define DSD_NAME_SIZE ( DSD_NAME_LEN + 1) +#define DSD_DATASTRUCT_STATUS_UNKNOWN 0x0000 +#define DSD_DATASTRUCT_STATUS_TEMPORARY 0x0001 +#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_VALUE_UNKNOWN_IS( V) ( ( V) == DSD_DATASTRUCT_STATUS_UNKNOWN) +#define DSD_DATASTRUCT_STATUS_VALUE_TEMPORARY( V) ( ( V) == DSD_DATASTRUCT_STATUS_TEMPORARY) +#define DSD_DATASTRUCT_STATUS_VALUE_VALID( V) ( ( V) == DSD_DATASTRUCT_STATUS_VALID) +#define DSD_DATASTRUCT_STATUS_VALUE_INVALID( V) ( ( V) == DSD_DATASTRUCT_STATUS_INVALID) + +#define DSD_DATASTRUCT_STATUS_VALUE_ASCII_GET( V) ( DSD_DATASTRUCT_STATUS_VALUE_UNKNOWN_IS( V) ? "UNKNOWN" : ( DSD_DATASTRUCT_STATUS_VALUE_TEMPORARY( V) ? "TEMPORARY" : ( DSD_DATASTRUCT_STATUS_VALUE_VALID( V) ? "VALID" : ( DSD_DATASTRUCT_STATUS_VALUE_INVALID( V) ? "INVALID" : "???")))) + + + +typedef struct DST_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; +} DST_Root; + /* On utilise le pointeur 'User' de la racine de la struture pour y rattacher des données sur le heap sous-jacent. */ -typedef struct DST_RootDesc +#define DSD_DS_ROOT_GET( ND_Root_Ptr) (( DST_Root *)( ( char *)( ND_Root_Ptr) - offsetof( DST_Root, ND_Root))) +#define DSD_ND_ROOT_GET( DS_Root_Ptr) (( NDT_Root *)( ( char *)( DS_Root_Ptr) + offsetof( DST_Root, ND_Root))) + + + +typedef struct DST_RootDescZ { char Heap_Name[ DSD_NAME_SIZE]; char *Manager_Name; 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 Valid; /* Indique si la structure est valide ou non */ -} DST_RootDesc; +} DST_RootDescZ; //char DS_Error_Msg [512]; @@ -159,20 +191,20 @@ typedef struct DST_RootDesc /* */ /*------------------------------------------------------------------------------*/ -#define DS_STRUCT_VALID_CHECK( Root_Ptr, RootDesc_Ptr) \ - if( (RootDesc_Ptr)->Valid == FALSE) \ - { \ - DST_Status status; \ - int nb_detected = 0, nb_corrected = 0; \ - \ - \ - 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"); \ - \ - return( status); \ - } \ - } \ +#define DS_STRUCT_VALID_CHECK( Root_Ptr) \ + if( !DSD_DATASTRUCT_STATUS_VALUE_VALID( (Root_Ptr)->Status)) \ + { \ + DST_Status status; \ + int nb_detected = 0, nb_corrected = 0; \ + \ + \ + 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"); \ + \ + return( status); \ + } \ + } \ @@ -395,7 +427,7 @@ DSD_API DST_Status DS_Library_Stderr_Set_CL( FILE *Out); /*----------------------------------------------------------------------------*/ -DSD_API DST_Status DS_DataStruct_Open_I( NDT_Root **Root, char *DS_Name, NDT_Index_Nb, NDT_Index_Type *, char *Manager_FileName, size_t Segment_Size, DST_Flags Open_Mode, short Own_Value); +DSD_API DST_Status DS_DataStruct_Open_I( DST_Root **Root, char *DS_Name, NDT_Index_Nb, NDT_Index_Type *, char *Manager_FileName, size_t Segment_Size, DST_Flags Open_Mode, short Own_Value); /* DSD_API DST_Status DS_DataStruct_Open_I( const char *DS_Name, NDT_Root **Root, NDT_DataStruct_Type Type, const char * Manager_FileName, size_t Segment_Size, DST_Flags Open_Mode, int Own_Value); @@ -412,9 +444,9 @@ DSD_API DST_Status DS_DataStruct_Open_CL( const char *DS_Name, NDT_Root **Roo /* (O) Locked : verrou effectif (TRUE ou FALSE) */ /*----------------------------------------------------------------------------*/ -DSD_API DST_Status DS_DataStruct_Lock_I( NDT_Root *Root_Ptr, DST_Flags Lock_Mode, int *Locked); -DSD_API DST_Status DS_DataStruct_Lock_L( NDT_Root *Root_Ptr, DST_Flags Lock_Mode, int *Locked); -DSD_API DST_Status DS_DataStruct_Lock_CL( NDT_Root *Root_Ptr, DST_Flags Lock_Mode, int *Locked); +DSD_API DST_Status DS_DataStruct_Lock_I( DST_Root *Root_Ptr, DST_Flags Lock_Mode, int *Locked); +DSD_API DST_Status DS_DataStruct_Lock_L( DST_Root *Root_Ptr, DST_Flags Lock_Mode, int *Locked); +DSD_API DST_Status DS_DataStruct_Lock_CL( DST_Root *Root_Ptr, DST_Flags Lock_Mode, int *Locked); @@ -424,9 +456,9 @@ DSD_API DST_Status DS_DataStruct_Lock_CL( NDT_Root *Root_Ptr, DST_Flags Lock_ /* (I) Root : pointeur sur la racine de la structure */ /*----------------------------------------------------------------------------*/ -DSD_API DST_Status DS_DataStruct_Unlock_I( NDT_Root *Root_Ptr); -DSD_API DST_Status DS_DataStruct_Unlock_L( NDT_Root *Root_Ptr); -DSD_API DST_Status DS_DataStruct_Unlock_CL( NDT_Root *Root_Ptr); +DSD_API DST_Status DS_DataStruct_Unlock_I( DST_Root *Root_Ptr); +DSD_API DST_Status DS_DataStruct_Unlock_L( DST_Root *Root_Ptr); +DSD_API DST_Status DS_DataStruct_Unlock_CL( DST_Root *Root_Ptr); @@ -437,9 +469,9 @@ DSD_API DST_Status DS_DataStruct_Unlock_CL( NDT_Root *Root_Ptr); /* (I) Close_Mode : mode de fermeture de la structure (destruction ou non) */ /*----------------------------------------------------------------------------*/ -DSD_API DST_Status DS_DataStruct_Close_I( NDT_Root *Root_Ptr, DST_Flags Close_Mode); -DSD_API DST_Status DS_DataStruct_Close_L( NDT_Root *Root_Ptr, DST_Flags Close_Mode); -DSD_API DST_Status DS_DataStruct_Close_CL( NDT_Root *Root_Ptr, DST_Flags Close_Mode); +DSD_API DST_Status DS_DataStruct_Close_I( DST_Root *Root_Ptr, DST_Flags Close_Mode); +DSD_API DST_Status DS_DataStruct_Close_L( DST_Root *Root_Ptr, DST_Flags Close_Mode); +DSD_API DST_Status DS_DataStruct_Close_CL( DST_Root *Root_Ptr, DST_Flags Close_Mode); @@ -449,9 +481,9 @@ DSD_API DST_Status DS_DataStruct_Close_CL( NDT_Root *Root_Ptr, DST_Flags Clo /* (I) Root_Ptr: Data structure pointer */ /*----------------------------------------------------------------------------*/ -DSD_API NDT_Status DS_DataStruct_Flush_I( NDT_Root *Root_Ptr); -DSD_API NDT_Status DS_DataStruct_Flush_L( NDT_Root *Root_Ptr); -DSD_API NDT_Status DS_DataStruct_Flush_CL( NDT_Root *Root_Ptr); +DSD_API NDT_Status DS_DataStruct_Flush_I( DST_Root *Root_Ptr); +DSD_API NDT_Status DS_DataStruct_Flush_L( DST_Root *Root_Ptr); +DSD_API NDT_Status DS_DataStruct_Flush_CL( DST_Root *Root_Ptr); @@ -466,9 +498,9 @@ DSD_API NDT_Status DS_DataStruct_Flush_CL( NDT_Root *Root_Ptr); /* (I) Out: Output stream */ /*----------------------------------------------------------------------------*/ -DSD_API DST_Status DS_DataStruct_Check_I( NDT_Root *Root_Ptr, int *Error_Detected_Nb_Ptr, int *Error_Corrected_Nb_Ptr, FILE *Out); -DSD_API DST_Status DS_DataStruct_Check_L( NDT_Root *Root_Ptr, int *Error_Detected_Nb_Ptr, int *Error_Corrected_Nb_Ptr, FILE *Out); -DSD_API DST_Status DS_DataStruct_Check_CL( NDT_Root *Root_Ptr, int *Error_Detected_Nb_Ptr, int *Error_Corrected_Nb_Ptr, FILE *Out); +DSD_API DST_Status DS_DataStruct_Check_I( DST_Root *Root_Ptr, int *Error_Detected_Nb_Ptr, int *Error_Corrected_Nb_Ptr, FILE *Out); +DSD_API DST_Status DS_DataStruct_Check_L( DST_Root *Root_Ptr, int *Error_Detected_Nb_Ptr, int *Error_Corrected_Nb_Ptr, FILE *Out); +DSD_API DST_Status DS_DataStruct_Check_CL( DST_Root *Root_Ptr, int *Error_Detected_Nb_Ptr, int *Error_Corrected_Nb_Ptr, FILE *Out); @@ -479,9 +511,9 @@ DSD_API DST_Status DS_DataStruct_Check_CL( NDT_Root *Root_Ptr, int *Error_Det /* (I) Index_Type_Ptr: Array of index type (List, tree, ...) */ /*----------------------------------------------------------------------------*/ -DSD_API DST_Status DS_DataStruct_Convert_I( NDT_Root *Root_Ptr, NDT_Index_Type *Index_Type_Ptr); -DSD_API DST_Status DS_DataStruct_Convert_L( NDT_Root *Root_Ptr, NDT_Index_Type *Index_Type_Ptr); -DSD_API DST_Status DS_DataStruct_Convert_CL( NDT_Root *Root_Ptr, NDT_Index_Type *Index_Type_Ptr); +DSD_API DST_Status DS_DataStruct_Convert_I( DST_Root *Root_Ptr, NDT_Index_Type *Index_Type_Ptr); +DSD_API DST_Status DS_DataStruct_Convert_L( DST_Root *Root_Ptr, NDT_Index_Type *Index_Type_Ptr); +DSD_API DST_Status DS_DataStruct_Convert_CL( DST_Root *Root_Ptr, NDT_Index_Type *Index_Type_Ptr); @@ -493,9 +525,9 @@ DSD_API DST_Status DS_DataStruct_Convert_CL( NDT_Root *Root_Ptr, NDT_Index_Typ /* (I) Root_Ptr: Data structure pointer */ /*----------------------------------------------------------------------------*/ -DSD_API DST_Status DS_DataStruct_Reorg_I( NDT_Root *Root_Ptr); -DSD_API DST_Status DS_DataStruct_Reorg_L( NDT_Root *Root_Ptr); -DSD_API DST_Status DS_DataStruct_Reorg_CL( NDT_Root *Root_Ptr); +DSD_API DST_Status DS_DataStruct_Reorg_I( DST_Root *Root_Ptr); +DSD_API DST_Status DS_DataStruct_Reorg_L( DST_Root *Root_Ptr); +DSD_API DST_Status DS_DataStruct_Reorg_CL( DST_Root *Root_Ptr); @@ -509,9 +541,9 @@ DSD_API DST_Status DS_DataStruct_Reorg_CL( NDT_Root *Root_Ptr); /* (I) Recursive_Offset: Curent print out offset */ /*----------------------------------------------------------------------------*/ -DSD_API DST_Status DS_DataStruct_Info_Print_I( FILE *Out, NDT_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset); -DSD_API DST_Status DS_DataStruct_Info_Print_L( FILE *Out, NDT_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset); -DSD_API DST_Status DS_DataStruct_Info_Print_CL( FILE *Out, NDT_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset); +DSD_API 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); +DSD_API DST_Status DS_DataStruct_Info_Print_L( FILE *Out, DST_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset); +DSD_API DST_Status DS_DataStruct_Info_Print_CL( FILE *Out, DST_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset); @@ -522,9 +554,9 @@ DSD_API DST_Status DS_DataStruct_Info_Print_CL( FILE *Out, NDT_Root *Root_Ptr, /* (I) Value_Ptr: Value pointer */ /*----------------------------------------------------------------------------*/ -DSD_API DST_Status DS_DataStruct_Value_Add_I( NDT_Root *Root_Ptr, void *Value_Ptr); -DSD_API DST_Status DS_DataStruct_Value_Add_L( NDT_Root *Root_Ptr, void *Value_Ptr); -DSD_API DST_Status DS_DataStruct_Value_Add_CL( NDT_Root *Root_Ptr, void *Value_Ptr); +DSD_API DST_Status DS_DataStruct_Value_Add_I( DST_Root *Root_Ptr, void *Value_Ptr); +DSD_API DST_Status DS_DataStruct_Value_Add_L( DST_Root *Root_Ptr, void *Value_Ptr); +DSD_API DST_Status DS_DataStruct_Value_Add_CL( DST_Root *Root_Ptr, void *Value_Ptr); @@ -567,9 +599,9 @@ DSD_API DST_Status DS_DataStruct_Print_CL( NDT_Root * Root, FILE * Out); /* (I) ...: User args */ /*----------------------------------------------------------------------------*/ -DSD_API DST_Status DS_DataStruct_Value_Print_I( FILE *Out_Ptr, NDT_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset, ...); -DSD_API DST_Status DS_DataStruct_Value_Print_L( FILE *Out_Ptr, NDT_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset, ...); -DSD_API DST_Status DS_DataStruct_Value_Print_CL( FILE *Out_Ptr, NDT_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset, ...); +DSD_API DST_Status DS_DataStruct_Value_Print_I( FILE *Out_Ptr, DST_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset, ...); +DSD_API DST_Status DS_DataStruct_Value_Print_L( FILE *Out_Ptr, DST_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset, ...); +DSD_API DST_Status DS_DataStruct_Value_Print_CL( FILE *Out_Ptr, DST_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset, ...); @@ -581,9 +613,9 @@ DSD_API DST_Status DS_DataStruct_Value_Print_CL( FILE *Out_Ptr, NDT_Root *Roo /* (I) Index_Type: Index type (List, tree, ...) */ /*----------------------------------------------------------------------------*/ -DSD_API NDT_Status DS_Index_Open_I( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); -DSD_API NDT_Status DS_Index_Open_L( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); -DSD_API NDT_Status DS_Index_Open_CL( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); +DSD_API NDT_Status DS_Index_Open_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); +DSD_API NDT_Status DS_Index_Open_L( DST_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); +DSD_API NDT_Status DS_Index_Open_CL( DST_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); @@ -594,9 +626,9 @@ DSD_API NDT_Status DS_Index_Open_CL( NDT_Root *Root_Ptr, NDT_Index_Id Index_I /* (I) Index_Id: Id of the index */ /*----------------------------------------------------------------------------*/ -DSD_API NDT_Status DS_Index_Close_I( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id); -DSD_API NDT_Status DS_Index_Close_L( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id); -DSD_API NDT_Status DS_Index_Close_CL( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id); +DSD_API NDT_Status DS_Index_Close_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id); +DSD_API NDT_Status DS_Index_Close_L( DST_Root *Root_Ptr, NDT_Index_Id Index_Id); +DSD_API NDT_Status DS_Index_Close_CL( DST_Root *Root_Ptr, NDT_Index_Id Index_Id); @@ -608,9 +640,9 @@ DSD_API NDT_Status DS_Index_Close_CL( NDT_Root *Root_Ptr, NDT_Index_Id Index_ /* (I) Index_Type: Index type (List, tree, ...) */ /*----------------------------------------------------------------------------*/ -DSD_API NDT_Status DS_Index_Convert_I( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); -DSD_API NDT_Status DS_Index_Convert_L( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); -DSD_API NDT_Status DS_Index_Convert_CL( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); +DSD_API NDT_Status DS_Index_Convert_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); +DSD_API NDT_Status DS_Index_Convert_L( DST_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); +DSD_API NDT_Status DS_Index_Convert_CL( DST_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type); @@ -714,9 +746,9 @@ DSD_API DST_Status DS_Node_Find_CL( NDT_Root * Root, NDT_Node ** Node, void * V /* (I) ... : arguments relatifs à l'allocation de la valeur */ /*----------------------------------------------------------------------------*/ -DSD_API DST_Status DS_Value_Alloc_I( void **Value_Ptr_Ptr, NDT_Root *Root_Ptr, ...); -DSD_API DST_Status DS_Value_Alloc_L( void **Value_Ptr_Ptr, NDT_Root *Root_Ptr, ...); -DSD_API DST_Status DS_Value_Alloc_CL( void **Value_Ptr_Ptr, NDT_Root *Root_Ptr, ...); +DSD_API DST_Status DS_Value_Alloc_I( void **Value_Ptr_Ptr, DST_Root *Root_Ptr, ...); +DSD_API DST_Status DS_Value_Alloc_L( void **Value_Ptr_Ptr, DST_Root *Root_Ptr, ...); +DSD_API DST_Status DS_Value_Alloc_CL( void **Value_Ptr_Ptr, DST_Root *Root_Ptr, ...); diff --git a/lib/libdatastr.c b/lib/libdatastr.c index b7aecde..0dab545 100644 --- a/lib/libdatastr.c +++ b/lib/libdatastr.c @@ -201,7 +201,9 @@ DST_Status DS_Library_Stderr_Set_I( FILE *Out) //DST_Status DS_DataStruct_Open_I( NDT_Root **Root, const char *DS_Name, NDT_DataStruct_Type Type, const char *Manager_FileName, size_t Segment_Size, DST_Flags Open_Mode, int Own_Values); -DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT_Index_Nb Index_Nb, NDT_Index_Type *Index_Type_Tab, char *Manager_Name, size_t Segment_Size, DST_Flags Open_Mode, short Own_Value) +//DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT_Index_Nb Index_Nb, NDT_Index_Type *Index_Type_Tab, char *Manager_Name, size_t Segment_Size, DST_Flags Open_Mode, short Own_Value) + +DST_Status DS_DataStruct_Open_I( DST_Root **Root_Ptr_Ptr, char *DS_Name, NDT_Index_Nb Index_Nb, NDT_Index_Type *Index_Type_Tab, char *Manager_Name, size_t Segment_Size, DST_Flags Open_Mode, short Own_Value) { DST_Status status; SMT_Status sm_status; @@ -211,7 +213,11 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT SMT_DSH *dsh_ptr; int locked, mode; - DST_RootDesc *rootdesc_ptr, rootdesc_tmp; + + DST_Root root_tmp; + NDT_Root *nd_root_ptr; +// DST_RootDesc *rootdesc_ptr, rootdesc_tmp; + DST_DataStruct *opened_datastruct_ptr; char prefixed_name[ DSD_NAME_SIZE]; union semun Sem_Ctl; @@ -221,6 +227,7 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT *Root_Ptr_Ptr = NULL; + /* On définit ce qu'on va faire en fonction du mode d'ouverture demandé et de ce qui existe déjà ou non */ if( SM_Heap_Exist( prefixed_name) == SMS_YES) @@ -260,12 +267,22 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT return( SMS_KO); } - /* Création de la node structure */ + /* Create the Root structure */ + + strncpy( root_tmp.Heap_Name, prefixed_name, DSD_NAME_LEN); + root_tmp.Heap_Name[ DSD_NAME_LEN] = '\0'; + + root_tmp.Status = DSD_DATASTRUCT_STATUS_TEMPORARY; + + + /* 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( 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_DataStruct_Alloc", NULL, "DS_DataStruct_Free", 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); @@ -284,7 +301,7 @@ DST_Status DS_DataStruct_Open_I( NDT_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); @@ -295,7 +312,8 @@ Strange: why end the heap here ? { 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) @@ -308,24 +326,44 @@ Strange: why end the heap here ? return( status); } +*/ + /* Initialise root */ + + *Root_Ptr_Ptr = DSD_DS_ROOT_GET( nd_root_ptr); + + strncpy( ( *Root_Ptr_Ptr)->Name, DS_Name, DSD_NAME_LEN); + ( *Root_Ptr_Ptr)->Name[ DSD_NAME_LEN] = '\0'; + + strncpy( ( *Root_Ptr_Ptr)->Heap_Name, prefixed_name, DSD_NAME_LEN); + ( *Root_Ptr_Ptr)->Heap_Name[ DSD_NAME_LEN] = '\0'; + + ( *Root_Ptr_Ptr)->Heap_Owner = FALSE; + ( *Root_Ptr_Ptr)->Status = DSD_DATASTRUCT_STATUS_VALID; + + ( *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; @@ -389,11 +427,12 @@ Strange: why end the heap here ? /* La racine de la structure se trouve dans le premier chunk du premier segment du heap */ - *Root_Ptr_Ptr = (NDT_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; @@ -437,20 +476,31 @@ Strange: why end the heap here ? return( DSS_ERRAPI); } + /* Création d'un nouveau heap */ 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)", DS_Name, sm_status); - return( sm_status); + return( DSS_KO); } - /* Création de la structure de données dans le heap */ + + /* Create the Root structure */ + strncpy( root_tmp.Heap_Name, prefixed_name, DSD_NAME_LEN); + root_tmp.Heap_Name[ DSD_NAME_LEN] = '\0'; + + root_tmp.Status = DSD_DATASTRUCT_STATUS_TEMPORARY; + + + /* 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( 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_DataStruct_Alloc", NULL, "DS_DataStruct_Free", 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); @@ -466,7 +516,7 @@ 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); @@ -487,19 +537,35 @@ Strange: why end the heap here ? /* 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 */ + + *Root_Ptr_Ptr = DSD_DS_ROOT_GET( nd_root_ptr); + + strncpy( ( *Root_Ptr_Ptr)->Name, DS_Name, DSD_NAME_LEN); + ( *Root_Ptr_Ptr)->Name[ DSD_NAME_LEN] = '\0'; + + strncpy( ( *Root_Ptr_Ptr)->Heap_Name, prefixed_name, DSD_NAME_LEN); + ( *Root_Ptr_Ptr)->Heap_Name[ DSD_NAME_LEN] = '\0'; + + ( *Root_Ptr_Ptr)->Heap_Owner = FALSE; + ( *Root_Ptr_Ptr)->Status = DSD_DATASTRUCT_STATUS_VALID; + + ( *Root_Ptr_Ptr)->ND_Root.User_Ptr = NULL; + /* On crée un sémaphore pour compter le nombre de processus qui ouvrent la structure */ @@ -529,7 +595,8 @@ Strange: why end the heap here ? /* 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( rootdesc_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); @@ -543,7 +610,8 @@ Strange: why end the heap here ? if( mode == 3) { - semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl); +// semctl( rootdesc_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) { @@ -552,7 +620,8 @@ Strange: why end the heap here ? } else { - DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1); +// DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1); + DS_Semaphore_Operate( ( *Root_Ptr_Ptr)->OpenSemId, DS_SemOp_Close, 1); } *Root_Ptr_Ptr = NULL; @@ -577,7 +646,8 @@ Strange: why end the heap here ? if( mode == 3) { - semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl); +// semctl( rootdesc_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) { @@ -586,7 +656,8 @@ Strange: why end the heap here ? } else { - DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1); +// DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1); + DS_Semaphore_Operate( ( *Root_Ptr_Ptr)->OpenSemId, DS_SemOp_Close, 1); } *Root_Ptr_Ptr = NULL; @@ -613,7 +684,8 @@ Strange: why end the heap here ? if( mode == 3) { - semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl); +// semctl( rootdesc_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) { @@ -622,7 +694,8 @@ Strange: why end the heap here ? } else { - DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1); +// DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1); + DS_Semaphore_Operate( ( *Root_Ptr_Ptr)->OpenSemId, DS_SemOp_Close, 1); } *Root_Ptr_Ptr = NULL; @@ -651,7 +724,8 @@ Strange: why end the heap here ? if( mode == 3) { - semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl); +// semctl( rootdesc_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) { @@ -660,7 +734,8 @@ Strange: why end the heap here ? } else { - DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1); +// DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1); + DS_Semaphore_Operate( ( *Root_Ptr_Ptr)->OpenSemId, DS_SemOp_Close, 1); } *Root_Ptr_Ptr = NULL; @@ -684,9 +759,9 @@ Strange: why end the heap here ? /* (O) Locked : verrou effectif (TRUE ou FALSE) */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Lock_I( NDT_Root *Root_Ptr, DST_Flags Lock_Mode, int *Locked ) +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; +// char *Heap_Name = ( (DST_RootDesc *)( Root_Ptr->User_Ptr))->Heap_Name; SMT_Status sm_status; SMT_Heap *heap_ptr; @@ -694,10 +769,10 @@ DST_Status DS_DataStruct_Lock_I( NDT_Root *Root_Ptr, DST_Flags Lock_Mode, int /* Réouverture du heap sous-jacent (rafraîchissement des segments) + verrouillage */ - if( ( sm_status = SM_Heap_Open( Heap_Name, &heap_ptr, 0, ( SMD_OPEN | Lock_Mode), Locked)) != SMS_OK) + 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)", - Heap_Name, (DSD_MSK_READ( Lock_Mode) ? "reading" : "writing"), sm_status); + Root_Ptr->Heap_Name, (DSD_MSK_READ( Lock_Mode) ? "reading" : "writing"), sm_status); return( DSS_KO); } @@ -715,17 +790,17 @@ DST_Status DS_DataStruct_Lock_I( NDT_Root *Root_Ptr, DST_Flags Lock_Mode, int /* (I) Root : pointeur sur la racine de la structure */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Unlock_I( NDT_Root *Root_Ptr) +DST_Status DS_DataStruct_Unlock_I( DST_Root *Root_Ptr) { - char *Heap_Name = ( (DST_RootDesc *)( Root_Ptr->User_Ptr))->Heap_Name; +// 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( Heap_Name, &heap_ptr)) != SMS_OK) + 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)", Heap_Name, sm_status); + LG_LOG_ERROR_2( "Unable to check if heap: [%s] is open, status: (%d)", Root_Ptr->Heap_Name, sm_status); return( DSS_KO); } @@ -733,7 +808,7 @@ DST_Status DS_DataStruct_Unlock_I( NDT_Root *Root_Ptr) { if( heap_ptr == NULL) { - LG_LOG_ERROR_1( "Data structure heap: [%s] is not open", Heap_Name); + LG_LOG_ERROR_1( "Data structure heap: [%s] is not open", Root_Ptr->Heap_Name); return( DSS_KO); } @@ -741,7 +816,7 @@ DST_Status DS_DataStruct_Unlock_I( NDT_Root *Root_Ptr) 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_Name, sm_status); + LG_LOG_ERROR_2( "Unable to unlock the data structure heap: [%s], status: (%d)", Root_Ptr->Heap_Name, sm_status); return( DSS_KO); } @@ -760,9 +835,9 @@ DST_Status DS_DataStruct_Unlock_I( NDT_Root *Root_Ptr) /* (I) Close_Mode : mode de fermeture de la structure (destruction ou non) */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Close_I( NDT_Root *Root_Ptr, DST_Flags Close_Mode) +DST_Status DS_DataStruct_Close_I( DST_Root *Root_Ptr, DST_Flags Close_Mode) { - DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr); +// DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr); DST_Status status; NDT_Status nd_status; @@ -774,22 +849,23 @@ DST_Status DS_DataStruct_Close_I( NDT_Root *Root_Ptr, DST_Flags Close_Mode) union semun sem_ctl; - strcpy( heap_name, RootDesc_Ptr->Heap_Name); - + strcpy( heap_name, Root_Ptr->Heap_Name); ds_name = strstr( heap_name, DS_PREFIX); + if( ds_name) ds_name += strlen( DS_PREFIX) + 1; else ds_name = heap_name; + if( Close_Mode == DSD_DESTROY) /* Destruction de la data structure */ { /* La data structure est-elle propriétaire du heap sous-jacent ? */ - if( RootDesc_Ptr->Heap_Owner == TRUE) + if( Root_Ptr->Heap_Owner == TRUE) { /* On vérifie qu'aucun autre processus n'a ouvert la data structure */ - if( ( status = DS_Semaphore_Operate( RootDesc_Ptr->OpenSemId, DS_SemOp_Destroy, 2)) != DSS_OK) + if( ( status = DS_Semaphore_Operate( Root_Ptr->OpenSemId, DS_SemOp_Destroy, 2)) != DSS_OK) { LG_LOG_ERROR_1( "Unable to destroy the data structure: [%s] because it is opened by another process", ds_name); @@ -799,7 +875,7 @@ DST_Status DS_DataStruct_Close_I( NDT_Root *Root_Ptr, DST_Flags Close_Mode) /* On supprime la structure proprement (toutes les valeurs sont supprimées les unes après les autres) */ - if( ( nd_status = ND_DataStruct_Close( Root_Ptr)) != NDS_OK) + if( ( nd_status = ND_DataStruct_Close( &( Root_Ptr->ND_Root))) != NDS_OK) { LG_LOG_ERROR_2( "Unable to close the node structure of data structure: [%s], status: (%d)", ds_name, nd_status); @@ -809,7 +885,7 @@ DST_Status DS_DataStruct_Close_I( NDT_Root *Root_Ptr, DST_Flags Close_Mode) /* Suppression du sémaphore */ - semctl( RootDesc_Ptr->OpenSemId, 0, IPC_RMID, sem_ctl); + semctl( Root_Ptr->OpenSemId, 0, IPC_RMID, sem_ctl); /* On supprime maintenant le heap */ @@ -830,14 +906,14 @@ DST_Status DS_DataStruct_Close_I( NDT_Root *Root_Ptr, DST_Flags Close_Mode) On la supprime donc sans contrôle. */ - if( ( nd_status = ND_DataStruct_Close( Root_Ptr)) != NDS_OK) + if( ( nd_status = ND_DataStruct_Close( &( Root_Ptr->ND_Root))) != NDS_OK) { LG_LOG_ERROR_2( "Unable to close the node structure of data structure: [%s], status: (%d)", ds_name, nd_status); return( DSS_KO); } - if( ( status = DS_DataStruct_Free( RootDesc_Ptr, (void *)RootDesc_Ptr)) != DSS_OK) + if( ( status = DS_DataStruct_Free( Root_Ptr, &( Root_Ptr->ND_Root), NULL)) != DSS_OK) { LG_LOG_ERROR_2( "Unable to free data structure: [%s], status: (%d)", ds_name, status); } @@ -849,7 +925,7 @@ DST_Status DS_DataStruct_Close_I( NDT_Root *Root_Ptr, DST_Flags Close_Mode) { /* On décrémente le sémaphore qui compte le nombre de processus ayant ouvert la data structure */ - if( ( status = DS_Semaphore_Operate( RootDesc_Ptr->OpenSemId, DS_SemOp_Close, 1)) != DSS_OK) + if( ( status = DS_Semaphore_Operate( Root_Ptr->OpenSemId, DS_SemOp_Close, 1)) != DSS_OK) { LG_LOG_ERROR_1( "Unable to decremente the semaphore of data structure: [%s]", ds_name); @@ -922,12 +998,12 @@ DST_Status DS_DataStruct_Close_I( NDT_Root *Root_Ptr, DST_Flags Close_Mode) /* (I) Root_Ptr: Data structure pointer */ /*----------------------------------------------------------------------------*/ -NDT_Status DS_DataStruct_Flush_I( NDT_Root *Root_Ptr) +NDT_Status DS_DataStruct_Flush_I( DST_Root *Root_Ptr) { NDT_Status nd_status; - if( ( nd_status = ND_DataStruct_Flush_I( Root_Ptr)) != NDS_OK) + if( ( nd_status = ND_DataStruct_Flush_I( &( Root_Ptr->ND_Root))) != NDS_OK) { LG_LOG_ERROR_1( "Unable to flush datastructure, status: (%d)", nd_status); @@ -954,10 +1030,10 @@ NDT_Status DS_DataStruct_Flush_I( NDT_Root *Root_Ptr) /* (I) Out: Output stream */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Check_I( NDT_Root *Root_Ptr, int *Error_Detected_Nb_Ptr, int *Error_Corrected_Nb_Ptr, FILE *Out) +DST_Status DS_DataStruct_Check_I( DST_Root *Root_Ptr, int *Error_Detected_Nb_Ptr, int *Error_Corrected_Nb_Ptr, FILE *Out) { - DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr); - char *Heap_Name = RootDesc_Ptr->Heap_Name; +// DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr); +// char *Heap_Name = RootDesc_Ptr->Heap_Name; DST_Status status, status2; SMT_Status sm_status; @@ -970,9 +1046,9 @@ DST_Status DS_DataStruct_Check_I( NDT_Root *Root_Ptr, int *Error_Detected_Nb /* On sauvegarde l'état de verrouillage précédent */ - if( ( sm_status = SM_Heap_IsOpen( Heap_Name, &heap_ptr)) != SMS_OK) + 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)", Heap_Name, sm_status); + LG_LOG_ERROR_2( "Unable to check if heap: [%s] is open, status: (%d)", Root_Ptr->Heap_Name, sm_status); return( DSS_KO); } @@ -980,7 +1056,7 @@ DST_Status DS_DataStruct_Check_I( NDT_Root *Root_Ptr, int *Error_Detected_Nb { if( heap_ptr == NULL) { - LG_LOG_ERROR_1( "Data structure heap: [%s] is not open", Heap_Name); + LG_LOG_ERROR_1( "Data structure heap: [%s] is not open", Root_Ptr->Heap_Name); return( DSS_KO); } @@ -993,7 +1069,7 @@ DST_Status DS_DataStruct_Check_I( NDT_Root *Root_Ptr, int *Error_Detected_Nb if( ( status = DS_DataStruct_Lock_I( Root_Ptr, SMD_WRITE, &locked)) != DSS_OK) { - LG_LOG_ERROR_2( "Unable to lock the data structure: [%s] for writing, status : (%s)", Heap_Name, status); + LG_LOG_ERROR_2( "Unable to lock the data structure: [%s] for writing, status : (%s)", Root_Ptr->Heap_Name, status); return( SMS_OK); } @@ -1003,7 +1079,7 @@ DST_Status DS_DataStruct_Check_I( NDT_Root *Root_Ptr, int *Error_Detected_Nb if( ( sm_status = SM_Heap_Check( heap_ptr, Error_Detected_Nb_Ptr, Error_Corrected_Nb_Ptr, Out)) != SMS_OK) { - LG_LOG_ERROR_2( "Unable to check the heap: [%s] for writing, status : (%s)", Heap_Name, sm_status); + LG_LOG_ERROR_2( "Unable to check the heap: [%s] for writing, status : (%s)", Root_Ptr->Heap_Name, sm_status); status= DSS_KO; } @@ -1013,9 +1089,9 @@ DST_Status DS_DataStruct_Check_I( NDT_Root *Root_Ptr, int *Error_Detected_Nb LG_LOG_INFO_0( "Checking the node structure..."); - if( ( nd_status = ND_DataStruct_Check( Root_Ptr, Error_Detected_Nb_Ptr, Error_Corrected_Nb_Ptr, Out)) != NDS_OK) + if( ( nd_status = ND_DataStruct_Check( &(Root_Ptr->ND_Root), Error_Detected_Nb_Ptr, Error_Corrected_Nb_Ptr, Out)) != NDS_OK) { - LG_LOG_ERROR_2( "Unable to check the data structure: [%s], status: (%d)", Heap_Name, nd_status); + LG_LOG_ERROR_2( "Unable to check the data structure: [%s], status: (%d)", Root_Ptr->Heap_Name, nd_status); status = DSS_KO; } @@ -1025,11 +1101,11 @@ DST_Status DS_DataStruct_Check_I( NDT_Root *Root_Ptr, int *Error_Detected_Nb if( *Error_Corrected_Nb_Ptr == *Error_Detected_Nb_Ptr) { - RootDesc_Ptr->Valid = TRUE; + Root_Ptr->Status = DSD_DATASTRUCT_STATUS_VALID; } else { - RootDesc_Ptr->Valid = FALSE; + Root_Ptr->Status = DSD_DATASTRUCT_STATUS_INVALID; } @@ -1066,7 +1142,7 @@ DST_Status DS_DataStruct_Check_I( NDT_Root *Root_Ptr, int *Error_Detected_Nb { if( ( status2 = DS_DataStruct_Unlock_I( Root_Ptr)) != DSS_OK) { - LG_LOG_ERROR_2( "Unable to unlock the data structure: [%s], status: (%d)", Heap_Name, status2); + LG_LOG_ERROR_2( "Unable to unlock the data structure: [%s], status: (%d)", Root_Ptr->Heap_Name, status2); status = status2; } } @@ -1074,7 +1150,7 @@ DST_Status DS_DataStruct_Check_I( NDT_Root *Root_Ptr, int *Error_Detected_Nb { if( ( status2 = DS_DataStruct_Lock_I( Root_Ptr, previous_lock, &locked)) != SMS_OK) { - LG_LOG_ERROR_2( "Unable to lock the data structure: [%s], status: (%d)", Heap_Name, status2); + LG_LOG_ERROR_2( "Unable to lock the data structure: [%s], status: (%d)", Root_Ptr->Heap_Name, status2); status = status2; } } @@ -1093,9 +1169,9 @@ DST_Status DS_DataStruct_Check_I( NDT_Root *Root_Ptr, int *Error_Detected_Nb /* (I) Index_Type_Ptr: Array of index type (List, tree, ...) */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Convert_I( NDT_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_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr); DST_Status status; NDT_Status nd_status; @@ -1103,17 +1179,17 @@ DST_Status DS_DataStruct_Convert_I( NDT_Root *Root_Ptr, NDT_Index_Type *Index /* On vérifie que la data structure est valide */ - DS_STRUCT_VALID_CHECK( Root_Ptr, RootDesc_Ptr); + DS_STRUCT_VALID_CHECK( Root_Ptr); /* On rend la structure invalide le temps de sa conversion */ - RootDesc_Ptr->Valid = FALSE; + Root_Ptr->Status = DSD_DATASTRUCT_STATUS_INVALID; /* Conversion de la node structure */ - if( ( nd_status = ND_DataStruct_Convert( Root_Ptr, Index_Type_Ptr)) != NDS_OK) + if( ( nd_status = ND_DataStruct_Convert( &( Root_Ptr->ND_Root), Index_Type_Ptr)) != NDS_OK) { LG_LOG_ERROR_1( "Unable to convert the node structure, status: (%d)", nd_status); @@ -1123,7 +1199,7 @@ DST_Status DS_DataStruct_Convert_I( NDT_Root *Root_Ptr, NDT_Index_Type *Index { /* On rend la structure à nouveau valide */ - RootDesc_Ptr->Valid = TRUE; + Root_Ptr->Status = DSD_DATASTRUCT_STATUS_VALID; return( DSS_OK); } @@ -1140,9 +1216,9 @@ DST_Status DS_DataStruct_Convert_I( NDT_Root *Root_Ptr, NDT_Index_Type *Index /* (I) Root_Ptr: Data structure pointer */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Reorg_I( NDT_Root *Root_Ptr) +DST_Status DS_DataStruct_Reorg_I( DST_Root *Root_Ptr) { - DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr); +// DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr); DST_Status status; NDT_Status nd_status; @@ -1150,17 +1226,17 @@ DST_Status DS_DataStruct_Reorg_I( NDT_Root *Root_Ptr) /* On vérifie que la data structure est valide */ - DS_STRUCT_VALID_CHECK( Root_Ptr, RootDesc_Ptr); + DS_STRUCT_VALID_CHECK( Root_Ptr); /* On rend la structure invalide, le temps de sa réorganisation */ - RootDesc_Ptr->Valid = FALSE; + Root_Ptr->Status = DSD_DATASTRUCT_STATUS_INVALID; /* Réorganisation de la node structure */ - if( ( nd_status = ND_DataStruct_Reorg( Root_Ptr)) != NDS_OK) + if( ( nd_status = ND_DataStruct_Reorg( &( Root_Ptr->ND_Root))) != NDS_OK) { LG_LOG_ERROR_1( "Unable to reorg the node structure, status: (%d)", nd_status); @@ -1170,7 +1246,7 @@ DST_Status DS_DataStruct_Reorg_I( NDT_Root *Root_Ptr) { /* On rend la structure à nouveau valide */ - RootDesc_Ptr->Valid = TRUE; + Root_Ptr->Status = DSD_DATASTRUCT_STATUS_VALID; return( DSS_OK); } @@ -1179,6 +1255,7 @@ DST_Status DS_DataStruct_Reorg_I( NDT_Root *Root_Ptr) + /*----------------------------------------------------------------------------*/ /* Print data structure information */ /*----------------------------------------------------------------------------*/ @@ -1189,26 +1266,26 @@ DST_Status DS_DataStruct_Reorg_I( NDT_Root *Root_Ptr) /* (I) Recursive_Offset: Curent print out offset */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Info_Print_I( FILE *Out, NDT_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_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr); DST_Status status; NDT_Status nd_status; - LG_LOG_INFO_5( "DatatStruct Heap_Name: [%s] Manager_Name: [%s] OpenSemId: (%d) Heap_Owner: [%s] Valid: [%s]", - RootDesc_Ptr->Heap_Name, RootDesc_Ptr->Manager_Name, RootDesc_Ptr->OpenSemId, DSD_BOOL_VALUE_ASCII_GET( RootDesc_Ptr->Heap_Owner), DSD_BOOL_VALUE_ASCII_GET( RootDesc_Ptr->Valid)); + LG_LOG_INFO_6( "DatatStruct: (%p) Name: [%s] Heap_Name: [%s] OpenSemId: (%d) Heap_Owner: [%s] Status: [%s]", + Root_Ptr, Root_Ptr->Name, Root_Ptr->Heap_Name, Root_Ptr->OpenSemId, DSD_BOOL_VALUE_ASCII_GET( Root_Ptr->Heap_Owner), DSD_DATASTRUCT_STATUS_VALUE_ASCII_GET( Root_Ptr->Status)); /* On vérifie que la data structure est valide */ - DS_STRUCT_VALID_CHECK( Root_Ptr, RootDesc_Ptr); +// DS_STRUCT_VALID_CHECK( Root_Ptr->ND_Root, RootDesc_Ptr); /* Affichage des informations sur la structure */ - if( ( nd_status = ND_DataStruct_Info_Print( Out, Root_Ptr, Recursive_Mode, Recursive_Depth, Recursive_Offset)) != NDS_OK) + if( ( nd_status = ND_DataStruct_Info_Print( Out, &( Root_Ptr->ND_Root), Recursive_Mode, Recursive_Depth, Recursive_Offset)) != NDS_OK) { LG_LOG_ERROR_1( "Unable to print info about the data structure: (%d)", nd_status); @@ -1236,7 +1313,7 @@ DST_Status DS_DataStruct_Info_Print_I( FILE *Out, NDT_Root *Root_Ptr, NDT_Recu /* Dump SM */ - SM_Library_Dump( stderr); + SM_Library_Dump( stderr); return( DSS_OK); } @@ -1326,9 +1403,9 @@ DST_Status DS_DataStruct_Print_I ( NDT_Root * Root, FILE * Out ) /* (I) Value_Ptr: Value pointer */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Value_Add_I( NDT_Root *Root_Ptr, void *Value_Ptr) +DST_Status DS_DataStruct_Value_Add_I( DST_Root *Root_Ptr, void *Value_Ptr) { - DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr); +// DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr); DST_Status status; NDT_Status nd_status; @@ -1336,17 +1413,17 @@ DST_Status DS_DataStruct_Value_Add_I( NDT_Root *Root_Ptr, void *Value_Ptr) /* On vérifie que la data structure est valide */ - DS_STRUCT_VALID_CHECK( Root_Ptr, RootDesc_Ptr); + DS_STRUCT_VALID_CHECK( Root_Ptr); /* On rend la structure invalide le temps de l'ajout */ - RootDesc_Ptr->Valid = FALSE; + Root_Ptr->Status = DSD_DATASTRUCT_STATUS_INVALID; /* Ajout de la valeur */ - if( ( nd_status = ND_DataStruct_Value_Add( Root_Ptr, Value_Ptr)) != NDS_OK) + if( ( nd_status = ND_DataStruct_Value_Add( &( Root_Ptr->ND_Root), Value_Ptr)) != NDS_OK) { LG_LOG_ERROR_1( "Unable to add a value to the data structure: (%d)", nd_status); @@ -1358,7 +1435,7 @@ DST_Status DS_DataStruct_Value_Add_I( NDT_Root *Root_Ptr, void *Value_Ptr) /* On rend la structure à nouveau valide */ - RootDesc_Ptr->Valid = TRUE; + Root_Ptr->Status = DSD_DATASTRUCT_STATUS_VALID; return( DSS_OK); } @@ -1438,9 +1515,9 @@ DST_Status DS_Value_Remove_I ( NDT_Root * Root, void * Reference_Value, void ** /* (I) ...: User args */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Value_Print_I( FILE *Out_Ptr, NDT_Root *Root_Ptr, NDT_Recursive_Mode Recursive_Mode, NDT_Recursive_Depth Recursive_Depth, NDT_Recursive_Offset Recursive_Offset, ...) +DST_Status DS_DataStruct_Value_Print_I( FILE *Out_Ptr, 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_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr); DST_Status status; NDT_Status nd_status; @@ -1451,12 +1528,12 @@ DST_Status DS_DataStruct_Value_Print_I( FILE *Out_Ptr, NDT_Root *Root_Ptr, ND /* On vérifie que la data structure est valide */ - DS_STRUCT_VALID_CHECK( Root_Ptr, RootDesc_Ptr); + DS_STRUCT_VALID_CHECK( Root_Ptr); /* Affichage de la node structure */ - if( ( nd_status = ND_DataStruct_Value_Print_VI( Out_Ptr, Root_Ptr, Recursive_Mode, Recursive_Depth, Recursive_Offset, &user_args)) != NDS_OK) + if( ( nd_status = ND_DataStruct_Value_Print_VI( Out_Ptr, &( Root_Ptr->ND_Root), Recursive_Mode, Recursive_Depth, Recursive_Offset, &user_args)) != NDS_OK) { LG_LOG_ERROR_1( "Unable to dump the node structure: (%d)", nd_status); @@ -1484,12 +1561,12 @@ DST_Status DS_DataStruct_Value_Print_I( FILE *Out_Ptr, NDT_Root *Root_Ptr, ND /* (I) Index_Type: Index type (List, tree, ...) */ /*----------------------------------------------------------------------------*/ -NDT_Status DS_Index_Open_I( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type) +NDT_Status DS_Index_Open_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type) { NDT_Status nd_status; - if( ( nd_status = ND_Index_Open_I( Root_Ptr, Index_Id, Index_Type)) != NDS_OK) + if( ( nd_status = ND_Index_Open_I( &( Root_Ptr->ND_Root), Index_Id, Index_Type)) != NDS_OK) { LG_LOG_ERROR_2( "Unable to open index: (%d), status: (%d)", Index_Id, nd_status); @@ -1512,12 +1589,12 @@ NDT_Status DS_Index_Open_I( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_In /* (I) Index_Id: Id of the index */ /*----------------------------------------------------------------------------*/ -NDT_Status DS_Index_Close_I( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id) +NDT_Status DS_Index_Close_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id) { NDT_Status nd_status; - if( ( nd_status = ND_Index_Close_I( Root_Ptr, Index_Id)) != NDS_OK) + if( ( nd_status = ND_Index_Close_I( &( Root_Ptr->ND_Root), Index_Id)) != NDS_OK) { LG_LOG_ERROR_2( "Unable to close index: (%d), status: (%d)", Index_Id, nd_status); @@ -1541,12 +1618,12 @@ NDT_Status DS_Index_Close_I( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id) /* (I) Index_Type: Index type (List, tree, ...) */ /*----------------------------------------------------------------------------*/ -NDT_Status DS_Index_Convert_I( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type) +NDT_Status DS_Index_Convert_I( DST_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Index_Type Index_Type) { NDT_Status nd_status; - if( ( nd_status = ND_Index_Convert_I( Root_Ptr, Index_Id, Index_Type)) != NDS_OK) + if( ( nd_status = ND_Index_Convert_I( &( Root_Ptr->ND_Root), Index_Id, Index_Type)) != NDS_OK) { LG_LOG_ERROR_2( "Unable to convert index: (%d), status: (%d)", Index_Id, nd_status); @@ -1879,7 +1956,7 @@ DST_Status DS_Node_Find_I ( NDT_Root * Root, NDT_Node ** Node, void * Value, voi /* (I) ... : arguments relatifs à l'allocation de la valeur */ /*----------------------------------------------------------------------------*/ -DST_Status DS_Value_Alloc_I( void **Value_Ptr_Ptr, NDT_Root *Root_Ptr, ... ) +DST_Status DS_Value_Alloc_I( void **Value_Ptr_Ptr, DST_Root *Root_Ptr, ... ) { DST_Status status; NDT_Status nd_status; @@ -1893,7 +1970,7 @@ DST_Status DS_Value_Alloc_I( void **Value_Ptr_Ptr, NDT_Root *Root_Ptr, ... ) /* Appel du manager */ - if( ( nd_status = ND_Manager_Exec( Root_Ptr, 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); @@ -1937,9 +2014,9 @@ DST_Status DS_Value_Free_I ( NDT_Root * Root, void * Value ) /* (I) Size : taille mémoire à allouer */ /*----------------------------------------------------------------------------*/ -DST_Status DS_Alloc_I( void **Ptr_Ptr, NDT_Root *Root_Ptr, size_t Size) +DST_Status DS_Alloc_I( void **Ptr_Ptr, NDT_Root *ND_Root_Ptr, size_t Size) { - return( DS_DataStruct_Alloc( Ptr_Ptr, Size, Root_Ptr->User_Ptr)); + return( DS_DataStruct_Alloc( Ptr_Ptr, ND_Root_Ptr, Size, NULL)); } @@ -1953,12 +2030,15 @@ DST_Status DS_Alloc_I( void **Ptr_Ptr, NDT_Root *Root_Ptr, size_t Size) /* (I) Ptr : pointeur sur la zone à désallouer */ /*----------------------------------------------------------------------------*/ -DST_Status DS_Free_I( NDT_Root *Root_Ptr, void *Ptr) +DST_Status DS_Free_I( NDT_Root *ND_Root_Ptr, void *Ptr) { - return( DS_DataStruct_Free( Ptr, Root_Ptr->User_Ptr)); + return( DS_DataStruct_Free( Ptr, ND_Root_Ptr, NULL)); } + + + /*----------------------------------------------------------------------------*/ /* FONCTIONS OPTIMISATION MOYENNE (DS_MODE = 1) */ /*----------------------------------------------------------------------------*/ @@ -2089,9 +2169,9 @@ NDT_Status DS_DataStruct_Flush_L( NDT_Root *Root_Ptr) /* (I) Out: Output stream */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Check_L( NDT_Root *Root_Ptr, int *Error_Detected_Nb_Ptr, int *Error_Corrected_Nb_Ptr, FILE *Out) +DST_Status DS_DataStruct_Check_L( DST_Root *Root_Ptr, int *Error_Detected_Nb_Ptr, int *Error_Corrected_Nb_Ptr, FILE *Out) { - return( DS_DataStruct_Check_L( Root_Ptr, Error_Detected_Nb_Ptr, Error_Corrected_Nb_Ptr, Out)); + return( DS_DataStruct_Check_I( Root_Ptr, Error_Detected_Nb_Ptr, Error_Corrected_Nb_Ptr, Out)); } @@ -3366,12 +3446,20 @@ DST_Status DS_Free_CL ( NDT_Root * Root, void * Ptr ) return DS_Free_L (Root, Ptr); } + + + + + + /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /* FONCTIONS PRIVEES */ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ + + /*----------------------------------------------------------------------------*/ /* Teste si une data structure a déjà été ouverte par le processus courant : */ /*----------------------------------------------------------------------------*/ @@ -3379,7 +3467,7 @@ DST_Status DS_Free_CL ( NDT_Root * Root, void * Ptr ) /* (O) Root : adresse du pointeur sur la racine de la structure */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_IsOpen( NDT_Root **Root_Ptr_Ptr, char *DS_Name) +DST_Status DS_DataStruct_IsOpen( DST_Root **Root_Ptr_Ptr, char *DS_Name) { NDT_Status nd_status; DST_DataStruct to_find, *found_ptr; @@ -3414,25 +3502,60 @@ DST_Status DS_DataStruct_IsOpen( NDT_Root **Root_Ptr_Ptr, char *DS_Name) + + /*----------------------------------------------------------------------------*/ /* Fonction d'allocation attachée à une structure de données : */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Alloc( void **Ptr_Ptr, size_t Size, void *Data_Ptr) +DST_Status DS_DataStruct_Alloc( void **Ptr_Ptr, NDT_Root *ND_Root_Ptr, size_t Size, void *User_Ptr) { - DST_Status status; - SMT_Status sm_status; - SMT_Heap *heap_ptr; - int locked; - DST_RootDesc *RootDesc = (DST_RootDesc *)Data_Ptr; -// char *heap_name = RootDesc->Heap_Name; +// DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)Data_Ptr; +// char *Heap_Name = RootDesc_Ptr->Heap_Name; + + DST_Root *Root_Ptr; + + DST_Status status; + SMT_Status sm_status; + + SMT_Heap *heap_ptr; + int locked; + size_t nd_root_offset; - if( ( sm_status = SM_Heap_IsOpen( RootDesc->Heap_Name, &heap_ptr)) != SMS_YES) + if( ND_Root_Ptr == NULL) { - LG_LOG_ERROR_1( "The data structure heap: [%s] is not open", RootDesc->Heap_Name); + if( User_Ptr == NULL) + { + LG_LOG_ERROR_0( "Unable to get data structure info"); + + return( DSS_ERRAPI); + } + else + { + /* 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; + } + - return( DSS_OK); + 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); } @@ -3440,17 +3563,81 @@ DST_Status DS_DataStruct_Alloc( void **Ptr_Ptr, size_t Size, void *Data_Ptr) 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)", RootDesc->Heap_Name, sm_status); + 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); +} + +/* +DST_Status DS_DataStruct_Alloc( void **Ptr_Ptr, size_t Size, void *Data_Ptr) +{ + DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)Data_Ptr; + char *Heap_Name = RootDesc_Ptr->Heap_Name; + + DST_Status status; + SMT_Status sm_status; + + SMT_Heap *heap_ptr; + int locked; + + + if( ( sm_status = SM_Heap_IsOpen( Heap_Name, &heap_ptr)) != SMS_YES) + { + LG_LOG_ERROR_1( "The data structure heap: [%s] is not open", Heap_Name); + + return( DSS_OK); + } + + + /* 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)", Heap_Name, sm_status); return( DSS_OK); } /* Allocation du 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, RootDesc->Heap_Name, sm_status); + LG_LOG_ERROR_3( "Unable to alloc size: (%d) in the heap: [%s] for writing, status: (%d)", Size, Heap_Name, sm_status); if( locked == TRUE) SM_Heap_Unlock( heap_ptr); return( DSS_KO); @@ -3458,7 +3645,7 @@ DST_Status DS_DataStruct_Alloc( void **Ptr_Ptr, size_t Size, void *Data_Ptr) /* Déverrouillage de la data structure si besoin */ - +/* if( locked == TRUE) { if( ( sm_status = SM_Heap_Unlock( heap_ptr)) != SMS_OK) @@ -3469,6 +3656,8 @@ DST_Status DS_DataStruct_Alloc( void **Ptr_Ptr, size_t Size, void *Data_Ptr) return( DSS_OK); } +*/ + @@ -3476,10 +3665,12 @@ DST_Status DS_DataStruct_Alloc( void **Ptr_Ptr, size_t Size, void *Data_Ptr) /* Fonction de désallocation attachée à une structure de données : */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Free( void *Ptr, void *Data_Ptr) +DST_Status DS_DataStruct_Free( void *Ptr, NDT_Root *ND_Root_Ptr, void *User_Ptr) { - DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)Data_Ptr; - char *Heap_Name = RootDesc_Ptr->Heap_Name; +// DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)Data_Ptr; +// char *Heap_Name = RootDesc_Ptr->Heap_Name; + + DST_Root *Root_Ptr; DST_Status status; SMT_Status sm_status; @@ -3487,10 +3678,24 @@ DST_Status DS_DataStruct_Free( void *Ptr, void *Data_Ptr) SMT_Heap *heap_ptr; int locked; - - if( ( sm_status = SM_Heap_IsOpen( Heap_Name, &heap_ptr)) != SMS_OK) + + if( ND_Root_Ptr == NULL) { - LG_LOG_ERROR_2( "Unable to check if heap: [%s] is open, status: (%d)", Heap_Name, sm_status); + /* Root node free case */ + + Root_Ptr = ( DST_Root *)Ptr; + } + else + { + /* Default free case */ + + Root_Ptr = DSD_DS_ROOT_GET( ND_Root_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); } @@ -3498,7 +3703,7 @@ DST_Status DS_DataStruct_Free( void *Ptr, void *Data_Ptr) { if( heap_ptr == NULL) { - LG_LOG_ERROR_1( "DatatStructure heap: [%s] is not open", Heap_Name); + LG_LOG_ERROR_1( "DatatStructure heap: [%s] is not open", Root_Ptr->Heap_Name); return( DSS_KO); } @@ -3578,17 +3783,20 @@ DST_Status DS_Name_Prefix( char *Prefixed_Name_Ptr, const char *Unprefixed_Na /* Création d'un sémaphore pour gérer l'ouverture d'une data structure */ /*----------------------------------------------------------------------------*/ -DST_Status DS_Semaphore_Create ( NDT_Root *Root_Ptr) +//DST_Status DS_Semaphore_Create ( NDT_Root *Root_Ptr) +DST_Status DS_Semaphore_Create ( DST_Root *Root_Ptr) { - DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr); +// DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr); union semun sem_ctl; /* Création du sémaphore */ - +/* RootDesc_Ptr->OpenSemId = semget( IPC_PRIVATE, 1, ( 0777 | IPC_CREAT | IPC_EXCL)); if( RootDesc_Ptr->OpenSemId == -1) +*/ + if( ( Root_Ptr->OpenSemId = semget( IPC_PRIVATE, 1, ( 0777 | IPC_CREAT | IPC_EXCL))) == -1) { switch( errno) { @@ -3622,11 +3830,12 @@ DST_Status DS_Semaphore_Create ( NDT_Root *Root_Ptr) sem_ctl.val = 0; - if( semctl( RootDesc_Ptr->OpenSemId, 0, SETVAL, sem_ctl)) +// if( semctl( RootDesc_Ptr->OpenSemId, 0, SETVAL, sem_ctl)) + if( semctl( Root_Ptr->OpenSemId, 0, SETVAL, sem_ctl)) { - LG_LOG_ERROR_1( "Unable to initialize the value of the semaphore: (%x)", RootDesc_Ptr->OpenSemId); + LG_LOG_ERROR_1( "Unable to initialize the value of the semaphore: (%x)", Root_Ptr->OpenSemId); - semctl( RootDesc_Ptr->OpenSemId, 0, IPC_RMID, sem_ctl); + semctl( Root_Ptr->OpenSemId, 0, IPC_RMID, sem_ctl); return( DSS_ERRSEM); } @@ -3798,7 +4007,7 @@ NDT_Status DS_OpenedDS_List_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id ND_VA_LIST_OPEN( user_args, *Args_Ptr); ND_VA_ARG_GET( DS_Name, user_args, char *); - ND_VA_ARG_GET( Root_Ptr, user_args, NDT_Root *); + ND_VA_ARG_GET( Root_Ptr, user_args, DST_Root *); ND_VA_LIST_CLOSE( user_args); diff --git a/lib/libdatastr.h b/lib/libdatastr.h index 4c84d97..d02c7c8 100644 --- a/lib/libdatastr.h +++ b/lib/libdatastr.h @@ -95,7 +95,7 @@ NDT_Root *OpenedDS_List; typedef struct DST_DataStruct { char Name[ DSD_NAME_SIZE]; - NDT_Root *Root_Ptr; + DST_Root *Root_Ptr; } DST_DataStruct; @@ -110,7 +110,7 @@ typedef struct DST_DataStruct /* Création d'un sémaphore pour gérer l'ouverture d'une data structure */ /*----------------------------------------------------------------------------*/ -DST_Status DS_Semaphore_Create( NDT_Root *); +DST_Status DS_Semaphore_Create( DST_Root *); @@ -118,7 +118,7 @@ DST_Status DS_Semaphore_Create( NDT_Root *); /* Opération sur un sémaphore */ /*----------------------------------------------------------------------------*/ -DST_Status DS_Semaphore_Operate (int, struct sembuf *, unsigned int); +DST_Status DS_Semaphore_Operate (int, struct sembuf *, unsigned int); @@ -126,7 +126,7 @@ DST_Status DS_Semaphore_Operate (int, struct sembuf *, unsigned int); /* Fonction d'allocation attachée à une structure de données : */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Alloc ( void **Ptr_Ptr, size_t Size, void *Data ); +DST_Status DS_DataStruct_Alloc ( void **Ptr_Ptr, NDT_Root *ND_Root_Ptr, size_t Size, void *User_Ptr); @@ -134,14 +134,14 @@ DST_Status DS_DataStruct_Alloc ( void **Ptr_Ptr, size_t Size, void *Data ); /* Fonction de désallocation attachée à une structure de données : */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Free ( void *Ptr, void *Data ); +DST_Status DS_DataStruct_Free ( void *Ptr, NDT_Root *ND_Root_Ptr, void *User_Ptr ); /*----------------------------------------------------------------------------*/ /* Routine d'affichage d'un message d'erreur */ /*----------------------------------------------------------------------------*/ -void DS_Error_Print ( void ); +void DS_Error_Print ( void ); @@ -157,7 +157,7 @@ DST_Status DS_Name_Prefix( char *Prefixed, const char *Unprefixed); /* Teste si une data structure a déjà été ouverte par le processus courant */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_IsOpen( NDT_Root **Root_Ptr_Ptr, char *DS_Name); +DST_Status DS_DataStruct_IsOpen( DST_Root **Root_Ptr_Ptr, char *DS_Name); @@ -165,5 +165,5 @@ DST_Status DS_DataStruct_IsOpen( NDT_Root **Root_Ptr_Ptr, char *DS_Name); /* Fonction manager de la liste des DS ouvertes */ /*----------------------------------------------------------------------------*/ -NDT_Status DS_OpenedDS_List_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node *Node_Ptr, NDT_Command Command, va_list *Args_Ptr); +NDT_Status DS_OpenedDS_List_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node *Node_Ptr, NDT_Command Command, va_list *Args_Ptr); diff --git a/util/dsbench.c b/util/dsbench.c index 8f00e19..748f082 100644 --- a/util/dsbench.c +++ b/util/dsbench.c @@ -223,13 +223,13 @@ NDT_Index_Type DBD_IDX_TYPE_BALANCED_TREE = NDD_INDEX_STATUS_OPENED | NDD_INDEX NDT_Status Module_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); -void Menu_Print( FILE *, NDT_Root *); +void Menu_Print( FILE *, DST_Root *); void Command_Get( int *, char **, char **, char **, FILE *, FILE *, short); void Command_Exec_Begin_Print( FILE *, int); void Command_Exec_End_Print( FILE *, int, cpt, int); void Command_Index_Range_Get( FILE *, int *, int *, char *, char *, FILE *, int, char *); -void Command_Exec( NDT_Root **, FILE *, int, char *, char *, char *, FILE *); -void Batch_Run( NDT_Root **, FILE *, FILE *, short); +void Command_Exec( DST_Root **, FILE *, int, char *, char *, char *, FILE *); +void Batch_Run( DST_Root **, FILE *, FILE *, short); @@ -588,7 +588,7 @@ NDT_Status Module_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod ND_VA_LIST_CLOSE( lib_args); char *Root_Type; - DST_RootDesc *RootDesc; +// DST_RootDesc *RootDesc; Command_Name = "NDD_CMD_INFO_PRINT"; @@ -682,7 +682,7 @@ NDT_Status Module_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod /* Menu_Print */ /*----------------------------------------------------------------------------*/ -void Menu_Print( FILE *File_Output, NDT_Root *DS_Ptr) +void Menu_Print( FILE *File_Output, DST_Root *DS_Ptr) { short i; char headc; @@ -692,7 +692,7 @@ void Menu_Print( FILE *File_Output, NDT_Root *DS_Ptr) for( i = 0; i < COMMAND_NB; i++) { - if( ( DS_Ptr && ( Command_Tab[i].DS_State & DS_STATE_OPENED) && ( DS_Ptr->Index_Tab[0].Type & Command_Tab[i].Index_Type)) + if( ( DS_Ptr && ( Command_Tab[i].DS_State & DS_STATE_OPENED) && ( DS_Ptr->ND_Root.Index_Tab[0].Type & Command_Tab[i].Index_Type)) || ( !DS_Ptr && ( Command_Tab[i].DS_State & DS_STATE_CLOSED))) { headc = '-'; @@ -890,7 +890,7 @@ void Command_Index_Range_Get( FILE *File_Output, int *Low, int *High, char /* Command_Exec */ /*----------------------------------------------------------------------------*/ -void Command_Exec( NDT_Root **DS_Ptr_Ptr, FILE *File_Output, int Choice, char *Arg1, char *Arg2, char *Arg3, FILE *File_Input) +void Command_Exec( DST_Root **DS_Ptr_Ptr, FILE *File_Output, int Choice, char *Arg1, char *Arg2, char *Arg3, FILE *File_Input) { DST_Status status; int sub_choice_int1, sub_choice_int2, low, high, i, j, inc, nb_removed, nb_detected, nb_corrected; @@ -1287,7 +1287,7 @@ void Command_Exec( NDT_Root **DS_Ptr_Ptr, FILE *File_Output, int Choice, cha for( i = low; i <= high; i++) { - ND_Index_Open( *DS_Ptr_Ptr, (NDT_Index_Id)i, DBD_IDX_TYPE_BALANCED_TREE); + ND_Index_Open( &( ( *DS_Ptr_Ptr)->ND_Root), (NDT_Index_Id)i, DBD_IDX_TYPE_BALANCED_TREE); } t_stop( t_exec); @@ -1313,7 +1313,7 @@ void Command_Exec( NDT_Root **DS_Ptr_Ptr, FILE *File_Output, int Choice, cha for( i = high; i >= low; i--) { - ND_Index_Close( *DS_Ptr_Ptr, (NDT_Index_Id)i); + ND_Index_Close( &( ( *DS_Ptr_Ptr)->ND_Root), (NDT_Index_Id)i); } t_stop( t_exec); @@ -1747,7 +1747,7 @@ void Command_Exec( NDT_Root **DS_Ptr_Ptr, FILE *File_Output, int Choice, cha /* Batch_Run */ /*----------------------------------------------------------------------------*/ -void Batch_Run( NDT_Root **DS_Ptr_Ptr, FILE *File_Output, FILE *File_Input, short Interactive_Flag) +void Batch_Run( DST_Root **DS_Ptr_Ptr, FILE *File_Output, FILE *File_Input, short Interactive_Flag) { int choice; char *arg1, *arg2, *arg3; @@ -1786,7 +1786,7 @@ int main( int argc, char **argv) { int rc = 0; LGT_Status lg_status; - NDT_Root *ds_ptr = NULL; + DST_Root *ds_ptr = NULL; if( ( lg_status = LG_Library_Open( LGD_LOG_WRITER_DEFAULT, true)) != LGS_OK)