l3.libnazgul/src/queueAdd.c

49 lines
1.2 KiB
C
Raw Normal View History

2004-02-23 21:19:20 +00:00
#include "libnazgul.h"
// on ajoute en fin de queue...
2004-02-23 21:41:20 +00:00
int msgQueueElemAdd(msgQueue * queue, msgQueueElemId newElemId){
msgQueueElem * queueOldTailElem;
msgQueueElem * queueNewTailElem;
// on informe l'element qu'il est le dernier
queueNewTailElem=msgQueueElemOpen(newElemId);
if (queueNewTailElem == NULL){
NZG_ERROR("msgQueueElemOpen",newElemId);
goto ERROR;
}
strcpy(queueNewTailElem->next,newElemId);
2004-02-23 22:02:37 +00:00
if (msgQueueElemClose(queueNewTailElem) <0 ){
2004-02-23 21:41:20 +00:00
NZG_ERROR("msgQueueElemClose",newElemId);
goto ERROR;
}
2004-02-23 21:19:20 +00:00
2004-02-23 21:41:20 +00:00
/* TODO: verifier si la liste n'est pas vide... */
2004-02-23 23:19:04 +00:00
if((strcmp(queue->headId,queue->id)==0)
&& (strcmp(queue->tailId,queue->id)==0)) {
2004-02-23 22:34:28 +00:00
NZG_ERROR("msgQueueAdd",queue->id);
goto ERROR;
}
2004-02-23 21:41:20 +00:00
/* on informe son pr<70>decesseur qu'il a un suivant */
queueOldTailElem=msgQueueElemOpen(queue->tailId);
if (queueOldTailElem == NULL){
NZG_ERROR("msgQueueElemOpen",queue->tailId);
goto ERROR;
}
strcpy(queueOldTailElem->next,newElemId);
if (msgQueueElemClose(queueOldTailElem)){
NZG_ERROR("msgQueueElemClose",queue->tailId);
goto ERROR;
}
// on donne a la queue l'id du dernier element
strcpy(queue->tailId,newElemId);
2004-02-23 22:34:28 +00:00
// on incremente elemCounter
queue->elemCounter++;
2004-02-23 21:41:20 +00:00
ERROR:
return -1;
2004-02-23 21:19:20 +00:00
}