70 lines
2.1 KiB
C++
70 lines
2.1 KiB
C++
|
|
#include "macros.h"
|
|
#include "lowreceiver.h"
|
|
|
|
void LowReceiver::manage_cbcast(Message * mesg) {
|
|
static std::list<Message *> fifo_undelivered;
|
|
static std::list<Message *> fifo_deliverable;
|
|
|
|
std::list<Message *>::iterator iter;
|
|
//
|
|
// identifiant = horloge + id_site_emeteur
|
|
bool iAmTheEmitter = false;
|
|
|
|
bool canAdjust = false;
|
|
if (mesg->getStamp().getIndex() == _group.getIndex()){
|
|
iAmTheEmitter = true;
|
|
}
|
|
|
|
if (iAmTheEmitter){
|
|
printf("LowReceiver::manage_cbcast - Received my own message -- delivering automatically\n");
|
|
// ajouter dans la file des message à délivrer...
|
|
fifo_deliverable.push_back(mesg);
|
|
|
|
} else {
|
|
printf("LowReceiver::manage_cbcast - Received a message from a friend\n");
|
|
|
|
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és, tant qu'on trouve un message à délivrer...
|
|
// et ajouter les délivrables à 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 à délivrer
|
|
fifo_deliverable.push_back(mesg);
|
|
// supprimer le message de la liste des non-délivrés
|
|
fifo_undelivered.erase(iter);
|
|
foundDeliveredMsg = true;
|
|
printf("LowReceiver::manage_cbcast - %sfound old deliverable%s...\n",
|
|
COLOR_RED, COLOR_NORMAL);
|
|
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();
|
|
|
|
// délivrer "pour de vrai"
|
|
this->deliver(deliverableMsg);
|
|
}
|
|
}
|
|
|
|
|