[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; |
---|
| 22 | }; // struct InvalidableObject |
---|
| 23 | |
---|
| 24 | /*! |
---|
[639] | 25 | * A basic garbage collector which ensures no old packets linger in the filter graph. |
---|
| 26 | */ |
---|
| 27 | class CGarbageCollector |
---|
| 28 | { |
---|
| 29 | public: |
---|
| 30 | /*! |
---|
| 31 | * Constructs a garbage collector. |
---|
| 32 | */ |
---|
| 33 | CGarbageCollector() |
---|
| 34 | { /* Nothing to do */ }; |
---|
| 35 | |
---|
| 36 | /*! |
---|
[1021] | 37 | * Registers an object for a specified timestamp. |
---|
[639] | 38 | * |
---|
[1021] | 39 | * \param object the object to register |
---|
| 40 | * \param timestamp the timestamp for which the object is registered |
---|
[639] | 41 | */ |
---|
[1021] | 42 | void registerObject(InvalidableObject* object, Time timestamp); |
---|
[639] | 43 | |
---|
| 44 | /*! |
---|
[1021] | 45 | * Removes a object previously registered for a specified timestamp. |
---|
[639] | 46 | * |
---|
[1021] | 47 | * \param object the object to unregister |
---|
| 48 | * \param timestamp the timestamp for which the object is unregistered |
---|
[639] | 49 | */ |
---|
[1021] | 50 | void unregisterObject(InvalidableObject* object, Time timestamp); |
---|
[639] | 51 | |
---|
| 52 | /*! |
---|
[1021] | 53 | * Ensures all registered objects invalidate packets older than the specified timestamp. |
---|
[639] | 54 | * |
---|
| 55 | * \param timestamp the timestamp used for invalidation |
---|
| 56 | */ |
---|
| 57 | void invalidate(Time timestamp); |
---|
| 58 | |
---|
| 59 | private: |
---|
| 60 | CGarbageCollector(const CGarbageCollector&); |
---|
| 61 | CGarbageCollector& operator=(const CGarbageCollector&); |
---|
| 62 | |
---|
[1021] | 63 | std::map<Time, std::set<InvalidableObject*> > registeredObjects; //!< Currently registered objects |
---|
[639] | 64 | }; // class CGarbageCollector |
---|
| 65 | } // namespace xios |
---|
| 66 | |
---|
| 67 | #endif //__XIOS_CGarbageCollector__ |
---|