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