DevicesImpl.mesa
Copyright Ó 1991, 1992 by Xerox Corporation. All rights reserved.
Bier, November 6, 1991 10:21 am PST
Contents: Routines on devices and device classes (e.g., keyboards, mice, pens, etc.).
DIRECTORY
Devices, DeviceClassTypes, DeviceTypes, RefTab;
DevicesImpl:
CEDAR
PROGRAM
IMPORTS RefTab
EXPORTS Devices, DeviceTypes =
BEGIN
Device: TYPE = DeviceTypes.Device;
DeviceClass: TYPE = DeviceClassTypes.DeviceClass;
DeviceClassObj: PUBLIC TYPE = DeviceClassTypes.DeviceClassObj;
DeviceState: TYPE = DeviceTypes.DeviceState;
globalDevices: RefTab.Ref ¬ RefTab.Create[];
QuaClass:
PUBLIC
PROC [ref:
REF]
RETURNS [class: DeviceClass] = {
Narrows ref to DeviceClass. Clients can't do this themselves because DeviceTypes.DeviceClass is an Opaque type. Returns NIL if ref is the wrong type.
WITH ref
SELECT
FROM
dc: DeviceClass => class ¬ dc;
ENDCASE => class ¬ NIL;
};
NameOfClass:
PUBLIC
PROC [class: DeviceClass]
RETURNS [name:
ATOM] = {
name ¬ class.name;
};
ClassOfDevice:
PUBLIC
PROC [device: Device]
RETURNS [class: DeviceClass] = {
class ¬ device.class;
};
RegisterClass:
PUBLIC
PROC [class: DeviceClass, name:
ATOM] = {
[] ¬ RefTab.Store[globalDevices, name, class];
};
ClassFromName:
PUBLIC
PROC [name:
ATOM]
RETURNS [class: DeviceClass ¬
NIL] = {
found: BOOL;
val: REF;
[found, val] ¬ RefTab.Fetch[globalDevices, name];
IF found THEN class ¬ NARROW[val];
};
InitialDeviceState:
PUBLIC
PROC [device: Device]
RETURNS [DeviceState] = {
For keyboards and mice, this returns the state with all keys up. For pointing devices, the device begins at position [0,0] in 2D, [0,0,0] in 3D, etc.
RETURN[device.class.getDeviceState[device]];
};
END.