home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff294.lzh / DNet / amiga / dnet / time.c < prev    next >
C/C++ Source or Header  |  1989-12-11  |  2KB  |  135 lines

  1.  
  2. /*
  3.  *  TIME.C
  4.  *
  5.  *  Handle IPC alert functions & timekeeping for connect and idle time.
  6.  */
  7.  
  8. #include "dnet.h"
  9. #include <stdio.h>
  10. #include <local/ipc.h>
  11.  
  12. #define TICKSIZE    10        /*    10 second intervals */
  13.  
  14. static long TickIdle;
  15. static long TickConnect;
  16.  
  17. static long AlertIdle;
  18. static long AlertConnect;
  19.  
  20. static char AIWho[64];        /*    app-name to alert   */
  21. static char ACWho[64];        /*    app-name to alert   */
  22.  
  23. /*
  24.  *  CTO:    Idle timeout (check carrier)
  25.  *
  26.  */
  27.  
  28. void
  29. do_cto(ior)
  30. IOT *ior;
  31. {
  32.     if (Cto_act) {
  33.     AbortIO((IOR *)ior);
  34.     WaitIO((IOR *)ior);
  35.     }
  36.     ior->tr_time.tv_secs = TICKSIZE;
  37.     ior->tr_time.tv_micro = 0;
  38.     SendIO((IOR *)ior);
  39.     Cto_act = 1;
  40.     if (Cd) {
  41.     ++TickConnect;
  42.     ++TickIdle;
  43.     }
  44.     if (DDebug)
  45.     printf("I/C: %ld %ld (%ld %ld)\n", TickIdle, TickConnect, AlertIdle, AlertConnect);
  46. #ifdef NOTDEF
  47.     if (AlertConnect && TickConnect > AlertConnect)      /*  alert ipc msg */
  48.     doipcmsg(ACWho, "\0connalert", 11);
  49.     if (AlertIdle && TickIdle > AlertIdle)               /*  alert ipc msg */
  50.     doipcmsg(AIWho, "\0idlealert", 11);
  51. #endif
  52. }
  53.  
  54. /*
  55.  *  Idle/Connect time & alerter vars.  IPC:
  56.  *            resetidle
  57.  *            alertidle <N>    (N in seconds)
  58.  *            alertconn <N>    (N in seconds)
  59.  */
  60.  
  61. void
  62. ResetIdle()
  63. {
  64.     TickIdle = 0;
  65. }
  66.  
  67. void
  68. ResetConnect()
  69. {
  70.     TickConnect = 0;
  71. }
  72.  
  73. void
  74. LessConnect(n)
  75. {
  76.     TickConnect -= n;
  77.     if (TickConnect < 0)
  78.     TickConnect = 0;
  79. }
  80.  
  81. void
  82. SetConnectAlert(n, who)
  83. char *who;
  84. {
  85.     AlertConnect = (n+(TICKSIZE-1))/TICKSIZE;
  86.     ACWho[0] = 0;
  87.     if (who)
  88.     strcpy(ACWho, who);
  89. }
  90.  
  91. void
  92. SetIdleAlert(n, who)
  93. char *who;
  94. {
  95.     AlertIdle = (n+(TICKSIZE-1))/TICKSIZE;
  96.     AIWho[0] = 0;
  97.     if (who)
  98.     strcpy(AIWho, who);
  99. }
  100.  
  101. GetIdle()
  102. {
  103.     return(TickIdle * TICKSIZE);
  104. }
  105.  
  106. GetConnect()
  107. {
  108.     return(TickConnect * TICKSIZE);
  109. }
  110.  
  111. #ifdef NOTDEF
  112.  
  113. doipcmsg(app, cmd, len)
  114. char *app;
  115. char *cmd;
  116. short len;
  117. {
  118.     IPCMSG *msg;
  119.     long res = 1;
  120.     IPCMSG *SendIPC();
  121.  
  122.     if (DDebug)
  123.     printf("IPC: <%s><%s> = ", app, cmd+1);
  124.     fflush(stdout);
  125.     if (msg = SendIPC(app, cmd, len, 0)) {
  126.     WaitMsg(msg);
  127.     res = msg->Error;
  128.     FreeIPC(msg);
  129.     }
  130.     if (DDebug)
  131.     printf("%ld\n", res);
  132. }
  133.  
  134. #endif
  135.