m2.mbcp/src/lowsender.cc

36 lines
767 B
C++
Raw Normal View History

2006-02-05 17:43:00 +00:00
2006-03-06 15:16:12 +00:00
#include <time.h>
#include "macros.h"
2006-02-05 17:43:00 +00:00
#include "lowsender.h"
2006-03-06 15:16:12 +00:00
#define DEBUG 0
2006-02-05 17:43:00 +00:00
#define MESSAGE "AB or CB cast from LowSender ? hehe...."
LowSender::LowSender(Group &grp, Clock &clk, Protocol::Type type) : _group(grp), _clock(clk), _type(type) {
}
void LowSender::run(){
// thread part
2006-03-06 15:16:12 +00:00
srand(time(NULL));
2006-03-06 16:17:28 +00:00
for (int delay = 10; delay >= 0; delay-- ){
printf("\rLowSender::run -- Waiting %d seconds... ", delay);
fflush(stdout);
sleep(1);
}
printf("\n");
2006-02-05 17:43:00 +00:00
while(1){
2006-03-06 16:17:28 +00:00
sleep(1);
printf("LowSender::run -- Broadcasting '%s'\n", MESSAGE);
TimeStamp ts = _clock.inc();
pDEBUG("Timestamp done\n");
2006-03-06 15:16:12 +00:00
2006-03-06 16:17:28 +00:00
Message msg(_type, ts, MESSAGE, strlen(MESSAGE));
pDEBUG("Mesg done and ready to send\n");
2006-03-06 15:16:12 +00:00
2006-03-06 16:17:28 +00:00
_group.broadcast(msg);
pDEBUG("Mesg sent\n");
2006-02-05 17:43:00 +00:00
}
}