home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mmpm21tk.zip / TK / FSSHT / SHSTOP.C < prev   
C/C++ Source or Header  |  1993-02-25  |  7KB  |  129 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                    Copyright (c) IBM Corporation 1992, 1993              */
  4. /*                           All Rights Reserved                            */
  5. /*                                                                          */
  6. /* SOURCE FILE NAME: SHSTOP.C                                               */
  7. /*                                                                          */
  8. /* DESCRIPTIVE NAME:  Stream Handler Stop stream routine                    */
  9. /*                                                                          */
  10. /* FUNCTION: This function stops a stream instance.                         */
  11. /*                                                                          */
  12. /* ENTRY POINTS: ShcStop                                                    */
  13. /*                                                                          */
  14. /*************************** END OF SPECIFICATIONS **************************/
  15. #define  INCL_NOPMAPI                  /* no PM include files required */
  16. #define  INCL_DOSSEMAPHORES
  17. #define  INCL_DOSPROCESS
  18. #include <os2.h>
  19. #include <os2me.h>
  20. #include <hhpheap.h>
  21. #include <shi.h>
  22.  
  23. /************************** START OF SPECIFICATIONS *************************/
  24. /*                                                                          */
  25. /* SUBROUTINE NAME: ShcStop                                                 */
  26. /*                                                                          */
  27. /* DESCRIPTIVE NAME: Stream Handler Command Stop stream routine             */
  28. /*                                                                          */
  29. /* FUNCTION: This stops the specified stream.  The flags passed indicate    */
  30. /*           if this should discard all buffers or not.                     */
  31. /*                                                                          */
  32. /* NOTES:                                                                   */
  33. /*                                                                          */
  34. /* ENTRY POINT: ShcStop                                                     */
  35. /*   LINKAGE:   CALL NEAR (0:32)                                            */
  36. /*                                                                          */
  37. /* INPUT: Pointer to shc stop parameter block (PARM_STOP) containing:       */
  38. /*   ULONG   ulFunction  Handler command function SHC_STOP                  */
  39. /*   HID     hid         handler ID                                         */
  40. /*   HSTREAM hstream     handle of stream instance                          */
  41. /*   ULONG   ulFlags     Stop flags (see SSM.H)                             */
  42. /*                                                                          */
  43. /* EXIT-NORMAL: NO_ERROR (0)                                                */
  44. /*                                                                          */
  45. /* EXIT-ERROR:                                                              */
  46. /*   None                                                                   */
  47. /*                                                                          */
  48. /* SIDE EFFECTS:                                                            */
  49. /*   The IO thread is blocked.                                              */
  50. /*                                                                          */
  51. /* INTERNAL REFERENCES:                                                     */
  52. /*        ROUTINES: None                                                    */
  53. /*                                                                          */
  54. /* EXTERNAL REFERENCES:                                                     */
  55. /*   ROUTINES:                                                              */
  56. /*     ShFindSib                                                            */
  57. /*                                                                          */
  58. /*   DATA STRUCTURES:                                                       */
  59. /*                                                                          */
  60. /*************************** END OF SPECIFICATIONS **************************/
  61.  
  62. RC ShcStop(pstparm)
  63. PPARM_STOP pstparm;
  64.  
  65. { /* Start of ShcStop */
  66.  
  67. RC    rc = NO_ERROR;                    /* local return code */
  68. PSIB  psib;                             /* Stream instance block */
  69.  
  70.   /*
  71.    * Find our Stream Instance Block
  72.    */
  73.   if (!(rc = ShFindSib(&psib, pstparm->hstream, pstparm->hid)))
  74.     { /* We have SIB */
  75.  
  76.       /* Don't bother checking most states since the stream manager does this */
  77.       /* for us before the command gets here. */
  78.  
  79.       /* If this is stop Flush and we are the target then we will stop when we */
  80.       /* run out of buffers.  So ignore the stop command. */
  81.  
  82.       if (!((pstparm->ulFlags & SPI_STOP_FLUSH) && (pstparm->hid == TgtHandlerID)))
  83.         { /* not flush and target handler */
  84.           if (pstparm->ulFlags & (SPI_STOP_DISCARD | SPI_STOP_FLUSH))
  85.             { /* We must release all buffers */
  86.               if (psib->ThreadID)
  87.                 {
  88.                   /*  Update action flags to stop the independent thread, and wait on the */
  89.                   /*  command sync semaphore to wait until it gets the command. */
  90.  
  91.                   if (pstparm->ulFlags & SPI_STOP_DISCARD)
  92.                     SYNC_SEND_MSG(psib,SIBACTFLG_STOP_DISCARD,SIB_RUNNING);
  93.  
  94.                   if (pstparm->ulFlags & SPI_STOP_FLUSH)
  95.                     SYNC_SEND_MSG(psib,SIBACTFLG_STOP_FLUSH,SIB_RUNNING);
  96.                 }
  97.  
  98.               else
  99.                 {
  100.                   if (pstparm->ulFlags & SPI_STOP_DISCARD)
  101.                     psib->ulActionFlags |= SIBACTFLG_STOP_DISCARD;
  102.                   if (pstparm->ulFlags & SPI_STOP_FLUSH)
  103.                     psib->ulActionFlags |= SIBACTFLG_STOP_FLUSH;
  104.                 }
  105.             } /* We must release all buffers */
  106.           else
  107.             { /* Assume stop pause command*/
  108.  
  109.               if (psib->ulStatus == SIB_RUNNING)
  110.                 {
  111.                   psib->ulStatus = SIB_PAUSED;
  112.  
  113.                   /* Check for NULL threadid (filter stream handlers) */
  114.  
  115.                   SUSPEND_IO(psib);
  116.                 }
  117.             } /* Assume stop pause command*/
  118.         } /* not flush and target handler */
  119.  
  120.       else
  121.         {
  122.           RESUME_IO(psib,SIB_RUNNING);            /* Flush the target */
  123.         }
  124.     } /* We have SIB */
  125.  
  126.   return(rc);
  127.  
  128. } /* End of ShcStop */
  129.