[637] | 1 | #include "output_pin.hpp" |
---|
| 2 | #include "exception.hpp" |
---|
[1704] | 3 | #include "workflow_graph.hpp" |
---|
[637] | 4 | |
---|
| 5 | namespace xios |
---|
| 6 | { |
---|
[1021] | 7 | COutputPin::COutputPin(CGarbageCollector& gc, bool manualTrigger /*= false*/) |
---|
| 8 | : gc(gc) |
---|
| 9 | , manualTrigger(manualTrigger) |
---|
[1704] | 10 | { } |
---|
[1021] | 11 | |
---|
[1704] | 12 | StdString COutputPin::GetName(void) |
---|
| 13 | { |
---|
| 14 | return StdString("Output pin"); |
---|
| 15 | } |
---|
| 16 | |
---|
[1542] | 17 | void COutputPin::connectOutput(std::shared_ptr<CInputPin> inputPin, size_t inputSlot) |
---|
[637] | 18 | { |
---|
| 19 | if (!inputPin) |
---|
| 20 | ERROR("void COutputPin::connectOutput(CInputPin* inputPin, size_t inputSlot)", |
---|
| 21 | "The input pin cannot be null."); |
---|
| 22 | |
---|
| 23 | outputs.push_back(std::make_pair(inputPin, inputSlot)); |
---|
[1021] | 24 | |
---|
| 25 | if (canBeTriggered()) |
---|
| 26 | inputPin->setInputTrigger(inputSlot, this); |
---|
[637] | 27 | } |
---|
| 28 | |
---|
[1021] | 29 | void COutputPin::onOutputReady(CDataPacketPtr packet) |
---|
| 30 | { |
---|
| 31 | if (!packet) |
---|
| 32 | ERROR("void COutputPin::onOutputReady(CDataPacketPtr packet)", |
---|
| 33 | "The packet cannot be null."); |
---|
| 34 | |
---|
| 35 | if (manualTrigger) // Don't use canBeTriggered here, this function is virtual and can be overriden |
---|
| 36 | { |
---|
| 37 | outputPackets[packet->timestamp] = packet; |
---|
| 38 | gc.registerObject(this, packet->timestamp); |
---|
| 39 | } |
---|
| 40 | else |
---|
| 41 | deliverOuput(packet); |
---|
| 42 | } |
---|
| 43 | |
---|
[637] | 44 | void COutputPin::deliverOuput(CDataPacketPtr packet) |
---|
| 45 | { |
---|
| 46 | if (!packet) |
---|
| 47 | ERROR("void COutputPin::deliverOuput(CDataPacketPtr packet)", |
---|
| 48 | "The packet cannot be null."); |
---|
| 49 | |
---|
[1542] | 50 | std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::iterator it, itEnd; |
---|
[637] | 51 | for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it) |
---|
| 52 | it->first->setInput(it->second, packet); |
---|
| 53 | } |
---|
[1021] | 54 | |
---|
| 55 | void COutputPin::trigger(Time timestamp) |
---|
| 56 | { |
---|
| 57 | if (manualTrigger) // Don't use canBeTriggered here, this function is virtual and can be overriden |
---|
| 58 | { |
---|
| 59 | std::map<Time, CDataPacketPtr>::iterator it = outputPackets.find(timestamp); |
---|
| 60 | if (it != outputPackets.end()) |
---|
| 61 | { |
---|
| 62 | gc.unregisterObject(this, timestamp); |
---|
| 63 | deliverOuput(it->second); |
---|
| 64 | outputPackets.erase(it); |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | bool COutputPin::canBeTriggered() const |
---|
| 70 | { |
---|
| 71 | return manualTrigger; |
---|
| 72 | } |
---|
| 73 | |
---|
[1358] | 74 | bool COutputPin::mustAutoTrigger() const |
---|
| 75 | { |
---|
[1542] | 76 | std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::const_iterator it, itEnd; |
---|
[1358] | 77 | for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it) |
---|
| 78 | { |
---|
| 79 | if (it->first->mustAutoTrigger()) |
---|
| 80 | return true; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | return false; |
---|
| 84 | } |
---|
| 85 | |
---|
[1021] | 86 | void COutputPin::setOutputTriggers() |
---|
| 87 | { |
---|
[1542] | 88 | std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::iterator it, itEnd; |
---|
[1021] | 89 | for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it) |
---|
| 90 | it->first->setInputTrigger(it->second, this); |
---|
| 91 | } |
---|
| 92 | |
---|
[1158] | 93 | bool COutputPin::isDataExpected(const CDate& date) const |
---|
| 94 | { |
---|
[1542] | 95 | std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::const_iterator it, itEnd; |
---|
[1158] | 96 | for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it) |
---|
| 97 | { |
---|
| 98 | if (it->first->isDataExpected(date)) |
---|
| 99 | return true; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | return false; |
---|
| 103 | } |
---|
| 104 | |
---|
[1021] | 105 | void COutputPin::invalidate(Time timestamp) |
---|
| 106 | { |
---|
| 107 | outputPackets.erase(outputPackets.begin(), outputPackets.lower_bound(timestamp)); |
---|
| 108 | } |
---|
[1704] | 109 | |
---|
| 110 | void COutputPin::setParentFiltersTag() |
---|
| 111 | { |
---|
| 112 | for(int i=0; i<parent_filters.size(); i++) |
---|
| 113 | { |
---|
| 114 | |
---|
| 115 | if(parent_filters[i]->start_graph<0) parent_filters[i]->start_graph = start_graph; |
---|
| 116 | else parent_filters[i]->start_graph = min(parent_filters[i]->start_graph, start_graph); |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | if(parent_filters[i]->end_graph<0) parent_filters[i]->end_graph = end_graph; |
---|
| 120 | else parent_filters[i]->end_graph = max(parent_filters[i]->end_graph, end_graph); |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | parent_filters[i]->tag += tag; |
---|
| 124 | parent_filters[i]->setParentFiltersTag(); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | |
---|
[637] | 131 | } // namespace xios |
---|