From 5ecb38599b05b49856a605bac0f0bcd3f8cb3f89 Mon Sep 17 00:00:00 2001 From: glenux Date: Wed, 25 Feb 2004 17:54:51 +0000 Subject: [PATCH] *** empty log message *** --- src/ids.c | 7 ++---- src/ids.h | 8 ++++++- src/iface.h | 9 +++++--- src/proto.h | 11 ++++++++- src/queueClose.c | 1 - src/spaceListAdd.c | 48 ++++++++++++++++++++++++++++++++++++++- src/spaceListElemCreate.c | 44 +++++++++++++++++------------------ 7 files changed, 94 insertions(+), 34 deletions(-) diff --git a/src/ids.c b/src/ids.c index 4adc693..5a33d4a 100644 --- a/src/ids.c +++ b/src/ids.c @@ -1,6 +1,3 @@ -#ifndef _NZG_IDS -#define _NZG_IDS 1 - #include "libnazgul.h" #include "ids.h" @@ -143,7 +140,7 @@ int msgQueueElemIdIntern( return 0; } -int spaceListElemIdIntern(msgSpaceListElemId elemListId,msgSpaceId externId){ +int msgSpaceListElemIdIntern(msgSpaceListElemId elemListId,msgSpaceId externId){ if (strlen(externId)>MSGSPACE_ID_LEN){ return -1; } @@ -158,4 +155,4 @@ int spaceListElemIdIntern(msgSpaceListElemId elemListId,msgSpaceId externId){ } -#endif + diff --git a/src/ids.h b/src/ids.h index 7c87d5f..ff03c3d 100644 --- a/src/ids.h +++ b/src/ids.h @@ -1,8 +1,14 @@ #ifndef _NZG_IDS #define _NZG_IDS 1 - #include "libnazgul.h" +#ifdef _NZG_REALFILEID +#define msgSpaceListId "/tmp/nzgSpaceList" +#else +#define msgSpaceListId "/nzgSpaceList" +#endif + + /* nzg_ids.c */ int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src); int msgPoolSemIdIntern(msgPoolSemId destSemId, const msgSpaceId srcPoolId, int poolIdx); diff --git a/src/iface.h b/src/iface.h index 9fcc337..fa8b332 100644 --- a/src/iface.h +++ b/src/iface.h @@ -59,15 +59,18 @@ typedef struct MsgSpace { typedef struct MsgSpaceListElem { - int ownerPid; + msgSpaceListElemId id; + msgSpaceId spaceId; msgSpaceListElemId next; } msgSpaceListElem; typedef struct MsgSpaceList { + msgSpaceListId id; + int elemCounter; - msgSpaceListElemId first; - msgSpaceListElemId last; + msgSpaceListElemId headId; + msgSpaceListElemId tailId; } msgSpaceList; typedef struct MsgQueueElem { diff --git a/src/proto.h b/src/proto.h index b5ea101..3616938 100644 --- a/src/proto.h +++ b/src/proto.h @@ -34,7 +34,7 @@ int msgQueueProtSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueId int msgQueueReadSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueIdx); int msgQueueIdIntern(msgQueueId dest, msgSpaceId externId, int queueIdx); int msgQueueElemIdIntern(msgQueueElemId dest, msgQueueId src, int counter); -int spaceListElemIdIntern(msgSpaceListElemId elemListId, msgSpaceId externId); +int msgSpaceListElemIdIntern(msgSpaceListElemId elemListId, msgSpaceId externId); /* list.c */ /* poolCreate.c */ int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize); @@ -87,14 +87,23 @@ msgSpace *msgSpaceCreate(msgSpaceId externId, int queueNb, int poolNb, msgPool * /* spaceDelete.c */ int msgSpaceDelete(msgSpaceId externId); /* spaceListAdd.c */ +int msgSpaceListAdd(msgSpaceListElemId newElemId); +/* spaceListClose.c */ +int msgSpaceListClose(msgSpaceList *list); +/* spaceListElemClose.c */ +int msgSpaceListElemClose(msgSpaceListElem *listElem); /* spaceListElemCreate.c */ int msgSpaceListElemCreate(msgSpaceListElemId elemenListId, msgSpace *space); /* spaceListElemLink.c */ +/* spaceListElemOpen.c */ +void *msgSpaceListElemOpen(msgSpaceListElemId listElemId); /* spaceListInit.c */ int msgSpaceListInit(void); /* spaceListLocking.c */ int msgSpaceListLock(void); int msgSpaceListUnlock(void); +/* spaceListOpen.c */ +void *msgSpaceListOpen(void); /* spaceListRem.c */ /* spaceOpen.c */ msgSpace *msgSpaceOpen(msgSpaceId externId); diff --git a/src/queueClose.c b/src/queueClose.c index 0f8ea7a..cca58bc 100644 --- a/src/queueClose.c +++ b/src/queueClose.c @@ -1,6 +1,5 @@ #include "libnazgul.h" #include "ids.h" -#include "libnazgul.h" int msgQueueClose(msgQueue * queue){ msgQueueId qId; diff --git a/src/spaceListAdd.c b/src/spaceListAdd.c index 5caa9cb..8371331 100644 --- a/src/spaceListAdd.c +++ b/src/spaceListAdd.c @@ -3,4 +3,50 @@ // ajoute un element en début de liste. // fait pointer l'ancien dernier vers lui // il s'enregistre en tant que dernier chez la liste -int msgSpaceListAdd(msgSpaceListElemId ); +int msgSpaceListAdd(msgSpaceListElemId newElemId){ + msgSpaceListElem * listOldTailElem; + msgSpaceListElem * listNewTailElem; + msgSpaceList * list=NULL; + + list=msgSpaceListOpen(); + + // on informe l'element qui est le dernier + listNewTailElem=msgSpaceListElemOpen(newElemId); + if (listNewTailElem==NULL){ + } + strcpy(listNewTailElem->next,newElemId); + if (msgSpaceListElemClose(listNewTailElem) <0 ){ + NZG_ERROR("msgQueueElemClose",newElemId); + goto ERROR; + } + + /* TODO: verifier si la liste n'est pas vide... */ + if((strcmp(list->headId,list->id)==0) + && (strcmp(list->tailId,list->id)==0)) { + printf("- premier elem de queue -\n"); + // on donne a la queue l'id de l'element + strcpy(list->headId,newElemId); + strcpy(list->tailId,newElemId); + } else { + /* on informe son prédecesseur qu'il a un suivant */ + listOldTailElem=msgSpaceListElemOpen(list->tailId); + if (listOldTailElem == NULL){ + NZG_ERROR("msgQueueElemOpen",list->tailId); + goto ERROR; + } + strcpy(listOldTailElem->next,newElemId); + if (msgSpaceListElemClose(listOldTailElem) < 0){ + NZG_ERROR("msgQueueElemClose",list->tailId); + goto ERROR; + } + // on donne a la queue l'id du dernier element + strcpy(list->tailId,newElemId); + } + // on incremente elemCounter + list->elemCounter++; + msgSpaceListClose(list); + return 0; +ERROR: + return -1; + +} diff --git a/src/spaceListElemCreate.c b/src/spaceListElemCreate.c index 100a111..05d40f5 100644 --- a/src/spaceListElemCreate.c +++ b/src/spaceListElemCreate.c @@ -2,33 +2,33 @@ #include "ids.h" // cree un nouvel elemen -int msgSpaceListElemCreate(msgSpaceListElemId elemenListId,msgSpace * space){ +int msgSpaceListElemCreate( + msgSpaceListElemId elemenListId, + msgSpace * space) +{ - int shmElemenList; - - /*Creation de lid pour lespace de message*/ + msgSpaceId listElemId; - spaceListElemIdIntern(elemenListId,space->externId); + strcpy(listElemId,space->id); + int listElemFd; + listElemFd=shm_open(listElemId, + O_RDWR|O_CREAT|O_EXCL|O_TRUNC, + SHM_DEFAULT_MODE); - if ((shmElemenList=shm_open(elemenListId, - O_RDWR|O_CREAT|O_EXCL|O_TRUNC, - MSGSPACE_DEFAULT_MODE))==-1){ - NZG_ERROR("shm_open:Space list creation",elemenListId); - goto ERROR; - } + if (listElemFd == -1 ) { + NZG_ERROR("shm_open : msgSpaceListElem creation",listElemId); + goto ERROR; + } - if(ftruncate(shmElemenList,sizeof(elemenListId) ) <0) { - NZG_ERROR("ftruncate",elemenListId); - goto ERROR; - }; - - close (shmElemenList); - //TODO: mapper le shm en mémoire et remplir avec des informations - - //strcpy(spaceListElem->spaceId,space->id); - return 0; + if (ftruncate(listElemFd, sizeof(msgQueueElem)) < 0){ + NZG_ERROR("ftruncate", listElemId); + goto ERROR; + } + + close(listElemFd); + return 0; ERROR: - return-1; + return -1; };