From edf061cbcacd79437687d0ad754680f8c1fcee74 Mon Sep 17 00:00:00 2001 From: glenux Date: Sun, 5 Feb 2006 21:16:43 +0000 Subject: [PATCH] --- src/lowreceiver_ab.cc | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/lowreceiver_ab.cc diff --git a/src/lowreceiver_ab.cc b/src/lowreceiver_ab.cc new file mode 100644 index 0000000..87d8216 --- /dev/null +++ b/src/lowreceiver_ab.cc @@ -0,0 +1,81 @@ + +#include "lowreceiver.h" +#include "messagecell_ab.h" + +void LowReceiver::manage_abcast(Message * mesg) { + static std::list fifo_get; + static std::list fifo_send; + + std::list::iterator iter; + printf("LowReceiver::manage_abcast -- init\n"); + + // identifiant = horloge + id_site_emeteur + bool iAmTheEmitter = false; + bool firstSeenMessage = true; + + if (mesg->getStamp().getIndex() == _group.getIndex()){ + iAmTheEmitter = true; + } + + if (iAmTheEmitter){ + printf("LowReceiver::manage_abcast - Received my own message \n"); + //on faire la gestion du abcast/send ici, c'est plus simple que + //de partager une variable+mutex avec le sender + + //FIXME: chercher si l'on a déja recu ce message + MessageCellAb * cell = NULL; + for (iter = fifo_send.begin(); iter != fifo_send.end(); iter++){ + //on fait pointer cell sur la cellule si égale a l'id du message + //courant + MessageCellAb * cur = *iter; + if (cur->message == mesg){ + printf("LowReceiver::manage_abcast -- message seen\n"); + firstSeenMessage = false; + cell = cur; + break; + } + } + if (firstSeenMessage){ + //sinon on le crée + printf("LowReceiver::manage_abcast -- message is first\n"); + cell = new MessageCellAb(); + //et on l'ajoute au fifo + fifo_send.push_back(cell); + } + + cell->message = new Message(*mesg); + //FIXME: comparer le timestamp max a ceux que l'on recoit + cell->count += 1; + + } else { + printf("LowReceiver::manage_abcast - Received a message from a friend\n"); + for (iter = fifo_get.begin(); iter != fifo_get.end(); iter++){ + MessageCellAb * cur = *iter; + if (cur->message == mesg) { + printf("LowReceiver::manage_abcast -- message seen\n"); + firstSeenMessage = false; + break; + } + } + + if (firstSeenMessage){ + printf("LowReceiver::manage_abcast -- message is first\n"); + // si le message est vu pour la premiere fois: + // - on l'ajoute dans la liste d'attente + MessageCellAb * cell = new MessageCellAb(); + cell->message = new Message(*mesg); + cell->type = MessageCellAb::TYPE_TEMPORARY; + // - on retourne une estampille(reception) a l'emeteur + + } else { + // sinon + // - l'estampille du message est mise a jour + TimeStamp * stamp = new TimeStamp (Protocol::TYPE_ABCAST, mesg->getData(), mesg->getDataSize()); + + // - le message est marqué comme final + // - on défile les estampille finale la + } + } +} + +