1 | #ifndef __XIOS_COutputPin__ |
---|
2 | #define __XIOS_COutputPin__ |
---|
3 | |
---|
4 | #include "garbage_collector.hpp" |
---|
5 | #include "input_pin.hpp" |
---|
6 | |
---|
7 | namespace xios |
---|
8 | { |
---|
9 | /*! |
---|
10 | * An output pin handles the connections with downstream filters. |
---|
11 | */ |
---|
12 | class COutputPin : public InvalidableObject |
---|
13 | { |
---|
14 | public: |
---|
15 | /*! |
---|
16 | * Constructs an ouput pin with manual or automatic trigger |
---|
17 | * and an associated garbage collector. |
---|
18 | * |
---|
19 | * \param gc the garbage collector associated with this ouput pin |
---|
20 | * \param slotsCount the number of slots |
---|
21 | */ |
---|
22 | COutputPin(CGarbageCollector& gc, bool manualTrigger = false); |
---|
23 | |
---|
24 | /*! |
---|
25 | * Connects to a specific slot of the input pin of a downstream filter. |
---|
26 | * Note that the output pin holds a reference on the downstream filter. |
---|
27 | * |
---|
28 | * \param inputPin the input pin to connect |
---|
29 | * \param inputSlot the input slot number |
---|
30 | */ |
---|
31 | void connectOutput(std::shared_ptr<CInputPin> inputPin, size_t inputSlot); |
---|
32 | |
---|
33 | /*! |
---|
34 | * Triggers the output of any buffered packet for the specified timestamp. |
---|
35 | * |
---|
36 | * \param timestamp the timestamp for which we are triggering the output |
---|
37 | */ |
---|
38 | void virtual trigger(Time timestamp); |
---|
39 | |
---|
40 | /*! |
---|
41 | * Tests if the pin can be triggered. |
---|
42 | * |
---|
43 | * \return true if the pin can be triggered |
---|
44 | */ |
---|
45 | bool virtual canBeTriggered() const; |
---|
46 | |
---|
47 | /*! |
---|
48 | * Tests if the pin must auto-trigger. |
---|
49 | * |
---|
50 | * \return true if the pin must auto-trigger |
---|
51 | */ |
---|
52 | bool virtual mustAutoTrigger() const; |
---|
53 | |
---|
54 | /*! |
---|
55 | * Tests whether data is expected for the specified date. |
---|
56 | * |
---|
57 | * \param date the date associated to the data |
---|
58 | */ |
---|
59 | bool virtual isDataExpected(const CDate& date) const; |
---|
60 | |
---|
61 | /*! |
---|
62 | * Removes all pending packets which are older than the specified timestamp. |
---|
63 | * |
---|
64 | * \param timestamp the timestamp used for invalidation |
---|
65 | */ |
---|
66 | void virtual invalidate(Time timestamp); |
---|
67 | |
---|
68 | protected: |
---|
69 | /*! |
---|
70 | * Function triggered when a packet is ready to be delivered. |
---|
71 | * |
---|
72 | * \param packet the packet ready for output |
---|
73 | */ |
---|
74 | void onOutputReady(CDataPacketPtr packet); |
---|
75 | |
---|
76 | /*! |
---|
77 | * Informs the downstream pins that this output pin should be triggered. |
---|
78 | */ |
---|
79 | void setOutputTriggers(); |
---|
80 | |
---|
81 | private: |
---|
82 | /*! |
---|
83 | * Delivers an output packet to the downstreams filter. |
---|
84 | * |
---|
85 | * \param packet the packet to output |
---|
86 | */ |
---|
87 | void deliverOuput(CDataPacketPtr packet); |
---|
88 | |
---|
89 | CGarbageCollector& gc; //!< The garbage collector associated to the output pin |
---|
90 | |
---|
91 | //!< Whether the ouput should be triggered manually |
---|
92 | bool manualTrigger; |
---|
93 | |
---|
94 | //!< The list of connected filters and the corresponding slot numbers |
---|
95 | std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> > outputs; |
---|
96 | |
---|
97 | //! Output buffer, store the packets until the output is triggered |
---|
98 | std::map<Time, CDataPacketPtr> outputPackets; |
---|
99 | }; // class COutputPin |
---|
100 | } // namespace xios |
---|
101 | |
---|
102 | #endif //__XIOS_COutputPin__ |
---|