home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 4 Drivers / 04-Drivers.zip / swd092.zip / WATCH.C < prev    next >
Text File  |  1996-07-08  |  3KB  |  81 lines

  1. /********************************************/
  2. /*   WATCH.C  8 Jul 1996 Juergen Dittmer    */
  3. /*   Sample program for Watchdog DD         */
  4. /********************************************/
  5.  
  6. #define INCL_DOSDEVICES   /* Device values */
  7. #define INCL_DOSPROCESS
  8. #include <os2.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <conio.h>
  12.  
  13. /* Returnvalues from Watchdog */
  14. typedef struct _IODATAPKT {
  15.             ULONG ulTimer;       /* Timeoutcounter */
  16.         } IODATAPKT;
  17.  
  18.  
  19. main(int argc, char *argv[])
  20. {
  21. HFILE     DevHandle;       /* Device handle specifies the device  */
  22. ULONG     Category = 0x91; /* Device category for IOCtl           */
  23. ULONG     Function = 0x01; /* Device function for IOCtl           */
  24. ULONG     delay    = 10;   /* Delay in seconds between IOCtl's    */
  25. ULONG     ulAction = 0;    /* For DosOpen                         */
  26. IODATAPKT IOData;          /* Watchdog returnvalues               */
  27. APIRET  rc;                /* Return code for API's               */
  28.  
  29.  
  30.     if (argc == 2) delay = atoi (argv[1]);  /* Get command line value */
  31.  
  32.     printf ("DosDevIOCtl Cat:%x Func:%x\n\n", Category, Function);
  33.  
  34.     /* First we have to open the device driver.        */
  35.     /* This process will be registered at the watchdog */
  36.     /* and must send periodic IOCtl's to the driver.   */
  37.  
  38.     rc = DosOpen("WATCHDG$", &DevHandle,
  39.               &ulAction, 0,
  40.               FILE_NORMAL,
  41.               FILE_OPEN,
  42.               OPEN_SHARE_DENYNONE | OPEN_FLAGS_FAIL_ON_ERROR | OPEN_ACCESS_READWRITE,
  43.               0L);
  44.  
  45.     if (rc != 0) 
  46.       {
  47.         /* An error has occured during open, show the return code */
  48.         printf("DosOpen error: return code = %ld\n", rc);
  49.         return;
  50.       }
  51.  
  52.     printf ("Time interval = %d seconds. Press space for return\n", delay);
  53.     
  54.     /* Send periodic IOCtl's to the driver until a key is pressed */
  55.     /* The watchdog passes back values in the IOData struct       */
  56.     while (!kbhit()) {
  57.         printf ("Send IOCtl, ");
  58.         rc = DosDevIOCtl(DevHandle, Category, Function, NULL,
  59.                         NULL, NULL, &IOData,
  60.                         sizeof (IOData), NULL);
  61.  
  62.         if (rc != 0)
  63.             {
  64.                 /* An error has occured during IOCtl, show the return code */
  65.                 printf ("DosDevIOCtl error: return code = %ld\n", rc);
  66.                 return;
  67.             } else {
  68.                 /* OK, show the watchdog's counter */
  69.                 printf ("Watchdogcounter: %d Seconds\n", IOData.ulTimer);
  70.             }
  71.  
  72.         DosSleep (delay * 1000);
  73.     } /* endwhile */
  74.  
  75.     /* A key has been pressed, terminate the programm. */
  76.     /* DosClose deregisters the process */
  77.     rc = DosClose (DevHandle);
  78. }
  79.  
  80.  
  81.