- Complete LibLog support into lib & smutil,

- Continue code clean-up.
This commit is contained in:
Arnaud G. GIBERT 2024-04-19 18:44:32 +02:00
parent a84d15e238
commit 8a783e09e9
4 changed files with 795 additions and 829 deletions

View File

@ -310,6 +310,7 @@ typedef struct {
/* (I) Context : nom du nouveau contexte */
/* (I) Flags : indicateur création/ouverture + mode d'affichage des erreurs */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Library_Open_I ( int Instance, const char * Context, SMT_Flags Flags );
SMD_API SMT_Status SM_Library_Open_C ( int Instance, const char * Context, SMT_Flags Flags );
@ -320,6 +321,7 @@ SMD_API SMT_Status SM_Library_Open_C ( int Instance, const char * Context, SMT_
/*------------------------------------------------------------------------------*/
/* (O) Instance : adresse du numéro de l'instance utilisée */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Library_Instance_Get_I ( int * Instance);
SMD_API SMT_Status SM_Library_Instance_Get_C ( int * Instance);
@ -330,6 +332,7 @@ SMD_API SMT_Status SM_Library_Instance_Get_C ( int * Instance);
/*------------------------------------------------------------------------------*/
/* (I) Context : nom du nouveau contexte */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Library_Context_Set_I ( const char * Context );
SMD_API SMT_Status SM_Library_Context_Set_C ( const char * Context );
@ -340,6 +343,7 @@ SMD_API SMT_Status SM_Library_Context_Set_C ( const char * Context );
/*------------------------------------------------------------------------------*/
/* (O) Context : adresse du nom du contexte utilisé */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Library_Context_Get_I ( char ** Context );
SMD_API SMT_Status SM_Library_Context_Get_C ( char ** Context );
@ -350,6 +354,7 @@ SMD_API SMT_Status SM_Library_Context_Get_C ( char ** Context );
/*------------------------------------------------------------------------------*/
/* (I) Flags : mode de fermeture (destruction ou fermeture simple) */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Library_Close_I ( SMT_Flags Flags );
SMD_API SMT_Status SM_Library_Close_C ( SMT_Flags Flags );
@ -360,6 +365,7 @@ SMD_API SMT_Status SM_Library_Close_C ( SMT_Flags Flags );
/*------------------------------------------------------------------------------*/
/* (I) Out : pointeur sur le flux de sortie */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Library_Dump_I ( FILE * Out );
SMD_API SMT_Status SM_Library_Dump_C ( FILE * Out );
@ -368,6 +374,7 @@ SMD_API SMT_Status SM_Library_Dump_C ( FILE * Out );
/*------------------------------------------------------------------------------*/
/* Libération de tous les verrous (base, heap) */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Library_Unlock_I ( void );
SMD_API SMT_Status SM_Library_Unlock_C ( void );
@ -376,6 +383,7 @@ SMD_API SMT_Status SM_Library_Unlock_C ( void );
/*------------------------------------------------------------------------------*/
/* Définition de la sortie standard des messages d'erreur de la librairie */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Library_Stderr_Set_I ( FILE * Out );
SMD_API SMT_Status SM_Library_Stderr_Set_C ( FILE * Out );
@ -386,6 +394,7 @@ SMD_API SMT_Status SM_Library_Stderr_Set_C ( FILE * Out );
/*------------------------------------------------------------------------------*/
/* (I) Heap_Name : nom du heap */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Heap_Exist_I ( const char * Heap_Name );
SMD_API SMT_Status SM_Heap_Exist_C ( const char * Heap_Name );
@ -400,6 +409,7 @@ SMD_API SMT_Status SM_Heap_Exist_C ( const char * Heap_Name );
/* (I) Flags : mode d'ouverture du heap */
/* (O) Locked : verrou effectif (TRUE ou FALSE) */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Heap_Open_I ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg_Size, SMT_Flags Flags, int * Locked );
SMD_API SMT_Status SM_Heap_Open_C ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg_Size, SMT_Flags Flags, int * Locked );
@ -411,6 +421,7 @@ SMD_API SMT_Status SM_Heap_Open_C ( const char * Heap_Name, SMT_Heap ** Heap, s
/* (I) Heap_Name : nom du heap */
/* (O) Heap : adresse du pointeur sur le heap ouvert */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Heap_IsOpen_I ( const char * Heap_Name, SMT_Heap ** Heap );
SMD_API SMT_Status SM_Heap_IsOpen_C ( const char * Heap_Name, SMT_Heap ** Heap );
@ -421,6 +432,7 @@ SMD_API SMT_Status SM_Heap_IsOpen_C ( const char * Heap_Name, SMT_Heap ** Heap
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap );
SMD_API SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap );
@ -431,6 +443,7 @@ SMD_API SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap );
/*------------------------------------------------------------------------------*/
/* (I) Heap_Name : nom du heap */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Heap_End_I ( const char * Heap_Name );
SMD_API SMT_Status SM_Heap_End_C ( const char * Heap_Name );
@ -442,6 +455,7 @@ SMD_API SMT_Status SM_Heap_End_C ( const char * Heap_Name );
/* (I) Heap : pointeur sur un heap ouvert */
/* (O) Compress : pointeur sur la taille mémoire gagnée */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Heap_Compress_I ( SMT_Heap * Heap, size_t * Compress );
SMD_API SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress );
@ -453,6 +467,7 @@ SMD_API SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress );
/* (I) Heap : pointeur sur un heap ouvert */
/* (I) Tag : type de configuration */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Heap_Config_I ( SMT_Heap * Heap, SMT_Config Tag, ... );
SMD_API SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... );
@ -466,6 +481,7 @@ SMD_API SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... );
/* (O) Nb_Corrected : pointeur sur le nombre d'erreurs corrigées */
/* (I) Out : pointeur sur le flux de sortie du rapport */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Corrected, FILE * Out);
SMD_API SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Corrected, FILE * Out);
@ -478,6 +494,7 @@ SMD_API SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap, int * Nb_Detected, int *
/* (I) Flags : mode de verrouillage (SMD_READ ou SMD_WRITE) */
/* (O) Locked : verrouillage effectué (TRUE ou FALSE) */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Flags, int * Locked );
SMD_API SMT_Status SM_Heap_Lock_C ( SMT_Heap * Heap, SMT_Flags Flags, int * Locked );
@ -488,6 +505,7 @@ SMD_API SMT_Status SM_Heap_Lock_C ( SMT_Heap * Heap, SMT_Flags Flags, int * Loc
/*------------------------------------------------------------------------------*/
/* (I) Heap : pointeur sur un heap ouvert */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Heap_Unlock_I ( SMT_Heap * Heap );
SMD_API SMT_Status SM_Heap_Unlock_C ( SMT_Heap * Heap );
@ -500,6 +518,7 @@ SMD_API SMT_Status SM_Heap_Unlock_C ( SMT_Heap * Heap );
/* (I) Size : taille du chunk */
/* (O) Ptr : pointeur sur la zone de données allouée */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr );
SMD_API SMT_Status SM_Chunk_Alloc_C ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr );
@ -511,6 +530,7 @@ SMD_API SMT_Status SM_Chunk_Alloc_C ( SMT_Heap * Heap, size_t Alloc_Size, void
/* (I) Heap : pointeur sur un heap ouvert */
/* (I) Ptr : adresse de la zone de données du chunk à désallouer */
/*------------------------------------------------------------------------------*/
SMD_API SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr );
SMD_API SMT_Status SM_Chunk_Free_C ( SMT_Heap * Heap, void * Ptr );

