00001
00002 #ifndef DDF_CHANNELFILTERBASE_HPP
00003 #define DDF_CHANNELFILTERBASE_HPP
00004
00005 #include <deque>
00006 #include <iostream>
00007 #include <fstream>
00008
00009 #include "commbase.hpp"
00010 #include "infocontainer.hpp"
00011 #include "predictenginebase.hpp"
00012
00013 namespace jafar
00014 {
00015 namespace ddf
00016 {
00017
00028 class ChannelFilterBase
00029 {
00030 typedef enum {EVENT_OUT, EVENT_SYNC, EVENT_NOSYNC} EVENT;
00031
00032 CommBase *m_comm;
00033 InfoContainer m_info_ij;
00034 InfoContainer m_new_ji;
00035 InfoContainer m_pred_j;
00036 PredictionEngineBase *m_pred_engine;
00037 unsigned short m_link_with_node;
00038 unsigned short m_belongs_to_node;
00039 time m_time_orig;
00040 bool m_do_log;
00041 std::ofstream m_dump_file;
00042
00043 void LogHeader();
00044 void DumpState(EVENT const& event, InfoContainer const& send_rec);
00045
00046 public:
00047
00048 ChannelFilterBase(unsigned short sv_size, unsigned short belongs_to_node, unsigned short link_with, CommBase *comm,
00049 PredictionEngineBase *pred_engine, InfoContainer const& info_init);
00050
00051 virtual ~ChannelFilterBase();
00052
00053
00054 unsigned short GetLinkWithNode() const { return m_link_with_node; }
00055 InfoContainer const& GetNewInfo() const { return m_new_ji; }
00056 void SetCommonInfoTime(time const& t) { m_info_ij.SetTime(t); }
00057
00061 void SetNow(time const& now) { m_time_orig = now; }
00062 bool Sync_Ok() const { return m_comm->Sync_Ok(); }
00063
00064 void ResetJustReceived() { m_comm->ResetJustReceived(); }
00065
00068 bool HasJustReceivedInfo() const { return m_comm->HasJustReceivedInfo(); }
00069
00072 void SetLog(bool log) { if(!m_do_log && log) InitLog(); m_do_log = log; }
00073
00074
00077 void OutputInfoToOtherNode(InfoContainer const& to_j);
00078
00085 bool Sync(time const& horizon);
00086 void PrintPredModel() { m_pred_engine->PrintModel(); }
00087
00088
00089 void CloseLogFile();
00090
00091 private:
00092 void InitLog();
00093 };
00094
00095
00096 }
00097 }
00098 #endif