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