/*----------------------------------------------------------------------------*/ /* libdatastr.h */ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /* This file is part of LibDataStr. */ /* */ /* LibDataStr is free software: you can redistribute it and/or modify it */ /* under the terms of the GNU Lesser General Public License as published */ /* by the Free Software Foundation, either version 3 of the License, or */ /* (at your option) any later version. */ /* */ /* LibDataStr is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU Lesser General Public License for more details. */ /* */ /* You should have received a copy of the GNU Lesser General Public */ /* License along with LibDataStr. If not, see */ /* . */ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /* Includes */ /*----------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include //#include #include #include /*----------------------------------------------------------------------------*/ /* Definitions */ /*----------------------------------------------------------------------------*/ #define LGD_MODULE_NAME "ds" extern char * strdup ( const char * ); /* Compteur d'ouverture de la librairie */ unsigned int DS_Open_Counter = 0; /* Tous les heaps créés via la librairie LIBDATASTR seront préfixés par le nom suivant */ #define DS_PREFIX "DATASTR" /* Flux de sortie des messages d'erreur */ FILE * DS_stderr; /* Pour gérer les ouvertures, fermetures ou destructions d'une data structure, on opère sur un sémaphore (OpenSemID) rattaché à la description de la structure qui comptabilise les processus ayant ouvert la data structure. */ struct sembuf DS_SemOp_Open [1] = { {0, 1, SEM_UNDO|IPC_NOWAIT} }; struct sembuf DS_SemOp_Close [1] = { {0, -1, SEM_UNDO|IPC_NOWAIT} }; struct sembuf DS_SemOp_Destroy [2] = { {0, -1, SEM_UNDO|IPC_NOWAIT}, {0, 0, SEM_UNDO|IPC_NOWAIT} }; typedef union semun { int val; struct semid_ds * buf; unsigned short int * array; } semun; /* Liste des data structure ouvertes par le processus courant */ NDT_Root *OpenedDS_List; typedef struct DST_DataStruct { char Name[ DSD_NAME_SIZE]; DST_Root *Root_Ptr; } DST_DataStruct; /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /* Fonctions privées de la librairie */ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /* Création d'un sémaphore pour gérer l'ouverture d'une data structure */ /*----------------------------------------------------------------------------*/ DST_Status DS_Semaphore_Create( DST_Root *); /*----------------------------------------------------------------------------*/ /* Opération sur un sémaphore */ /*----------------------------------------------------------------------------*/ DST_Status DS_Semaphore_Operate (int, struct sembuf *, unsigned int); /*----------------------------------------------------------------------------*/ /* Fonction d'allocation attachée à une structure de données : */ /*----------------------------------------------------------------------------*/ DST_Status DS_Allocator( void **Ptr_Ptr, NDT_Root *ND_Root_Ptr, size_t Size, void *User_Ptr); /*----------------------------------------------------------------------------*/ /* Fonction de désallocation attachée à une structure de données : */ /*----------------------------------------------------------------------------*/ DST_Status DS_Deallocator( void *Ptr, NDT_Root *ND_Root_Ptr, void *User_Ptr ); /*----------------------------------------------------------------------------*/ /* Routine d'affichage d'un message d'erreur */ /*----------------------------------------------------------------------------*/ void DS_Error_Print ( void ); /*----------------------------------------------------------------------------*/ /* Pour préfixer les noms de heap avec l'identifiant de la librairie */ /*----------------------------------------------------------------------------*/ DST_Status DS_Name_Prefix( char *Prefixed, const char *Unprefixed); /*----------------------------------------------------------------------------*/ /* Teste si une data structure a déjà été ouverte par le processus courant */ /*----------------------------------------------------------------------------*/ DST_Status DS_DataStruct_IsOpen( DST_Root **Root_Ptr_Ptr, char *DS_Name); /*----------------------------------------------------------------------------*/ /* Init handler: */ /* - Return extra root size */ /* - Update handler tab */ /*----------------------------------------------------------------------------*/ /* (O) Root_Extra_Size_Ptr: Pointer on the extra root size */ /* (I) User_Ptr: User pointer */ /*----------------------------------------------------------------------------*/ NDT_Status DS_Handler_Init( size_t *Root_Extra_Size_Ptr, void *User_Ptr); /*----------------------------------------------------------------------------*/ /* Alloc handler: */ /* malloc() function wrapper with NDT_Status return status */ /*----------------------------------------------------------------------------*/ /* (O) Memory_Ptr_Ptr: Memory pointer address */ /* (I) Root_Ptr: Data structure pointer */ /* (I) Size: Allocation size */ /* (I) User_Ptr: User pointer */ /*----------------------------------------------------------------------------*/ NDT_Status DS_Handler_Alloc( void **Memory_Ptr_Ptr, NDT_Root *Root_Ptr, size_t Size, void *User_Ptr); /*----------------------------------------------------------------------------*/ /* Free handler: */ /* free() function wrapper with NDT_Status return status */ /*----------------------------------------------------------------------------*/ /* (I) Memory_Ptr: Memory pointer */ /* (I) Root_Ptr: Data structure pointer */ /* (I) User_Ptr: User pointer */ /*----------------------------------------------------------------------------*/ NDT_Status DS_Handler_Free( void *Memory_Ptr, NDT_Root *Root_Ptr, void *User_Ptr); /*----------------------------------------------------------------------------*/ /* Open handler */ /*----------------------------------------------------------------------------*/ /* (I) Root_Ptr: Data structure pointer */ /* (I) Open_Mode: Open mode */ /* (I) Handler_Open_Name: Free handler function name */ /* (I) Handler_Open_Ptr: Free handler function pointer */ /* (I) User_Ptr: User pointer */ /*----------------------------------------------------------------------------*/ NDT_Status DS_Handler_Open( NDT_Root *Root_Ptr, NDT_Open_Flag Open_Mode, void *User_Ptr); /*----------------------------------------------------------------------------*/ /* Close handler */ /*----------------------------------------------------------------------------*/ /* (I) Root_Ptr: Data structure pointer */ /* (I) Close_Mode: Close mode */ /* (I) Handler_Close_Name: Free handler function name */ /* (I) Handler_Close_Ptr: Free handler function pointer */ /* (I) User_Ptr: User pointer */ /*----------------------------------------------------------------------------*/ NDT_Status DS_Handler_Close( NDT_Root *Root_Ptr, NDT_Close_Flag Close_Mode, void *User_Ptr); /*----------------------------------------------------------------------------*/ /* Info handler */ /*----------------------------------------------------------------------------*/ /* (I) Root_Ptr: Data structure pointer */ /* (I) Recursive_Offset: Print line offset */ /*----------------------------------------------------------------------------*/ NDT_Status DS_Handler_Info( NDT_Root *Root_Ptr, NDT_Recursive_Offset Recursive_Offset); /*----------------------------------------------------------------------------*/ /* Lock handler */ /*----------------------------------------------------------------------------*/ /* (I) Root_Ptr: Data structure pointer */ /* (I) Open_Mode: Lock mode */ /* (O) Locked_Ptr: Locked flag */ /* (I) Handler_Lock_Name: Free handler function name */ /* (I) Handler_Lock_Ptr: Free handler function pointer */ /* (I) User_Ptr: User pointer */ /*----------------------------------------------------------------------------*/ NDT_Status DS_Handler_Lock( NDT_Root *Root_Ptr, NDT_Lock_Flag Lock_Mode, bool *Locked_Ptr, void *User_Ptr); /*----------------------------------------------------------------------------*/ /* Unlock handler */ /*----------------------------------------------------------------------------*/ /* (I) Root_Ptr: Data structure pointer */ /* (I) Handler_Unlock_Name: Free handler function name */ /* (I) Handler_Unlock_Ptr: Free handler function pointer */ /* (I) User_Ptr: User pointer */ /*----------------------------------------------------------------------------*/ NDT_Status DS_Handler_Unlock( NDT_Root *Root_Ptr, void *User_Ptr); /*----------------------------------------------------------------------------*/ /* Fonction manager de la liste des DS ouvertes */ /*----------------------------------------------------------------------------*/ NDT_Status DS_OpenedDS_List_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node *Node_Ptr, NDT_Command Command, va_list *Args_Ptr);