Home2L - C/C++ API v1.4-0-g38cc (2024-05-25)
Smart Tools for a Private Home
Public Member Functions | Protected Member Functions | List of all members
CRcEventDriver Class Reference

Description

Local driver using the event processor mechanism for the 'DriveValue()' functionality.

The class is useful for the Python API to allow writing simple applications (e.g. 'rules' scripts) without parallel threads and an event loop design.

Definition at line 2576 of file resources.H.

#include "resources.H"

Inheritance diagram for CRcEventDriver:
Inheritance graph
[legend]

Public Member Functions

 CRcEventDriver (const char *_lid, ERcState _successState=rcsBusy)
 Initialize the driver (does not register). More...
 
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
 
- Public Member Functions inherited from CRcDriver
void Register ()
 Register and enable the driver. This must be done between the calls to RcInit() and RcStart(), i.e. the initialization phase. The class takes over the ownership of 'this', which must be a dynamically allocated object, which is deleted during RcDone().
 
void Unregister ()
 Unregister the driver. This is only allowed in the elaboration phase or on shutdown. Calling this method will delete 'this' soon, so that no further accesses are allowed after this.
 
const char * Lid ()
 
const char * ToStr (CString *)
 
CResourceRegisterResource (const char *rcLid, ERcType _type, bool _writable, void *_data=NULL)
 
CResourceRegisterResource (const char *rcLid, const char *rcTypeDef, void *_data=NULL)
 see also: CResource::Register()
 
void PrintInfo (FILE *f=stdout)
 
CResourceGetResource (const char *rcLid)
 
int LockResources ()
 
CResourceGetResource (int n)
 
void UnlockResources ()
 
- 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)
 

Protected Member Functions

virtual void Stop ()
 The caller/owner must do this before 'RcDone()'. (The event processor may not work anymore by the time this method is called.)
 
virtual void DriveValue (CResource *rc, CRcValueState *vs)
 Callback to drive a new value, will be called from CResource::DriveValue(). More...
 
- Protected Member Functions inherited from CRcDriver
void Lock ()
 
void Unlock ()
 
void ClearResources ()
 Unregister all resources.
 

Additional Inherited Members

- Static Public Member Functions inherited from CRcDriver
static void RegisterAndInit (const char *_lid, FRcDriverFunc *_func)
 Create, register and initialize a function-based driver.
 
- 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...
 

Constructor & Destructor Documentation

◆ CRcEventDriver()

CRcEventDriver::CRcEventDriver ( const char *  _lid,
ERcState  _successState = rcsBusy 
)
inline

Initialize the driver (does not register).

Parameters
_lidis the local ID.
_successState'controls the value returned by 'DriveValue'. Note: These do a bit more than just setting the type of 'vs' in CRcDriver::DriveValue():
  • 'rcsBusy': (default) 'rcsBusy' with the old value is reported now; the application must report a valid and new value later.
  • 'rcsValid': the driven value is reported back; no further action by the driver necessary, but no errors are allowed to happen.
  • 'rcsUnknown' or 'rcsNoReport': nothing is reported back now; the application should report something soon and must report a valid and new value later.

Definition at line 2578 of file resources.H.

Member Function Documentation

◆ DriveValue()

virtual void CRcEventDriver::DriveValue ( CResource rc,
CRcValueState vs 
)
protectedvirtual

Callback to drive a new value, will be called from CResource::DriveValue().

When called, this method must propagate a new requested value to the device (e.g. to an actor). Afterwards, the new value and state pointed at by 'vs' will be reported automatically by the caller.

If there are no pending requests at all, this method is called with vs->State() == rcsUnknown. Most drivers will do nothing then (e.g. the "signal" driver does so) and keep the previous value active. Some drivers (e.g. brownies/shades) may switch off their actors now. For other drivers, please remember that unknown value/states may come in and must be ignored.

In all other cases, the state of '*vs' is preset with rcsValid.

IMPORTANT: It is not allowed to call any method of the 'rc' object (e.g. 'Report' methods) from here, since the resource may be locked.

It is legal to modify '*vs' to reflect a new state or even a value different from the driven one. The method shall change the value and eventually the state as adequate.

If the new value is not known yet, the state should be set to 'rcsBusy' by calling CRcValueState::SetToReportBusy() now on 'vs', and the new value should be reported later with a valid value and state of rcsValid by calling a 'CRcResource::Report...()' method.

To report a certain (e.g. the new) value with the rcsBusy state now, the state may be set to rcsBusy and the value be set as appropriate or left as it is, in which case the driven value is reported. Again, a valid value (state of rcsValid) should be reported later.

To report nothing at all this time, call CRcValueState::SetToReportNothing() on '*vs' or set the state to rcsUnknown.

In most cases, just writing to the device is sufficient.

Reimplemented from CRcDriver.


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