[2507] | 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 | field_ = fieldIn ; |
---|
| 33 | freqOp_ = fieldOut->getRelFile()->output_freq ; |
---|
| 34 | offset_ = fieldOut->freq_offset ; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | void CClientOnlineReaderFilter::connectOutput(std::shared_ptr<CInputPin> inputPin, size_t inputSlot) |
---|
| 39 | { |
---|
| 40 | // connection to redistributeFilter cannot be done at construction time due to shared_from_this(), doing it now |
---|
| 41 | redistributeFilter_->connectOutput(shared_from_this(), 0); |
---|
| 42 | CFilter::connectOutput(inputPin,inputSlot) ; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | CDataPacketPtr CClientOnlineReaderFilter::apply(std::vector<CDataPacketPtr> data) |
---|
| 46 | { |
---|
| 47 | const CDate& currentDate = CContext::getCurrent()->getCalendar()->getCurrentDate(); |
---|
| 48 | |
---|
| 49 | data[0]->date = currentDate ; |
---|
| 50 | data[0]->timestamp = currentDate ; |
---|
| 51 | |
---|
| 52 | if (data[0]->status == CDataPacket::END_OF_STREAM) |
---|
| 53 | { |
---|
| 54 | isEOF_=true ; |
---|
| 55 | dateEOF_ = data[0]->date ; |
---|
| 56 | } |
---|
| 57 | return data[0]; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | bool CClientOnlineReaderFilter::sendReadDataRequest(const CDate& tsDataRequested) |
---|
| 61 | { |
---|
| 62 | CContext* context = CContext::getCurrent(); |
---|
| 63 | const CDate& currentDate = CContext::getCurrent()->getCalendar()->getCurrentDate(); |
---|
| 64 | CDate checkDate ; |
---|
| 65 | if (isFirstDataSent_) checkDate = lastDateReceived_ + freqOp_ ; |
---|
| 66 | else checkDate = context->getCalendar()->getInitDate() + offset_ ; |
---|
| 67 | |
---|
| 68 | if (currentDate >= checkDate) |
---|
| 69 | { |
---|
| 70 | fileReaderSourceFilter_->streamData(); |
---|
| 71 | if (isFirstDataSent_) lastDateReceived_ = lastDateReceived_ + freqOp_ ; |
---|
| 72 | else lastDateReceived_ = context->getCalendar()->getInitDate() + offset_ ; |
---|
| 73 | isFirstDataSent_ = true ; |
---|
| 74 | } |
---|
| 75 | return !isEOF_; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | bool CClientOnlineReaderFilter::sendReadDataRequestIfNeeded(void) |
---|
| 79 | TRY |
---|
| 80 | { |
---|
| 81 | const CDate& currentDate = CContext::getCurrent()->getCalendar()->getCurrentDate(); |
---|
| 82 | return sendReadDataRequest(currentDate); |
---|
| 83 | } |
---|
| 84 | CATCH |
---|
| 85 | |
---|
| 86 | void CClientOnlineReaderFilter::checkForLateData(void) |
---|
| 87 | TRY |
---|
| 88 | { |
---|
| 89 | return ; |
---|
| 90 | } |
---|
| 91 | CATCH |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | bool CClientOnlineReaderFilter::isDataLate(void) |
---|
| 95 | { |
---|
| 96 | return false ; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | } // namespace xios |
---|