ProsecCoAP 🥂
 
Loading...
Searching...
No Matches
Coap::ObserverRegistry< N > Class Template Reference

A resource observer registry. More...

#include <Observers.h>

Public Member Functions

Observeroperator[] (size_t index)
 Get the observer at the given index.
 
const Observeroperator[] (size_t index) const
 Get the observer at the given index.
 
size_t length () const
 Get the maximum number of observers that can be stored in the registry.
 
ErrorCode add (IPAddress ip, uint16_t port, const uint8_t *token, uint8_t tokenLength)
 Add a new observer to the registry.
 
ErrorCode remove (IPAddress ip, uint16_t port, const uint8_t *token, uint8_t tokenLength)
 Remove an observer from the registry.
 
ErrorCode remove (const Observer &observer)
 Remove an observer from the registry.
 

Detailed Description

template<size_t N>
class Coap::ObserverRegistry< N >

A resource observer registry.

It tracks the observers registered to a specific resource.

Example:

Coap::ObserverRegistry<5> myRegistry; // Create a registry with a maximum of 5 observers.
myRegistry.add(ip1, port1, token1, tokenLength1); // Add an observer to the registry.
Observer &observer = myRegistry[0]; // Get the first observer in the registry.
A resource observer registry.
Definition Observers.h:163
ErrorCode add(IPAddress ip, uint16_t port, const uint8_t *token, uint8_t tokenLength)
Add a new observer to the registry.
Definition Observers.h:215
A remote CoAP observer, actively observing a resource.
Definition Observers.h:23
Todo
Add support to clean up older observers.

Member Function Documentation

◆ add()

template<size_t N>
ErrorCode Coap::ObserverRegistry< N >::add ( IPAddress ip,
uint16_t port,
const uint8_t * token,
uint8_t tokenLength )
inline

Add a new observer to the registry.

If the observer already exists and is active, it will not be added again.

Parameters
ipThe IP address of the observer.
portThe port of the observer.
tokenThe token used by the observer.
tokenLengthThe length of the token in bytes.
Returns
An error code indicating success or failure. It will return ErrorCode::OK if the observer is successfully added (or was already present). It will return ErrorCode::NOT_SUPPORTED if the registry is full and the observer cannot be added.

◆ length()

template<size_t N>
size_t Coap::ObserverRegistry< N >::length ( ) const
inline

Get the maximum number of observers that can be stored in the registry.

Returns
The maximum number of entries.

◆ operator[]() [1/2]

template<size_t N>
Observer & Coap::ObserverRegistry< N >::operator[] ( size_t index)
inline

Get the observer at the given index.

Parameters
index
Returns
Reference to the observer.

◆ operator[]() [2/2]

template<size_t N>
const Observer & Coap::ObserverRegistry< N >::operator[] ( size_t index) const
inline

Get the observer at the given index.

Parameters
index
Returns
Const reference to the observer.

◆ remove() [1/2]

template<size_t N>
ErrorCode Coap::ObserverRegistry< N >::remove ( const Observer & observer)
inline

Remove an observer from the registry.

Parameters
observerThe observer to be removed.
Returns
An error code indicating success or failure.
See also
remove(IPAddress ip, uint16_t port, const uint8_t *token, uint8_t tokenLength) for more details.

◆ remove() [2/2]

template<size_t N>
ErrorCode Coap::ObserverRegistry< N >::remove ( IPAddress ip,
uint16_t port,
const uint8_t * token,
uint8_t tokenLength )
inline

Remove an observer from the registry.

The observer must match the provided combination of IP address, port, token and token length.

Parameters
ipThe IP address of the observer that needs to be removed.
portThe port of the observer.
tokenThe token used by the observer.
tokenLengthThe length of the token in bytes.
Returns
An error code indicating success or failure. It will return ErrorCode::OK if the observer is successfully removed. It will return ErrorCode::NOT_FOUND if no matching observer is found

The documentation for this class was generated from the following file: