source: XIOS/dev/dev_olga/src/filter/input_pin.hpp @ 1654

Last change on this file since 1654 was 1654, checked in by oabramkina, 3 years ago

Corrections for workflow visualization.

File size: 4.0 KB
Line 
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
10namespace 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      StdString virtual GetName(void);
30
31      /*!
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      /*!
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
49      /*!
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      /*!
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      /*!
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      /*!
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     
84      /*!
85       * Returns filter's id needed in case of building workflow graph
86       * This function should never be called from this class, instead functions defined in derived classes or in class COutputPin should be used
87       */
88      int virtual getFilterId();
89
90    protected:
91      /*!
92       * Function triggered when all slots have been filled for a specific timestamp.
93       * It should be implemented by the filter class to process the data.
94       *
95       * \param data a vector of packets corresponding to each slot
96       */
97      void virtual onInputReady(std::vector<CDataPacketPtr> data) = 0;
98
99    private:
100      /*!
101       * Helper structure, groups a vector of packets corresponding to each slot
102       * with the number of slots currently filled
103       */
104      struct InputBuffer
105      {
106        size_t slotsFilled; //!< Number of slots currently filled
107        std::vector<CDataPacketPtr> packets; //< Vector of packets corresponding to each slot
108
109        /*!
110         * Initialize an empty input buffer for the specified number of slots.
111         *
112         * \param slotsCount the number of slots
113         */
114        InputBuffer(size_t slotsCount)
115          : slotsFilled(0)
116          , packets(slotsCount)
117        { /* Nothing to do */ };
118      };
119
120      CGarbageCollector& gc; //!< The garbage collector associated to the input pin
121
122      size_t slotsCount; //!< The number of slots
123
124      //! Input buffer, store the packets until all slots are full for a timestep
125      std::map<Time, InputBuffer> inputs;
126
127      //! Store the triggers corresponding to the input slots
128      std::vector<COutputPin*> triggers;
129
130      //! Whether some triggers have been set
131      bool hasTriggers;
132
133  }; // class CInputPin
134} // namespace xios
135
136#endif //__XIOS_CInputPin__
Note: See TracBrowser for help on using the repository browser.