Poco::Net

template < class C, class N >

class HTTPObserver

Library: Foundation
Package: Net
Header: Poco/Net/HTTPObserver.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.

Note: Despite the similar naming, HTTPObserver is NOT related to the deprecated Poco::Observer class. HTTPObserver derives directly from AbstractObserver (like NObserver) and does not trigger deprecation warnings.

HTTPObserver vs NObserver:

  • Both use AutoPtr<N> for automatic notification memory management

  • NObserver takes a reference (C&) - observer does not own the object

  • HTTPObserver takes a shared_ptr<C> - observer shares object ownership, suitable for cases where the observed object may be destroyed while still registered (e.g., connection objects using shared_from_this())

HTTPObserver cannot use the addNObserver() convenience method because it requires shared_ptr ownership semantics. Instead, construct the HTTPObserver explicitly and register it directly:

reactor.addEventHandler(socket,
    HTTPObserver<MyClass, ReadableNotification>(
        shared_from_this(), &MyClass::onReadable));

Or with NotificationCenter:

nc.addObserver(
    HTTPObserver<MyClass, MyNotification>(
        sharedPtr, &MyClass::handleNotification));

The addObserver(const AbstractObserver&) overload accepts any AbstractObserver subclass and does not trigger deprecation warnings.

Inheritance

Direct Base Classes: Poco::AbstractObserver

All Base Classes: Poco::AbstractObserver

Member Summary

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

Inherited Functions: accepts, acceptsSync, backlog, clone, disable, equals, notify, notifySync, 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 >;

SharedPtrC

using SharedPtrC = std::shared_ptr < C >;

Type

using Type = HTTPObserver < C, N >;

Constructors

HTTPObserver

HTTPObserver() = delete;

HTTPObserver inline

HTTPObserver(
    const HTTPObserver & observer
);

HTTPObserver inline

HTTPObserver(
    SharedPtrC object,
    Handler method,
    Matcher matcher = nullptr
);

Destructor

~HTTPObserver virtual inline

~HTTPObserver();

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

HTTPObserver & operator = (
    const HTTPObserver & 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;