- 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:
parent
d90beb9860
commit
6492980a9b
@ -144,7 +144,7 @@ typedef int DST_Flags;
|
|||||||
|
|
||||||
typedef struct DST_RootDesc
|
typedef struct DST_RootDesc
|
||||||
{
|
{
|
||||||
char *Heap_Name;
|
char Heap_Name[ DSD_NAME_SIZE];
|
||||||
char *Manager_Name;
|
char *Manager_Name;
|
||||||
int OpenSemId; /* Indique le nombre de processus ayant ouvert la struture */
|
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 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) Root : pointeur sur la racine de la structure de données */
|
||||||
/* (I) Close_Mode : mode de fermeture de la structure (destruction ou non) */
|
/* (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_I( NDT_Root *Root_Ptr, 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_L( NDT_Root *Root_Ptr, 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_CL( NDT_Root *Root_Ptr, DST_Flags Close_Mode);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
506
lib/libdatastr.c
506
lib/libdatastr.c
@ -213,15 +213,17 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
|
|||||||
int locked, mode;
|
int locked, mode;
|
||||||
DST_RootDesc *rootdesc_ptr, rootdesc_tmp;
|
DST_RootDesc *rootdesc_ptr, rootdesc_tmp;
|
||||||
DST_DataStruct *opened_datastruct_ptr;
|
DST_DataStruct *opened_datastruct_ptr;
|
||||||
char *Prefixed_Name = DS_Name_Prefix( DS_Name);
|
char prefixed_name[ DSD_NAME_SIZE];
|
||||||
union semun Sem_Ctl;
|
union semun Sem_Ctl;
|
||||||
|
|
||||||
|
|
||||||
|
DS_Name_Prefix( prefixed_name, DS_Name);
|
||||||
|
|
||||||
*Root_Ptr_Ptr = NULL;
|
*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 */
|
/* 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;
|
if( DSD_MSK_OPEN( Open_Mode)) mode = 2;
|
||||||
else if( DSD_MSK_NEW( Open_Mode)) mode = 1;
|
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 */
|
/* 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);
|
return( SMS_KO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Création de la node structure */
|
/* 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)
|
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)
|
||||||
|
{
|
||||||
|
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;
|
*Root_Ptr_Ptr = NULL;
|
||||||
|
|
||||||
return( SMS_KO);
|
return( SMS_KO);
|
||||||
@ -277,16 +287,30 @@ 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)
|
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 ?
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SM_Heap_End( Prefixed_Name);
|
|
||||||
if( locked == TRUE) SM_Heap_Unlock( heap_ptr);
|
|
||||||
*Root_Ptr_Ptr = NULL;
|
*Root_Ptr_Ptr = NULL;
|
||||||
|
|
||||||
return( status);
|
return( status);
|
||||||
}
|
}
|
||||||
|
|
||||||
rootdesc_ptr->Heap_Name = heap_ptr->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;
|
rootdesc_ptr->Manager_Name = ( *Root_Ptr_Ptr)->Manager_Name;
|
||||||
|
|
||||||
|
|
||||||
@ -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)
|
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);
|
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)
|
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);
|
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 */
|
/* 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;
|
*Root_Ptr_Ptr = NULL;
|
||||||
|
|
||||||
return( status);
|
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);
|
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;
|
*Root_Ptr_Ptr = NULL;
|
||||||
|
|
||||||
return( DSS_ERRAPI);
|
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;
|
return DSS_ERRDLL;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
break;
|
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 */
|
/* 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);
|
return( sm_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Création de la structure de données dans le heap */
|
/* 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)
|
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;
|
*Root_Ptr_Ptr = NULL;
|
||||||
|
|
||||||
return( SMS_KO);
|
return( SMS_KO);
|
||||||
@ -424,15 +469,20 @@ 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)
|
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;
|
*Root_Ptr_Ptr = NULL;
|
||||||
|
|
||||||
return( status);
|
return( status);
|
||||||
}
|
}
|
||||||
|
|
||||||
rootdesc_ptr->Heap_Name = heap_ptr->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;
|
rootdesc_ptr->Manager_Name = ( *Root_Ptr_Ptr)->Manager_Name;
|
||||||
|
|
||||||
|
|
||||||
@ -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)
|
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);
|
||||||
|
|
||||||
|
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;
|
*Root_Ptr_Ptr = NULL;
|
||||||
|
|
||||||
return( status);
|
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)
|
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)
|
if( mode == 3)
|
||||||
{
|
{
|
||||||
semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
|
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
|
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)
|
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)
|
if( mode == 3)
|
||||||
{
|
{
|
||||||
semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
|
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
|
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)
|
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)
|
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)
|
if( mode == 3)
|
||||||
{
|
{
|
||||||
semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
|
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
|
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)
|
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)
|
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)
|
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)
|
if( mode == 3)
|
||||||
{
|
{
|
||||||
semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
|
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
|
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) Root : pointeur sur la racine de la structure de données à fermer */
|
||||||
/* (I) Close_Mode : mode de fermeture de la structure (destruction ou non) */
|
/* (I) 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;
|
DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr);
|
||||||
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;
|
|
||||||
|
|
||||||
strcpy (Heap_Name, RootDesc->Heap_Name);
|
DST_Status status;
|
||||||
|
NDT_Status nd_status;
|
||||||
|
SMT_Status sm_status;
|
||||||
|
|
||||||
DS_Name = strstr (Heap_Name, DS_PREFIX);
|
SMT_Heap *heap_ptr;
|
||||||
if (DS_Name) DS_Name += strlen (DS_PREFIX) + 1;
|
char heap_name[ DSD_NAME_SIZE], *ds_name;
|
||||||
else DS_Name = Heap_Name;
|
DST_DataStruct to_remove, *opened_datastruct_ptr;
|
||||||
|
union semun sem_ctl;
|
||||||
|
|
||||||
|
|
||||||
|
strcpy( heap_name, RootDesc_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 */
|
if( Close_Mode == DSD_DESTROY) /* Destruction de la data structure */
|
||||||
/* {
|
{
|
||||||
/* La data structure est-elle propriétaire du heap sous-jacent ? */
|
/* 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 */
|
/* On vérifie qu'aucun autre processus n'a ouvert la data structure */
|
||||||
/*
|
|
||||||
rc = DS_Semaphore_Operate (RootDesc->OpenSemId, DS_SemOp_Destroy, 2);
|
if( ( status = DS_Semaphore_Operate( RootDesc_Ptr->OpenSemId, DS_SemOp_Destroy, 2)) != DSS_OK)
|
||||||
if (rc != 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( status);
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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;
|
/* 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)
|
||||||
|
{
|
||||||
|
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 */
|
/* 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 */
|
/* 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
|
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.
|
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 */
|
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)
|
|
||||||
{
|
{
|
||||||
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to decremente the semaphore of data structure \"%s\"", DS_Name);
|
/* On décrémente le sémaphore qui compte le nombre de processus ayant ouvert la data structure */
|
||||||
DS_Error_Print ();
|
|
||||||
|
|
||||||
return rc;
|
if( ( status = DS_Semaphore_Operate( RootDesc_Ptr->OpenSemId, DS_SemOp_Close, 1)) != DSS_OK)
|
||||||
|
{
|
||||||
|
LG_LOG_ERROR_1( "Unable to decremente the semaphore of data structure: [%s]", ds_name);
|
||||||
|
|
||||||
|
return( status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Fermeture simple du heap */
|
/* 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 */
|
/* 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_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;
|
DST_Status status;
|
||||||
NDT_Status nd_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]",
|
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 */
|
/* On vérifie que la data structure est valide */
|
||||||
|
|
||||||
if( rootdesc_ptr->Valid == FALSE)
|
if( RootDesc_Ptr->Valid == FALSE)
|
||||||
{
|
{
|
||||||
int Nb_Detected, Nb_Corrected;
|
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);
|
return( DSS_KO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Dump SM */
|
||||||
|
|
||||||
|
SM_Library_Dump( stderr);
|
||||||
|
|
||||||
return( DSS_OK);
|
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)
|
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);
|
return( DSS_KO);
|
||||||
}
|
}
|
||||||
@ -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)
|
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);
|
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)
|
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);
|
if( locked == TRUE) SM_Heap_Unlock( heap_ptr);
|
||||||
return( DSS_KO);
|
return( DSS_KO);
|
||||||
@ -3090,58 +3219,92 @@ DST_Status DS_DataStruct_Alloc ( void **Ptr_Ptr, size_t Size, void *Data_Ptr)
|
|||||||
|
|
||||||
/* Déverrouillage de la data structure si besoin */
|
/* Déverrouillage de la data structure si besoin */
|
||||||
|
|
||||||
if( locked == TRUE) SM_Heap_Unlock( heap_ptr);
|
if( locked == TRUE)
|
||||||
|
{
|
||||||
return DSS_OK;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* Fonction de désallocation attachée à une structure de données : */
|
/* Fonction de désallocation attachée à une structure de données : */
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/*
|
|
||||||
DST_Status DS_DataStruct_Free ( void * Ptr, void * Data )
|
|
||||||
{
|
|
||||||
DST_Status rc;
|
|
||||||
SMT_Heap * Heap;
|
|
||||||
int Locked;
|
|
||||||
DST_RootDesc * RootDesc = (DST_RootDesc *)Data;
|
|
||||||
char * Heap_Name = RootDesc->Heap_Name;
|
|
||||||
|
|
||||||
rc = SM_Heap_IsOpen (Heap_Name, &Heap);
|
DST_Status DS_DataStruct_Free( void *Ptr, void *Data_Ptr)
|
||||||
if (rc != SMS_YES)
|
|
||||||
{
|
{
|
||||||
sprintf (DS_Error_Msg, "Error DS_DataStruct_Free : the data structure heap \"%s\" is not open", Heap_Name);
|
DST_RootDesc *RootDesc_Ptr = (DST_RootDesc *)Data_Ptr;
|
||||||
DS_Error_Print ();
|
char *Heap_Name = RootDesc_Ptr->Heap_Name;
|
||||||
|
|
||||||
return rc;
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
LG_LOG_ERROR_1( "DatatStructure heap: [%s] is not open", Heap_Name);
|
||||||
|
|
||||||
|
return( DSS_KO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Verrouillage de la data structure en écriture */
|
/* 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 */
|
/* Désallocation du chunk */
|
||||||
/*
|
|
||||||
rc = SM_Chunk_Free (Heap, Ptr);
|
if( ( sm_status = SM_Chunk_Free( heap_ptr, Ptr)) != SMS_OK)
|
||||||
if (rc != SMS_OK)
|
|
||||||
{
|
{
|
||||||
if (Locked == TRUE) SM_Heap_Unlock (Heap);
|
LG_LOG_ERROR_3( "Unable to free a chuck: [%p] from the datastructure heap: [%s], status: [%s]", Ptr, heap_ptr->Name, sm_status);
|
||||||
return rc;
|
|
||||||
|
status = DSS_KO;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = DSS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Déverrouillage de la data structure si besoin */
|
/* 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 */
|
/* 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);
|
if (DS_stderr) fprintf (DS_stderr, "%s\n", DS_Error_Msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* Pour préfixer les noms de heap avec l'identifiant de la librairie */
|
/* 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( DSS_OK);
|
||||||
|
|
||||||
return( Prefixed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* Création d'un sémaphore pour gérer l'ouverture d'une data structure */
|
/* 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_RootDesc *RootDesc_Ptr = (DST_RootDesc *)( Root_Ptr->User_Ptr);
|
||||||
|
|
||||||
union semun sem_ctl;
|
union semun sem_ctl;
|
||||||
DST_RootDesc *rootdesc_ptr = (DST_RootDesc *)(Root_Ptr->User_Ptr);
|
|
||||||
|
|
||||||
|
|
||||||
/* Création du sémaphore */
|
/* Création du sémaphore */
|
||||||
|
|
||||||
rootdesc_ptr->OpenSemId = semget( IPC_PRIVATE, 1, ( 0777 | IPC_CREAT | IPC_EXCL));
|
RootDesc_Ptr->OpenSemId = semget( IPC_PRIVATE, 1, ( 0777 | IPC_CREAT | IPC_EXCL));
|
||||||
if( rootdesc_ptr->OpenSemId == -1)
|
if( RootDesc_Ptr->OpenSemId == -1)
|
||||||
{
|
{
|
||||||
switch( errno)
|
switch( errno)
|
||||||
{
|
{
|
||||||
@ -3214,11 +3382,11 @@ DST_Status DS_Semaphore_Create ( NDT_Root *Root_Ptr)
|
|||||||
|
|
||||||
sem_ctl.val = 0;
|
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);
|
return( DSS_ERRSEM);
|
||||||
}
|
}
|
||||||
@ -3228,13 +3396,15 @@ DST_Status DS_Semaphore_Create ( NDT_Root *Root_Ptr)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* Opération sur un sémaphore */
|
/* 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)
|
switch( errno)
|
||||||
{
|
{
|
||||||
@ -3247,28 +3417,28 @@ DST_Status DS_Semaphore_Operate( int SemID, struct sembuf *Operations, unsign
|
|||||||
|
|
||||||
case EACCES:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EIDRM:
|
case EIDRM:
|
||||||
{
|
{
|
||||||
LG_LOG_ERROR_1( "Semaphore: (%x) does not exist", SemID);
|
LG_LOG_ERROR_1( "Semaphore: (%x) does not exist", SemId);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EINTR:
|
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);
|
return( DSS_ERRSIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
case EINVAL:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
@ -3282,14 +3452,14 @@ DST_Status DS_Semaphore_Operate( int SemID, struct sembuf *Operations, unsign
|
|||||||
|
|
||||||
case ERANGE:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
@ -3303,6 +3473,8 @@ DST_Status DS_Semaphore_Operate( int SemID, struct sembuf *Operations, unsign
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* Fonction manager de la liste des DS ouvertes */
|
/* Fonction manager de la liste des DS ouvertes */
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -133,8 +133,11 @@ DST_Status DS_DataStruct_Alloc ( void **Ptr, size_t Size, void *Data );
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* Fonction de désallocation attachée à une structure de données : */
|
/* 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 */
|
/* 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 */
|
/* 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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -637,22 +637,24 @@ int main( int argc, char **argv)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// strcpy( Root->Manager, "Module_Manager");
|
|
||||||
|
|
||||||
LG_LOG_INFO_1( "Data structure: [%s] created", DataStruct_Name);
|
LG_LOG_INFO_1( "Data structure: [%s] created", DataStruct_Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
case DELETE_STRUCT:
|
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
|
else
|
||||||
{
|
{
|
||||||
printf ("\nStructure détruite : OK\n");
|
LG_LOG_INFO_1( "Data structure: [%s] deleted", DataStruct_Name);
|
||||||
Root = NULL;
|
|
||||||
|
Root_Ptr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -661,28 +663,42 @@ int main( int argc, char **argv)
|
|||||||
case OPEN_STRUCT:
|
case OPEN_STRUCT:
|
||||||
{
|
{
|
||||||
fprintf (stdout, "\nNom de la structure à ouvrir ? ");
|
fprintf (stdout, "\nNom de la structure à ouvrir ? ");
|
||||||
gets (DataStruct_Name);
|
fgets( DataStruct_Name, 100, stdin);
|
||||||
|
if( strlen( DataStruct_Name) < 2)
|
||||||
if (DS_DataStruct_Open (DataStruct_Name, &Root, 0, NULL, 0, DSD_OPEN, TRUE) == NDS_KO)
|
{
|
||||||
printf ("\nNOK\n");
|
fprintf( stdout, "Bad name!\n");
|
||||||
|
}
|
||||||
else
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case CLOSE_STRUCT:
|
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
|
else
|
||||||
{
|
{
|
||||||
printf ("\nStructure fermée : OK\n");
|
LG_LOG_INFO_1( "Data structure: [%s] Closed", DataStruct_Name);
|
||||||
Root = NULL;
|
Root_Ptr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
case FIND_VALUE:
|
case FIND_VALUE:
|
||||||
{
|
{
|
||||||
fprintf (stdout, "\nPlage de recherche (?->?) : ");
|
fprintf (stdout, "\nPlage de recherche (?->?) : ");
|
||||||
|
Loading…
Reference in New Issue
Block a user