[2482] | 1 | #include "client_from_server_source_filter.hpp" |
---|
| 2 | #include "grid.hpp" |
---|
| 3 | #include "field.hpp" |
---|
| 4 | #include "file.hpp" |
---|
| 5 | #include "exception.hpp" |
---|
| 6 | #include "calendar_util.hpp" |
---|
| 7 | #include "context.hpp" |
---|
| 8 | #include "event_client.hpp" |
---|
| 9 | #include "timer.hpp" |
---|
| 10 | #include "tracer.hpp" |
---|
| 11 | #include <limits> |
---|
| 12 | #include "workflow_graph.hpp" |
---|
| 13 | #include "grid_redistribute_filter_in.hpp" |
---|
| 14 | |
---|
| 15 | namespace xios |
---|
| 16 | { |
---|
| 17 | CClientOnlineReaderFilter::CClientOnlineReaderFilter(CGarbageCollector& gc, CField* fieldOut) |
---|
| 18 | : CFilter(gc, 1, this) |
---|
| 19 | { |
---|
| 20 | CContext* context = CContext::getCurrent(); |
---|
| 21 | |
---|
| 22 | CField* fieldIn ; |
---|
| 23 | redistributeFilter_ = std::shared_ptr<CGridRedistributeFilterIn>(new CGridRedistributeFilterIn(gc, fieldOut, fieldIn)); |
---|
| 24 | fieldIn->setFileIn(fieldOut->getFileIn()); |
---|
| 25 | fieldOut->getFileIn()->replaceEnabledFields(fieldOut, fieldIn) ; |
---|
| 26 | fileReaderSourceFilter_ = std::shared_ptr<CFileReaderSourceFilter>(new CFileReaderSourceFilter(gc, fieldIn)); |
---|
| 27 | fieldIn->solveServerOperation() ; // might not be called, create a new time functor.... find a better solution later |
---|
| 28 | |
---|
| 29 | // connect filters |
---|
| 30 | fileReaderSourceFilter_->connectOutput(redistributeFilter_, 0); |
---|
| 31 | |
---|
| 32 | // shared_ptr<CClientOnlineReaderFilter> toto = shared_from_this() ; |
---|
| 33 | // very bad thing to bypass shared pointer assignement in constructor: just for test ! |
---|
| 34 | auto sharedThis = new std::shared_ptr<CClientOnlineReaderFilter>(this) ; |
---|
| 35 | redistributeFilter_->connectOutput(*sharedThis, 0); |
---|
| 36 | |
---|
| 37 | field_ = fieldIn ; |
---|
| 38 | freqOp_ = fieldOut->getRelFile()->output_freq ; |
---|
| 39 | offset_ = fieldOut->freq_offset ; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | CDataPacketPtr CClientOnlineReaderFilter::apply(std::vector<CDataPacketPtr> data) |
---|
| 43 | { |
---|
| 44 | const CDate& currentDate = CContext::getCurrent()->getCalendar()->getCurrentDate(); |
---|
| 45 | |
---|
| 46 | data[0]->date = currentDate ; |
---|
| 47 | data[0]->timestamp = currentDate ; |
---|
| 48 | |
---|
| 49 | if (data[0]->status == CDataPacket::END_OF_STREAM) |
---|
| 50 | { |
---|
| 51 | isEOF_=true ; |
---|
| 52 | dateEOF_ = data[0]->date ; |
---|
| 53 | } |
---|
| 54 | return data[0]; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | bool CClientOnlineReaderFilter::sendReadDataRequest(const CDate& tsDataRequested) |
---|
| 58 | { |
---|
| 59 | CContext* context = CContext::getCurrent(); |
---|
| 60 | const CDate& currentDate = CContext::getCurrent()->getCalendar()->getCurrentDate(); |
---|
| 61 | CDate checkDate ; |
---|
| 62 | if (isFirstDataSent_) checkDate = lastDateReceived_ + freqOp_ ; |
---|
| 63 | else checkDate = context->getCalendar()->getInitDate() + offset_ ; |
---|
| 64 | |
---|
| 65 | if (currentDate >= checkDate) |
---|
| 66 | { |
---|
| 67 | fileReaderSourceFilter_->streamData(); |
---|
| 68 | if (isFirstDataSent_) lastDateReceived_ = lastDateReceived_ + freqOp_ ; |
---|
| 69 | else lastDateReceived_ = context->getCalendar()->getInitDate() + offset_ ; |
---|
| 70 | isFirstDataSent_ = true ; |
---|
| 71 | } |
---|
| 72 | return !isEOF_; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | bool CClientOnlineReaderFilter::sendReadDataRequestIfNeeded(void) |
---|
| 76 | TRY |
---|
| 77 | { |
---|
| 78 | const CDate& currentDate = CContext::getCurrent()->getCalendar()->getCurrentDate(); |
---|
| 79 | return sendReadDataRequest(currentDate); |
---|
| 80 | } |
---|
| 81 | CATCH |
---|
| 82 | |
---|
| 83 | void CClientOnlineReaderFilter::checkForLateData(void) |
---|
| 84 | TRY |
---|
| 85 | { |
---|
| 86 | return ; |
---|
| 87 | } |
---|
| 88 | CATCH |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | bool CClientOnlineReaderFilter::isDataLate(void) |
---|
| 92 | { |
---|
| 93 | return false ; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | } // namespace xios |
---|