/* > device.h

 *  SJ Middleton, 1993
   
 * Device numbers and prototypes for Wimp device claim protocol

 */                                             

#ifndef __device_h
# define __device_h

typedef struct device__str *device;     /* abstract device handle */

/* Major numbers */

typedef enum
{
/* Acorn */
    device_Parallel = 1,                        /* 0 = internal port */
    device_Serial,                                      /* 0 = internal port */
    device_ScreenPalette,                       /* 0 = main screen */
    device_Midi,                                        /* -1 = all ports, 0-3 = port number */
    device_Floppy,                                      /* -1 = all drives, 0-3 = drive number */
    device_Sound,                                       /* 0 = entire system */
/* ISV */
        device_RS422 = 0x1002                   /* 0 = port A, 1 = port B ... */
} device_number;

/* ----------------------------------------------------------------------------------------
 * Device names
 * These are NOT present in device.c and should always be in the Messages resource of
 * any application that uses this code.

devtype1:Parallel
devtype2:Serial
devtype3:Screen palette
devtype4:MIDI
devtype5:Floppy
devtype6:Sound system

 */

/* ---------------------------------- device_releasefn -------------------------------------
 *
 * Description: Called when another task tries to claim adevice we have claimed
 *
 * Parameters:  device dev -- device handle returned by device_claim.
 *              const char *info -- description of potential new claimant
 *                              void *handle -- handle passed into device_claim
 *
 * Return:              TRUE if device_release() has been called
 *                              FALSE if we want to object to the device claim.
 */

typedef BOOL (*device_releasefn)(device dev, const char *info, void *handle);


/* ---------------------------------- device_claim -----------------------------------------
 *
 * Description: Check to see if we can claim a device, and if we can set up message handler
 *              to tell anyone else who asks.
 *
 * Parameters:  device_number major, minor -- numbers as allocated by Acorn.
 *              const char *info -- description of claimant, if NULL uses task name as supplied to wimpt.
 *                              device_releasefn fn -- fn to call when someone else wants the device or 0.
 *                              void *handle -- handle to call above function with
 *
 * Returns:             device handle or NULL
 *                              device_claim will report an error with werr() if it can't claim the device.
 *                              device_claim_nomsg() will just NULL.
 */

extern device device_claim(device_number major, device_number minor, const char *info, device_releasefn fn, void *handle);
extern device device_claim_nomsg(device_number major, device_number minor, const char *info, device_releasefn fn, void *handle);


/* ---------------------------------- device_release -----------------------------------------
 *
 * Description: Release a device previously claimed with device_claim.
 *
 * Parameters:  device *dev -- ptr to handle as passed to device_claim
 *
 * Returns:     void
 */

extern void device_release(device *pdev);

#endif

/* eof device.h */