File diff suppressed because it is too large Load Diff

View File

@ -99,6 +99,8 @@ SMT_Heap * System_Heap;
NDT_Root * Opened_Heap_List;
/*
Taille par défaut des chunks alloués dans le heap système :
Cette taille est fixée à la taille maximale des chunks pouvant
@ -115,6 +117,8 @@ NDT_Root * Opened_Heap_List;
#define FREE_CHUNK_LIMIT 3
int SM_Instance;
char * SM_Context;
@ -168,6 +172,13 @@ typedef union semun
unsigned short int * array;
} semun;
/*------------------------------------------------------------------------------*/
/* */
/*------------------------------------------------------------------------------*/
#define SM_LIBSHMEM_OPEN_CHECK() if( !SM_Base) { LG_LOG_ERROR_0( "LibShMem library is not open"); return( SMS_ERRAPI); }
#define SM_HEAP_NAME_CHECK(ptr) if( !(ptr)) { LG_LOG_ERROR_0( "Heap name is undefined"); return( SMS_ERRAPI); }
#define SM_HEAP_CHECK( ptr) if( !(ptr)) { LG_LOG_ERROR_0( "Heap is undefined"); return( SMS_ERRAPI); }
@ -176,127 +187,192 @@ typedef union semun
/*------------------------------------------------------------------------------*/
/* Allocation de mémoire dans la base */
/*------------------------------------------------------------------------------*/
NDT_Status SM_Base_Alloc( void **, size_t, void *);
/*------------------------------------------------------------------------------*/
/* Désallocation de mémoire dans la base */
/*------------------------------------------------------------------------------*/
NDT_Status SM_Base_Free( void *, void *);
/*------------------------------------------------------------------------------*/
/* Allocation de mémoire dans le heap système */
/*------------------------------------------------------------------------------*/
NDT_Status SM_System_Alloc( void **, size_t, void *);
/*------------------------------------------------------------------------------*/
/* Désallocation de mémoire dans le heap système */
/*------------------------------------------------------------------------------*/
NDT_Status SM_System_Free( void *, void *);
/*------------------------------------------------------------------------------*/
/* Initialisation de la base */
/*------------------------------------------------------------------------------*/
SMT_Status SM_Base_Init (void);
/*------------------------------------------------------------------------------*/
/* Terminaison de la base */
/*------------------------------------------------------------------------------*/
SMT_Status SM_Base_End (void);
/*------------------------------------------------------------------------------*/
/* Ouverture de la base */
/*------------------------------------------------------------------------------*/
SMT_Status SM_Base_Open (void);
/*------------------------------------------------------------------------------*/
/* Fermeture de la base */
/*------------------------------------------------------------------------------*/
SMT_Status SM_Base_Close (void);
/*------------------------------------------------------------------------------*/
/* Pose d'un verrou sur la base : */
/*------------------------------------------------------------------------------*/
SMT_Status SM_Base_Lock (SMT_Flags);
/*------------------------------------------------------------------------------*/
/* Libération d'un verrou sur la base : */
/*------------------------------------------------------------------------------*/
SMT_Status SM_Base_Unlock (SMT_Flags);
/*------------------------------------------------------------------------------*/
/* Fonction manager de la liste des heaps ouverts */
/*------------------------------------------------------------------------------*/
NDT_Status SM_Opened_Heap_List_Manager ( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *);
/*------------------------------------------------------------------------------*/
/* Fonction manager du MHR (Memory Heap Root) */
/*------------------------------------------------------------------------------*/
NDT_Status MHR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *);
/*------------------------------------------------------------------------------*/
/* Destruction d'un MHH (Memory Heap Header) */
/*------------------------------------------------------------------------------*/
SMT_Status SM_MHH_End (SMT_MHH *);
/*------------------------------------------------------------------------------*/
/* Fonction manager pour un DSR (Data Segment Root) */
/*------------------------------------------------------------------------------*/
NDT_Status SM_DSR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *);
/*------------------------------------------------------------------------------*/
/* Ouverture d'un segment de données */
/*------------------------------------------------------------------------------*/
SMT_Status SM_DataSegment_Open (SMT_DSH *);
/*------------------------------------------------------------------------------*/
/* Fermeture d'un segment de données */
/*------------------------------------------------------------------------------*/
SMT_Status SM_DataSegment_Close (SMT_DSH *);
/*------------------------------------------------------------------------------*/
/* Compression d'un segment de données */
/*------------------------------------------------------------------------------*/
size_t SM_DataSegment_Compress (SMT_DSH *, NDT_Root *);
/*------------------------------------------------------------------------------*/
/* Fonction manager pour un ACR (Allocated Chunk Root) */
/*------------------------------------------------------------------------------*/
NDT_Status SM_ACR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *);
/*------------------------------------------------------------------------------*/
/* Fonction manager pour un FCR (Free Chunk Root) */
/*------------------------------------------------------------------------------*/
NDT_Status SM_FCR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *);
/*------------------------------------------------------------------------------*/
/* Pose d'un verrou sur un heap : */
/*------------------------------------------------------------------------------*/
SMT_Status SM_Heap_Lock_Set (SMT_MHH *, SMT_Flags);
/*------------------------------------------------------------------------------*/
/* Changement d'un verrou sur un heap : */
/*------------------------------------------------------------------------------*/
SMT_Status SM_Heap_Lock_Change (SMT_MHH *, SMT_Flags);
/*------------------------------------------------------------------------------*/
/* Libération d'un verrou sur un heap : */
/*------------------------------------------------------------------------------*/
SMT_Status SM_Heap_Lock_Release (SMT_MHH *, SMT_Flags);
/*------------------------------------------------------------------------------*/
/* Opération sur un sémaphore */
/*------------------------------------------------------------------------------*/
SMT_Status SM_Semaphore_Operate (int, struct sembuf *, unsigned int);
/*------------------------------------------------------------------------------*/
/* Récupère sous forme explicite l'état d'un verrou */
/*------------------------------------------------------------------------------*/
char * SM_Lock_Status_Get (const char *, void *);
/*------------------------------------------------------------------------------*/
/* Routine d'affichage d'un message d'erreur */
/*------------------------------------------------------------------------------*/
void SM_Error_Print (void);
char * SM_Lock_Status_Get (const char *, void *);

