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