Home2L - C/C++ API v1.4-0-g38cc (2024-05-25)
Smart Tools for a Private Home
Classes | Macros | Typedefs | Enumerations
Drivers

Description

Defining custom drivers.

Defining an own driver can be done in two ways:

  1. Deriving an own class from CRcDriver and overriding the interface methods (see "protected:" section).
  2. Instantiating an CRcDriver object and passing a driver function to CRcDriver::Register() (function-based driver).
  3. Instantiating an event-based driver (see CRcEventDriver).

The advantage of an event-based driver is that all driver functionality can be implemented in a single thread (the driver thread), so that the necessity of synchronization inside the driver can be avoided.

Loadable drivers must always provide a driver function and are thus by default function-based drivers. See HOME2L_DRIVER on how loadable drivers can use their own CRcDriver class or CRcEventDriver .

There is a clear distinction between an initialization (or elaboration) phase and the active phase. All resources must be registered in the initialization phase (Operation rcdOpInit). rcdOpDriveValue operations can only occur in the active phase.

Collaboration diagram for Drivers:

Classes

class  CRcDriver
 Driver for local resources. More...
 
class  CRcEventDriver
 Local driver using the event processor mechanism for the 'DriveValue()' functionality. More...
 

Macros

#define HOME2L_DRIVER(NAME)
 Define the entry point of a binary driver. More...
 

Typedefs

typedef void FRcDriverFunc(ERcDriverOperation, CRcDriver *, CResource *, CRcValueState *)
 Resources driver function. More...
 

Enumerations

enum  ERcDriverOperation { rcdOpInit = 0 , rcdOpStop , rcdOpDriveValue }
 Driver operations. More...
 

Macro Definition Documentation

◆ HOME2L_DRIVER

#define HOME2L_DRIVER (   NAME)
Value:
extern "C" { void Home2lRcDriverFunc_##NAME (ERcDriverOperation, CRcDriver *, CResource *, CRcValueState *); } \
void Home2lRcDriverFunc_##NAME
Driver for local resources.
Definition: resources.H:2460
Typed value tagged with a state and a time stamp.
Definition: resources.H:488
Home2L Resource.
Definition: resources.H:909
ERcDriverOperation
Driver operations.
Definition: resources.H:2376

Define the entry point of a binary driver.

Example 1: Function-Based Driver

switch (op) {
case rcdOpInit:
...
break;
case rcdOpStop:
...
break;
...
break;
}
}
#define HOME2L_DRIVER(NAME)
Define the entry point of a binary driver.
Definition: resources.H:2408
@ rcdOpDriveValue
Drive a value; refers to CRcDriver::DriveValue(). Parameters: CRcDriver *driver, CResource *rc,...
Definition: resources.H:2393
@ rcdOpInit
Initialize driver object(s) of a linked-in driver. Parameter: CRcDriver *drv.
Definition: resources.H:2379
@ rcdOpStop
Stop the driver; refers to CRcDriver::Stop(). Parameter: CRcDriver *drv.
Definition: resources.H:2390

Example 2: Class-Based Driver

This pattern allows loadable drives to use a different CRcDriver class than the base class, for example, CRcEventDriver or an own derived class.

ASSERT(op == rcdOpInit); // just in case you do not trust the Home2Ls ...
drv->Unregister (); // ... this function will never be called again after this.
drv = new CRcMyOwnDriver ("foo"); // Create a new driver object (must pass the driver ID "foo" to ...
// ... the constructor of @ref CRcDriver).
drv->Register (); // Register the driver.
... // Register all resources, then we are done.
}
#define ASSERT(COND)
Check a condition and abort the application if not true.
Definition: base.H:276

Definition at line 2448 of file resources.H.

Typedef Documentation

◆ FRcDriverFunc

typedef void FRcDriverFunc(ERcDriverOperation, CRcDriver *, CResource *, CRcValueState *)

Resources driver function.

Example:

void DriverFunc_sample (int appOp, CRcDriver *driver, CResource *rc, CRcValueState *vs);

Definition at line 2399 of file resources.H.

Enumeration Type Documentation

◆ ERcDriverOperation

Driver operations.

Enumerator
rcdOpInit 

Initialize driver object(s) of a linked-in driver. Parameter: CRcDriver *drv.

'drv' is a 'CRcDriver' (base class) object pre-initialized and registered with a LID and 'FRcDriverFunc' according to the driver declaration table. For a function-based driver which implements 'rcdStop' and 'rcdOpDriveValue' accordingly, everything is fine now. If the driver wants to use its own objects with classes derived from 'CRcDriver', it must unregister 'drv' and may then create and register own driver(s).

rcdOpStop 

Stop the driver; refers to CRcDriver::Stop(). Parameter: CRcDriver *drv.

rcdOpDriveValue 

Drive a value; refers to CRcDriver::DriveValue(). Parameters: CRcDriver *driver, CResource *rc, CRcValueState *vs.

Definition at line 2376 of file resources.H.