View File

@ -47,6 +47,10 @@
//VER_INFO_EXPORT (smadmin, "$Revision: 2.3 $", "$Name: $", __FILE__, "$Author: agibert $")
#define LGD_MODULE_NAME "sma"
#define USAGE "Usage : %s [ --help | --version [-v] | --create | --destroy ]\n"
#define QUIT 0
@ -232,14 +236,24 @@ void Entry_Prompt( void *Out_Ptr, char *Prompt_Ptr, short Type)
int main( int argc, char **argv)
{
int choice;
char name[ NAME_SIZE];
int Mode, Locked;
void *ptr;
char answer[ 10];
SMT_Heap *Heap;
int Nb_Detected, Nb_Corrected;
size_t size;
LGT_Status lg_status;
int choice;
char name[ NAME_SIZE];
int Mode, Locked;
void *ptr;
char answer[ 10];
SMT_Heap *Heap;
int Nb_Detected, Nb_Corrected;
size_t size;
if( ( lg_status = LG_Library_Open( LGD_LOG_WRITER_DEFAULT, true)) != LGS_OK)
{
fprintf( stderr, "Can't open LibLog library: (%d)\n", lg_status);
return( -1);
}
LG_LOG_INFO_0( "Start SMAdmin");
/* Lancement de commande d'administration */
@ -546,5 +560,13 @@ int main( int argc, char **argv)
choice = Print_Menu();
}
LG_LOG_INFO_0( "End SMAdmin");
if( ( lg_status = LG_Library_Close( true)) != LGS_OK)
{
fprintf( stderr, "Can't close LibLog library: (%d)\n", lg_status);
return( -1);
}
return( 0);
}