home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 239.lha / amiga / src / dnet / time.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-02  |  2.0 KB  |  124 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. do_cto(ior)
  29. IOT *ior;
  30. {
  31.     if (Cto_act) {
  32.     AbortIO(ior);
  33.     WaitIO(ior);
  34.     }
  35.     ior->tr_time.tv_secs = TICKSIZE;
  36.     ior->tr_time.tv_micro = 0;
  37.     SendIO(ior);
  38.     Cto_act = 1;
  39.     if (Cd) {
  40.     ++TickConnect;
  41.     ++TickIdle;
  42.     }
  43.     if (DDebug)
  44.     printf("I/C: %ld %ld (%ld %ld)\n", TickIdle, TickConnect, AlertIdle, AlertConnect);
  45.     if (AlertConnect && TickConnect > AlertConnect)      /*  alert ipc msg */
  46.     doipcmsg(ACWho, "\0connalert", 11);
  47.     if (AlertIdle && TickIdle > AlertIdle)               /*  alert ipc msg */
  48.     doipcmsg(AIWho, "\0idlealert", 11);
  49. }
  50.  
  51. /*
  52.  *  Idle/Connect time & alerter vars.  IPC:
  53.  *            resetidle
  54.  *            alertidle <N>    (N in seconds)
  55.  *            alertconn <N>    (N in seconds)
  56.  */
  57.  
  58. ResetIdle()
  59. {
  60.     TickIdle = 0;
  61. }
  62.  
  63. ResetConnect()
  64. {
  65.     TickConnect = 0;
  66. }
  67.  
  68. LessConnect(n)
  69. {
  70.     TickConnect -= n;
  71.     if (TickConnect < 0)
  72.     TickConnect = 0;
  73. }
  74.  
  75. SetConnectAlert(n, who)
  76. char *who;
  77. {
  78.     AlertConnect = (n+(TICKSIZE-1))/TICKSIZE;
  79.     ACWho[0] = 0;
  80.     if (who)
  81.     strcpy(ACWho, who);
  82. }
  83.  
  84. SetIdleAlert(n, who)
  85. char *who;
  86. {
  87.     AlertIdle = (n+(TICKSIZE-1))/TICKSIZE;
  88.     AIWho[0] = 0;
  89.     if (who)
  90.     strcpy(AIWho, who);
  91. }
  92.  
  93. GetIdle()
  94. {
  95.     return(TickIdle * TICKSIZE);
  96. }
  97.  
  98. GetConnect()
  99. {
  100.     return(TickConnect * TICKSIZE);
  101. }
  102.  
  103. doipcmsg(app, cmd, len)
  104. char *app;
  105. char *cmd;
  106. short len;
  107. {
  108.     register IPCMSG *msg;
  109.     register long res = 1;
  110.     IPCMSG *SendIPC();
  111.  
  112.     if (DDebug)
  113.     printf("IPC: <%s><%s> = ", app, cmd+1);
  114.     fflush(stdout);
  115.     if (msg = SendIPC(app, cmd, len, 0)) {
  116.     WaitMsg(msg);
  117.     res = msg->Error;
  118.     FreeIPC(msg);
  119.     }
  120.     if (DDebug)
  121.     printf("%ld\n", res);
  122. }
  123.  
  124.