From 749807ec3ff289b29cab3cd0a4406e2c682faa32 Mon Sep 17 00:00:00 2001 From: glenux Date: Sat, 4 Mar 2006 14:24:03 +0000 Subject: [PATCH] Corrected ClockCb --- src/Makefile.am | 1 + src/clock_ab.cc | 16 ---------------- src/clock_cb.cc | 29 ++++++++++++++++++++++++++++- src/config.cc | 2 +- src/dabroadcast.cc | 4 ++-- src/lowreceiver.cc | 3 --- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 3938c9b..1ab318d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,6 +10,7 @@ dabcast_SOURCES = \ group.cc \ lowreceiver.cc \ lowreceiver_ab.cc \ + lowreceiver_cb.cc \ lowsender.cc \ highreceiver.cc \ message.cc \ diff --git a/src/clock_ab.cc b/src/clock_ab.cc index 75a1592..1f26680 100644 --- a/src/clock_ab.cc +++ b/src/clock_ab.cc @@ -8,22 +8,6 @@ ClockAb::ClockAb(size_t myindex){ _ticks = 0; } -/*int numb, int myindex){ - // lock jusqu'a la fin de la fonction - if ((myindex < 0) || (myindex > numb)) { - throw ClockInitError(); - // throw exception - } - - Glib::Mutex::Lock lock(_mutex); - - _myidx = myindex; - for (int idx = 0; idx < numb; idx++){ - //printf("ext vector %d\n",idx); - _ticks.push_back(0); - } -}*/ - TimeStamp ClockAb::inc(){ // lock jusqu'a la fin de la fonction Glib::Mutex::Lock lock(_mutex); diff --git a/src/clock_cb.cc b/src/clock_cb.cc index a160166..ccfa57f 100644 --- a/src/clock_cb.cc +++ b/src/clock_cb.cc @@ -2,11 +2,38 @@ #include "clock_cb.h" ClockCb::ClockCb(size_t size, size_t index){ - printf("ClockCb::ClockCb -- create\n"); + Glib::Mutex::Lock lock(_mutex); + printf("ClockCb::ClockCb -- constructor\n"); + _cur_index = index; + //_ticks = 0; + // lock jusqu'a la fin de la fonction + if ((index < 0) || (index > size)) { + throw ClockInitError(); + // throw exception + } + + for (int idx = 0; idx < size; idx++){ + printf ("ClockCb::ClockCb -- extending vector to %d\n", idx); + _ticks.push_back (0); + } } void ClockCb::adjust(TimeStamp ts){ } TimeStamp ClockCb::inc(){ + // lock jusqu'a la fin de la fonction + Glib::Mutex::Lock lock(_mutex); + + printf("ClockAb::inc -- creating timestamp\n"); + // FIXME incrémenter le nombre de messages émis localement. + _ticks[_cur_index] = _ticks[_cur_index] + 1; + + TimeStamp ts(Protocol::TYPE_CBCAST, _cur_index); + // on push tous les ticks de l'horloge + for (int idx = 0; idx < _ticks.size(); idx++){ + printf ("ClockCb::ClockCb -- adding %d to timestamp\n", idx); + ts.push_back (_ticks.at(idx)); + } + return ts; } diff --git a/src/config.cc b/src/config.cc index 8162f7d..ba5a0a4 100644 --- a/src/config.cc +++ b/src/config.cc @@ -79,7 +79,7 @@ Config::Config(int argc, char **argv) { { HostId g_host; string optstr(optarg); - ///stringstream s_host, s_port; + stringstream s_host, s_port; int idx = optstr.find(":"); if (idx > 0){ diff --git a/src/dabroadcast.cc b/src/dabroadcast.cc index d018005..73037e5 100644 --- a/src/dabroadcast.cc +++ b/src/dabroadcast.cc @@ -40,11 +40,11 @@ int main(int argc, char ** argv){ printf("Test mode!\n"); break; case Protocol::TYPE_ABCAST: - clk = new ClockAb(config.getIndex()); + clk = new ClockAb (config.getIndex()); printf("AbCast mode!\n"); break; case Protocol::TYPE_CBCAST: - clk = new ClockCb(4,1); + clk = new ClockCb (grp.getCount(), config.getIndex()); printf("CbCast mode!\n"); break; case Protocol::TYPE_UNKNOWN: diff --git a/src/lowreceiver.cc b/src/lowreceiver.cc index bf54fdb..4b53350 100644 --- a/src/lowreceiver.cc +++ b/src/lowreceiver.cc @@ -104,6 +104,3 @@ void LowReceiver::manage(Message * mesg){ } } -void LowReceiver::manage_cbcast(Message * mesg) { - printf("LowReceiver::manage_cbcast -- init\n"); -}