#include <Hardware.hh>
The Hardware template provides uniform facilities for hardware classes. By using the template to define their hardware classes through convenience macros HARDWARE_IMPL(), and HARDWARE_DECL() or HARDWARE_DECL2(), users add standard methods to create and access instances of those hardware to their classes
Most importantly, the Hardware template provides users with facilities for registering and looking up hardware instances. For hardware classes for which there will be exactly one instance, this can be done by using registerInstance() and instance() with no arguments. For hardware classes for which there will be multiple instance, this we can pass registerInstance() and instance() unique name strings to differentiate between the instances.
In addition, the Hardware template provides rudimentary facilities for "grabbing" and "releasing" hardware instances. This may be useful in order to mark a piece of hardware which, for physical reasons, should only have one user at a time, such as a digital output. grab() and release() are not coercive, i.e., the user has to check the results of a grab() and react properly. There is nothing which prevents a hardware instance from being used after a failed grab(). Normally, hardware instances have a maximum number of users of 1. This can be changed by overriding the max_users() method to return the maximum number of users minus 1 (for example: the default behaviour is obtained by returning 0).
grab() and release() also provide for "multi-channel" hardware instances, such as a multi-channel A/D board. Individual channels are then grabbed and released by passing in the channel index. Multi-channel hardware can be set up by overriding the max_index() method to return more than 1.
Public Member Functions | |
virtual bool | grab (int index=0) |
Grab an instance of hardware. | |
virtual bool | release (int index=0) |
Release an instance of hardware. | |
virtual int | max_users (int index=0) |
Defines the number of users for a hardware instance. | |
virtual int | max_index (void) |
Defines the number of indexed channels for this hardware class Hardware classes should override this to become multi-channel. | |
Static Public Member Functions | |
void | registerInstance (T *instance) |
Register the "default" instance. | |
void | registerInstance (const char *name, T *instance) |
Register a named instance. | |
T * | instance (const char *name=NULL) |
Lookup an instance by name. | |
void | clear () |
Clear out all instances of this class of hardware. |
|
Grab an instance of hardware. This call is typically done in the activation of a module (MMActivateModule()) and "marks" a hardware instance as being used.
|
|
Lookup an instance by name. If the specified instance does not exist, the routine returns NULL.
|
|
Defines the number of users for a hardware instance. This call returns the maximum number of simultaneous users for a hardware instance. The default value of this is 0, but the class T can override this method to have the effect of a multi-user piece of hardware
|
|
Register a named instance. This is typically called from the hardware libraries initHardware() call to provide access to the instance by name
|
|
Register the "default" instance. This is typically called from the hardware libraries initHardware() call to provide access to the instance through instance() with no arguments.
|
|
Release an instance of hardware. This call is typically done in the deactivation of a module (MMDeactivateModule() to "undo" the effect of a grab()
|