- Update LibDataStr Open & Close,
- Make compile dsbench...
This commit is contained in:
parent
ed0f5062df
commit
33be3b6070
@ -137,7 +137,7 @@ typedef struct {
|
||||
int Valid; /* Indique si la structure est valide ou non */
|
||||
} DST_RootDesc;
|
||||
|
||||
char DS_Error_Msg [512];
|
||||
//char DS_Error_Msg [512];
|
||||
|
||||
/* Définition des alias de l'API */
|
||||
|
||||
|
172
lib/libdatastr.c
172
lib/libdatastr.c
@ -37,6 +37,9 @@
|
||||
|
||||
#include <libdatastr.h>
|
||||
|
||||
|
||||
|
||||
|
||||
//VER_INFO_EXPORT (libdatastr,"$Revision: 1.1 $", "$Name: $",__FILE__,"$Author: smas $")
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@ -57,33 +60,43 @@
|
||||
/* (I) Debug_Mode : mode d'affichage des messages d'erreur */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
DST_Status DS_Library_Open_I ( int Instance, const char * Context, DST_Flags Debug_Mode )
|
||||
DST_Status DS_Library_Open_I ( int Instance, const char *Context, DST_Flags Debug_Mode )
|
||||
{
|
||||
DST_Status rc;
|
||||
int SM_Debug = SMD_DEBUG_NONE;
|
||||
LGT_Status lg_status;
|
||||
SMT_Status sm_status;
|
||||
NDT_Status nd_status;
|
||||
int sm_debug_flag = SMD_DEBUG_NONE;
|
||||
NDT_Index_Type index_type = ( NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_TREE | NDD_INDEX_SUBTYPE_BALANCED);
|
||||
|
||||
|
||||
/* Définition du mode debug */
|
||||
|
||||
if (Debug_Mode & DSD_DEBUG)
|
||||
if( Debug_Mode & DSD_DEBUG)
|
||||
{
|
||||
DS_stderr = stderr;
|
||||
SM_Debug = SMD_DEBUG;
|
||||
sm_debug_flag = SMD_DEBUG;
|
||||
}
|
||||
else if (Debug_Mode & DSD_DEBUG_ALL)
|
||||
else if( Debug_Mode & DSD_DEBUG_ALL)
|
||||
{
|
||||
DS_stderr = stderr;
|
||||
SM_Debug = SMD_DEBUG_ALL;
|
||||
sm_debug_flag = SMD_DEBUG_ALL;
|
||||
}
|
||||
|
||||
|
||||
if( ( lg_status = LG_Library_Open( LGD_LOG_WRITER_DEFAULT, false)) != LGS_OK)
|
||||
{
|
||||
fprintf( stderr, "Can't open LibLog library: (%d)\n", lg_status);
|
||||
return( -1);
|
||||
}
|
||||
|
||||
|
||||
/* Ouverture de la librairie LIBSHMEM */
|
||||
|
||||
rc = SM_Library_Open (Instance, Context, SMD_OPEN | SM_Debug);
|
||||
if (rc != SMS_OK)
|
||||
if( ( sm_status = SM_Library_Open( Instance, Context, SMD_OPEN | sm_debug_flag)) != SMS_OK)
|
||||
{
|
||||
sprintf (DS_Error_Msg, "Error DS_Library_Open : unable to open the LIBSHMEM library");
|
||||
DS_Error_Print ();
|
||||
|
||||
return rc;
|
||||
LG_LOG_ERROR_1( "Unable to open the LibShMem library: (%d)", sm_status);
|
||||
return( DSS_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -92,22 +105,24 @@ DST_Status DS_Library_Open_I ( int Instance, const char * Context, DST_Flags Deb
|
||||
les data structures ouvertes.
|
||||
*/
|
||||
|
||||
if (DS_Open_Counter == 0)
|
||||
if( DS_Open_Counter == 0)
|
||||
{
|
||||
rc = ND_DataStruct_Open (&OpenedDS_List, NDD_DS_TREE | NDD_MN_AUTO_EQU, NULL, NULL, NULL, TRUE);
|
||||
if (rc != NDS_OK)
|
||||
if( ( nd_status = ND_DataStruct_Open( &OpenedDS_List, 1, &index_type, "DS_OpenedDS_List_Manager", NULL, NULL, NULL, NULL, NULL, TRUE, NULL)) != NDS_OK)
|
||||
{
|
||||
sprintf (DS_Error_Msg, "Error DS_Library_Open : unable to create the opened data structure list");
|
||||
DS_Error_Print ();
|
||||
LG_LOG_ERROR_1( "Unable to create the opened data structure list: (%d)", nd_status);
|
||||
SM_Library_Close (SMD_CLOSE);
|
||||
return rc;
|
||||
|
||||
return( SMS_KO);
|
||||
}
|
||||
else
|
||||
{
|
||||
// strcpy( OpenedDS_List->Manager, "DS_OpenedDS_List_Manager");
|
||||
}
|
||||
else strcpy (OpenedDS_List->Manager, "DS_OpenedDS_List_Manager");
|
||||
}
|
||||
|
||||
DS_Open_Counter++;
|
||||
|
||||
return DSS_OK;
|
||||
return( DSS_OK);
|
||||
}
|
||||
|
||||
|
||||
@ -116,41 +131,45 @@ DST_Status DS_Library_Open_I ( int Instance, const char * Context, DST_Flags Deb
|
||||
/* Fermeture de l'instance de la librairie */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
DST_Status DS_Library_Close_I ( void )
|
||||
DST_Status DS_Library_Close_I( void)
|
||||
{
|
||||
DST_Status rc;
|
||||
NDT_Status nd_status;
|
||||
SMT_Status sm_status;
|
||||
LGT_Status lg_status;
|
||||
|
||||
|
||||
/*
|
||||
A la dernière fermeture de la librairie LIBDATASTR, on détruit
|
||||
la structure locale qui référence les data structures ouvertes.
|
||||
*/
|
||||
|
||||
if (DS_Open_Counter == 1)
|
||||
if( DS_Open_Counter == 1)
|
||||
{
|
||||
rc = ND_DataStruct_Close (OpenedDS_List);
|
||||
if (rc != NDS_OK)
|
||||
if( ( nd_status = ND_DataStruct_Close( OpenedDS_List)) != NDS_OK)
|
||||
{
|
||||
sprintf (DS_Error_Msg, "Error DS_Library_Close : unable to close the opened data structure list");
|
||||
DS_Error_Print ();
|
||||
LG_LOG_ERROR_1( "Unable to close the opened data structure list: (%d)", nd_status);
|
||||
return( DSS_KO);
|
||||
}
|
||||
}
|
||||
|
||||
if (DS_ERROR(rc)) return rc;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fermeture de la librairie LIBSHMEM */
|
||||
|
||||
rc = SM_Library_Close (SMD_CLOSE);
|
||||
if (rc != SMS_OK)
|
||||
if( ( sm_status = SM_Library_Close( SMD_CLOSE)) != SMS_OK)
|
||||
{
|
||||
sprintf (DS_Error_Msg, "Error DS_Library_Close : unable to close the LIBSHMEM library");
|
||||
DS_Error_Print ();
|
||||
|
||||
if (DS_ERROR(rc)) return rc;
|
||||
LG_LOG_ERROR_1( "Unable to close the LibShMem library: (%d)", sm_status);
|
||||
return( DSS_KO);
|
||||
}
|
||||
|
||||
DS_Open_Counter--;
|
||||
|
||||
return rc;
|
||||
if( ( lg_status = LG_Library_Close( false)) != LGS_OK)
|
||||
{
|
||||
fprintf( stderr, "Can't close LibLog library: (%d)\n", lg_status);
|
||||
return( DSS_KO);
|
||||
}
|
||||
|
||||
return( DSS_OK);
|
||||
}
|
||||
|
||||
|
||||
@ -161,10 +180,11 @@ DST_Status DS_Library_Close_I ( void )
|
||||
/* (I) Out : flux de sortie des messages d'erreur */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
DST_Status DS_Library_Stderr_Set_I ( FILE * Out )
|
||||
DST_Status DS_Library_Stderr_Set_I( FILE *Out)
|
||||
{
|
||||
DS_stderr = Out;
|
||||
return DSS_OK;
|
||||
|
||||
return( DSS_OK);
|
||||
}
|
||||
|
||||
|
||||
@ -180,10 +200,8 @@ DST_Status DS_Library_Stderr_Set_I ( FILE * Out )
|
||||
/* (I) Open_Mode : mode d'ouverture de la structure */
|
||||
/* (I) Own_Values : 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 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;
|
||||
@ -197,7 +215,7 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
*Root = 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 (DSD_MSK_OPEN (Open_Mode)) Mode = 2;
|
||||
@ -226,7 +244,7 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
/*--------------- 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)
|
||||
{
|
||||
@ -237,7 +255,7 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
}
|
||||
|
||||
/* 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);
|
||||
@ -253,7 +271,7 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
}
|
||||
|
||||
/* Allocation de mémoire pour la description de la nouvelle data structure */
|
||||
|
||||
/*
|
||||
rc = DS_DataStruct_Alloc (sizeof (DST_RootDesc) + strlen (Prefixed_Name) + strlen (Manager_FileName) + 2, (void **)(&RootDesc), &Tmp_RootDesc);
|
||||
if (rc != DSS_OK)
|
||||
{
|
||||
@ -274,21 +292,21 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
strcpy (RootDesc->Manager_FileName, Manager_FileName);
|
||||
|
||||
/* On indique que la structure n'est pas propriétaire de son heap */
|
||||
|
||||
/*
|
||||
RootDesc->Heap_Owner = FALSE;
|
||||
|
||||
/*
|
||||
/* On indique que la structure est valide */
|
||||
|
||||
/*
|
||||
RootDesc->Valid = TRUE;
|
||||
|
||||
/*
|
||||
/* On rattache la desription de la data structure à la racine */
|
||||
|
||||
/*
|
||||
(*Root)->User = RootDesc;
|
||||
|
||||
/* Pour une telle data structure, on ne crée pas de sémaphore d'ouverture */
|
||||
|
||||
/* Déverrouillage du heap */
|
||||
|
||||
/*
|
||||
if (Locked == TRUE)
|
||||
{
|
||||
rc = SM_Heap_Unlock (Heap);
|
||||
@ -309,13 +327,13 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
/*--------------- Ouverture d'une data structure existante ------------------*/
|
||||
|
||||
/* Si la structure a déjà été ouverte, on ne recommence pas */
|
||||
|
||||
/*
|
||||
rc = DS_DataStruct_IsOpen (DS_Name, Root);
|
||||
if (rc == DSS_YES) return DSS_OK;
|
||||
else if (DS_ERROR(rc)) return rc;
|
||||
|
||||
/* Accès au heap sous-jacent en lecture */
|
||||
|
||||
/*
|
||||
rc = SM_Heap_Open (Prefixed_Name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked);
|
||||
if (rc != SMS_OK)
|
||||
{
|
||||
@ -327,11 +345,11 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
DSH = Heap->MHH->DSR->Head->Value;
|
||||
|
||||
/* La racine de la structure se trouve dans le premier chunk du premier segment du heap */
|
||||
|
||||
/*
|
||||
*Root = ( NDT_Root *)((size_t)(DSH->Start) + sizeof (NDT_Node) + sizeof (SMT_Chunk));
|
||||
|
||||
/* Chargement des fonctions manager de la structure */
|
||||
|
||||
/*
|
||||
RootDesc = (*Root)->User;
|
||||
|
||||
if (!RootDesc)
|
||||
@ -357,7 +375,7 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
case 3:
|
||||
|
||||
/*--------------- Création d'une nouvelle structure de données dans un nouveau heap -----------------*/
|
||||
|
||||
/*
|
||||
if (!Manager_FileName)
|
||||
{
|
||||
sprintf (DS_Error_Msg, "Error DS_DataStruct_Open : the manager file name (.so) is undefined");
|
||||
@ -366,7 +384,7 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
}
|
||||
|
||||
/* Création d'un nouveau heap */
|
||||
|
||||
/*
|
||||
rc = SM_Heap_Open (Prefixed_Name, &Heap, Segment_Size, SMD_CREATE | SMD_WRITE, &Locked);
|
||||
if (rc != SMS_OK)
|
||||
{
|
||||
@ -376,7 +394,7 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
}
|
||||
|
||||
/* 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);
|
||||
@ -390,7 +408,7 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
}
|
||||
|
||||
/* Allocation de mémoire pour la description de la structure */
|
||||
|
||||
/*
|
||||
rc = DS_DataStruct_Alloc (sizeof (DST_RootDesc) + strlen (Prefixed_Name) + strlen (Manager_FileName) + 2, (void **)(&RootDesc), &Tmp_RootDesc);
|
||||
if (rc != DSS_OK)
|
||||
{
|
||||
@ -408,19 +426,19 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
strcpy (RootDesc->Manager_FileName, Manager_FileName);
|
||||
|
||||
/* On indique que la structure est propriétaire du heap */
|
||||
|
||||
/*
|
||||
RootDesc->Heap_Owner = TRUE;
|
||||
|
||||
/* On indique que la structure est valide */
|
||||
|
||||
/*
|
||||
RootDesc->Valid = TRUE;
|
||||
|
||||
/* On rattache la desription de la data structure à la racine */
|
||||
|
||||
/*
|
||||
(*Root)->User = RootDesc;
|
||||
|
||||
/* On crée un sémaphore pour compter le nombre de processus qui ouvrent la structure */
|
||||
|
||||
/*
|
||||
rc = DS_Semaphore_Create (*Root);
|
||||
if (rc != DSS_OK)
|
||||
{
|
||||
@ -438,7 +456,7 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
}
|
||||
|
||||
/* 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 (rc != DSS_OK)
|
||||
{
|
||||
@ -460,7 +478,7 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
}
|
||||
|
||||
/* 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;
|
||||
@ -486,7 +504,7 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
}
|
||||
|
||||
/* Déverrouillage du heap */
|
||||
|
||||
/*
|
||||
if (Locked == TRUE)
|
||||
{
|
||||
rc = SM_Heap_Unlock (Heap);
|
||||
@ -515,6 +533,9 @@ DST_Status DS_DataStruct_Open_I ( const char * DS_Name, NDT_Root ** Root, \
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Verrouillage d'une structure de données */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@ -1533,22 +1554,24 @@ DST_Status DS_Value_Free_I ( NDT_Root * Root, void * Value )
|
||||
/* (I) Size : taille mémoire à allouer */
|
||||
/* (O) Ptr : adresse du pointeur sur la zone de données allouée */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*
|
||||
DST_Status DS_Alloc_I ( NDT_Root * Root, size_t Size, void ** Ptr )
|
||||
|
||||
DST_Status DS_Alloc_I( NDT_Root *Root, size_t Size, void **Ptr)
|
||||
{
|
||||
return DS_DataStruct_Alloc (Size, Ptr, Root->User);
|
||||
// return DS_DataStruct_Alloc (Size, Ptr, Root->User);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Désallocation d'une ressource pour une structure de données : */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* (I) Root : pointeur sur la racine de la structure de données */
|
||||
/* (I) Ptr : pointeur sur la zone à désallouer */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*
|
||||
DST_Status DS_Free_I ( NDT_Root * Root, void * Ptr )
|
||||
|
||||
DST_Status DS_Free_I( NDT_Root *Root, void *Ptr)
|
||||
{
|
||||
return DS_DataStruct_Free (Ptr, Root->User);
|
||||
// return DS_DataStruct_Free (Ptr, Root->User);
|
||||
}
|
||||
|
||||
|
||||
@ -3197,3 +3220,4 @@ NDT_Status DS_OpenedDS_List_Manager ( va_list Args )
|
||||
|
||||
return NDS_OK;
|
||||
}
|
||||
*/
|
||||
|
@ -41,6 +41,21 @@
|
||||
#include <node.h>
|
||||
#include <datastr.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Definitions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#define LGD_MODULE_NAME "ds"
|
||||
|
||||
|
||||
|
||||
|
||||
extern char * strdup ( const char * );
|
||||
|
||||
/* Compteur d'ouverture de la librairie */
|
||||
|
@ -12,7 +12,7 @@ include ../Makefile.rule
|
||||
|
||||
|
||||
DEP_STATIC += ../lib/libdatastr.a ../../libshmem/lib/libshmem.a ../../libnode/lib/libnode.a ../../liblog/lib/liblog.a
|
||||
DEP_DYNAMIC += ../lib/libdatastr.so ../lib/libnode.so ../../liblog/lib/liblog.so
|
||||
DEP_DYNAMIC += ../lib/libdatastr.so ../../libshmem/lib/libshmem.so ../../libnode/lib/libnode.so ../../liblog/lib/liblog.so
|
||||
INCLUDE += -I . -I ../include -I ../../liblog/include -I ../../libnode/include -I ../../libshmem/include
|
||||
LIBDIR += -L . -L ../lib -L ../../liblog/lib -L ../../libnode/lib -L ../../libshmem/lib
|
||||
LIB_STATIC += ../lib/libdatastr.a ../../libshmem/lib/libshmem.a ../../libnode/lib/libnode.a ../../liblog/lib/liblog.a -ldl
|
||||
|
785
util/dsbench.c
785
util/dsbench.c
@ -1,3 +1,30 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* dsbench.c */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* This file is part of LibDataStr. */
|
||||
/* */
|
||||
/* LibDataStr is free software: you can redistribute it and/or modify it */
|
||||
/* under the terms of the GNU 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 General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with LibDataStr. If not, see <https://www.gnu.org/licenses/>. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Includes */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#define DS_MODE 2
|
||||
|
||||
#include <stdio.h>
|
||||
@ -5,9 +32,19 @@
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <log.h>
|
||||
#include <node.h>
|
||||
#include <datastr.h>
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Defines */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#define LGD_MODULE_NAME "dsb"
|
||||
|
||||
extern char * strdup ( const char *);
|
||||
|
||||
#define QUIT 0
|
||||
@ -32,9 +69,19 @@ char DataStruct_Name [100];
|
||||
char menu [1000];
|
||||
char buf [100];
|
||||
long int random ( void );
|
||||
NDT_Status Module_Manager (va_list Args);
|
||||
void init_menu ( NDT_Root *);
|
||||
int print_menu ( NDT_Root *);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Prototype */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
NDT_Status Module_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *);
|
||||
|
||||
void Menu_Init ( NDT_Root *);
|
||||
int Menu_Print ( NDT_Root *);
|
||||
|
||||
/* Mesure des temps d'exécution */
|
||||
|
||||
@ -44,8 +91,8 @@ typedef struct {
|
||||
struct timeval stop;
|
||||
} T_Cpt;
|
||||
|
||||
#define t_start(x) {gettimeofday (&(x.start), NULL);}
|
||||
#define t_stop(x) {gettimeofday (&(x.stop), NULL); x.sec = (double)(x.stop.tv_sec) - (double)(x.start.tv_sec) + ((double)(x.stop.tv_usec) - (double)(x.start.tv_usec)) / 1000000;}
|
||||
#define t_start(x) { gettimeofday (&(x.start), NULL);}
|
||||
#define t_stop( x) { gettimeofday (&(x.stop), NULL); x.sec = (double)(x.stop.tv_sec) - (double)(x.start.tv_sec) + ((double)(x.stop.tv_usec) - (double)(x.start.tv_usec)) / 1000000;}
|
||||
|
||||
T_Cpt t_exec;
|
||||
|
||||
@ -56,46 +103,534 @@ typedef struct {
|
||||
char * Nom;
|
||||
} T_Module;
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Module_Manager */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
NDT_Status Module_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node *Node_Ptr, NDT_Command Command, va_list *Args_Ptr)
|
||||
{
|
||||
NDT_Root * Root = NULL;
|
||||
char * tmp;
|
||||
NDT_Command_Name Command_Name;
|
||||
|
||||
|
||||
switch( Command)
|
||||
{
|
||||
case NDD_CMD_MANAGER_VERSION:
|
||||
{
|
||||
ND_VA_ARG_GET( Version_Name_Ptr, *Args_Ptr, NDT_Version_Name *);
|
||||
|
||||
|
||||
Command_Name = "NDD_CMD_MANAGER_VERSION";
|
||||
|
||||
*Version_Name_Ptr = "$Revision: 2.13 $ $Name: libnode-2_2_0-1 $ $Date: 2010/06/06 21:26:31 $ $Author: agibert $";
|
||||
|
||||
return( NDS_OK);
|
||||
}
|
||||
|
||||
case NDD_CMD_INDEX_GET:
|
||||
{
|
||||
/*
|
||||
ND_VA_ARG_GET( Reply_Index_Id_Ptr, *Args_Ptr, NDT_Index_Id *);
|
||||
ND_VA_ARG_GET( Reply_Command_Ptr, *Args_Ptr, NDT_Command *);
|
||||
ND_VA_ARG_GET( Cmd, *Args_Ptr, NDT_Command);
|
||||
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
|
||||
*/
|
||||
ND_VA_ARG_GET( Reply_Index_Id_Ptr, *Args_Ptr, NDT_Index_Id *);
|
||||
ND_VA_ARG_GET( Reply_Command_Ptr, *Args_Ptr, NDT_Command *);
|
||||
ND_VA_ARG_GET( Cmd, *Args_Ptr, NDT_Command);
|
||||
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
|
||||
|
||||
|
||||
Command_Name = "NDD_CMD_INDEX_GET";
|
||||
|
||||
switch(Cmd)
|
||||
{
|
||||
/*
|
||||
case NDT_CMD_SOME_USER_CMD:
|
||||
{
|
||||
*Reply_Index_Id_Ptr = 0;
|
||||
*Reply_Command_Ptr = NDD_CMD_SOME_OTHER_CMD;
|
||||
break;
|
||||
}
|
||||
|
||||
...
|
||||
*/
|
||||
|
||||
default:
|
||||
{
|
||||
*Reply_Index_Id_Ptr = Index_Id;
|
||||
*Reply_Command_Ptr = Cmd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return( NDS_OK);
|
||||
}
|
||||
|
||||
case NDD_CMD_VALUE_ALLOC:
|
||||
{
|
||||
/*
|
||||
ND_VA_ARG_GET( Value_Ptr_Ptr, *Args_Ptr, void **);
|
||||
|
||||
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
|
||||
|
||||
ND_VA_ARG_GET( user_data, user_args, user_type);
|
||||
ND_VA_ARG_GET( ..., user_args, ...);
|
||||
|
||||
ND_VA_LIST_CLOSE( user_args);
|
||||
*/
|
||||
|
||||
ND_VA_ARG_GET( Module_Ptr_Ptr, *Args_Ptr, T_Module **);
|
||||
|
||||
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
|
||||
|
||||
ND_VA_ARG_GET( Nom, user_args, char *);
|
||||
ND_VA_ARG_GET( Id, user_args, int);
|
||||
|
||||
ND_VA_LIST_CLOSE( user_args);
|
||||
|
||||
|
||||
Command_Name = "NDD_CMD_VALUE_ALLOC";
|
||||
/*
|
||||
if( DS_Alloc( Root, sizeof( T_Module) + strlen( Nom) + 1, (void **)Module) == DSS_OK)
|
||||
{
|
||||
(* Module_Ptr_Ptr)->Id = Id;
|
||||
(* Module_Ptr_Ptr)->Nom = (char *)((size_t)(*Module) + sizeof (T_Module));
|
||||
strcpy( ( *Module)->Nom, Nom);
|
||||
|
||||
return( DSS_OK)
|
||||
}
|
||||
else
|
||||
{
|
||||
LG_LOG_ERROR_0( "Allocation error");
|
||||
|
||||
return( DSS_KO)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
case NDD_CMD_VALUE_FREE:
|
||||
{
|
||||
/*
|
||||
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
|
||||
|
||||
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
|
||||
|
||||
ND_VA_ARG_GET( user_data, user_args, user_type);
|
||||
ND_VA_ARG_GET( ..., user_args, ...);
|
||||
|
||||
ND_VA_LIST_CLOSE( user_args);
|
||||
*/
|
||||
|
||||
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
|
||||
|
||||
|
||||
Command_Name = "NDD_CMD_VALUE_FREE";
|
||||
|
||||
/*
|
||||
DS_Free( Root_Ptr, Value_Ptr);
|
||||
*/
|
||||
return( NDS_OK);
|
||||
}
|
||||
|
||||
case NDD_CMD_VALUE_COMP:
|
||||
{
|
||||
/*
|
||||
ND_VA_ARG_GET( Value1_Ptr, *Args_Ptr, void *);
|
||||
ND_VA_ARG_GET( Value2_Ptr, *Args_Ptr, void *);
|
||||
|
||||
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
|
||||
|
||||
ND_VA_ARG_GET( user_data, user_args, user_type);
|
||||
ND_VA_ARG_GET( ..., user_args, ...);
|
||||
|
||||
ND_VA_LIST_CLOSE( user_args);
|
||||
*/
|
||||
|
||||
ND_VA_ARG_GET( Value1_Ptr, *Args_Ptr, T_Module *);
|
||||
ND_VA_ARG_GET( Value2_Ptr, *Args_Ptr, T_Module *);
|
||||
|
||||
|
||||
Command_Name = "NDD_CMD_VALUE_COMP";
|
||||
|
||||
|
||||
switch( Index_Id)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if( Value1_Ptr->Id < Value2_Ptr->Id)
|
||||
{
|
||||
return(NDS_LOWER);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( Value1_Ptr->Id > Value2_Ptr->Id)
|
||||
{
|
||||
return(NDS_GREATER);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(NDS_EQUAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
printf( "Unknown COMP idx (%d) !\n", Index_Id);
|
||||
return( NDS_KO);
|
||||
}
|
||||
}
|
||||
|
||||
return( NDS_OK);
|
||||
}
|
||||
|
||||
case NDD_CMD_VALUE_ADD:
|
||||
{
|
||||
/*
|
||||
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
|
||||
|
||||
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
|
||||
|
||||
ND_VA_ARG_GET( user_data, user_args, user_type);
|
||||
ND_VA_ARG_GET( ..., user_args, ...);
|
||||
|
||||
ND_VA_LIST_CLOSE( user_args);
|
||||
*/
|
||||
|
||||
|
||||
Command_Name = "NDD_CMD_VALUE_ADD";
|
||||
|
||||
/*
|
||||
return( NDS_OK);
|
||||
*/
|
||||
}
|
||||
|
||||
case NDD_CMD_VALUE_REMOVE:
|
||||
{
|
||||
/*
|
||||
ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *);
|
||||
|
||||
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
|
||||
|
||||
ND_VA_ARG_GET( user_data, user_args, user_type);
|
||||
ND_VA_ARG_GET( ..., user_args, ...);
|
||||
|
||||
ND_VA_LIST_CLOSE( user_args);
|
||||
*/
|
||||
|
||||
Command_Name = "NDD_CMD_VALUE_REMOVE";
|
||||
|
||||
return( NDS_OK);
|
||||
}
|
||||
|
||||
case NDD_CMD_VALUE_PRINT:
|
||||
{
|
||||
/*
|
||||
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
|
||||
|
||||
ND_VA_LIST_OPEN( lib_args, *Args_Ptr);
|
||||
|
||||
ND_VA_ARG_GET( Out, lib_args, FILE *);
|
||||
ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode);
|
||||
ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth);
|
||||
ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset);
|
||||
|
||||
ND_VA_LIST_OPEN( user_args, lib_args);
|
||||
|
||||
ND_VA_ARG_GET( user_data, user_args, user_type);
|
||||
ND_VA_ARG_GET( ..., user_args, ...);
|
||||
|
||||
ND_VA_LIST_CLOSE( user_args);
|
||||
ND_VA_LIST_CLOSE( lib_args);
|
||||
|
||||
void *Value_Ptr = Node_Ptr->Value;
|
||||
*/
|
||||
|
||||
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
|
||||
|
||||
ND_VA_LIST_OPEN( lib_args, *Args_Ptr);
|
||||
|
||||
ND_VA_ARG_GET( Out, lib_args, FILE *);
|
||||
ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode);
|
||||
ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth);
|
||||
ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset);
|
||||
|
||||
ND_VA_LIST_CLOSE( lib_args);
|
||||
|
||||
T_Module *Module_Ptr = (T_Module *)Node_Ptr->Value;
|
||||
|
||||
Command_Name = "NDD_CMD_VALUE_PRINT";
|
||||
|
||||
fprintf( Out, "Id Module: (%d) Nom Module: [%s]", Module_Ptr->Id, Module_Ptr->Nom);
|
||||
|
||||
return( NDS_OK);
|
||||
}
|
||||
|
||||
case NDD_CMD_INFO_PRINT:
|
||||
{
|
||||
/*
|
||||
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
|
||||
|
||||
ND_VA_LIST_OPEN( lib_args, *Args_Ptr);
|
||||
|
||||
ND_VA_ARG_GET( Out, lib_args, FILE *);
|
||||
ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode);
|
||||
ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth);
|
||||
ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset);
|
||||
|
||||
ND_VA_LIST_OPEN( user_args, lib_args);
|
||||
|
||||
ND_VA_ARG_GET( user_data, user_args, user_type);
|
||||
ND_VA_ARG_GET( ..., user_args, ...);
|
||||
|
||||
ND_VA_LIST_CLOSE( user_args);
|
||||
ND_VA_LIST_CLOSE( lib_args);
|
||||
*/
|
||||
|
||||
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
|
||||
|
||||
ND_VA_LIST_OPEN( lib_args, *Args_Ptr);
|
||||
|
||||
ND_VA_ARG_GET( Out, lib_args, FILE *);
|
||||
ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode);
|
||||
ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth);
|
||||
ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset);
|
||||
|
||||
ND_VA_LIST_CLOSE( lib_args);
|
||||
|
||||
char *Root_Type;
|
||||
DST_RootDesc *RootDesc;
|
||||
|
||||
|
||||
Command_Name = "NDD_CMD_INFO_PRINT";
|
||||
|
||||
/*
|
||||
switch( (int)(Root_Ptr->Type & NDD_DS_MSK))
|
||||
{
|
||||
case NDD_DS_LIST:
|
||||
{
|
||||
switch ((int)(Root_Ptr->Type & NDD_MN_MSK))
|
||||
{
|
||||
case NDD_MN_ORDERED: Root_Type = strdup ("liste triée"); break;
|
||||
case NDD_MN_FILO: Root_Type = strdup ("liste FILO"); break;
|
||||
case NDD_MN_FIFO: Root_Type = strdup ("liste FIFO"); break;
|
||||
default: Root_Type = strdup ("inconnu"); break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case NDD_DS_TREE :
|
||||
{
|
||||
switch( (int)(Root_Ptr->Type & NDD_MN_MSK))
|
||||
{
|
||||
case NDD_MN_AUTO_EQU: Root_Type = strdup ("arbre auto-équilibré"); break;
|
||||
default: Root_Type = strdup ("arbre non auto-équilibré"); break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default: Root_Type = strdup ("inconnu"); break;
|
||||
}
|
||||
|
||||
RootDesc = (DST_RootDesc *)(Root->User);
|
||||
fprintf( Out, \
|
||||
"\nStructure de type %s :\n\t- Nom = %s\n\t- Manager = %s\n\t- Nombre de modules = %ld\n", \
|
||||
Root_Type, RootDesc->Heap_Name, RootDesc->Manager_FileName, Root_Ptr->Node_Number);
|
||||
|
||||
if( ( Root->Type & NDD_DS_MSK) == NDD_DS_TREE)
|
||||
fprintf( Out, "\t- Profondeur maxi = %ld\n\t- Profondeur mini = %ld\n\t- Différence maximale autorisée = %ld\n\t- Nombre d'équilibrages = %ld\n", \
|
||||
Root_Ptr->Max_Depth, Root_Ptr->Min_Depth, Root_Ptr->Max_Dif, Root_Ptr->Nb_Equ);
|
||||
|
||||
if( Root_Type) free( Root_Type);
|
||||
*/
|
||||
return( NDS_OK);
|
||||
}
|
||||
|
||||
case NDD_CMD_USER_TRAVERSE:
|
||||
{
|
||||
/*
|
||||
ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *);
|
||||
|
||||
ND_VA_LIST_OPEN( user_args, *Args_Ptr);
|
||||
|
||||
ND_VA_ARG_GET( user_data, user_args, user_type);
|
||||
ND_VA_ARG_GET( ..., user_args, ...);
|
||||
|
||||
ND_VA_LIST_CLOSE( user_args);
|
||||
|
||||
|
||||
void *Value_Ptr = Node_Ptr->Value;
|
||||
*/
|
||||
|
||||
|
||||
Command_Name = "NDD_CMD_USER_TRAVERSE";
|
||||
|
||||
/*
|
||||
return( NDS_OK);
|
||||
*/
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
LG_LOG_ERROR_1( "Manager called with an undefined command: (%d)", Command);
|
||||
return( NDS_ERRAPI);
|
||||
}
|
||||
}
|
||||
|
||||
LG_LOG_ERROR_2( "Manager internal error with command: (%d) name: [%s]", Command, Command_Name);
|
||||
return( NDS_OK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Menu_Init */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
void Menu_Init( NDT_Root *Root )
|
||||
{
|
||||
sprintf (menu, "Menu :\n");
|
||||
sprintf (buf, " - %d) %-30s\n", QUIT, "Quitter");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s", CREATE_STRUCT, "Création de structure");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s\n", OPEN_STRUCT, "Ouverture de structure");
|
||||
strcat (menu, buf);
|
||||
if (Root != NULL)
|
||||
{
|
||||
sprintf (buf, " - %d) %-30s", CLOSE_STRUCT, "Fermer la structure");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s\n", DELETE_STRUCT, "Détruire la structure");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s", ADD_VALUE, "Ajout de valeurs");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s\n", REMOVE_VALUE, "Suppression de valeurs");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s\n", FIND_VALUE, "Recherche de valeurs aléatoires");
|
||||
strcat (menu, buf);
|
||||
|
||||
if( ND_INDEX_TYPE_LIST_IS( Root, NDD_INDEX_PRIMARY))
|
||||
{
|
||||
sprintf (buf, " - %d) %-30s", CHG_LIST_TYPE, "Changement de type de liste");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s\n", CONVERT_TO_TREE, "Conversion en arbre");
|
||||
strcat (menu, buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf (buf, " - %d) %-30s", CONVERT_TO_LIST, "Conversion en liste triée");
|
||||
strcat (menu, buf);
|
||||
}
|
||||
|
||||
sprintf (buf, " - %d) %-30s\n", REORG, "Réorganisation");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s", INFO, "Informations sur la structure");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s\n", SHOW, "Affichage de la structure");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s\n", CHECK, "Vérification de la structure");
|
||||
strcat (menu, buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Menu_Print */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
int Menu_Print( NDT_Root *Root )
|
||||
{
|
||||
Menu_Init (Root);
|
||||
fprintf (stdout, "\n---------------------------------------------------------\n");
|
||||
fprintf (stdout, menu);
|
||||
buf [0] = '\0';
|
||||
while (buf [0] == '\0')
|
||||
{
|
||||
printf ("\nChoice ? ");
|
||||
fgets( buf, 100, stdin);
|
||||
}
|
||||
|
||||
return atoi (buf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* main */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
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;
|
||||
T_Module *Module, Ref_Module;
|
||||
NDT_Node *Node;
|
||||
|
||||
if (argc > 1 && !strcmp (argv[1], "-h"))
|
||||
|
||||
if( ( lg_status = LG_Library_Open( LGD_LOG_WRITER_DEFAULT, true)) != LGS_OK)
|
||||
{
|
||||
fprintf (stdout, "Usage : %s [-h] [instance [context]]\n", argv[0]);
|
||||
return 0;
|
||||
fprintf( stderr, "Can't open LibLog library: (%d)\n", lg_status);
|
||||
return( -1);
|
||||
}
|
||||
|
||||
if (DS_Library_Open (0, NULL, DSD_DEBUG_ALL) != NDS_OK) return 0;
|
||||
LG_LOG_INFO_0( "Start DSBench");
|
||||
|
||||
choice = print_menu (Root);
|
||||
|
||||
if( argc > 1 && !strcmp (argv[1], "-h"))
|
||||
{
|
||||
fprintf( stdout, "Usage : %s [-h] [instance [context]]\n", argv[0]);
|
||||
rc = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( DS_Library_Open (0, NULL, DSD_DEBUG_ALL) != NDS_OK)
|
||||
{
|
||||
rc = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
choice = Menu_Print( Root);
|
||||
|
||||
while (choice != QUIT)
|
||||
{
|
||||
switch (choice)
|
||||
{
|
||||
case CREATE_STRUCT:
|
||||
fprintf (stdout, "\nNom de la structure à créer ? ");
|
||||
gets (DataStruct_Name);
|
||||
|
||||
if (DS_DataStruct_Open (DataStruct_Name, &Root, NDD_DS_LIST | NDD_MN_FIFO, \
|
||||
MANAGER_FILE_NAME, 0, DSD_CREATE, TRUE) != DSS_OK)
|
||||
{
|
||||
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)
|
||||
{
|
||||
printf ("\nNOK\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy (Root->Manager, "Module_Manager");
|
||||
printf ("\nStructure créée : OK\n");
|
||||
strcpy( Root->Manager, "Module_Manager");
|
||||
printf( "\nStructure créée : OK\n");
|
||||
}
|
||||
|
||||
*/
|
||||
break;
|
||||
|
||||
}
|
||||
/*
|
||||
case DELETE_STRUCT:
|
||||
{
|
||||
if (DS_DataStruct_Close (Root, DSD_DESTROY) == DSS_KO) printf ("\nNOK\n");
|
||||
else
|
||||
{
|
||||
@ -104,8 +639,10 @@ int main (int argc, char ** argv)
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case OPEN_STRUCT:
|
||||
{
|
||||
fprintf (stdout, "\nNom de la structure à ouvrir ? ");
|
||||
gets (DataStruct_Name);
|
||||
|
||||
@ -115,8 +652,10 @@ int main (int argc, char ** argv)
|
||||
printf ("\nStructure ouverte : OK\n");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CLOSE_STRUCT:
|
||||
{
|
||||
if (DS_DataStruct_Close (Root, DSD_CLOSE) == DSS_KO) printf ("\nNOK\n");
|
||||
else
|
||||
{
|
||||
@ -125,8 +664,10 @@ int main (int argc, char ** argv)
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case FIND_VALUE:
|
||||
{
|
||||
fprintf (stdout, "\nPlage de recherche (?->?) : ");
|
||||
gets (buf);
|
||||
tmp = strstr (buf, "->");
|
||||
@ -167,8 +708,10 @@ int main (int argc, char ** argv)
|
||||
fprintf (stdout, "\n%d valeur(s) recherchée(s) en %.4f sec (%.2f select/sec)\n", \
|
||||
m - n + 1, t_exec.sec, (m - n + 1) / t_exec.sec);
|
||||
break;
|
||||
}
|
||||
|
||||
case ADD_VALUE:
|
||||
{
|
||||
fprintf (stdout, "\nPlage des valeurs à ajouter (?->?) : ");
|
||||
gets (buf);
|
||||
tmp = strstr (buf, "->");
|
||||
@ -226,8 +769,10 @@ int main (int argc, char ** argv)
|
||||
fprintf (stdout, "\n%d valeur(s) ajoutée(s) en %.4f sec (%.2f ajouts/sec)\n", m - n + 1, \
|
||||
t_exec.sec, (m - n + 1) / t_exec.sec);
|
||||
break;
|
||||
}
|
||||
|
||||
case REMOVE_VALUE:
|
||||
{
|
||||
Nb_Removed = 0;
|
||||
fprintf (stdout, "\nPlage des valeurs à supprimer (?->?) : ");
|
||||
gets (buf);
|
||||
@ -296,8 +841,10 @@ int main (int argc, char ** argv)
|
||||
fprintf (stdout, "\n%d valeur(s) supprimée(s) en %.4f sec (%.2f suppressions/sec)\n",\
|
||||
Nb_Removed, t_exec.sec, (m - n + 1) / t_exec.sec);
|
||||
break;
|
||||
}
|
||||
|
||||
case CHG_LIST_TYPE:
|
||||
{
|
||||
fprintf (stdout, "\nType de liste (FIFO=0 ; FILO=1 ; triée=2) ? ");
|
||||
gets (buf);
|
||||
choice = atoi (buf);
|
||||
@ -319,8 +866,10 @@ int main (int argc, char ** argv)
|
||||
}
|
||||
DS_DataStruct_Unlock (Root);
|
||||
break;
|
||||
}
|
||||
|
||||
case REORG:
|
||||
{
|
||||
t_start (t_exec);
|
||||
DS_DataStruct_Lock (Root, DSD_WRITE, &Locked);
|
||||
DS_DataStruct_Reorg (Root);
|
||||
@ -328,8 +877,10 @@ int main (int argc, char ** argv)
|
||||
t_stop (t_exec);
|
||||
fprintf (stdout, "\nRéorganisation de la structure en %.4f sec\n", t_exec.sec);
|
||||
break;
|
||||
}
|
||||
|
||||
case CONVERT_TO_LIST:
|
||||
{
|
||||
t_start (t_exec);
|
||||
DS_DataStruct_Lock (Root, DSD_WRITE, &Locked);
|
||||
DS_DataStruct_Convert (Root, NDD_DS_LIST | NDD_MN_ORDERED);
|
||||
@ -337,8 +888,10 @@ int main (int argc, char ** argv)
|
||||
t_stop (t_exec);
|
||||
fprintf (stdout, "\nConversion arbre vers liste en %.4f sec\n", t_exec.sec);
|
||||
break;
|
||||
}
|
||||
|
||||
case CONVERT_TO_TREE:
|
||||
{
|
||||
t_start (t_exec);
|
||||
DS_DataStruct_Lock (Root, DSD_WRITE, &Locked);
|
||||
DS_DataStruct_Convert (Root, NDD_DS_TREE | NDD_MN_AUTO_EQU);
|
||||
@ -346,184 +899,54 @@ int main (int argc, char ** argv)
|
||||
t_stop (t_exec);
|
||||
fprintf (stdout, "\nConversion liste vers arbre en %.4f sec\n", t_exec.sec);
|
||||
break;
|
||||
}
|
||||
|
||||
case INFO:
|
||||
{
|
||||
DS_DataStruct_Lock (Root, DSD_READ, &Locked);
|
||||
DS_DataStruct_Info_Print (Root, stdout);
|
||||
DS_DataStruct_Unlock (Root);
|
||||
break;
|
||||
}
|
||||
|
||||
case SHOW:
|
||||
{
|
||||
DS_DataStruct_Lock (Root, DSD_READ, &Locked);
|
||||
DS_DataStruct_Dump (Root, stdout);
|
||||
DS_DataStruct_Unlock (Root);
|
||||
break;
|
||||
}
|
||||
|
||||
case CHECK:
|
||||
{
|
||||
Nb_Corrected = Nb_Detected = 0;
|
||||
ND_DataStruct_Check (Root, &Nb_Detected, &Nb_Corrected, stderr);
|
||||
break;
|
||||
|
||||
}
|
||||
*/
|
||||
default:
|
||||
{
|
||||
fprintf (stdout, "\nChoix %d non défini\n", choice);
|
||||
}
|
||||
choice = print_menu (Root);
|
||||
}
|
||||
DS_Library_Close ();
|
||||
return 0;
|
||||
choice = Menu_Print( Root);
|
||||
}
|
||||
|
||||
DS_Library_Close();
|
||||
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
LG_LOG_INFO_0( "End DSBench");
|
||||
|
||||
if( ( lg_status = LG_Library_Close( true)) != LGS_OK)
|
||||
{
|
||||
fprintf( stderr, "Can't close LibLog library: (%d)\n", lg_status);
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
return( rc);
|
||||
}
|
||||
|
||||
|
||||
NDT_Status Module_Manager (va_list Args)
|
||||
{
|
||||
NDT_Command Command = (NDT_Command) va_arg (Args, NDT_Command);
|
||||
|
||||
if (Command == NDD_CMD_MAKE_VALUE)
|
||||
{
|
||||
NDT_Root * Root = va_arg (Args, NDT_Root *);
|
||||
T_Module ** Module = va_arg (Args, T_Module **);
|
||||
va_list Value_Args = va_arg (Args, va_list);
|
||||
char * Nom = va_arg (Value_Args, char *);
|
||||
int Id = va_arg (Value_Args, int);
|
||||
if (DS_Alloc (Root, sizeof (T_Module) + strlen (Nom) + 1, (void **)Module) == DSS_OK)
|
||||
{
|
||||
(* Module)->Id = Id;
|
||||
(* Module)->Nom = (char *)((size_t)(*Module) + sizeof (T_Module));
|
||||
strcpy ((* Module)->Nom, Nom);
|
||||
}
|
||||
return (NDS_OK);
|
||||
}
|
||||
|
||||
if (Command == NDD_CMD_PRINT_VALUE)
|
||||
{
|
||||
T_Module * Module = (T_Module *) va_arg (Args, void *);
|
||||
FILE * Out = va_arg (Args, FILE *);
|
||||
fprintf (Out, "Id Module=%d Nom Module='%s'", Module->Id, Module->Nom);
|
||||
return (NDS_OK);
|
||||
}
|
||||
|
||||
if (Command == NDD_CMD_DELETE_VALUE)
|
||||
{
|
||||
NDT_Root * Root = va_arg (Args, NDT_Root *);
|
||||
T_Module * value = (T_Module *) va_arg (Args, void *);
|
||||
DS_Free (Root, value);
|
||||
return (NDS_OK);
|
||||
}
|
||||
|
||||
if (Command == NDD_CMD_PRINT_INFO)
|
||||
{
|
||||
NDT_Root * Root = va_arg (Args, NDT_Root *);
|
||||
FILE * Out = va_arg (Args, FILE *);
|
||||
char * Root_Type;
|
||||
DST_RootDesc * RootDesc;
|
||||
|
||||
switch ((int)(Root->Type & NDD_DS_MSK))
|
||||
{
|
||||
case NDD_DS_LIST :
|
||||
switch ((int)(Root->Type & NDD_MN_MSK))
|
||||
{
|
||||
case NDD_MN_ORDERED : Root_Type = strdup ("liste triée"); break;
|
||||
case NDD_MN_FILO : Root_Type = strdup ("liste FILO"); break;
|
||||
case NDD_MN_FIFO : Root_Type = strdup ("liste FIFO"); break;
|
||||
default: Root_Type = strdup ("inconnu"); break;
|
||||
}
|
||||
break;
|
||||
|
||||
case NDD_DS_TREE :
|
||||
switch ((int)(Root->Type & NDD_MN_MSK))
|
||||
{
|
||||
case NDD_MN_AUTO_EQU : Root_Type = strdup ("arbre auto-équilibré"); break;
|
||||
default: Root_Type = strdup ("arbre non auto-équilibré"); break;
|
||||
}
|
||||
break;
|
||||
|
||||
default: Root_Type = strdup ("inconnu"); break;
|
||||
}
|
||||
|
||||
RootDesc = (DST_RootDesc *)(Root->User);
|
||||
fprintf (Out, \
|
||||
"\nStructure de type %s :\n\t- Nom = %s\n\t- Manager = %s\n\t- Nombre de modules = %ld\n", \
|
||||
Root_Type, RootDesc->Heap_Name, RootDesc->Manager_FileName, Root->Node_Number);
|
||||
|
||||
if ((Root->Type & NDD_DS_MSK) == NDD_DS_TREE)
|
||||
fprintf (Out, "\t- Profondeur maxi = %ld\n\t- Profondeur mini = %ld\n\t- Différence maximale autorisée = %ld\n\t- Nombre d'équilibrages = %ld\n", \
|
||||
Root->Max_Depth, Root->Min_Depth, Root->Max_Dif, Root->Nb_Equ);
|
||||
|
||||
if (Root_Type) free (Root_Type);
|
||||
|
||||
return (NDS_OK);
|
||||
}
|
||||
|
||||
if (Command == NDD_CMD_COMP_VALUE)
|
||||
{
|
||||
T_Module * Value1, * Value2;
|
||||
long comp;
|
||||
|
||||
Value1 = (T_Module *) va_arg (Args, void *);
|
||||
Value2 = (T_Module *) va_arg (Args, void *);
|
||||
va_end (Args);
|
||||
comp = Value1->Id - Value2->Id;
|
||||
if (comp < 0) return NDS_LOWER;
|
||||
if (comp > 0) return NDS_GREATER;
|
||||
return NDS_EQUAL;
|
||||
}
|
||||
return (NDS_OK);
|
||||
}
|
||||
|
||||
void init_menu ( NDT_Root * Root )
|
||||
{
|
||||
sprintf (menu, "Menu :\n");
|
||||
sprintf (buf, " - %d) %-30s\n", QUIT, "Quitter");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s", CREATE_STRUCT, "Création de structure");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s\n", OPEN_STRUCT, "Ouverture de structure");
|
||||
strcat (menu, buf);
|
||||
if (Root != NULL)
|
||||
{
|
||||
sprintf (buf, " - %d) %-30s", CLOSE_STRUCT, "Fermer la structure");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s\n", DELETE_STRUCT, "Détruire la structure");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s", ADD_VALUE, "Ajout de valeurs");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s\n", REMOVE_VALUE, "Suppression de valeurs");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s\n", FIND_VALUE, "Recherche de valeurs aléatoires");
|
||||
strcat (menu, buf);
|
||||
if (ND_IS_LIST(Root))
|
||||
{
|
||||
sprintf (buf, " - %d) %-30s", CHG_LIST_TYPE, "Changement de type de liste");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s\n", CONVERT_TO_TREE, "Conversion en arbre");
|
||||
strcat (menu, buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf (buf, " - %d) %-30s", CONVERT_TO_LIST, "Conversion en liste triée");
|
||||
strcat (menu, buf);
|
||||
}
|
||||
sprintf (buf, " - %d) %-30s\n", REORG, "Réorganisation");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s", INFO, "Informations sur la structure");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s\n", SHOW, "Affichage de la structure");
|
||||
strcat (menu, buf);
|
||||
sprintf (buf, " - %d) %-30s\n", CHECK, "Vérification de la structure");
|
||||
strcat (menu, buf);
|
||||
}
|
||||
}
|
||||
|
||||
int print_menu ( NDT_Root * Root )
|
||||
{
|
||||
init_menu (Root);
|
||||
fprintf (stdout, "\n---------------------------------------------------------\n");
|
||||
fprintf (stdout, menu);
|
||||
buf [0] = '\0';
|
||||
while (buf [0] == '\0')
|
||||
{
|
||||
printf ("\nChoice ? ");
|
||||
gets (buf);
|
||||
}
|
||||
return atoi (buf);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user