[637] | 1 | #ifndef __XIOS_CInputPin__ |
---|
| 2 | #define __XIOS_CInputPin__ |
---|
| 3 | |
---|
| 4 | #include <vector> |
---|
| 5 | #include <map> |
---|
| 6 | |
---|
[1021] | 7 | #include "garbage_collector.hpp" |
---|
[637] | 8 | #include "data_packet.hpp" |
---|
| 9 | |
---|
| 10 | namespace xios |
---|
| 11 | { |
---|
[1021] | 12 | class COutputPin; |
---|
[639] | 13 | |
---|
[637] | 14 | /*! |
---|
| 15 | * An input pin handles the data packets received by a filter. |
---|
| 16 | */ |
---|
[1021] | 17 | class CInputPin : public InvalidableObject |
---|
[637] | 18 | { |
---|
| 19 | public: |
---|
| 20 | /*! |
---|
[639] | 21 | * Constructs an input pin with the specified number of slots |
---|
| 22 | * and an associated garbage collector. |
---|
[637] | 23 | * |
---|
[639] | 24 | * \param gc the garbage collector associated with this input pin |
---|
[637] | 25 | * \param slotsCount the number of slots |
---|
| 26 | */ |
---|
[639] | 27 | CInputPin(CGarbageCollector& gc, size_t slotsCount); |
---|
[637] | 28 | |
---|
| 29 | /*! |
---|
[1021] | 30 | * Sets the trigger for a specific input slot. |
---|
| 31 | * |
---|
| 32 | * \param inputSlot the input slot number |
---|
| 33 | * \param trigger the corresponding trigger |
---|
| 34 | */ |
---|
| 35 | void virtual setInputTrigger(size_t inputSlot, COutputPin* trigger); |
---|
| 36 | |
---|
| 37 | /*! |
---|
[637] | 38 | * Receives a data packet from an upstream filter on |
---|
| 39 | * the specified input slot. |
---|
| 40 | * The receiving filter takes ownership of the packet. |
---|
| 41 | * |
---|
| 42 | * \param inputSlot the input slot number |
---|
| 43 | * \param packet the data packet to be received |
---|
| 44 | */ |
---|
| 45 | void setInput(size_t inputSlot, CDataPacketPtr packet); |
---|
| 46 | |
---|
[639] | 47 | /*! |
---|
[1021] | 48 | * Triggers the input of any buffered packet for the specified timestamp. |
---|
| 49 | * |
---|
| 50 | * \param timestamp the timestamp for which we are triggering the input |
---|
| 51 | */ |
---|
| 52 | void virtual trigger(Time timestamp); |
---|
| 53 | |
---|
| 54 | /*! |
---|
| 55 | * Tests if the pin can be triggered. |
---|
| 56 | * |
---|
| 57 | * \return true if the pin can be triggered |
---|
| 58 | */ |
---|
| 59 | bool virtual canBeTriggered() const; |
---|
| 60 | |
---|
| 61 | /*! |
---|
[1158] | 62 | * Tests whether data is expected for the specified date. |
---|
| 63 | * |
---|
| 64 | * \param date the date associated to the data |
---|
| 65 | */ |
---|
| 66 | bool virtual isDataExpected(const CDate& date) const = 0; |
---|
| 67 | |
---|
| 68 | /*! |
---|
[639] | 69 | * Removes all pending packets which are older than the specified timestamp. |
---|
| 70 | * |
---|
| 71 | * \param timestamp the timestamp used for invalidation |
---|
| 72 | */ |
---|
| 73 | void virtual invalidate(Time timestamp); |
---|
| 74 | |
---|
[637] | 75 | protected: |
---|
| 76 | /*! |
---|
| 77 | * Function triggered when all slots have been filled for a specific timestamp. |
---|
| 78 | * It should be implemented by the filter class to process the data. |
---|
| 79 | * |
---|
| 80 | * \param data a vector of packets corresponding to each slot |
---|
| 81 | */ |
---|
| 82 | void virtual onInputReady(std::vector<CDataPacketPtr> data) = 0; |
---|
| 83 | |
---|
| 84 | private: |
---|
| 85 | /*! |
---|
| 86 | * Helper structure, groups a vector of packets corresponding to each slot |
---|
| 87 | * with the number of slots currently filled |
---|
| 88 | */ |
---|
| 89 | struct InputBuffer |
---|
| 90 | { |
---|
| 91 | size_t slotsFilled; //!< Number of slots currently filled |
---|
| 92 | std::vector<CDataPacketPtr> packets; //< Vector of packets corresponding to each slot |
---|
| 93 | |
---|
| 94 | /*! |
---|
| 95 | * Initialize an empty input buffer for the specified number of slots. |
---|
| 96 | * |
---|
| 97 | * \param slotsCount the number of slots |
---|
| 98 | */ |
---|
| 99 | InputBuffer(size_t slotsCount) |
---|
| 100 | : slotsFilled(0) |
---|
| 101 | , packets(slotsCount) |
---|
| 102 | { /* Nothing to do */ }; |
---|
| 103 | }; |
---|
| 104 | |
---|
[1021] | 105 | CGarbageCollector& gc; //!< The garbage collector associated to the input pin |
---|
| 106 | |
---|
[637] | 107 | size_t slotsCount; //!< The number of slots |
---|
| 108 | |
---|
| 109 | //! Input buffer, store the packets until all slots are full for a timestep |
---|
| 110 | std::map<Time, InputBuffer> inputs; |
---|
[1021] | 111 | |
---|
| 112 | //! Store the triggers corresponding to the input slots |
---|
| 113 | std::vector<COutputPin*> triggers; |
---|
| 114 | |
---|
| 115 | //! Whether some triggers have been set |
---|
| 116 | bool hasTriggers; |
---|
[637] | 117 | }; // class CInputPin |
---|
| 118 | } // namespace xios |
---|
| 119 | |
---|
| 120 | #endif //__XIOS_CInputPin__ |
---|