Poco

template < class C, class N >

class NObserver

Library: Foundation
Package: Notifications
Header: Poco/NObserver.h

Description

This template class implements an adapter that sits between a NotificationCenter and an object receiving notifications from it. It is quite similar in concept to the RunnableAdapter, but provides some NotificationCenter specific additional methods. See the NotificationCenter class for information on how to use this template class.

This class template is quite similar to the Observer class template. The differences are:

  • NObserver expects the callback function to accept a const AutoPtr& instead of a plain pointer as argument, thus simplifying memory management.

  • In addition to dispatching notifications based on the Notification runtime type, NObserver can also notify subscribers based on the Notification name. To enable this functionality, a matcher function must be provided. Null matcher means no matching is performed and all notificiations of the type subscribed to are dispatched.

Inheritance

Direct Base Classes: AbstractObserver

All Base Classes: AbstractObserver

Member Summary

Member Functions: accepts, clone, disable, equals, handle, match, mutex, notify, operator =

Inherited Functions: accepts, backlog, clone, disable, equals, notify, operator =, start

Types Aliases

Callback

using Callback = void (C::*)(const NotificationPtr &);

Handler

using Handler = Callback;

Matcher

using Matcher = bool (C::*)(const std::string &)const;

NotificationPtr

using NotificationPtr = AutoPtr < N >;

Type

using Type = NObserver < C, N >;

Constructors

NObserver

NObserver() = delete;

NObserver inline

NObserver(
    const NObserver & observer
);

NObserver inline

NObserver(
    C & object,
    Handler method,
    Matcher matcher = nullptr
);

Destructor

~NObserver virtual inline

~NObserver();

Member Functions

accepts virtual inline

virtual bool accepts(
    Notification * pNf,
    const char * pName
) const;

accepts virtual inline

virtual bool accepts(
    const Notification::Ptr & pNf
) const;

clone virtual inline

virtual AbstractObserver * clone() const;

disable virtual inline

virtual void disable();

equals virtual inline

virtual bool equals(
    const AbstractObserver & abstractObserver
) const;

notify virtual inline

virtual void notify(
    Notification * pNf
) const;

operator = inline

NObserver & operator = (
    const NObserver & observer
);

handle protected inline

void handle(
    const NotificationPtr & ptr
) const;

match protected inline

bool match(
    const Notification::Ptr & ptr
) const;

mutex protected inline

Mutex & mutex() const;