diff --git a/src/poolDataTabClose.c b/src/poolDataTabClose.c new file mode 100644 index 0000000..79b1107 --- /dev/null +++ b/src/poolDataTabClose.c @@ -0,0 +1,13 @@ +#include "libnazgul.h" + +int msgPoolDataTabClose(msgSpace * space,void * addr){ + /* unmapper le msgPoolDataTab */ + + if (munmap(addr,(space->poolNb) * sizeof( msgPoolData )) < 0){ + NZG_ERROR("unmap",space->poolDataTabId); + goto ERROR; + } + return 0; +ERROR: + return -1; +} diff --git a/src/poolDataTabLock.c b/src/poolDataTabLock.c new file mode 100644 index 0000000..907afe7 --- /dev/null +++ b/src/poolDataTabLock.c @@ -0,0 +1,28 @@ +#include "libnazgul.h" +#include "ids.h" + +int msgPoolDataTabLock(msgSpace * space){ + sem_t * poolDataTabSemFd; + + poolDataTabSemFd=sem_open( + space->poolDataTabSemId + ,O_CREAT, + SEM_DEFAULT_MODE, + 1); + if(poolDataTabSemFd==SEM_FAILED){ + NZG_ERROR("sem_open",space->poolDataTabSemId); + goto ERROR; + } + + if(sem_wait(poolDataTabSemFd)==-1){ + NZG_ERROR("sem_wait",space->poolDataTabSemId); + goto ERROR; + } + + sem_close(poolDataTabSemFd); + + return 0; +ERROR: + return -1; +} + diff --git a/src/poolDataTabOpen.c b/src/poolDataTabOpen.c new file mode 100644 index 0000000..14e6d8c --- /dev/null +++ b/src/poolDataTabOpen.c @@ -0,0 +1,31 @@ +#include "libnazgul.h" +#include "ids.h" + +void * msgPoolDataTabOpen(msgSpace * space){ + int poolDataTabFd; + void * poolDataTabAddr; + + poolDataTabFd=shm_open(space->poolDataTabId, + O_RDWR, + MSGSPACE_DEFAULT_MODE); + if (poolDataTabFd == -1 ) { + NZG_ERROR("shm_open",space->poolDataTabId); + goto ERROR; + } + + + poolDataTabAddr = mmap( NULL, (space->poolNb) * sizeof( msgPoolData ), + PROT_READ | PROT_WRITE, + MAP_SHARED, poolDataTabFd, 0 ); + + if( poolDataTabAddr == MAP_FAILED) { + NZG_ERROR("mmap",space->poolDataTabId); + goto ERROR; + } + + close(poolDataTabFd); + + return poolDataTabAddr; +ERROR: + return NULL; +} diff --git a/src/poolDataTabUnlock.c b/src/poolDataTabUnlock.c new file mode 100644 index 0000000..e69de29 diff --git a/src/put.c b/src/put.c new file mode 100644 index 0000000..1ba76e4 --- /dev/null +++ b/src/put.c @@ -0,0 +1,54 @@ +#include "libnazgul.h" + +int msgPut(msgSpace * space,int queueIndex, void * addr){ + // retrouver le pool, buffer qui correspondent à l'addresse... + msgPoolData * poolDataTabAddr; +int poolIndex; +int bufferIndex; +int err; + msgPoolDataTabLock(space); + poolDataTabAddr=msgPoolDataTabOpen(space); + + err=msgBufferGetProcAttach( + poolDataTabAddr, + space->poolNb, + &poolIndex, + &bufferIndex, + addr + ); + + + // ouvrir la queue avec le bon index + msgQueueId queueId; + msgQueue * queue; + msgQueueIdIntern(queueId,space->externId,queueIndex); + queue = msgQueueOpen(queueId); + + // TODO:creer un element vide + msgQueueElemId newElemId; + msgQueueElem * queueElem; + + msgQueueElemCreate(newElemId,queueId,queue->elemCounter); + // ouvrir l'element + queueElem=msgQueueElemOpen(newElemId); + // modifier les index pour retrouver le buffer + queueElem->poolIndex=poolIndex; + queueElem->bufferIndex=bufferIndex; + // fermer l'element + msgQueueElemClose(queueElem); + + //ajouter le message a la bonne file... +msgQueueElemAdd(queue,newElemId); + + // fermer la file + msgQueueClose(queue); + + msgPoolDataTabClose(space,poolDataTabAddr); + /* msgPoolDataTabUnlock(space->id); + */ + return 0; +ERROR: + return -1; +} + +