home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 8 / 08.iso / d / d026 / 25.ddi / NET / WNETPOLL.AS_ / WNETPOLL.AS
Encoding:
Text File  |  1991-04-19  |  5.2 KB  |  241 lines

  1. ;
  2. ;   WNETPOLL.ASM
  3. ;
  4. ;   Contains WNetWatchQueue() and WNetUnwatchQueue(), and supporting functions
  5. ;   and data
  6. ;
  7. ;   Copyright (C) 1989-1990 Microsoft Corp, all rights reserved.
  8. ;
  9.  
  10.  
  11. memS=1                ; small model
  12. ?PLM=1                ; PASCAL calling conventions
  13. ?WIN=1                ; Windows support
  14.  
  15. .xlist
  16. include cmacros.inc
  17. include wnet.inc
  18. .list
  19.  
  20. externFP <PostMessage>        ; necessary USER things
  21. externFP <SetTimer>
  22. externFP <KillTimer>
  23.  
  24. externFP <UTLIsSerialDevice>   ; in UTILS.ASM
  25.  
  26. ;================================
  27. ;   Automatic data
  28. ;
  29.  
  30. sBegin data
  31.  
  32. globalW     hwndSpooler,0,1 ; window handle of spooler
  33.  
  34. globalW     cWatches,0,1    ; number of watches
  35.  
  36. globalW     rgfWatch,0,<4 * size WatchEntry>
  37.  
  38. globalW     wElapse,30000,1 ; millisecond polling interval
  39.  
  40. globalW     nIDEvent,0,1    ; timer handle
  41.  
  42. lpfnTimer    dd  far ptr TimerProc
  43.  
  44. sEnd data
  45.  
  46. ;================================
  47. ;   code segment
  48. ;
  49.  
  50. sBegin code
  51.  
  52.     assumes cs,code
  53.     assumes ds,data
  54.     assumes es,nothing
  55.     assumes ss,nothing
  56.  
  57.  
  58. ;----------------------
  59. ;   TimerProc()
  60. ;
  61. ;   Called by DispatchMessage() when a WM_TIMER message is posted with
  62. ;   NULL hwnd and lParam = TimerProc.  Causes posting of an SP_QUEUECHANGE
  63. ;   message if there are watches on any queues
  64. ;
  65. cProc    TimerProc, <FAR,PUBLIC>
  66.  
  67.     parmW   hwnd
  68.     parmW   timermsg
  69.     parmW   nID
  70.     parmD   time
  71.  
  72. cBegin
  73.     cmp     cWatches,0        ; make sure we're watching in case there's an extra
  74.     jz        timer_exit        ; message floating in
  75.  
  76.     push    hwndSpooler
  77.     mov     ax,SP_QUEUECHANGED
  78.     push    ax            ; message
  79.     sub     ax,ax
  80.     dec     ax
  81.     push    ax            ; wParam = invalidate all queues (-1)
  82.     push    ax            ; lParam = unused
  83.     push    ax
  84.     cCall   PostMessage     ; tell the spooler
  85.  
  86. timer_exit:
  87. cEnd
  88.  
  89. ;----------------------
  90. ;   StartPolling()
  91. ;
  92. ;   Start the timer for the first spooler watch
  93. ;
  94. cProc    StartPolling, <NEAR>
  95.  
  96. cBegin
  97.     sub     ax,ax
  98.  
  99.     push    ax            ; NULL hwnd (call callback, don't post)
  100.     push    ax            ; NULL nIDEvent
  101.     push    wElapse        ; millisecond delay
  102.  
  103.     push    word ptr lpfnTimer[2]   ; segment and...
  104.     push    word ptr lpfnTimer[0]   ; ...offset of timer procedure
  105.  
  106.     cCall   SetTimer        ; make a timer
  107.     or        ax,ax        ; did we really get it?
  108.     jnz     st_gotone
  109.  
  110.     mov     ax,WN_WINDOWS_ERROR
  111.     jmp     short st_exit
  112.  
  113. st_gotone:
  114.     mov     nIDEvent,ax
  115.     sub     ax,ax        ; return WN_SUCCESS
  116.  
  117. st_exit:
  118. cEnd
  119.  
  120. ;--------------------
  121. ;   StopPolling()
  122. ;
  123. ;   Stop watching the remote queues after the last watch is ended.
  124. ;   Halts posting of SP_QUEUECHANGED messages
  125. ;
  126. cProc    StopPolling, <NEAR>
  127.  
  128. cBegin
  129.     sub     ax,ax
  130.     push    ax            ; NULL hwnd
  131.     push    nIDEvent        ; timer ID
  132.     cCall   KillTimer
  133.     or        ax,ax
  134.     jnz     stopp_stopped
  135.  
  136.     mov     ax,WN_WINDOWS_ERROR
  137.     jmp     short stopp_exit
  138.  
  139. stopp_stopped:
  140.     sub     ax,ax
  141.  
  142. stopp_exit:
  143. cEnd
  144.  
  145.  
  146. ;----------------------------
  147. ;   WNetWatchQueue
  148. ;
  149. ;   Causes SP_QUEUECHANGED messages to be posted every 30 seconds for
  150. ;   for this queue.  Marks it out in the flag array.
  151. ;
  152. cProc    WNetWatchQueue, <FAR,PUBLIC>, <SI>
  153.  
  154.     parmW   hwnd        ; spooler window handle
  155.     parmD   lpszQueue        ; local queue to watch
  156.     parmD   lpszUser        ; unused
  157.     parmW   nQueue        ; unused
  158.  
  159. cBegin
  160.     mov     ax,hwnd
  161.     mov     hwndSpooler,ax    ; save spooler window handle
  162.  
  163.     push    seg_lpszQueue
  164.     push    off_lpszQueue    ; is the queue a local port?
  165.     cCall   UTLIsSerialDevice
  166.  
  167.     or        ax,ax        ; NULL?
  168.     jnz     wnwq_validport
  169.  
  170.     mov     ax,WN_BAD_QUEUE    ; invalid queue
  171.     jmp     short wnwq_exit
  172.  
  173. wnwq_validport:
  174.     xchg    ax,si
  175.     test    byte ptr [si].fWatch, PORT_WATCHED
  176.     jz        wnwq_notwatched
  177.  
  178.     mov     ax,WN_ALREADY_LOCKED    ; already being watched
  179.     jmp     short wnwq_exit
  180.  
  181. wnwq_notwatched:
  182.     cmp     cWatches,0
  183.     jnz     wnwq_dontstarttimer
  184.     cCall   StartPolling
  185.     or        ax,ax
  186.     jnz     wnwq_exit        ; if not WN_SUCCESS, return error
  187.  
  188. wnwq_dontstarttimer:
  189.     inc     cWatches        ; increment number of watchers
  190.     or        byte ptr [si].fWatch, PORT_WATCHED     ; set watch flag for port
  191.  
  192.     sub     ax,ax        ; return WN_SUCCESS
  193.  
  194. wnwq_exit:
  195. cEnd
  196.  
  197. ;----------------------------------------
  198. ;   WNetUnwatchQueue
  199. ;
  200. ;   Halts posting of SP_QUEUECHANGED messages for a particular queue
  201. ;
  202. cProc    WNetUnwatchQueue, <FAR,PUBLIC>
  203.  
  204.     parmD   lpszQueue
  205.  
  206. cBegin
  207.  
  208.     push    seg_lpszQueue
  209.     push    off_lpszQueue
  210.     cCall   UTLIsSerialDevice    ; is it an LPTx: port?
  211.     or        ax,ax
  212.     jnz     wnuq_validport
  213.  
  214.     mov     ax,WN_BAD_QUEUE    ; invalid queue name
  215.     jmp     short wnuq_exit
  216.  
  217. wnuq_validport:
  218.     xchg    ax,bx
  219.     test    byte ptr [bx].fWatch, PORT_WATCHED
  220.     jnz     wnuq_watched
  221.  
  222.     mov     ax,WN_ALREADY_LOCKED
  223.     jmp     short wnuq_exit
  224.  
  225. wnuq_watched:
  226.     and     byte ptr [bx].fWatch, not PORT_WATCHED  ; clear the flag
  227.     dec     cWatches        ; reduce the number of watchers
  228.     jnz     wnuq_dontstoptimer    ; if any left, keep polling
  229.     cCall   StopPolling     ; return status from StopPolling
  230.     jmp     short wnuq_exit
  231.  
  232. wnuq_dontstoptimer:
  233.     sub     ax,ax        ; return WN_SUCCESS
  234.  
  235. wnuq_exit:
  236. cEnd
  237.  
  238. sEnd
  239.  
  240. end
  241.