diff --git a/Makefile b/Makefile index bb88aab..5763e8e 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ -SUBDIRS := include lib util demo doc +SUBDIRS := include lib util doc FILE_DOC := *.txt diff --git a/include/datastr.h b/include/datastr.h index 7653a7c..8cf9fdc 100644 --- a/include/datastr.h +++ b/include/datastr.h @@ -313,16 +313,20 @@ DSD_API DST_Status DS_Library_Stderr_Set_CL( FILE *Out); /*----------------------------------------------------------------------------*/ /* Création / ouverture d'une structure de données */ /*----------------------------------------------------------------------------*/ -/* (O) Root : adresse du pointeur sur la racine de la structure */ -/* (I) DS_Name : nom de la structure */ -/* (I) Type : type de la structure de données */ -/* (I) Manager_FileName : nom du fichier qui définit les fonctions manager */ +/* (O) Root_Ptr_Ptr: Pointer adress of the new data structure */ +/* (I) DS_Name: Data structure name */ +/* (I) Index_Nb: Number of index */ +/* (I) Index_Type_Ptr: Array of Index type (List, tree, ...) */ +/* (I) Manager_Name: Manager function name */ /* (I) Segment_Size : taille ds segments du heap sous-jacent */ /* (I) Open_Mode : mode d'ouverture de la structure */ -/* (I) Own_Value : indique si la structure possède ses valeurs */ +/* (I) Own_Value: Flag indicating if the structure is the node owner */ + +/* (I) Manager_FileName : nom du fichier qui définit les fonctions manager */ + /*----------------------------------------------------------------------------*/ -DSD_API DST_Status DS_DataStruct_Open_I( NDT_Root **Root, const char *DS_Name, NDT_Index_Nb, NDT_Index_Type *, const char * Manager_FileName, size_t Segment_Size, DST_Flags Open_Mode, int Own_Value); +DSD_API DST_Status DS_DataStruct_Open_I( NDT_Root **Root, char *DS_Name, NDT_Index_Nb, NDT_Index_Type *, char *Manager_FileName, size_t Segment_Size, DST_Flags Open_Mode, short Own_Value); /* DSD_API DST_Status DS_DataStruct_Open_I( const char *DS_Name, NDT_Root **Root, NDT_DataStruct_Type Type, const char * Manager_FileName, size_t Segment_Size, DST_Flags Open_Mode, int Own_Value); diff --git a/lib/libdatastr.c b/lib/libdatastr.c index 8eb38a2..92500a5 100644 --- a/lib/libdatastr.c +++ b/lib/libdatastr.c @@ -192,82 +192,84 @@ DST_Status DS_Library_Stderr_Set_I( FILE *Out) /*----------------------------------------------------------------------------*/ /* Création / ouverture d'une structure de données */ /*----------------------------------------------------------------------------*/ -/* (I) DS_Name : nom de la structure */ /* (O) Root : adresse du pointeur sur la racine de la structure */ +/* (I) DS_Name : nom de la structure */ /* (I) Type : type de la structure de données */ /* (I) Manager_FileName : nom du fichier qui définit les fonctions manager */ /* (I) Segment_Size : taille ds segments du heap sous-jacent */ /* (I) Open_Mode : mode d'ouverture de la structure */ -/* (I) Own_Values : indique si la structure possède ses valeurs */ +/* (I) Own_Value : indique si la structure possède ses valeurs */ /*----------------------------------------------------------------------------*/ -/* -DST_Status DS_DataStruct_Open_I( const char *DS_Name, NDT_Root **Root, NDT_DataStruct_Type Type, const char *Manager_FileName, size_t Segment_Size, DST_Flags Open_Mode, int Own_Values) -{ - DST_Status rc; - SMT_Heap * Heap; - SMT_DSH * DSH; - int Locked, Mode; - DST_RootDesc * RootDesc, Tmp_RootDesc; - DST_DataStruct * Opened_DataStruct; - char * Prefixed_Name = DS_Name_Prefix (DS_Name); - union semun Sem_Ctl; +//ND_DataStruct_Open( &OpenedDS_List, 1, &index_type, "DS_OpenedDS_List_Manager", NULL, NULL, NULL, NULL, NULL, TRUE, NULL)) != NDS_OK) - *Root = NULL; +//DST_Status DS_DataStruct_Open_I( NDT_Root **Root, const char *DS_Name, NDT_DataStruct_Type Type, const char *Manager_FileName, size_t Segment_Size, DST_Flags Open_Mode, int Own_Values); + +DST_Status DS_DataStruct_Open_I( NDT_Root **Root_Ptr_Ptr, char *DS_Name, NDT_Index_Nb Index_Nb, NDT_Index_Type *Index_Type_Tab, char *Manager_FileName, size_t Segment_Size, DST_Flags Open_Mode, short Own_Value) +{ + DST_Status status; + SMT_Status sm_status; + NDT_Status nd_status; + SMT_Heap *heap_ptr; + SMT_DSH *dsh; + int locked, mode; + DST_RootDesc *RootDesc, Tmp_RootDesc; + DST_DataStruct *Opened_DataStruct; + char *Prefixed_Name = DS_Name_Prefix( DS_Name); + union semun Sem_Ctl; + + + *Root_Ptr_Ptr = NULL; /* On définit ce qu'on va faire en fonction du mode d'ouverture demandé et de ce qui existe déjà ou non */ -/* - if (SM_Heap_Exist (Prefixed_Name) == SMS_YES) + + if( SM_Heap_Exist( Prefixed_Name) == SMS_YES) { - if (DSD_MSK_OPEN (Open_Mode)) Mode = 2; - else if (DSD_MSK_NEW (Open_Mode)) Mode = 1; + if( DSD_MSK_OPEN( Open_Mode)) mode = 2; + else if( DSD_MSK_NEW( Open_Mode)) mode = 1; else { - sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : the data structure already exists and (Flags & DSD_OPEN & DSD_NEW) is false"); - DS_Error_Print (); + LG_LOG_ERROR_1( "The data structure: [%s] already exists and (Flags & DSD_OPEN & DSD_NEW) is false", DS_Name); - return DSS_ERRAPI; + return( DSS_ERRAPI); } } - else if (DSD_MSK_CREATE (Open_Mode)) Mode = 3; + else if( DSD_MSK_CREATE( Open_Mode)) mode = 3; else { - sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : the data structure \"%s\" does no exist and (Flags & DSD_CREATE) is false", DS_Name); - DS_Error_Print (); + LG_LOG_ERROR_1( "The data structure: [%s] does no exist and (Flags & DSD_CREATE) is false", DS_Name); - return DSS_ERRAPI; + return( DSS_ERRAPI); } - switch (Mode) + LG_LOG_TRACE_1( LGD_LOG_LEVEL_DEFAULT, "Creation Mode:(%d)", mode); + + switch( mode) { case 1: - + { /*--------------- Création d'une nouvelle data structure dans un heap existant -------------*/ /* Ouverture du heap en écriture */ -/* - rc = SM_Heap_Open (Prefixed_Name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked); - if (rc != SMS_OK) - { - sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to open the data structure heap \"%s\" for writing", Prefixed_Name); - DS_Error_Print (); - return rc; + 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); + + return( SMS_KO); } /* Création de la node structure */ -/* + Tmp_RootDesc.Heap_Name = Prefixed_Name; - rc = ND_DataStruct_Open (Root, Type, "DS_DataStruct_Alloc", "DS_DataStruct_Free", &Tmp_RootDesc, Own_Values); - if (rc != NDS_OK) + if( ( nd_status = ND_DataStruct_Open( Root_Ptr_Ptr, Index_Nb, Index_Type_Tab, Manager_FileName, NULL, "DS_DataStruct_Alloc", NULL, "DS_DataStruct_Free", NULL, Own_Value, &Tmp_RootDesc)) != NDS_OK) { - sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to create a new node structure in the existing heap \"%s\"", Heap->Name); - DS_Error_Print (); + LG_LOG_ERROR_2( "Unable to create a new node structure in the existing heap: [%s], error: (%d)", heap_ptr->Name, nd_status); - if (Locked == TRUE) SM_Heap_Unlock (Heap); - *Root = NULL; + if( locked == TRUE) SM_Heap_Unlock( heap_ptr); + *Root_Ptr_Ptr = NULL; - return rc; + return( SMS_KO); } /* Allocation de mémoire pour la description de la nouvelle data structure */ @@ -279,7 +281,7 @@ DST_Status DS_DataStruct_Open_I( const char *DS_Name, NDT_Root **Root, NDT_Da DS_Error_Print (); DS_DataStruct_Free (*Root, &Tmp_RootDesc); - if (Locked == TRUE) SM_Heap_Unlock (Heap); + if (locked == TRUE) SM_Heap_Unlock (Heap); *Root = NULL; return rc; @@ -319,9 +321,10 @@ DST_Status DS_DataStruct_Open_I( const char *DS_Name, NDT_Root **Root, NDT_Da } return DSS_OK; - +*/ break; - + } +/* case 2: /*--------------- Ouverture d'une data structure existante ------------------*/ @@ -371,40 +374,36 @@ DST_Status DS_DataStruct_Open_I( const char *DS_Name, NDT_Root **Root, NDT_Da } break; - +*/ case 3: - + { /*--------------- Création d'une nouvelle structure de données dans un nouveau heap -----------------*/ -/* - if (!Manager_FileName) + + if( !Manager_FileName) { - sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : the manager file name (.so) is undefined"); - DS_Error_Print (); - return DSS_ERRAPI; + LG_LOG_ERROR_0( "The manager file name (.so) is undefined"); + return( DSS_ERRAPI); } /* Création d'un nouveau heap */ -/* - rc = SM_Heap_Open (Prefixed_Name, &Heap, Segment_Size, SMD_CREATE | SMD_WRITE, &Locked); - if (rc != SMS_OK) + + if( ( sm_status = SM_Heap_Open( Prefixed_Name, &heap_ptr, Segment_Size, ( SMD_CREATE | SMD_WRITE), &locked)) != SMS_OK) { - sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to create a heap for the data structure \"%s\"", DS_Name); - DS_Error_Print (); - return rc; + LG_LOG_ERROR_2( "Unable to create a heap for the data structure [%s], error: (%d)", DS_Name, sm_status); + return( sm_status); } /* Création de la structure de données dans le heap */ -/* + Tmp_RootDesc.Heap_Name = Prefixed_Name; - rc = ND_DataStruct_Open (Root, Type, "DS_DataStruct_Alloc", "DS_DataStruct_Free", &Tmp_RootDesc, Own_Values); - if (rc != NDS_OK) + if( ( nd_status = ND_DataStruct_Open( Root_Ptr_Ptr, Index_Nb, Index_Type_Tab, Manager_FileName, NULL, "DS_DataStruct_Alloc", NULL, "DS_DataStruct_Free", NULL, Own_Value, &Tmp_RootDesc)) != NDS_OK) { - sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : unable to create the node structure"); - DS_Error_Print (); - SM_Heap_End (Prefixed_Name); - *Root = NULL; - return rc; + LG_LOG_ERROR_2( "Unable to create a new node structure in new heap: [%s], error: (%d)", heap_ptr->Name, nd_status); + SM_Heap_End( Prefixed_Name); + *Root_Ptr_Ptr = NULL; + + return( SMS_KO); } /* Allocation de mémoire pour la description de la structure */ @@ -448,11 +447,14 @@ DST_Status DS_DataStruct_Open_I( const char *DS_Name, NDT_Root **Root, NDT_Da *Root = NULL; return rc; } - +*/ break; + } default: + { break; + } } /* On incrémente le sémaphore qui compte le nombre de processus qui ouvrent la structure */ @@ -528,8 +530,8 @@ DST_Status DS_DataStruct_Open_I( const char *DS_Name, NDT_Root **Root, NDT_Da return rc; } } - - return DSS_OK; +*/ + return( DSS_OK); } @@ -2967,50 +2969,54 @@ DST_Status DS_DataStruct_IsOpen ( const char * DS_Name, NDT_Root ** Root ) return DSS_YES; } + + /*----------------------------------------------------------------------------*/ /* Fonction d'allocation attachée à une structure de données : */ /*----------------------------------------------------------------------------*/ -/* -DST_Status DS_DataStruct_Alloc ( size_t Size, void ** Ptr, void * Data ) + +DST_Status DS_DataStruct_Alloc ( void **Ptr_Ptr, size_t Size, void *Data_Ptr) { - DST_Status rc; - SMT_Heap * Heap; - int Locked; - DST_RootDesc * RootDesc = (DST_RootDesc *)Data; - char * Heap_Name = RootDesc->Heap_Name; + DST_Status status; + SMT_Status sm_status; + SMT_Heap *heap_ptr; + int locked; + DST_RootDesc *RootDesc = (DST_RootDesc *)Data_Ptr; +// char *heap_name = RootDesc->Heap_Name; - rc = SM_Heap_IsOpen (Heap_Name, &Heap); - if (rc != SMS_YES) + + if( ( sm_status = SM_Heap_IsOpen( RootDesc->Heap_Name, &heap_ptr)) != SMS_YES) { - sprintf (DS_Error_Msg, "Error DS_DataStruct_Alloc : the data structure heap \"%s\" is not open", Heap_Name); - DS_Error_Print (); + LG_LOG_ERROR_1( "The data structure heap: [%s] is not open", RootDesc->Heap_Name); - return rc; + return( DSS_OK); } + /* Verrouillage du heap en écriture */ -/* - rc = SM_Heap_Lock (Heap, SMD_WRITE, &Locked); - if (rc != DSS_OK) - { - sprintf (DS_Error_Msg, "Error DS_DataStruct_Alloc : 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, error: (%d)", RootDesc->Heap_Name, sm_status); + + return( DSS_OK); } + /* Allocation du chunk */ -/* - rc = SM_Chunk_Alloc (Heap, Size, Ptr); - if (rc != SMS_OK) - { - if (Locked == TRUE) SM_Heap_Unlock (Heap); - return rc; - } + 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); + + if( locked == TRUE) SM_Heap_Unlock( heap_ptr); + return( DSS_KO); + } + + /* Déverrouillage de la data structure si besoin */ -/* - if (Locked == TRUE) SM_Heap_Unlock (Heap); + + if( locked == TRUE) SM_Heap_Unlock( heap_ptr); return DSS_OK; } @@ -3075,14 +3081,14 @@ void DS_Error_Print ( void ) /*----------------------------------------------------------------------------*/ /* Pour préfixer les noms de heap avec l'identifiant de la librairie */ /*----------------------------------------------------------------------------*/ -/* -static char * DS_Name_Prefix ( const char * Name ) + +static char *DS_Name_Prefix( const char *Name ) { static char Prefixed [256]; sprintf (Prefixed, "%s/%s", DS_PREFIX, Name); - return Prefixed; + return( Prefixed); } /*----------------------------------------------------------------------------*/ diff --git a/lib/libdatastr.h b/lib/libdatastr.h index 5c7c98a..cc2fc9f 100644 --- a/lib/libdatastr.h +++ b/lib/libdatastr.h @@ -111,10 +111,15 @@ DST_Status DS_Semaphore_Create (NDT_Root * Root); /*----------------------------------------------------------------------------*/ DST_Status DS_Semaphore_Operate (int, struct sembuf *, unsigned int); + + /*----------------------------------------------------------------------------*/ /* Fonction d'allocation attachée à une structure de données : */ /*----------------------------------------------------------------------------*/ -DST_Status DS_DataStruct_Alloc ( size_t Size, void ** Ptr, void * Data ); + +DST_Status DS_DataStruct_Alloc ( void **Ptr, size_t Size, void *Data ); + + /*----------------------------------------------------------------------------*/ /* Fonction de désallocation attachée à une structure de données : */ @@ -126,10 +131,14 @@ DST_Status DS_DataStruct_Free ( void * Ptr, void * Data ); /*----------------------------------------------------------------------------*/ void DS_Error_Print ( void ); + + /*----------------------------------------------------------------------------*/ /* Pour préfixer les noms de heap avec l'identifiant de la librairie */ /*----------------------------------------------------------------------------*/ -static char * DS_Name_Prefix (const char * Name); +static char *DS_Name_Prefix (const char *Name); + + /*----------------------------------------------------------------------------*/ /* Teste si une data structure a déjà été ouverte par le processus courant */ diff --git a/util/dsbench.c b/util/dsbench.c index aac5c8c..03c1be9 100644 --- a/util/dsbench.c +++ b/util/dsbench.c @@ -194,6 +194,9 @@ NDT_Status Module_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod Command_Name = "NDD_CMD_VALUE_ALLOC"; + + LG_LOG_TRACE_0( LGD_LOG_LEVEL_DEFAULT, "CMD_VALUE_ALLOC called..."); + /* if( DS_Alloc( Root, sizeof( T_Module) + strlen( Nom) + 1, (void **)Module) == DSS_OK) { @@ -572,15 +575,17 @@ int Menu_Print( NDT_Root *Root ) int main( int argc, char **argv) { - LGT_Status lg_status; - int rc; - NDT_Root *Root = NULL; - char *tmp; - int n, m, i, j; - int choice, Nb_Removed, Locked; - int Nb_Detected, Nb_Corrected; - T_Module *Module, Ref_Module; - NDT_Node *Node; + DST_Status status; + LGT_Status lg_status; + int rc; + NDT_Root *Root_Ptr = NULL; + NDT_Index_Type index_type = ( NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_FIFO); + char *tmp; + int n, m, i, j; + int choice, Nb_Removed, Locked; + int Nb_Detected, Nb_Corrected; + T_Module *Module, Ref_Module; + NDT_Node *Node; if( ( lg_status = LG_Library_Open( LGD_LOG_WRITER_DEFAULT, true)) != LGS_OK) @@ -605,7 +610,7 @@ int main( int argc, char **argv) } else { - choice = Menu_Print( Root); + choice = Menu_Print( Root_Ptr); while (choice != QUIT) { @@ -615,17 +620,25 @@ int main( int argc, char **argv) { fprintf( stdout, "\nNom de la structure à créer ? "); fgets( DataStruct_Name, 100, stdin); -/* - if( DS_DataStruct_Open( DataStruct_Name, &Root, NDD_DS_LIST | NDD_MN_FIFO, MANAGER_FILE_NAME, 0, DSD_CREATE, TRUE) != DSS_OK) + if( strlen( DataStruct_Name) < 2) { - printf ("\nNOK\n"); + fprintf( stdout, "Bad name!\n"); } else { - strcpy( Root->Manager, "Module_Manager"); - printf( "\nStructure créée : OK\n"); + DataStruct_Name[ strlen( DataStruct_Name) - 1] = 0; + if( ( status = DS_DataStruct_Open( &Root_Ptr, DataStruct_Name, 1, &index_type, MANAGER_FILE_NAME, 0, DSD_CREATE, TRUE)) != DSS_OK) + { + LG_LOG_ERROR_1( "Can't create data structure: (%d)", status); + } + else + { +// strcpy( Root->Manager, "Module_Manager"); + + LG_LOG_INFO_1( "Data structure: [%s] created", DataStruct_Name); + } } -*/ + break; } /* @@ -929,7 +942,7 @@ int main( int argc, char **argv) fprintf (stdout, "\nChoix %d non défini\n", choice); } } - choice = Menu_Print( Root); + choice = Menu_Print( Root_Ptr); } DS_Library_Close();