diff --git a/src/nzg_buffer.c b/src/nzg_buffer.c index 57a51e6..623b689 100644 --- a/src/nzg_buffer.c +++ b/src/nzg_buffer.c @@ -1,4 +1,15 @@ -/* - int msgBufferDetachProc(msgSpace * space, int poolIndex){ - } - */ +#include "libnazgul.h" + +int msgBufferGetAttachedProcIndex( + msgPoolData * poolDataTabAddr, + int poolIndex, + void * addr + ){ + + //TODO: parcourrir tous les index, et regarder s'il y + //a une addresse qui correspond avec le meme processus... + //et renvoyer l'index du buffer correspondant a l'addresse... +return 0; +} + + diff --git a/src/nzg_bufferAttachProc.c b/src/nzg_bufferAttachProc.c new file mode 100644 index 0000000..8e81bc5 --- /dev/null +++ b/src/nzg_bufferAttachProc.c @@ -0,0 +1,37 @@ +#include "libnazgul.h" + +int msgBufferAttachProc( + msgPoolData * poolDataTabAddr, + int poolIndex, + int bufferIndex, + void * addr) +{ + msgBufferInfoTabId bufferInfoTabId; + int bufferInfoTabFd; + msgBufferInfo * bufferInfoTabAddr; + int bufferInfoNb; + + //récuperer l'ID du BufferInfoTab; + strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId); + + bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE); + if (bufferInfoTabFd<0){ + perror("shm_open"); + return -1; + } + + /** on regarde dans le tableau d'infos de buffer **/ + bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb; + bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo), + PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0); + + bufferInfoTabAddr[bufferIndex].ownerPid = getpid(); + bufferInfoTabAddr[bufferIndex].addr = addr; + + if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0) + { perror("munmap"); return -1; } + + return 0; +} + + diff --git a/src/nzg_bufferDetachProc.c b/src/nzg_bufferDetachProc.c new file mode 100644 index 0000000..24b26a4 --- /dev/null +++ b/src/nzg_bufferDetachProc.c @@ -0,0 +1,36 @@ +#include "libnazgul.h" + +int msgBufferDetachProc( + msgPoolData * poolDataTabAddr, + int poolIndex, + int bufferIndex, + void * addr + ){ + msgBufferInfoTabId bufferInfoTabId; + int bufferInfoTabFd; + msgBufferInfo * bufferInfoTabAddr; + int bufferInfoNb; + + //récuperer l'ID du BufferInfoTab; + strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId); + + bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE); + if (bufferInfoTabFd<0){ + perror("shm_open"); + return -1; + } + + /** on regarde dans le tableau d'infos de buffer **/ + bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb; + bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo), + PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0); + + bufferInfoTabAddr[bufferIndex].ownerPid = (pid_t)-1; + bufferInfoTabAddr[bufferIndex].addr = NULL; + + if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0) + { perror("munmap"); return -1; } + + return 0; +} + diff --git a/src/nzg_bufferGetFreeIndex.c b/src/nzg_bufferGetFreeIndex.c new file mode 100644 index 0000000..4a0f9d3 --- /dev/null +++ b/src/nzg_bufferGetFreeIndex.c @@ -0,0 +1,35 @@ +#include "libnazgul.h" + +int msgBufferGetFreeIndex(msgPoolData * poolDataTabAddr,int poolIndex){ + msgBufferInfoTabId bufferInfoTabId; +int bufferInfoTabFd; +msgBufferInfo * bufferInfoTabAddr; +int bufferInfoNb; +int bufferFreeIndex; + + //récuperer l'ID du BufferInfoTab; + strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId); + + bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE); + if (bufferInfoTabFd<0){ + perror("shm_open"); + return -1; + } + + /** on regarde dans le tableau d'infos de buffer **/ + bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb; + bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo), + PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0); + + int i=0; + while ((i