[639] | 1 | #ifndef __XIOS_CGarbageCollector__ |
---|
| 2 | #define __XIOS_CGarbageCollector__ |
---|
| 3 | |
---|
| 4 | #include <map> |
---|
| 5 | #include <set> |
---|
| 6 | |
---|
[1021] | 7 | #include "date.hpp" |
---|
[639] | 8 | |
---|
| 9 | namespace xios |
---|
| 10 | { |
---|
| 11 | /*! |
---|
[1021] | 12 | * Interface shared by all objects that might need to invalidate packets. |
---|
| 13 | */ |
---|
| 14 | struct InvalidableObject |
---|
| 15 | { |
---|
| 16 | /*! |
---|
| 17 | * Removes all pending packets which are older than the specified timestamp. |
---|
| 18 | * |
---|
| 19 | * \param timestamp the timestamp used for invalidation |
---|
| 20 | */ |
---|
| 21 | void virtual invalidate(Time timestamp) = 0; |
---|
[1653] | 22 | |
---|
| 23 | static int count; //!< Counter used to identify a filter in case building workflow graph |
---|
| 24 | |
---|
[1021] | 25 | }; // struct InvalidableObject |
---|
| 26 | |
---|
| 27 | /*! |
---|
[639] | 28 | * A basic garbage collector which ensures no old packets linger in the filter graph. |
---|
| 29 | */ |
---|
| 30 | class CGarbageCollector |
---|
| 31 | { |
---|
| 32 | public: |
---|
| 33 | /*! |
---|
| 34 | * Constructs a garbage collector. |
---|
| 35 | */ |
---|
| 36 | CGarbageCollector() |
---|
| 37 | { /* Nothing to do */ }; |
---|
| 38 | |
---|
| 39 | /*! |
---|
[1021] | 40 | * Registers an object for a specified timestamp. |
---|
[639] | 41 | * |
---|
[1021] | 42 | * \param object the object to register |
---|
| 43 | * \param timestamp the timestamp for which the object is registered |
---|
[639] | 44 | */ |
---|
[1021] | 45 | void registerObject(InvalidableObject* object, Time timestamp); |
---|
[639] | 46 | |
---|
| 47 | /*! |
---|
[1021] | 48 | * Removes a object previously registered for a specified timestamp. |
---|
[639] | 49 | * |
---|
[1021] | 50 | * \param object the object to unregister |
---|
| 51 | * \param timestamp the timestamp for which the object is unregistered |
---|
[639] | 52 | */ |
---|
[1021] | 53 | void unregisterObject(InvalidableObject* object, Time timestamp); |
---|
[639] | 54 | |
---|
| 55 | /*! |
---|
[1021] | 56 | * Ensures all registered objects invalidate packets older than the specified timestamp. |
---|
[639] | 57 | * |
---|
| 58 | * \param timestamp the timestamp used for invalidation |
---|
| 59 | */ |
---|
| 60 | void invalidate(Time timestamp); |
---|
| 61 | |
---|
| 62 | private: |
---|
| 63 | CGarbageCollector(const CGarbageCollector&); |
---|
| 64 | CGarbageCollector& operator=(const CGarbageCollector&); |
---|
| 65 | |
---|
[1021] | 66 | std::map<Time, std::set<InvalidableObject*> > registeredObjects; //!< Currently registered objects |
---|
[639] | 67 | }; // class CGarbageCollector |
---|
| 68 | } // namespace xios |
---|
| 69 | |
---|
| 70 | #endif //__XIOS_CGarbageCollector__ |
---|