Main Page | Modules | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

Hardware< T > Class Template Reference
[Hardware abstraction layer]

#include <Hardware.hh>

List of all members.


Detailed Description

template<class T>
class Hardware< T >

Basic template for Hardware classes.

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.


Member Function Documentation

template<class T>
virtual bool Hardware< T >::grab int  index = 0  )  [inline, virtual]
 

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.

Parameters:
index Optional argument used for a multi-channel hardware instance

template<class T>
T* Hardware< T >::instance const char *  name = NULL  )  [inline, static]
 

Lookup an instance by name.

If the specified instance does not exist, the routine returns NULL.

Parameters:
name The instance name. If NULL, look up the default instance.

template<class T>
virtual int Hardware< T >::max_users int  index = 0  )  [inline, virtual]
 

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

Parameters:
index Optional argument used for a multi-channel hardware instance

template<class T>
void Hardware< T >::registerInstance const char *  name,
T *  instance
[inline, static]
 

Register a named instance.

This is typically called from the hardware libraries initHardware() call to provide access to the instance by name

Parameters:
name The name of the instance
instance The instance to be installed with name

template<class T>
void Hardware< T >::registerInstance T *  instance  )  [inline, static]
 

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.

Parameters:
instance The instance to be installed as the default.

template<class T>
virtual bool Hardware< T >::release int  index = 0  )  [inline, virtual]
 

Release an instance of hardware.

This call is typically done in the deactivation of a module (MMDeactivateModule() to "undo" the effect of a grab()

Parameters:
index Optional argument used for a multi-channel hardware instance


RHexLib Reference Documentation