1 | #ifndef __XIOS_CInputPin__ |
---|
2 | #define __XIOS_CInputPin__ |
---|
3 | |
---|
4 | #include <vector> |
---|
5 | #include <map> |
---|
6 | |
---|
7 | #include "garbage_collector.hpp" |
---|
8 | #include "data_packet.hpp" |
---|
9 | |
---|
10 | namespace xios |
---|
11 | { |
---|
12 | class COutputPin; |
---|
13 | |
---|
14 | /*! |
---|
15 | * An input pin handles the data packets received by a filter. |
---|
16 | */ |
---|
17 | class CInputPin : public InvalidableObject |
---|
18 | { |
---|
19 | public: |
---|
20 | /*! |
---|
21 | * Constructs an input pin with the specified number of slots |
---|
22 | * and an associated garbage collector. |
---|
23 | * |
---|
24 | * \param gc the garbage collector associated with this input pin |
---|
25 | * \param slotsCount the number of slots |
---|
26 | */ |
---|
27 | CInputPin(CGarbageCollector& gc, size_t slotsCount); |
---|
28 | |
---|
29 | /*! |
---|
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 | /*! |
---|
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 | |
---|
47 | /*! |
---|
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 | /*! |
---|
62 | * Tests if the pin must auto-trigger. |
---|
63 | * |
---|
64 | * \return true if the pin must auto-trigger |
---|
65 | */ |
---|
66 | bool virtual mustAutoTrigger() const = 0; |
---|
67 | |
---|
68 | /*! |
---|
69 | * Tests whether data is expected for the specified date. |
---|
70 | * |
---|
71 | * \param date the date associated to the data |
---|
72 | */ |
---|
73 | bool virtual isDataExpected(const CDate& date) const = 0; |
---|
74 | |
---|
75 | /*! |
---|
76 | * Removes all pending packets which are older than the specified timestamp. |
---|
77 | * |
---|
78 | * \param timestamp the timestamp used for invalidation |
---|
79 | */ |
---|
80 | void virtual invalidate(Time timestamp); |
---|
81 | |
---|
82 | protected: |
---|
83 | /*! |
---|
84 | * Function triggered when all slots have been filled for a specific timestamp. |
---|
85 | * It should be implemented by the filter class to process the data. |
---|
86 | * |
---|
87 | * \param data a vector of packets corresponding to each slot |
---|
88 | */ |
---|
89 | void virtual onInputReady(std::vector<CDataPacketPtr> data) = 0; |
---|
90 | |
---|
91 | private: |
---|
92 | /*! |
---|
93 | * Helper structure, groups a vector of packets corresponding to each slot |
---|
94 | * with the number of slots currently filled |
---|
95 | */ |
---|
96 | struct InputBuffer |
---|
97 | { |
---|
98 | size_t slotsFilled; //!< Number of slots currently filled |
---|
99 | std::vector<CDataPacketPtr> packets; //< Vector of packets corresponding to each slot |
---|
100 | |
---|
101 | /*! |
---|
102 | * Initialize an empty input buffer for the specified number of slots. |
---|
103 | * |
---|
104 | * \param slotsCount the number of slots |
---|
105 | */ |
---|
106 | InputBuffer(size_t slotsCount) |
---|
107 | : slotsFilled(0) |
---|
108 | , packets(slotsCount) |
---|
109 | { /* Nothing to do */ }; |
---|
110 | }; |
---|
111 | |
---|
112 | CGarbageCollector& gc; //!< The garbage collector associated to the input pin |
---|
113 | |
---|
114 | size_t slotsCount; //!< The number of slots |
---|
115 | |
---|
116 | //! Input buffer, store the packets until all slots are full for a timestep |
---|
117 | std::map<Time, InputBuffer> inputs; |
---|
118 | |
---|
119 | //! Store the triggers corresponding to the input slots |
---|
120 | std::vector<COutputPin*> triggers; |
---|
121 | |
---|
122 | //! Whether some triggers have been set |
---|
123 | bool hasTriggers; |
---|
124 | }; // class CInputPin |
---|
125 | } // namespace xios |
---|
126 | |
---|
127 | #endif //__XIOS_CInputPin__ |
---|