Base module

TimedManager

Timed pointer manager Provides timed persistent data storage for class instances.

TimedManager

#include <icy/timedmanager.h>

Inherits: KeyedStore< TKey, TValue >

Timed pointer manager

Provides timed persistent data storage for class instances. TValue must implement the clone() method.

Public Methods

ReturnNameDescription
TimedManager inlineConstructs a TimedManager and starts the internal expiry-check timer.
voidadd inlineAdd an item which will expire (and be deleted) after the specified timeout value. If the timeout is 0 the item will be stored indefinitely. The TimedManager assumes ownership of the given pointer.
boolexpires virtual inlineUpdate the item expiry timeout.
boolexpires virtual inlineUpdate the item expiry timeout.
voidclear virtual inlineRemoves all items and their associated timeouts.

TimedManager

inline

inline TimedManager(uv::Loop * loop)

Constructs a TimedManager and starts the internal expiry-check timer.

Parameters

  • loop Event loop used by the internal timer (default: process-wide default loop).

add

inline

inline void add(constTKey & key, std::unique_ptr< TValue > item, long timeout)

Add an item which will expire (and be deleted) after the specified timeout value. If the timeout is 0 the item will be stored indefinitely. The TimedManager assumes ownership of the given pointer.


expires

virtual inline

virtual inline bool expires(constTKey & key, long timeout)

Update the item expiry timeout.


expires

virtual inline

virtual inline bool expires(TValue * item, long timeout)

Update the item expiry timeout.


clear

virtual inline

virtual inline void clear()

Removes all items and their associated timeouts.

Protected Attributes

ReturnNameDescription
std::mutex_tmutex
TimeoutMap_timeouts
Timer_timer

_tmutex

std::mutex _tmutex

_timeouts

TimeoutMap _timeouts

_timer

Timer _timer

Protected Methods

ReturnNameDescription
boolsetTimeout virtual inlineSets or removes the expiry timeout for a specific item pointer. If timeout > 0, starts a countdown; if timeout == 0, removes any existing timeout.
voidonRemove virtual inlineCalled when an item is removed from the collection. Erases the item's timeout entry and calls the base implementation.
voidonTimeout virtual inlineCalled when an item's timeout expires. Default implementation removes and deletes the item.
voidonTimerUpdate inlineInternal timer callback; iterates all tracked timeouts and calls onTimeout() for any that have expired.

setTimeout

virtual inline

virtual inline bool setTimeout(TValue * item, long timeout)

Sets or removes the expiry timeout for a specific item pointer. If timeout > 0, starts a countdown; if timeout == 0, removes any existing timeout.

Parameters

  • item Pointer to the managed item.

  • timeout Delay in milliseconds, or 0 to clear the timeout.

Returns

true on success.

Exceptions

  • std::logic_error if item is nullptr.

onRemove

virtual inline

virtual inline void onRemove(constTKey & key, TValue * item)

Called when an item is removed from the collection. Erases the item's timeout entry and calls the base implementation.

Parameters

  • key Key of the removed item.

  • item Pointer to the removed item.


onTimeout

virtual inline

virtual inline void onTimeout(TValue * item)

Called when an item's timeout expires. Default implementation removes and deletes the item.

Parameters

  • item Pointer to the expired item.

onTimerUpdate

inline

inline void onTimerUpdate()

Internal timer callback; iterates all tracked timeouts and calls onTimeout() for any that have expired.

Public Types

NameDescription
Base
TimeoutMap

Base

KeyedStore< TKey, TValue > Base()

TimeoutMap

std::map< TValue *, Timeout > TimeoutMap()