- Succed to compile DS_DataStruct_Open_I() full implementation. Tests needed!

This commit is contained in:
Arnaud G. GIBERT 2024-04-27 20:00:00 +02:00
parent 0c06f14b49
commit d90beb9860
3 changed files with 206 additions and 104 deletions

View File

@ -134,8 +134,8 @@ typedef int DST_Flags;
#define DSD_BOOL_VALUE_ASCII_GET( v) ( ( (v) == true) ? "TRUE" : "FALSE") #define DSD_BOOL_VALUE_ASCII_GET( v) ( ( (v) == true) ? "TRUE" : "FALSE")
#define SDD_NAME_LEN ( short)SMD_NAME_SIZE #define DSD_NAME_LEN ( short)SMD_NAME_LEN
#define SDD_NAME_SIZE ( SDD_NAME_LEN + 1) #define DSD_NAME_SIZE ( DSD_NAME_LEN + 1)
/* /*
On utilise le pointeur 'User' de la racine de la struture pour y On utilise le pointeur 'User' de la racine de la struture pour y

View File

@ -206,11 +206,13 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
DST_Status status; DST_Status status;
SMT_Status sm_status; SMT_Status sm_status;
NDT_Status nd_status; NDT_Status nd_status;
SMT_Heap *heap_ptr; SMT_Heap *heap_ptr;
SMT_DSH *dsh_ptr; SMT_DSH *dsh_ptr;
int locked, mode; int locked, mode;
DST_RootDesc *rootdesc_ptr, rootdesc_tmp; DST_RootDesc *rootdesc_ptr, rootdesc_tmp;
DST_DataStruct *Opened_DataStruct; DST_DataStruct *opened_datastruct_ptr;
char *Prefixed_Name = DS_Name_Prefix( DS_Name); char *Prefixed_Name = DS_Name_Prefix( DS_Name);
union semun Sem_Ctl; union semun Sem_Ctl;
@ -450,17 +452,17 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
/* On crée un sémaphore pour compter le nombre de processus qui ouvrent la structure */ /* On crée un sémaphore pour compter le nombre de processus qui ouvrent la structure */
/*
rc = DS_Semaphore_Create (*Root); if( ( status = DS_Semaphore_Create( *Root_Ptr_Ptr)) != DSS_OK)
if (rc != DSS_OK)
{ {
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to create a semaphore for the data structure \"%s\"", DS_Name); LG_LOG_ERROR_2( "Unable to create a semaphore for the data structure: [%s], error: (%d)", DS_Name, status);
DS_Error_Print ();
SM_Heap_End (Prefixed_Name); SM_Heap_End( Prefixed_Name);
*Root = NULL; *Root_Ptr_Ptr = NULL;
return rc;
return( status);
} }
*/
break; break;
} }
@ -470,80 +472,115 @@ DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT
} }
} }
/* On incrémente le sémaphore qui compte le nombre de processus qui ouvrent la structure */ /* On incrémente le sémaphore qui compte le nombre de processus qui ouvrent la structure */
/*
rc = DS_Semaphore_Operate (RootDesc->OpenSemID, DS_SemOp_Open, 1); if( ( status = DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Open, 1)) != DSS_OK)
if (rc != DSS_OK)
{ {
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to incremente the semaphore of data structure \"%s\"", DS_Name); LG_LOG_ERROR_2( "Unable to incremente the semaphore of data structure: [%s], error: (%d)", DS_Name, status);
DS_Error_Print ();
if (Locked == TRUE) SM_Heap_Unlock (Heap); if( locked == TRUE) SM_Heap_Unlock( heap_ptr);
if (Mode == 3) if( mode == 3)
{ {
semctl (RootDesc->OpenSemID, 0, IPC_RMID, Sem_Ctl); semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
SM_Heap_End (Prefixed_Name); SM_Heap_End( Prefixed_Name);
}
else
{
DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1);
} }
else DS_Semaphore_Operate (RootDesc->OpenSemID, DS_SemOp_Close, 1);
*Root = NULL; *Root_Ptr_Ptr = NULL;
return rc; return( status);
} }
/* On ajoute la data structure à la liste des structures ouvertes par le processus courant */ /* On ajoute la data structure à la liste des structures ouvertes par le processus courant */
/*
Opened_DataStruct = (DST_DataStruct *)malloc (sizeof (DST_DataStruct));
Opened_DataStruct->Name = strdup (DS_Name);
Opened_DataStruct->Root = *Root;
rc = ND_Value_Add (OpenedDS_List, Opened_DataStruct); if( ( nd_status = ND_Value_Alloc( (void **)&opened_datastruct_ptr, OpenedDS_List, DS_Name, Root_Ptr_Ptr)) != NDS_OK)
if (rc != NDS_OK)
{ {
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to add structure \"%s\" to the opened structure list", DS_Name); LG_LOG_ERROR_2( "Unable to alloc a new opened data structure element: [%s], error: (%d)", DS_Name, nd_status);
DS_Error_Print ();
if (Locked == TRUE) SM_Heap_Unlock (Heap); if( locked == TRUE) SM_Heap_Unlock( heap_ptr);
if (Mode == 3) if( mode == 3)
{ {
semctl (RootDesc->OpenSemID, 0, IPC_RMID, Sem_Ctl); semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
SM_Heap_End (Prefixed_Name); SM_Heap_End( Prefixed_Name);
}
else
{
DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1);
} }
else DS_Semaphore_Operate (RootDesc->OpenSemID, DS_SemOp_Close, 1);
*Root = NULL; *Root_Ptr_Ptr = NULL;
return rc; return( DSS_KO);
}
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);
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);
}
if( locked == TRUE) SM_Heap_Unlock( heap_ptr);
if( mode == 3)
{
semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
SM_Heap_End( Prefixed_Name);
}
else
{
DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1);
}
*Root_Ptr_Ptr = NULL;
return( DSS_KO);
} }
/* Déverrouillage du heap */ /* Déverrouillage du heap */
/*
if (Locked == TRUE) if( locked == TRUE)
{ {
rc = SM_Heap_Unlock (Heap); if( sm_status = ( SM_Heap_Unlock( heap_ptr)) != SMS_OK)
if (rc != SMS_OK)
{ {
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to unlock the data structure heap \"%s\"", Prefixed_Name); LG_LOG_ERROR_2( "Unable to unlock the data structure heap: [%s], status: (%d)", Prefixed_Name, sm_status);
DS_Error_Print ();
ND_Value_Remove (OpenedDS_List, Opened_DataStruct, (void **)&Opened_DataStruct); if( ( nd_status = ND_DataStruct_Value_Remove( OpenedDS_List, opened_datastruct_ptr)) != NDS_OK)
ND_Value_Free (OpenedDS_List, Opened_DataStruct);
if (Mode == 3)
{ {
semctl (RootDesc->OpenSemID, 0, IPC_RMID, Sem_Ctl); LG_LOG_ERROR_2( "Unable to remove a data structure element: [%s] to the opened structure list, error: (%d)", DS_Name, status);
SM_Heap_End (Prefixed_Name); }
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);
}
if( mode == 3)
{
semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, Sem_Ctl);
SM_Heap_End( Prefixed_Name);
}
else
{
DS_Semaphore_Operate( rootdesc_ptr->OpenSemId, DS_SemOp_Close, 1);
} }
else DS_Semaphore_Operate (RootDesc->OpenSemID, DS_SemOp_Close, 1);
*Root = NULL; *Root_Ptr_Ptr = NULL;
return rc; return( DSS_KO);
} }
} }
*/
return( DSS_OK); return( DSS_OK);
} }
@ -643,7 +680,7 @@ DST_Status DS_DataStruct_Close_I ( NDT_Root * Root, DST_Flags Close_Mode )
{ {
/* 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); rc = DS_Semaphore_Operate (RootDesc->OpenSemId, DS_SemOp_Destroy, 2);
if (rc != 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); sprintf (DS_Error_Msg, "Error DS_DataStruct_Close : unable to destroy the data structure \"%s\" because it is opened by another process", DS_Name);
@ -666,7 +703,7 @@ DST_Status DS_DataStruct_Close_I ( NDT_Root * Root, DST_Flags Close_Mode )
/* Suppression du sémaphore */ /* Suppression du sémaphore */
/* /*
semctl (RootDesc->OpenSemID, 0, IPC_RMID, Sem_Ctl); semctl (RootDesc->OpenSemId, 0, IPC_RMID, Sem_Ctl);
/* On supprime maintenant le heap */ /* On supprime maintenant le heap */
/* /*
@ -704,7 +741,7 @@ DST_Status DS_DataStruct_Close_I ( NDT_Root * Root, DST_Flags Close_Mode )
/* { /* {
/* On décrémente le sémaphore qui compte le nombre de processus ayant ouvert 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); rc = DS_Semaphore_Operate (RootDesc->OpenSemId, DS_SemOp_Close, 1);
if (rc != DSS_OK) if (rc != DSS_OK)
{ {
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to decremente the semaphore of data structure \"%s\"", DS_Name); sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to decremente the semaphore of data structure \"%s\"", DS_Name);
@ -3128,107 +3165,144 @@ static char *DS_Name_Prefix( const char *Name )
return( Prefixed); 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 )
{
union semun Sem_Ctl;
DST_RootDesc * RootDesc = (DST_RootDesc *)(Root->User);
DST_Status DS_Semaphore_Create ( NDT_Root *Root_Ptr)
{
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->OpenSemID = semget (IPC_PRIVATE, 1, 0777|IPC_CREAT|IPC_EXCL); rootdesc_ptr->OpenSemId = semget( IPC_PRIVATE, 1, ( 0777 | IPC_CREAT | IPC_EXCL));
if (RootDesc->OpenSemID == -1) if( rootdesc_ptr->OpenSemId == -1)
{ {
switch (errno) switch( errno)
{ {
case ENOMEM: case ENOMEM:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Create : the amount of memory is not sufficient to create a new semaphore"); {
LG_LOG_ERROR_0( "Not enough memory to create a new semaphore");
break; break;
}
case ENOSPC: case ENOSPC:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Create : the number of semaphores exceeds the system-imposed limit"); {
LG_LOG_ERROR_0( "The number of semaphores would exceeds the system-imposed limit");
break; break;
}
default: default:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Create : unknown error (%d) while creating a semaphore", errno); {
LG_LOG_ERROR_1( "Unknown error: (%d) while creating a semaphore", errno);
break; break;
}
} }
DS_Error_Print (); return( DSS_ERRSEM);
return DSS_ERRSEM;
} }
/* Initialisation du sémaphore à 0 */ /* Initialisation du sémaphore à 0 */
/*
Sem_Ctl.val = 0; sem_ctl.val = 0;
if (semctl (RootDesc->OpenSemID, 0, SETVAL, Sem_Ctl))
if( semctl( rootdesc_ptr->OpenSemId, 0, SETVAL, sem_ctl))
{ {
sprintf (DS_Error_Msg, "Error DS_Semaphore_Create : unable to initialize the value of the semaphore %x", RootDesc->OpenSemID); LG_LOG_ERROR_1( "Unable to initialize the value of the semaphore: (%x)", rootdesc_ptr->OpenSemId);
DS_Error_Print ();
semctl (RootDesc->OpenSemID, 0, IPC_RMID, Sem_Ctl); semctl( rootdesc_ptr->OpenSemId, 0, IPC_RMID, sem_ctl);
return DSS_ERRSEM; return( DSS_ERRSEM);
} }
return DSS_OK; return( DSS_OK);
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* 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)
{ {
case EAGAIN: case EAGAIN:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate : the operation would result in suspension of the calling process but the operations have been defined in no wait mode"); {
LG_LOG_ERROR_0( "The operation would result in suspension of the calling process but the operations have been defined in no wait mode");
break; break;
}
case EACCES: case EACCES:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate : 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:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate : semaphore %x does not exist", SemID); {
LG_LOG_ERROR_1( "Semaphore: (%x) does not exist", SemID);
break; break;
}
case EINTR: case EINTR:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate : a signal was received while operating on semaphore %x", SemID); {
return DSS_ERRSIG; LG_LOG_ERROR_1( "A signal was received while operating on semaphore: (%x)", SemID);
return( DSS_ERRSIG);
}
case EINVAL: case EINVAL:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate : 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;
}
case ENOSPC: case ENOSPC:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate : the maximum number of process which can operate on semaphore in UNDO mode has been reached"); {
LG_LOG_ERROR_0( "The maximum number of process which can operate on semaphore in UNDO mode has been reached");
break; break;
}
case ERANGE: case ERANGE:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate: 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:
sprintf (DS_Error_Msg, "Error DS_Semaphore_Operate : 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;
}
} }
DS_Error_Print (); return( DSS_ERRSEM);
return DSS_ERRSEM;
} }
return DSS_OK; return( DSS_OK);
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Fonction manager de la liste des DS ouvertes */ /* Fonction manager de la liste des DS ouvertes */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -3307,12 +3381,33 @@ NDT_Status DS_OpenedDS_List_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id
ND_VA_LIST_CLOSE( user_args); ND_VA_LIST_CLOSE( user_args);
*/ */
ND_VA_ARG_GET( Opened_DataStruct_Ptr_Ptr, *Args_Ptr, DST_DataStruct **);
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_LIST_CLOSE( user_args);
Command_Name = "NDD_CMD_VALUE_ALLOC"; Command_Name = "NDD_CMD_VALUE_ALLOC";
LG_LOG_TRACE_0( LGD_LOG_LEVEL_DEFAULT, "CMD_VALUE_ALLOC called..."); LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Command: [%s] called", Command_Name);
return( DSS_OK); if( ( *Opened_DataStruct_Ptr_Ptr = (DST_DataStruct *)malloc( sizeof( DST_DataStruct))) == NULL)
{
LG_LOG_ERROR_1( "Can't allocate value zise: (%d)", sizeof( DST_DataStruct));
return( DSS_KO);
}
else
{
( *Opened_DataStruct_Ptr_Ptr)->Name = DS_Name;
( *Opened_DataStruct_Ptr_Ptr)->Root_Ptr = Root_Ptr;
return( DSS_OK);
}
} }
case NDD_CMD_VALUE_FREE: case NDD_CMD_VALUE_FREE:
@ -3328,11 +3423,14 @@ NDT_Status DS_OpenedDS_List_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id
ND_VA_LIST_CLOSE( user_args); ND_VA_LIST_CLOSE( user_args);
*/ */
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *); ND_VA_ARG_GET( Opened_DataStruct_Ptr, *Args_Ptr, DST_DataStruct *);
Command_Name = "NDD_CMD_VALUE_FREE"; Command_Name = "NDD_CMD_VALUE_FREE";
LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Command: [%s] called", Command_Name);
free( Opened_DataStruct_Ptr);
/* /*
DS_Free( Root_Ptr, Value_Ptr); DS_Free( Root_Ptr, Value_Ptr);
*/ */

View File

@ -94,8 +94,8 @@ NDT_Root *OpenedDS_List;
typedef struct DST_DataStruct typedef struct DST_DataStruct
{ {
NDT_Root *Root_Ptr;
char *Name; char *Name;
NDT_Root *Root_Ptr;
} DST_DataStruct; } DST_DataStruct;
@ -109,12 +109,16 @@ typedef struct DST_DataStruct
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* 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);
DST_Status DS_Semaphore_Create( NDT_Root *);
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Opération sur un sémaphore */ /* 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);