Home2L - C/C++ API  v1.2-2-ga4fe (2023-04-15)
Smart Tools for a Private Home
Friends | List of all members
CRcSubscriber Class Reference

Description

Subscriber to follow an arbitrary set of resources.

A subscriber monitors any number of resources. The resources can be specified by their real URIs or alias names. Wildcards as well as presently unkown resources are allowed. Events can be fetched using the CRcEventProcessor mechanisms, typically Select() and PollEvent().

Note: All public methods must be called from the same thread. Subscribers are generally managed by the user/owner object. Internally, each remote host object owns one subscriber to serve subscriptions from the remote host to local resources.

Definition at line 1880 of file resources.H.

#include "resources.H"

Inheritance diagram for CRcSubscriber:
Inheritance graph
[legend]

Friends

class CResource
 

Registration ...

bool Register (const char *_lid)
 Enable the subscriber, set its LID and GID. Caller remains owner of object. If '_lid' refers to an invalid string, 'false' is returned and a warning is emitted.
 
void Unregister ()
 Clear and unregister the subscriber.
 

Properties and stringification ...

const char * Lid ()
 
const char * Gid ()
 
virtual const char * TypeId ()
 (optional) Hint for the main event loop: object type
 
virtual const char * InstId ()
 (optional) Hint for the main event loop: object instance
 
const char * ToStr (CString *ret)
 
bool IsEmpty ()
 

Adding/removing resources ...

CResourceAddResource (CResource *rc)
 
CResourceAddResources (const char *pattern)
 Add new resources by pattern. The pattern is also stored internally to catch possible resources added in the future. More...
 
void DelResource (CResource *rc)
 
void DelResources (const char *pattern)
 Remove resources by pattern. See AddResources() for details on possible patterns. More...
 
void Clear ()
 Remove all resources.
 

Synonyms for adding/removing resources (mainly for the Python wrappers) ...

CResourceSubscribe (CResource *rc)
 
CResourceSubscribe (const char *uri)
 
void Unsubscribe (CResource *rc)
 
void Unsubscribe (const char *pattern)
 

For directory services ...

void GetInfo (CString *ret, int verbosity=1)
 Get Info. 'verbosity == 0': single line, 1: list entries / resources.
 
void GetPatternSet (CKeySet *retPatternSet)
 Get current pattern set. Patterns from the watch set are followed by a "?".
 
void PrintInfo (FILE *f=stdout, int verbosity=1)
 
static void GetInfoAll (CString *ret, int verbosity=1)
 Get info for all subscribers of this instance (see GetInfo() for info on 'verbosity').
 

Additional Inherited Members

- Public Member Functions inherited from CRcEventProcessor
void PutEvent (CRcEvent *ev)
 Enqueue/process an event; caller remains owner of 'ev'.
 
bool PollEvent (CRcEvent *ev)
 Check for an event (non-blocking) and return it at '*ev'. More...
 
bool WaitEvent (CRcEvent *ev, TTicks *maxTime=NULL)
 Wait for an event and return it at '*ev'. More...
 
void Interrupt ()
 Request a running WaitEvent() to stop now.
 
void FlushEvents ()
 Remove all presently queued events; also waits until a concurrently running OnEvent() invocation returns.
 
virtual bool OnEvent (CRcEvent *ev)
 Handle an event asynchronously (may have been called from any thread) More...
 
void SetCbOnEvent (FRcEventFunc *_cbEvent, void *_cbEventData=NULL)
 
void ClearCbOnEvent ()
 
void SetInSelectSet (bool _inSelectSet)
 Set whether or not the event processor is contained in the set of upcoming Select() operations.
 
bool InSelectSet ()
 
const char * ToStr (CString *ret)
 
- Static Public Member Functions inherited from CRcEventProcessor
static CRcEventProcessorSelect (TTicks maxTime=-1)
 Wait until any of the existing 'CRcEventProcessor' objects has an event available. More...
 

Member Function Documentation

◆ AddResources()

CResource* CRcSubscriber::AddResources ( const char *  pattern)

Add new resources by pattern. The pattern is also stored internally to catch possible resources added in the future.

Parameters
patternis a single or be a comma- or whitespace-separated list of URIs (expressions).
Returns
the resource, if 'pattern' refers to a single valid URI, or 'NULL' otherwise. It is allowed to pass multiple, comma-separated URIs or patterns here.

Within the resource expressions, both MQTT-style and filename-style wildcards can be used to select multiple resources:

  • '?' matches any single character except '/'.
  • '*' matches 0 or more characters except '/'.
  • '+' matches 1 or more characters except '/'.
  • '#' matches the complete remaining string (including '/' characters) and can thus be used to select a complete subtree. If used, '#' must be the last character in the expression. Anything behind a '#' is ignored silently.

◆ DelResources()

void CRcSubscriber::DelResources ( const char *  pattern)

Remove resources by pattern. See AddResources() for details on possible patterns.

Note: When using wildcards, all patterns previously passed to AddResources() must either be covered completely or be identical. Otherwise, it may happen that not all resources covered by 'pattern' here are unsuscribed. For example, in the following sequence, the DelResources() call has no effect:

sub->AddResources ("/host/z3/a+"); // may subscribe to "host/z3/ab" and others
sub->DelResources ("/host/z3/+b"); // conflict with other pattern, i.e. "host/z3/ab" may remain subscribed

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