[637] | 1 | #include "input_pin.hpp" |
---|
[1021] | 2 | #include "output_pin.hpp" |
---|
[639] | 3 | #include "garbage_collector.hpp" |
---|
[637] | 4 | #include "exception.hpp" |
---|
[1704] | 5 | #include "workflow_graph.hpp" |
---|
[637] | 6 | |
---|
| 7 | namespace xios |
---|
| 8 | { |
---|
[639] | 9 | CInputPin::CInputPin(CGarbageCollector& gc, size_t slotsCount) |
---|
| 10 | : gc(gc) |
---|
| 11 | , slotsCount(slotsCount) |
---|
[1021] | 12 | , triggers(slotsCount) |
---|
| 13 | , hasTriggers(false) |
---|
[1704] | 14 | { } |
---|
[637] | 15 | |
---|
[1704] | 16 | StdString CInputPin::GetName(void) |
---|
| 17 | { |
---|
| 18 | return StdString("Input pin"); |
---|
| 19 | } |
---|
| 20 | |
---|
[637] | 21 | void CInputPin::setInput(size_t inputSlot, CDataPacketPtr packet) |
---|
| 22 | { |
---|
| 23 | if (inputSlot >= slotsCount) |
---|
| 24 | ERROR("void CInputPin::setInput(size_t inputSlot, CDataPacketPtr packet)", |
---|
| 25 | "The input slot " << inputSlot << " does not exist."); |
---|
| 26 | if (!packet) |
---|
| 27 | ERROR("void CInputPin::setInput(size_t inputSlot, CDataPacketPtr packet)", |
---|
| 28 | "The packet cannot be null."); |
---|
| 29 | |
---|
| 30 | std::map<Time, InputBuffer>::iterator it = inputs.find(packet->timestamp); |
---|
| 31 | if (it == inputs.end()) |
---|
[639] | 32 | { |
---|
[637] | 33 | it = inputs.insert(std::make_pair(packet->timestamp, InputBuffer(slotsCount))).first; |
---|
[1021] | 34 | gc.registerObject(this, packet->timestamp); |
---|
[639] | 35 | } |
---|
[637] | 36 | it->second.slotsFilled++; |
---|
| 37 | it->second.packets[inputSlot] = packet; |
---|
| 38 | |
---|
| 39 | if (it->second.slotsFilled == slotsCount) |
---|
| 40 | { |
---|
[639] | 41 | // Unregister before calling onInputReady in case the filter registers again |
---|
[1021] | 42 | gc.unregisterObject(this, packet->timestamp); |
---|
[637] | 43 | onInputReady(it->second.packets); |
---|
| 44 | inputs.erase(it); |
---|
| 45 | } |
---|
| 46 | } |
---|
[639] | 47 | |
---|
[1021] | 48 | void CInputPin::setInputTrigger(size_t inputSlot, COutputPin* trigger) |
---|
| 49 | { |
---|
| 50 | if (inputSlot >= slotsCount) |
---|
| 51 | ERROR("void CInputPin::setInputTrigger(size_t inputSlot, COutputPin* trigger)", |
---|
| 52 | "The input slot " << inputSlot << " does not exist."); |
---|
| 53 | if (triggers[inputSlot]) |
---|
| 54 | ERROR("void CInputPin::setInputTrigger(size_t inputSlot, COutputPin* trigger)", |
---|
| 55 | "The trigger for input slot " << inputSlot << " has already been set."); |
---|
| 56 | |
---|
| 57 | triggers[inputSlot] = trigger; |
---|
| 58 | hasTriggers = true; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void CInputPin::trigger(Time timestamp) |
---|
| 62 | { |
---|
| 63 | if (hasTriggers) // Don't use canBeTriggered here, this function is virtual and can be overriden |
---|
| 64 | { |
---|
| 65 | std::map<Time, InputBuffer>::iterator it = inputs.find(timestamp); |
---|
| 66 | bool nothingReceived = (it == inputs.end()); |
---|
| 67 | |
---|
| 68 | for (size_t s = 0; s < slotsCount; s++) |
---|
| 69 | { |
---|
| 70 | if (triggers[s] && (nothingReceived || !it->second.packets[s])) |
---|
| 71 | triggers[s]->trigger(timestamp); |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | bool CInputPin::canBeTriggered() const |
---|
| 77 | { |
---|
| 78 | return hasTriggers; |
---|
| 79 | } |
---|
| 80 | |
---|
[639] | 81 | void CInputPin::invalidate(Time timestamp) |
---|
| 82 | { |
---|
| 83 | inputs.erase(inputs.begin(), inputs.lower_bound(timestamp)); |
---|
| 84 | } |
---|
[637] | 85 | } // namespace xios |
---|