home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 199.lha / GimmeLib / inputhand.c < prev    next >
C/C++ Source or Header  |  1988-12-27  |  2KB  |  86 lines

  1. /*
  2.  *  FILE: inputhand.c
  3.  *  Support routines for installing/removing an input handler.
  4.  *
  5.  *  Public Domain, but keep my name in it as the original author.
  6.  *  31-Oct-88    Jan Sven Trabandt   added to gimme.lib
  7.  */
  8.  
  9.  
  10. #define I_AM_INPUTHAND
  11. #include "gimmelib/gimmefuncs.h"
  12.  
  13.  
  14. struct IOStdReq *addInputHandler( handler, data, pri, name )
  15.     void    (*handler)();
  16.     APTR    data;
  17.     BYTE    pri;
  18.     UBYTE   *name;
  19. {
  20.     struct MsgPort    *port;
  21.     struct IOStdReq    *ioreq;
  22.     struct Interrupt    *handint;
  23.  
  24. #ifdef GIMME_WIMPY
  25.     if( !handler ) {
  26.     return( NULL );
  27.     }
  28. #endif
  29.     if( !(port = CreatePort(NULL, 0L)) ) {
  30.     return( NULL );
  31.     }
  32.     if( !(ioreq = CreateStdIO(port)) ) {
  33.     DeletePort( port );
  34.     return( NULL );
  35.     }
  36.     if( !(handint = AllocMem((ULONG)sizeof(struct Interrupt),
  37.                 MEMF_PUBLIC | MEMF_CLEAR)) ) {
  38.     DeleteStdIO( ioreq );
  39.     DeletePort( port );
  40.     return( NULL );
  41.     }
  42.     handint->is_Data = data;
  43.     handint->is_Code = handler;
  44.     handint->is_Node.ln_Type = NT_MESSAGE;
  45.     handint->is_Node.ln_Pri = pri;
  46.     handint->is_Node.ln_Name = (char *) name;
  47.     if( OpenDevice("input.device", 0L, ioreq, 0L) ) {
  48.     FreeMem( handint, (ULONG)sizeof(struct Interrupt) );
  49.     DeleteStdIO( ioreq );
  50.     DeletePort( port );
  51.     return( NULL );
  52.     }
  53.     ioreq->io_Command = IND_ADDHANDLER;
  54.     ioreq->io_Data = (APTR) handint;
  55.     ioreq->io_Length = sizeof(struct Interrupt);
  56.     if( DoIO(ioreq) ) {
  57.     CloseDevice( ioreq );
  58.     FreeMem( handint, (ULONG)sizeof(struct Interrupt) );
  59.     DeleteStdIO( ioreq );
  60.     DeletePort( port );
  61.     return( NULL );
  62.     }
  63.     return( ioreq );
  64. } /* addInputHandler */
  65.  
  66.  
  67. short removeInputHandler( ioreq )
  68.     struct IOStdReq *ioreq;
  69. {
  70. #ifdef GIMME_WIMPY
  71.     if( !ioreq ) {
  72.     return( -1 );
  73.     }
  74. #endif
  75.     ioreq->io_Command = IND_REMHANDLER;
  76.     ioreq->io_Message.mn_Node.ln_Type = NT_MESSAGE;
  77.     if( DoIO(ioreq) ) {
  78.     return( -1 );
  79.     }
  80.     CloseDevice( ioreq );
  81.     FreeMem( ioreq->io_Data, (ULONG)sizeof(struct Interrupt) );
  82.     DeletePort( ioreq->io_Message.mn_ReplyPort );
  83.     DeleteStdIO( ioreq );
  84.     return( 0 );
  85. } /* removeInputHandler */
  86.