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.
- 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
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
HTTPObserver(
const HTTPObserver & observer
);
HTTPObserver
HTTPObserver(
SharedPtrC object,
Handler method,
Matcher matcher = nullptr
);
Destructor
~HTTPObserver
~HTTPObserver();
Member Functions
accepts
virtual bool accepts(
Notification * pNf,
const char * pName
) const;
See also: Poco::AbstractObserver::accepts()
accepts
virtual bool accepts(
const Notification::Ptr & pNf
) const;
See also: Poco::AbstractObserver::accepts()
clone
virtual AbstractObserver * clone() const;
See also: Poco::AbstractObserver::clone()
disable
virtual void disable();
See also: Poco::AbstractObserver::disable()
equals
virtual bool equals(
const AbstractObserver & abstractObserver
) const;
See also: Poco::AbstractObserver::equals()
notify
virtual void notify(
Notification * pNf
) const;
See also: Poco::AbstractObserver::notify()
operator =
HTTPObserver & operator = (
const HTTPObserver & observer
);
handle
void handle(
const NotificationPtr & ptr
) const;
match
bool match(
const Notification::Ptr & ptr
) const;
mutex
Mutex & mutex() const;