- Implement DS_DataStruct_Close_I(), DS_DataStruct_Alloc(), DS_DataStruct_Free(),

- Fix DS_Name_Prefix() implementation (As for ShMemLib),
- Debug with dsbech: CREATE_STRUCT, OPEN_STRUCT, CLOSE_STRUCT, DELETE_STRUCT.
This commit is contained in:
Arnaud G. GIBERT 2024-04-28 19:59:38 +02:00
parent d90beb9860
commit 6492980a9b
4 changed files with 383 additions and 191 deletions

View File

@ -144,7 +144,7 @@ typedef int DST_Flags;
typedef struct DST_RootDesc
{
char *Heap_Name;
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 */
@ -384,10 +384,10 @@ DSD_API DST_Status DS_DataStruct_Unlock_CL( NDT_Root * Root);
/* (I) Root : pointeur sur la racine de la structure de données */
/* (I) Close_Mode : mode de fermeture de la structure (destruction ou non) */
/*----------------------------------------------------------------------------*/
/*
DSD_API DST_Status DS_DataStruct_Close_I( NDT_Root * Root, DST_Flags Close_Mode);
DSD_API DST_Status DS_DataStruct_Close_L( NDT_Root * Root, DST_Flags Close_Mode);
DSD_API DST_Status DS_DataStruct_Close_CL( NDT_Root * Root, DST_Flags Close_Mode);
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);

View File

@ -213,15 +213,17 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
int locked, mode;
DST_RootDesc *rootdesc_ptr, rootdesc_tmp;
DST_DataStruct *opened_datastruct_ptr;
char *Prefixed_Name = DS_Name_Prefix( DS_Name);
char prefixed_name[ DSD_NAME_SIZE];
union semun Sem_Ctl;
DS_Name_Prefix( prefixed_name, DS_Name);
*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)
if( SM_Heap_Exist( prefixed_name) == SMS_YES)
{
if( DSD_MSK_OPEN( Open_Mode)) mode = 2;
else if( DSD_MSK_NEW( Open_Mode)) mode = 1;
@ -251,22 +253,30 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
/* Ouverture du heap en écriture */
if( ( status = SM_Heap_Open( Prefixed_Name, &heap_ptr, 0, ( SMD_OPEN | SMD_WRITE), &locked)) != SMS_OK)
if( ( status = SM_Heap_Open( prefixed_name, &heap_ptr, 0, ( SMD_OPEN | SMD_WRITE), &locked)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to open the data structure heap: [%s] for writing, error: (%d)", Prefixed_Name, sm_status);
LG_LOG_ERROR_2( "Unable to open the data structure heap: [%s] for writing, status: (%d)", prefixed_name, sm_status);
return( SMS_KO);
}
/* Création de la node structure */
rootdesc_tmp.Heap_Name = Prefixed_Name;
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)
{
LG_LOG_ERROR_2( "Unable to create a new node structure in the existing heap: [%s], error: (%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);
if( locked == TRUE) SM_Heap_Unlock( heap_ptr);
if( locked == TRUE)
{
if( ( sm_status = SM_Heap_Unlock( heap_ptr)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to unlock the data structure heap: [%s], status: (%d)", heap_ptr->Name, sm_status);
}
}
*Root_Ptr_Ptr = NULL;
return( SMS_KO);
@ -277,17 +287,31 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
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], error: (%d)", heap_ptr->Name, status);
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 ?
SM_Heap_End( Prefixed_Name);
if( locked == TRUE) SM_Heap_Unlock( heap_ptr);
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);
}
rootdesc_ptr->Heap_Name = heap_ptr->Name;
rootdesc_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 */
@ -311,7 +335,8 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
{
if( ( sm_status = SM_Heap_Unlock( heap_ptr)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to unlock the data structure heap: [%s], error: (%d)", heap_ptr->Name, status);
LG_LOG_ERROR_2( "Unable to unlock the data structure heap: [%s], status: (%d)", heap_ptr->Name, sm_status);
return( DSS_KO);
}
}
@ -327,7 +352,7 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
if( ( status = DS_DataStruct_IsOpen( Root_Ptr_Ptr, DS_Name)) != DSS_OK)
{
LG_LOG_ERROR_2( "Unable test data structure: [%s] state, error: (%d)", DS_Name, status);
LG_LOG_ERROR_2( "Unable test data structure: [%s] state, status: (%d)", DS_Name, status);
return( status);
}
@ -342,11 +367,18 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
/* Accès au heap sous-jacent en lecture */
if( ( status = SM_Heap_Open( Prefixed_Name, &heap_ptr, 0, ( SMD_OPEN | SMD_READ), &locked)) != SMS_OK)
if( ( status = SM_Heap_Open( prefixed_name, &heap_ptr, 0, ( SMD_OPEN | SMD_READ), &locked)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to open the data structure heap: [%s] for reading, error: (%d)", heap_ptr->Name, status);
LG_LOG_ERROR_2( "Unable to open the data structure heap: [%s] for reading, status: (%d)", heap_ptr->Name, 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);
}
}
if( locked == TRUE) SM_Heap_Unlock( heap_ptr);
*Root_Ptr_Ptr = NULL;
return( status);
@ -369,7 +401,14 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
{
LG_LOG_ERROR_1( "Data structure [%s] has no description defined", DS_Name);
if( locked == TRUE) SM_Heap_Unlock( heap_ptr);
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);
@ -384,6 +423,7 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
return DSS_ERRDLL;
}
*/
break;
}
@ -399,21 +439,26 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
/* 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)
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], error: (%d)", DS_Name, sm_status);
LG_LOG_ERROR_2( "Unable to create a heap for the data structure [%s], status: (%d)", DS_Name, sm_status);
return( sm_status);
}
/* Création de la structure de données dans le heap */
rootdesc_tmp.Heap_Name = Prefixed_Name;
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)
{
LG_LOG_ERROR_2( "Unable to create a new node structure in new heap: [%s], error: (%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);
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);
}
SM_Heap_End( Prefixed_Name);
*Root_Ptr_Ptr = NULL;
return( SMS_KO);
@ -424,16 +469,21 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
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], error: (%d)", heap_ptr->Name, status);
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);
}
SM_Heap_End( Prefixed_Name);
*Root_Ptr_Ptr = NULL;
return( status);
}
rootdesc_ptr->Heap_Name = heap_ptr->Name;
rootdesc_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 est propriétaire du heap */
@ -455,9 +505,13 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
if( ( status = DS_Semaphore_Create( *Root_Ptr_Ptr)) != DSS_OK)
{
LG_LOG_ERROR_2( "Unable to create a semaphore for the data structure: [%s], error: (%d)", DS_Name, status);
LG_LOG_ERROR_2( "Unable to create a semaphore for the data structure: [%s], status: (%d)", DS_Name, status);
SM_Heap_End( Prefixed_Name);
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);
@ -477,14 +531,24 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
if( ( status = DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Open, 1)) != DSS_OK)
{
LG_LOG_ERROR_2( "Unable to incremente the semaphore of data structure: [%s], error: (%d)", DS_Name, status);
LG_LOG_ERROR_2( "Unable to incremente the semaphore of data structure: [%s], status: (%d)", DS_Name, status);
if( locked == TRUE) SM_Heap_Unlock( heap_ptr);
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);
}
}
if( mode == 3)
{
semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
SM_Heap_End( Prefixed_Name);
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);
}
}
else
{
@ -501,14 +565,24 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
if( ( nd_status = ND_Value_Alloc( (void **)&opened_datastruct_ptr, OpenedDS_List, DS_Name, Root_Ptr_Ptr)) != NDS_OK)
{
LG_LOG_ERROR_2( "Unable to alloc a new opened data structure element: [%s], error: (%d)", DS_Name, nd_status);
LG_LOG_ERROR_2( "Unable to alloc a new opened data structure element: [%s], status: (%d)", DS_Name, nd_status);
if( locked == TRUE) SM_Heap_Unlock( heap_ptr);
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);
}
}
if( mode == 3)
{
semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
SM_Heap_End( Prefixed_Name);
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);
}
}
else
{
@ -522,19 +596,29 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
if( ( nd_status = ND_DataStruct_Value_Add( OpenedDS_List, (void *)opened_datastruct_ptr)) != NDS_OK)
{
LG_LOG_ERROR_2( "Unable to add an new data structure element: [%s] to the opened structure list, error: (%d)", DS_Name, status);
LG_LOG_ERROR_2( "Unable to add an new data structure element: [%s] to the opened structure list, status: (%d)", DS_Name, status);
if( ( nd_status = ND_Value_Free( OpenedDS_List, (void *)opened_datastruct_ptr)) != NDS_OK)
{
LG_LOG_ERROR_2( "Unable to free a new opened data structure element: [%s], error: (%d)", DS_Name, nd_status);
LG_LOG_ERROR_2( "Unable to free a new opened data structure element: [%s], status: (%d)", DS_Name, nd_status);
}
if( locked == TRUE) SM_Heap_Unlock( heap_ptr);
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);
}
}
if( mode == 3)
{
semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
SM_Heap_End( Prefixed_Name);
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);
}
}
else
{
@ -553,22 +637,26 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
{
if( sm_status = ( SM_Heap_Unlock( heap_ptr)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to unlock the data structure heap: [%s], status: (%d)", Prefixed_Name, sm_status);
LG_LOG_ERROR_2( "Unable to unlock the data structure heap: [%s], status: (%d)", prefixed_name, sm_status);
if( ( nd_status = ND_DataStruct_Value_Remove( OpenedDS_List, opened_datastruct_ptr)) != NDS_OK)
{
LG_LOG_ERROR_2( "Unable to remove a data structure element: [%s] to the opened structure list, error: (%d)", DS_Name, status);
LG_LOG_ERROR_2( "Unable to remove a data structure element: [%s] to the opened structure list, status: (%d)", DS_Name, status);
}
if( ( nd_status = ND_Value_Free( OpenedDS_List, opened_datastruct_ptr)) != NDS_OK)
{
LG_LOG_ERROR_2( "Unable to free a new opened data structure element: [%s], error: (%d)", DS_Name, nd_status);
LG_LOG_ERROR_2( "Unable to free a new opened data structure element: [%s], status: (%d)", DS_Name, nd_status);
}
if( mode == 3)
{
semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
SM_Heap_End( Prefixed_Name);
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);
}
}
else
{
@ -656,64 +744,65 @@ DST_Status DS_DataStruct_Unlock_I ( NDT_Root * Root )
/* (I) Root : pointeur sur la racine de la structure de données à fermer */
/* (I) Close_Mode : mode de fermeture de la structure (destruction ou non) */
/*----------------------------------------------------------------------------*/
/*
DST_Status DS_DataStruct_Close_I ( NDT_Root * Root, DST_Flags Close_Mode )
DST_Status DS_DataStruct_Close_I( NDT_Root *Root_Ptr, DST_Flags Close_Mode)
{
DST_Status rc;
SMT_Heap * Heap;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
char Heap_Name [256], * DS_Name;
DST_DataStruct To_Remove, * Opened_DataStruct;
union semun Sem_Ctl;
DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr);
strcpy (Heap_Name, RootDesc->Heap_Name);
DST_Status status;
NDT_Status nd_status;
SMT_Status sm_status;
SMT_Heap *heap_ptr;
char heap_name[ DSD_NAME_SIZE], *ds_name;
DST_DataStruct to_remove, *opened_datastruct_ptr;
union semun sem_ctl;
DS_Name = strstr (Heap_Name, DS_PREFIX);
if (DS_Name) DS_Name += strlen (DS_PREFIX) + 1;
else DS_Name = Heap_Name;
strcpy( heap_name, RootDesc_Ptr->Heap_Name);
if (Close_Mode == DSD_DESTROY) /* Destruction de la data structure */
/* {
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->Heap_Owner == TRUE)
if( RootDesc_Ptr->Heap_Owner == TRUE)
{
/* On vérifie qu'aucun autre processus n'a ouvert la data structure */
/*
rc = DS_Semaphore_Operate (RootDesc->OpenSemId, DS_SemOp_Destroy, 2);
if (rc != DSS_OK)
if( ( status = DS_Semaphore_Operate( RootDesc_Ptr->OpenSemId, DS_SemOp_Destroy, 2)) != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Close : unable to destroy the data structure \"%s\" because it is opened by another process", DS_Name);
LG_LOG_ERROR_1( "Unable to destroy the data structure: [%s] because it is opened by another process", ds_name);
DS_Error_Print ();
return rc;
return( status);
}
/* On supprime la structure proprement (toutes les valeurs sont supprimées les unes après les autres) */
/*
rc = ND_DataStruct_Close (Root);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Close : unable to close the node structure of \"%s\" data structure", DS_Name);
DS_Error_Print ();
return rc;
if( ( nd_status =ND_DataStruct_Close( Root_Ptr)) != 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);
}
/* Suppression du sémaphore */
/*
semctl (RootDesc->OpenSemId, 0, IPC_RMID, Sem_Ctl);
semctl( RootDesc_Ptr->OpenSemId, 0, IPC_RMID, sem_ctl);
/* On supprime maintenant le heap */
/*
rc = SM_Heap_End (Heap_Name);
if (rc != SMS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Close : unable to remove heap \"%s\"", Heap_Name);
DS_Error_Print ();
return rc;
if( ( sm_status = SM_Heap_End( heap_name)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to remove the heap: [%s], status: (%d)", heap_name, sm_status);
return( DSS_KO);
}
}
else
@ -724,55 +813,89 @@ DST_Status DS_DataStruct_Close_I ( NDT_Root * Root, DST_Flags Close_Mode )
On la supprime donc sans contrôle.
*/
/*
rc = ND_DataStruct_Close (Root);
if (rc != NDS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Close : unable to close the node structure of \"%s\" data structure", DS_Name);
DS_Error_Print ();
return rc;
if( ( nd_status = ND_DataStruct_Close( Root_Ptr)) != 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);
}
return DS_DataStruct_Free (RootDesc, (void *)RootDesc);
if( ( status = DS_DataStruct_Free( RootDesc_Ptr, (void *)RootDesc_Ptr)) != DSS_OK)
{
LG_LOG_ERROR_2( "Unable to free data structure: [%s], status: (%d)", ds_name, status);
return( status);
}
return( DSS_OK);
}
}
else /* Fermeture simple de la data structure */
/* {
{
/* On décrémente le sémaphore qui compte le nombre de processus ayant ouvert la data structure */
/*
rc = DS_Semaphore_Operate (RootDesc->OpenSemId, DS_SemOp_Close, 1);
if (rc != DSS_OK)
if( ( status = DS_Semaphore_Operate( RootDesc_Ptr->OpenSemId, DS_SemOp_Close, 1)) != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to decremente the semaphore of data structure \"%s\"", DS_Name);
DS_Error_Print ();
LG_LOG_ERROR_1( "Unable to decremente the semaphore of data structure: [%s]", ds_name);
return rc;
return( status);
}
/* Fermeture simple du heap */
/*
rc = SM_Heap_IsOpen (Heap_Name, &Heap);
if (rc == SMS_YES)
{
rc = SM_Heap_Close (Heap);
if (rc != SMS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Close : unable to close heap \"%s\"", Heap_Name);
DS_Error_Print ();
return rc;
if( ( sm_status = SM_Heap_IsOpen( heap_name, &heap_ptr)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to check if heap: [%s] is open, status: (%d)", heap_name, sm_status);
return( DSS_KO);
}
else
{
if( heap_ptr != NULL)
{
if( ( sm_status = SM_Heap_Close( heap_ptr)) != SMS_OK)
{
LG_LOG_ERROR_2( "Unable to close heap: [%s], status: (%d)", heap_name, sm_status);
return( DSS_KO);
}
}
}
}
/* Suppression de la data structure de la liste des structures ouvertes */
/*
To_Remove.Name = DS_Name;
rc = ND_Value_Remove (OpenedDS_List, &To_Remove, (void **)&Opened_DataStruct);
if (rc == NDS_OK) ND_Value_Free (OpenedDS_List, Opened_DataStruct);
return DSS_OK;
to_remove.Name = ds_name;
if( ( nd_status = ND_DataStruct_Value_Find( ( void **)&opened_datastruct_ptr, OpenedDS_List, &to_remove)) != NDS_OK)
{
LG_LOG_ERROR_2( "Unable to find data struct element: [%s] from opened structure list, status: (%d)", ds_name, nd_status);
return( DSS_KO);
}
else
{
if( ( nd_status = ND_DataStruct_Value_Remove( OpenedDS_List, opened_datastruct_ptr)) != NDS_OK)
{
LG_LOG_ERROR_2( "Unable to remove data struct element: [%s] from opened structure list, status: (%d)", ds_name, nd_status);
return( DSS_KO);
}
else
{
if( ( nd_status = ND_Value_Free( OpenedDS_List, opened_datastruct_ptr)) != NDS_OK)
{
LG_LOG_ERROR_2( "Unable to free data struct element: [%s] from opened structure list, status: (%d)", ds_name, nd_status);
return( DSS_KO);
}
}
}
return( DSS_OK);
}
@ -786,18 +909,19 @@ DST_Status DS_DataStruct_Close_I ( NDT_Root * Root, DST_Flags Close_Mode )
DST_Status DS_DataStruct_Info_Print_I( FILE *Out, NDT_Root *Root_Ptr)
{
DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr);
DST_Status status;
NDT_Status nd_status;
DST_RootDesc *rootdesc_ptr = (DST_RootDesc *)(Root_Ptr->User_Ptr);
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));
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));
/* On vérifie que la data structure est valide */
if( rootdesc_ptr->Valid == FALSE)
if( RootDesc_Ptr->Valid == FALSE)
{
int Nb_Detected, Nb_Corrected;
@ -826,6 +950,11 @@ DST_Status DS_DataStruct_Info_Print_I( FILE *Out, NDT_Root *Root_Ptr)
return( DSS_KO);
}
/* Dump SM */
SM_Library_Dump( stderr);
return( DSS_OK);
}
@ -3020,7 +3149,7 @@ DST_Status DS_DataStruct_IsOpen( NDT_Root **Root_Ptr_Ptr, char *DS_Name)
if( ( nd_status = ND_DataStruct_Value_Find( (void **)&found_ptr, OpenedDS_List, &to_find)) != NDS_OK)
{
LG_LOG_ERROR_2( "Can't lookup for opened data structure: [%s], error: (%d)", DS_Name, nd_status);
LG_LOG_ERROR_2( "Can't lookup for opened data structure: [%s], status: (%d)", DS_Name, nd_status);
return( DSS_KO);
}
@ -3049,7 +3178,7 @@ 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, size_t Size, void *Data_Ptr)
{
DST_Status status;
SMT_Status sm_status;
@ -3071,7 +3200,7 @@ 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, error: (%d)", RootDesc->Heap_Name, sm_status);
LG_LOG_ERROR_2( "Unable to lock the data structure heap: [%s] for writing, status: (%d)", RootDesc->Heap_Name, sm_status);
return( DSS_OK);
}
@ -3081,7 +3210,7 @@ DST_Status DS_DataStruct_Alloc ( void **Ptr_Ptr, size_t Size, void *Data_Ptr)
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, error: (%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, RootDesc->Heap_Name, sm_status);
if( locked == TRUE) SM_Heap_Unlock( heap_ptr);
return( DSS_KO);
@ -3090,59 +3219,93 @@ 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) SM_Heap_Unlock( heap_ptr);
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);
}
}
return DSS_OK;
return( DSS_OK);
}
/*----------------------------------------------------------------------------*/
/* 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, void *Data_Ptr)
{
DST_Status rc;
SMT_Heap * Heap;
int Locked;
DST_RootDesc * RootDesc = (DST_RootDesc *)Data;
char * Heap_Name = RootDesc->Heap_Name;
DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)Data_Ptr;
char *Heap_Name = RootDesc_Ptr->Heap_Name;
rc = SM_Heap_IsOpen (Heap_Name, &Heap);
if (rc != SMS_YES)
DST_Status status;
SMT_Status sm_status;
SMT_Heap *heap_ptr;
int locked;
if( ( sm_status = SM_Heap_IsOpen( Heap_Name, &heap_ptr)) != SMS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Free : the data structure heap \"%s\" is not open", Heap_Name);
DS_Error_Print ();
LG_LOG_ERROR_2( "Unable to check if heap: [%s] is open, status: (%d)", Heap_Name, sm_status);
return rc;
return( DSS_KO);
}
else
{
if( heap_ptr == NULL)
{
LG_LOG_ERROR_1( "DatatStructure heap: [%s] is not open", Heap_Name);
return( DSS_KO);
}
}
/* Verrouillage de la data structure en écriture */
/*
rc = SM_Heap_Lock (Heap, SMD_WRITE, &Locked);
if (rc != DSS_OK)
{
sprintf (DS_Error_Msg, "Error DS_DataStruct_Free : unable to lock the data structure heap \"%s\" for writing", Heap_Name);
DS_Error_Print ();
return rc;
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_ptr->Name, sm_status);
return( DSS_KO);
}
/* Désallocation du chunk */
/*
rc = SM_Chunk_Free (Heap, Ptr);
if (rc != SMS_OK)
if( ( sm_status = SM_Chunk_Free( heap_ptr, Ptr)) != SMS_OK)
{
if (Locked == TRUE) SM_Heap_Unlock (Heap);
return rc;
LG_LOG_ERROR_3( "Unable to free a chuck: [%p] from the datastructure heap: [%s], status: [%s]", Ptr, heap_ptr->Name, sm_status);
status = DSS_KO;
}
else
{
status = DSS_OK;
}
/* Déverrouillage de la data structure si besoin */
/*
if (Locked == TRUE) SM_Heap_Unlock (Heap);
return DSS_OK;
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);
}
/*----------------------------------------------------------------------------*/
/* Routine d'affichage d'un message d'erreur */
/*----------------------------------------------------------------------------*/
@ -3152,35 +3315,40 @@ void DS_Error_Print ( void )
if (DS_stderr) fprintf (DS_stderr, "%s\n", DS_Error_Msg);
}
/*----------------------------------------------------------------------------*/
/* Pour préfixer les noms de heap avec l'identifiant de la librairie */
/*----------------------------------------------------------------------------*/
static char *DS_Name_Prefix( const char *Name )
DST_Status DS_Name_Prefix( char *Prefixed_Name_Ptr, const char *Unprefixed_Name_Ptr)
{
static char Prefixed [256];
snprintf( Prefixed_Name_Ptr, DSD_NAME_SIZE, "%s/%s", DS_PREFIX, Unprefixed_Name_Ptr);
sprintf (Prefixed, "%s/%s", DS_PREFIX, Name);
return( Prefixed);
return( DSS_OK);
}
/*----------------------------------------------------------------------------*/
/* 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_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr);
union semun sem_ctl;
DST_RootDesc *rootdesc_ptr = (DST_RootDesc *)(Root_Ptr->User_Ptr);
/* Création du sémaphore */
rootdesc_ptr->OpenSemId = semget( IPC_PRIVATE, 1, ( 0777 | IPC_CREAT | IPC_EXCL));
if( rootdesc_ptr->OpenSemId == -1)
RootDesc_Ptr->OpenSemId = semget( IPC_PRIVATE, 1, ( 0777 | IPC_CREAT | IPC_EXCL));
if( RootDesc_Ptr->OpenSemId == -1)
{
switch( errno)
{
@ -3214,11 +3382,11 @@ 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))
{
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)", RootDesc_Ptr->OpenSemId);
semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, sem_ctl);
semctl( RootDesc_Ptr->OpenSemId, 0, IPC_RMID, sem_ctl);
return( DSS_ERRSEM);
}
@ -3228,13 +3396,15 @@ DST_Status DS_Semaphore_Create ( NDT_Root *Root_Ptr)
/*----------------------------------------------------------------------------*/
/* Opération sur un sémaphore */
/*----------------------------------------------------------------------------*/
DST_Status DS_Semaphore_Operate( int SemID, struct sembuf *Operations, unsigned int Nb_Oper)
DST_Status DS_Semaphore_Operate( int SemId, struct sembuf *Operations, unsigned int Nb_Oper)
{
if( semop( SemID, Operations, Nb_Oper) == -1)
if( semop( SemId, Operations, Nb_Oper) == -1)
{
switch( errno)
{
@ -3247,28 +3417,28 @@ DST_Status DS_Semaphore_Operate( int SemID, struct sembuf *Operations, unsign
case EACCES:
{
LG_LOG_ERROR_1( "Current process is not allowed to operate on semaphore: (%x)", SemID);
LG_LOG_ERROR_1( "Current process is not allowed to operate on semaphore: (%x)", SemId);
break;
}
case EIDRM:
{
LG_LOG_ERROR_1( "Semaphore: (%x) does not exist", SemID);
LG_LOG_ERROR_1( "Semaphore: (%x) does not exist", SemId);
break;
}
case EINTR:
{
LG_LOG_ERROR_1( "A signal was received while operating on semaphore: (%x)", SemID);
LG_LOG_ERROR_1( "A signal was received while operating on semaphore: (%x)", SemId);
return( DSS_ERRSIG);
}
case EINVAL:
{
LG_LOG_ERROR_1( "The semaphore key: (%x) is incorrect or the number of operations which can be done in UNDO mode exceeds the system-imposed limit", SemID);
LG_LOG_ERROR_1( "The semaphore key: (%x) is incorrect or the number of operations which can be done in UNDO mode exceeds the system-imposed limit", SemId);
break;
}
@ -3282,14 +3452,14 @@ DST_Status DS_Semaphore_Operate( int SemID, struct sembuf *Operations, unsign
case ERANGE:
{
LG_LOG_ERROR_1( "The value of semaphore: (%x) has reached the system-imposed limit", SemID);
LG_LOG_ERROR_1( "The value of semaphore: (%x) has reached the system-imposed limit", SemId);
break;
}
default:
{
LG_LOG_ERROR_2( "Unknown error: (%d) while operating on semaphore: (%x)", errno, SemID);
LG_LOG_ERROR_2( "Unknown error: (%d) while operating on semaphore: (%x)", errno, SemId);
break;
}
@ -3303,6 +3473,8 @@ DST_Status DS_Semaphore_Operate( int SemID, struct sembuf *Operations, unsign
/*----------------------------------------------------------------------------*/
/* Fonction manager de la liste des DS ouvertes */
/*----------------------------------------------------------------------------*/

View File

@ -133,7 +133,10 @@ DST_Status DS_DataStruct_Alloc ( void **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, void *Data );
/*----------------------------------------------------------------------------*/
/* Routine d'affichage d'un message d'erreur */
@ -145,7 +148,8 @@ void DS_Error_Print ( void );
/*----------------------------------------------------------------------------*/
/* Pour préfixer les noms de heap avec l'identifiant de la librairie */
/*----------------------------------------------------------------------------*/
static char *DS_Name_Prefix (const char *Name);
DST_Status DS_Name_Prefix( char *Prefixed, const char *Unprefixed);

View File

@ -636,23 +636,25 @@ int main( int argc, char **argv)
LG_LOG_ERROR_1( "Can't create data structure: (%d)", status);
}
else
{
// strcpy( Root->Manager, "Module_Manager");
{
LG_LOG_INFO_1( "Data structure: [%s] created", DataStruct_Name);
}
}
break;
}
/*
case DELETE_STRUCT:
{
if (DS_DataStruct_Close (Root, DSD_DESTROY) == DSS_KO) printf ("\nNOK\n");
if( ( status = DS_DataStruct_Close( Root_Ptr, DSD_DESTROY)) != DSS_OK)
{
LG_LOG_ERROR_2( "Can't delete data structure: [%s], status: (%d)", DataStruct_Name, status);
}
else
{
printf ("\nStructure détruite : OK\n");
Root = NULL;
LG_LOG_INFO_1( "Data structure: [%s] deleted", DataStruct_Name);
Root_Ptr = NULL;
}
break;
@ -661,28 +663,42 @@ int main( int argc, char **argv)
case OPEN_STRUCT:
{
fprintf (stdout, "\nNom de la structure à ouvrir ? ");
gets (DataStruct_Name);
if (DS_DataStruct_Open (DataStruct_Name, &Root, 0, NULL, 0, DSD_OPEN, TRUE) == NDS_KO)
printf ("\nNOK\n");
fgets( DataStruct_Name, 100, stdin);
if( strlen( DataStruct_Name) < 2)
{
fprintf( stdout, "Bad name!\n");
}
else
printf ("\nStructure ouverte : OK\n");
{
DataStruct_Name[ strlen( DataStruct_Name) - 1] = 0;
if( ( status = DS_DataStruct_Open( &Root_Ptr, DataStruct_Name, 1, &index_type, "Module_Manager", 0, DSD_OPEN, TRUE)) != DSS_OK)
{
LG_LOG_ERROR_1( "Can't open data structure: (%d)", status);
}
else
{
LG_LOG_INFO_1( "Data structure: [%s] opened", DataStruct_Name);
}
}
break;
}
case CLOSE_STRUCT:
{
if (DS_DataStruct_Close (Root, DSD_CLOSE) == DSS_KO) printf ("\nNOK\n");
if( ( status = DS_DataStruct_Close( Root_Ptr, DSD_CLOSE) != DSS_OK))
{
LG_LOG_ERROR_1( "Can't close data structure: (%d)", status);
}
else
{
printf ("\nStructure fermée : OK\n");
Root = NULL;
LG_LOG_INFO_1( "Data structure: [%s] Closed", DataStruct_Name);
Root_Ptr = NULL;
}
break;
}
/*
case FIND_VALUE:
{
fprintf (stdout, "\nPlage de recherche (?->?) : ");