template class Poco::AbstractEvent<void, TStrategy, TDelegate, TMutex>

Overview

#include <AbstractEvent.h>

template <
    class TStrategy,
    class TDelegate,
    class TMutex
    >
class AbstractEvent<void, TStrategy, TDelegate, TMutex>
{
public:
    // typedefs

    typedef TDelegate* DelegateHandle;

    // structs

    template <>
    struct AbstractEvent<void, TStrategy, TDelegate, TMutex>;

    // construction

    AbstractEvent();
    AbstractEvent(const TStrategy& strat);

    // methods

    void
    operator+=(const TDelegate& aDelegate);

    void
    operator-=(const TDelegate& aDelegate);

    DelegateHandle
    add(const TDelegate& aDelegate);

    void
    remove(DelegateHandle delegateHandle);

    void
    operator()(const void* pSender);

    void
    operator()();

    void
    notify(const void* pSender);

    ActiveResult<void>
    notifyAsync(const void* pSender);

    void
    enable();

    void
    disable();

    bool
    isEnabled() const;

    void
    clear();

    bool
    empty() const;

protected:
    // fields

    ActiveMethod<void, NotifyAsyncParams, AbstractEvent> _executeAsync;
    TStrategy _strategy;
    bool _enabled;
    TMutex _mutex;

    // methods

    void
    executeAsyncImpl(const NotifyAsyncParams& par);
};

Detailed Documentation

Fields

TStrategy _strategy

The strategy used to notify observers.

bool _enabled

Stores if an event is enabled. Notfies on disabled events have no effect.

Methods

void
operator+=(const TDelegate& aDelegate)

Adds a delegate to the event.

Exact behavior is determined by the TStrategy.

void
operator-=(const TDelegate& aDelegate)

Removes a delegate from the event.

If the delegate is not found, this function does nothing.

DelegateHandle
add(const TDelegate& aDelegate)

Adds a delegate to the event.

Exact behavior is determined by the TStrategy.

Returns a DelegateHandle which can be used in call to remove() to remove the delegate.

void
remove(DelegateHandle delegateHandle)

Removes a delegate from the event using a DelegateHandle returned by add().

If the delegate is not found, this function does nothing.

void
operator()(const void* pSender)

Shortcut for notify(pSender, args);.

void
operator()()

Shortcut for notify(args).

void
notify(const void* pSender)

Sends a notification to all registered delegates.

The order is determined by the TStrategy. This method is blocking. While executing, the list of delegates may be modified. These changes don’t influence the current active notifications but are activated with the next notify. If a delegate is removed during a notify(), the delegate will no longer be invoked (unless it has already been invoked prior to removal). If one of the delegates throws an exception, the notify method is immediately aborted and the exception is propagated to the caller.

ActiveResult<void>
notifyAsync(const void* pSender)

Sends a notification to all registered delegates.

The order is determined by the TStrategy. This method is not blocking and will immediately return. The delegates are invoked in a seperate thread. Call activeResult.wait() to wait until the notification has ended. While executing, other objects can change the delegate list. These changes don’t influence the current active notifications but are activated with the next notify. If a delegate is removed during a notify(), the delegate will no longer be invoked (unless it has already been invoked prior to removal). If one of the delegates throws an exception, the execution is aborted and the exception is propagated to the caller.

void
enable()

Enables the event.

void
disable()

Disables the event.

notify and notifyAsnyc will be ignored, but adding/removing delegates is still allowed.

void
clear()

Removes all delegates.

bool
empty() const

Checks if any delegates are registered at the delegate.