home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 13 / MA_Cover_13.bin / source / c / stefanb_src / private_projects / yath / yathmonitor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-06  |  2.4 KB  |  121 lines

  1. /*
  2.  * yathmonitor.c   V0.01 (beta)
  3.  *
  4.  * tape handler monitor
  5.  *
  6.  * (c) 1992 by Stefan Becker
  7.  *
  8.  */
  9. #ifdef DEBUG
  10. #include "yath.h"
  11.  
  12. void main(int argc, char *argv)
  13. {
  14.  BOOL notend=TRUE,open=FALSE;
  15.  struct MsgPort *MonitorPort;
  16.  ULONG PortSig,SigMask;
  17.  
  18.  /* Print banner */
  19.  puts("YATH Debug Monitor V0.01");
  20.  
  21.  /* Create debug monitor port */
  22.  if (!(MonitorPort=CreateMsgPort()))
  23.   {
  24.    puts("Couldn't create port!");
  25.    exit(20);
  26.   }
  27.  
  28.  /* Make port available to the public */
  29.  MonitorPort->mp_Node.ln_Pri=0;
  30.  MonitorPort->mp_Node.ln_Name=MPORTNAME;
  31.  AddPort(MonitorPort);
  32.  
  33.  /* Create signal masks */
  34.  PortSig=1L<<MonitorPort->mp_SigBit;
  35.  SigMask=PortSig|SIGBREAKF_CTRL_C;
  36.  
  37.  /* Main event loop */
  38.  while (notend || open)
  39.   {
  40.    ULONG RcvdSigs;
  41.  
  42.    /* Wait on signal */
  43.    RcvdSigs=Wait(SigMask);
  44.  
  45.    /* Received a CTRL-C? */
  46.    if (RcvdSigs&SIGBREAKF_CTRL_C)
  47.     {
  48.      if (open)
  49.       puts("Can't close yet, will exit ASAP!"); /* Sorry.... */
  50.      else
  51.       RemPort(MonitorPort); /* Remove port from list */
  52.      notend=FALSE; /* Set exit flag */
  53.     }
  54.  
  55.    /* Received a message from tape handler? */
  56.    if (RcvdSigs&PortSig)
  57.     {
  58.      struct MonitorMessage *msg;
  59.      ULONG cmd,arg1,arg2;
  60.  
  61.      /* Retrieve message from port */
  62.      msg=GetMsg(MonitorPort);
  63.  
  64.      /* Copy message values */
  65.      cmd=msg->mm_cmd;
  66.      arg1=msg->mm_arg1;
  67.      arg2=msg->mm_arg2;
  68.  
  69.      /* Close command and pending CTRL-C? */
  70.      if (!notend && (cmd==YATH_CLOSE))
  71.       RemPort(MonitorPort); /* Yes, remove port from list */
  72.  
  73.      /* Reply message */
  74.      ReplyMsg((struct Message *) msg);
  75.  
  76.      switch(cmd)
  77.       {
  78.        case YATH_OPEN:
  79.         printf("Opened for %s.\n",(arg1)?"reading":"writing");
  80.         open=TRUE;
  81.         break;
  82.  
  83.        case YATH_CLOSE:
  84.         puts("Closed.");
  85.         open=FALSE;
  86.         break;
  87.  
  88.        case YATH_READ:
  89.         printf("Read %ld bytes.\n",arg1);
  90.         break;
  91.  
  92.        case YATH_WRITE:
  93.         printf("Write %ld bytes.\n",arg1);
  94.         break;
  95.  
  96.        case YATH_FLUSH:
  97.         puts("Flushing buffers.");
  98.         break;
  99.  
  100.        case YATH_IOERR:
  101.         printf("I/O Error %d, SCSI status 0x%02x\n",arg1,arg2);
  102.         break;
  103.  
  104.        case YATH_SCSI:
  105.         printf("SCSI Command 0x%02x, %synch I/O\n",arg1,(arg2)?"As":"S");
  106.         break;
  107.  
  108.        default:
  109.         printf("Unknown message received: %ld %ld %ld\n",cmd,arg1,arg2);
  110.         break;
  111.       }
  112.     }
  113.   }
  114.  
  115.  /* The end... */
  116.  puts("Monitor closing...");
  117.  DeleteMsgPort(MonitorPort);
  118.  exit(0);
  119. }
  120. #endif
  121.