2006-03-04 14:31:32 +00:00
|
|
|
|
|
|
|
|
|
#include "lowreceiver.h"
|
2006-03-06 12:14:40 +00:00
|
|
|
|
#include "messagecell_cb.h"
|
2006-03-04 14:31:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LowReceiver::manage_cbcast(Message * mesg) {
|
2006-03-06 12:14:40 +00:00
|
|
|
|
static std::list<MessageCellCb *> fifo_get;
|
|
|
|
|
static std::list<MessageCellCb *> fifo_send;
|
2006-03-04 14:31:32 +00:00
|
|
|
|
|
2006-03-06 12:14:40 +00:00
|
|
|
|
std::list<MessageCellCb *>::iterator iter;
|
2006-03-04 14:31:32 +00:00
|
|
|
|
printf("LowReceiver::manage_cbcast -- 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_cbcast - Received my own message \n");
|
|
|
|
|
//on faire la gestion du cbcast/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
|
2006-03-06 12:14:40 +00:00
|
|
|
|
MessageCellCb * cell = NULL;
|
2006-03-04 14:31:32 +00:00
|
|
|
|
for (iter = fifo_send.begin(); iter != fifo_send.end(); iter++){
|
|
|
|
|
//on fait pointer cell sur la cellule si <20>gale a l'id du message
|
|
|
|
|
//courant
|
2006-03-06 12:14:40 +00:00
|
|
|
|
MessageCellCb * cur = *iter;
|
2006-03-04 14:31:32 +00:00
|
|
|
|
if (cur->message == mesg){
|
|
|
|
|
printf("LowReceiver::manage_cbcast -- message seen\n");
|
|
|
|
|
firstSeenMessage = false;
|
|
|
|
|
cell = cur;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (firstSeenMessage){
|
|
|
|
|
//sinon on le cr<63>e
|
|
|
|
|
printf("LowReceiver::manage_cbcast -- message is first\n");
|
2006-03-06 12:14:40 +00:00
|
|
|
|
cell = new MessageCellCb();
|
2006-03-04 14:31:32 +00:00
|
|
|
|
cell->message = new Message(*mesg);
|
|
|
|
|
//et on l'ajoute au fifo
|
|
|
|
|
fifo_send.push_back(cell);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//FIXME: comparer le timestamp max a ceux que l'on recoit
|
|
|
|
|
cell->count += 1;
|
|
|
|
|
if (cell->count == _group.getCount()){
|
|
|
|
|
// broadcaster le nouveau timestamp du message
|
|
|
|
|
//
|
|
|
|
|
// le message a broadcaster est exactement le message max
|
|
|
|
|
// re<72>u... mais bon... on le reconstruit quand m^eme
|
|
|
|
|
// IMPROVE
|
|
|
|
|
|
|
|
|
|
TimeStamp st = cell->message->getStamp();
|
|
|
|
|
Message * nMsg = new Message(Protocol::TYPE_ABCAST,
|
|
|
|
|
st,
|
|
|
|
|
cell->maximum->getRaw(),
|
|
|
|
|
cell->maximum->getRawSize());
|
|
|
|
|
_group.broadcast(*nMsg);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
printf("LowReceiver::manage_cbcast - Received a message from a friend\n");
|
|
|
|
|
for (iter = fifo_get.begin(); iter != fifo_get.end(); iter++){
|
2006-03-06 12:14:40 +00:00
|
|
|
|
MessageCellCb * cur = *iter;
|
2006-03-04 14:31:32 +00:00
|
|
|
|
if (cur->message == mesg) {
|
|
|
|
|
printf("LowReceiver::manage_cbcast -- message seen\n");
|
|
|
|
|
firstSeenMessage = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (firstSeenMessage){
|
|
|
|
|
printf("LowReceiver::manage_cbcast -- message is first\n");
|
|
|
|
|
// si le message est vu pour la premiere fois:
|
|
|
|
|
// - on l'ajoute dans la liste d'attente
|
2006-03-06 12:14:40 +00:00
|
|
|
|
MessageCellCb * cell = new MessageCellCb();
|
2006-03-04 14:31:32 +00:00
|
|
|
|
cell->message = new Message(*mesg);
|
2006-03-06 12:14:40 +00:00
|
|
|
|
cell->type = MessageCellCb::TYPE_TEMPORARY;
|
2006-03-04 14:31:32 +00:00
|
|
|
|
// - 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<71> comme final
|
|
|
|
|
// - on d<>file les estampille finale la
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|