2006-03-04 14:31:32 +00:00
|
|
|
|
|
2006-03-06 16:40:15 +00:00
|
|
|
|
#include "macros.h"
|
2006-03-04 14:31:32 +00:00
|
|
|
|
#include "lowreceiver.h"
|
|
|
|
|
|
|
|
|
|
void LowReceiver::manage_cbcast(Message * mesg) {
|
2006-03-06 15:16:12 +00:00
|
|
|
|
static std::list<Message *> fifo_undelivered;
|
|
|
|
|
static std::list<Message *> fifo_deliverable;
|
2006-03-04 14:31:32 +00:00
|
|
|
|
|
2006-03-06 15:16:12 +00:00
|
|
|
|
std::list<Message *>::iterator iter;
|
2006-03-06 16:40:15 +00:00
|
|
|
|
//
|
2006-03-04 14:31:32 +00:00
|
|
|
|
// identifiant = horloge + id_site_emeteur
|
|
|
|
|
bool iAmTheEmitter = false;
|
|
|
|
|
|
2006-03-06 15:16:12 +00:00
|
|
|
|
bool canAdjust = false;
|
2006-03-04 14:31:32 +00:00
|
|
|
|
if (mesg->getStamp().getIndex() == _group.getIndex()){
|
|
|
|
|
iAmTheEmitter = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (iAmTheEmitter){
|
2006-03-06 12:42:03 +00:00
|
|
|
|
printf("LowReceiver::manage_cbcast - Received my own message -- delivering automatically\n");
|
2006-03-06 15:16:12 +00:00
|
|
|
|
// ajouter dans la file des message <20> d<>livrer...
|
|
|
|
|
fifo_deliverable.push_back(mesg);
|
2006-03-06 12:42:03 +00:00
|
|
|
|
|
2006-03-04 14:31:32 +00:00
|
|
|
|
} else {
|
|
|
|
|
printf("LowReceiver::manage_cbcast - Received a message from a friend\n");
|
2006-03-06 14:06:03 +00:00
|
|
|
|
|
2006-03-06 15:16:12 +00:00
|
|
|
|
canAdjust == _clock.adjust(mesg->getStamp());
|
|
|
|
|
printf("LowReceiver::manage_cbcast - Can Adjust %d\n",canAdjust);
|
|
|
|
|
|
|
|
|
|
// si l'horloge est ajustable (donc les contraintes FIFO et reception)
|
|
|
|
|
// alors on d<>livre directement
|
|
|
|
|
if (canAdjust){
|
|
|
|
|
fifo_deliverable.push_back(mesg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool foundDeliveredMsg = false;
|
|
|
|
|
// boucler sur la file des message non-d<>livr<76>s, tant qu'on trouve un message <20> d<>livrer...
|
|
|
|
|
// et ajouter les d<>livrables <20> la FIFO
|
|
|
|
|
do {
|
|
|
|
|
printf("LowReceiver::manage_cbcast - looking for old deliverable messages...\n");
|
|
|
|
|
Message * mesg = NULL;
|
|
|
|
|
foundDeliveredMsg = false;
|
|
|
|
|
for (iter = fifo_undelivered.begin(); iter != fifo_undelivered.end(); iter++){
|
|
|
|
|
mesg = *iter;
|
|
|
|
|
if (_clock.adjust(mesg->getStamp())){
|
|
|
|
|
// ajouter dans la file des message <20> d<>livrer
|
|
|
|
|
fifo_deliverable.push_back(mesg);
|
|
|
|
|
// supprimer le message de la liste des non-d<>livr<76>s
|
|
|
|
|
fifo_undelivered.erase(iter);
|
|
|
|
|
foundDeliveredMsg = true;
|
2006-03-06 16:40:15 +00:00
|
|
|
|
printf("LowReceiver::manage_cbcast - %sfound old deliverable%s...\n",
|
|
|
|
|
COLOR_RED, COLOR_NORMAL);
|
2006-03-06 15:16:12 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (foundDeliveredMsg == true);
|
|
|
|
|
|
|
|
|
|
for (int idx = fifo_deliverable.size(); idx > 0; idx--){
|
|
|
|
|
printf("LowReceiver::manage_cbcast - delivering message...\n");
|
|
|
|
|
// on POP_FRONT et on send...
|
|
|
|
|
Message * deliverableMsg = fifo_deliverable.front();
|
|
|
|
|
fifo_deliverable.pop_front();
|
2006-03-06 15:29:19 +00:00
|
|
|
|
|
|
|
|
|
// d<>livrer "pour de vrai"
|
|
|
|
|
this->deliver(deliverableMsg);
|
2006-03-04 14:31:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|