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