1 | #ifndef __XIOS_CInputPin__ |
---|
2 | #define __XIOS_CInputPin__ |
---|
3 | |
---|
4 | #include <vector> |
---|
5 | #include <map> |
---|
6 | |
---|
7 | #include "data_packet.hpp" |
---|
8 | |
---|
9 | namespace xios |
---|
10 | { |
---|
11 | class CGarbageCollector; |
---|
12 | |
---|
13 | /*! |
---|
14 | * An input pin handles the data packets received by a filter. |
---|
15 | */ |
---|
16 | class CInputPin |
---|
17 | { |
---|
18 | public: |
---|
19 | /*! |
---|
20 | * Constructs an input pin with the specified number of slots |
---|
21 | * and an associated garbage collector. |
---|
22 | * |
---|
23 | * \param gc the garbage collector associated with this input pin |
---|
24 | * \param slotsCount the number of slots |
---|
25 | */ |
---|
26 | CInputPin(CGarbageCollector& gc, size_t slotsCount); |
---|
27 | |
---|
28 | /*! |
---|
29 | * Receives a data packet from an upstream filter on |
---|
30 | * the specified input slot. |
---|
31 | * The receiving filter takes ownership of the packet. |
---|
32 | * |
---|
33 | * \param inputSlot the input slot number |
---|
34 | * \param packet the data packet to be received |
---|
35 | */ |
---|
36 | void setInput(size_t inputSlot, CDataPacketPtr packet); |
---|
37 | |
---|
38 | /*! |
---|
39 | * Removes all pending packets which are older than the specified timestamp. |
---|
40 | * |
---|
41 | * \param timestamp the timestamp used for invalidation |
---|
42 | */ |
---|
43 | void virtual invalidate(Time timestamp); |
---|
44 | |
---|
45 | protected: |
---|
46 | CGarbageCollector& gc; //!< The garbage collector associated to the input pin |
---|
47 | |
---|
48 | /*! |
---|
49 | * Function triggered when all slots have been filled for a specific timestamp. |
---|
50 | * It should be implemented by the filter class to process the data. |
---|
51 | * |
---|
52 | * \param data a vector of packets corresponding to each slot |
---|
53 | */ |
---|
54 | void virtual onInputReady(std::vector<CDataPacketPtr> data) = 0; |
---|
55 | |
---|
56 | private: |
---|
57 | /*! |
---|
58 | * Helper structure, groups a vector of packets corresponding to each slot |
---|
59 | * with the number of slots currently filled |
---|
60 | */ |
---|
61 | struct InputBuffer |
---|
62 | { |
---|
63 | size_t slotsFilled; //!< Number of slots currently filled |
---|
64 | std::vector<CDataPacketPtr> packets; //< Vector of packets corresponding to each slot |
---|
65 | |
---|
66 | /*! |
---|
67 | * Initialize an empty input buffer for the specified number of slots. |
---|
68 | * |
---|
69 | * \param slotsCount the number of slots |
---|
70 | */ |
---|
71 | InputBuffer(size_t slotsCount) |
---|
72 | : slotsFilled(0) |
---|
73 | , packets(slotsCount) |
---|
74 | { /* Nothing to do */ }; |
---|
75 | }; |
---|
76 | |
---|
77 | size_t slotsCount; //!< The number of slots |
---|
78 | |
---|
79 | //! Input buffer, store the packets until all slots are full for a timestep |
---|
80 | std::map<Time, InputBuffer> inputs; |
---|
81 | }; // class CInputPin |
---|
82 | } // namespace xios |
---|
83 | |
---|
84 | #endif //__XIOS_CInputPin__ |
---|