home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / runnable / mmos2 / mmtoolkt / samples / fssht / shstart.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-06  |  5.7 KB  |  109 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                    Copyright (c) IBM Corporation 1992                    */
  4. /*                           All Rights Reserved                            */
  5. /*                                                                          */
  6. /* SOURCE FILE NAME: SHSTART.C                                              */
  7. /*                                                                          */
  8. /* DESCRIPTIVE NAME:  Stream Handler Start stream routine                   */
  9. /*                                                                          */
  10. /* FUNCTION: This function starts a stream instance.                        */
  11. /*                                                                          */
  12. /* ENTRY POINTS: ShcStart                                                   */
  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: ShcStart                                                */
  26. /*                                                                          */
  27. /* DESCRIPTIVE NAME: Stream Handler Command Start stream routine            */
  28. /*                                                                          */
  29. /* FUNCTION: This routine kick starts the IO thread to start reading or     */
  30. /*   writing.  It may be called indirectly from SpiStartStream, or by the   */
  31. /*   stream manager buffer control code.  If we had to block because no     */
  32. /*   buffers were available, then the buffer control code will send a start.*/
  33. /*                                                                          */
  34. /* NOTES:                                                                   */
  35. /*                                                                          */
  36. /* ENTRY POINT: ShcStart                                                    */
  37. /*   LINKAGE:   CALL NEAR (0:32)                                            */
  38. /*                                                                          */
  39. /* INPUT: Pointer to shc start parameter block (PARM_START) containing:     */
  40. /*   ULONG   ulFunction  Handler command function SHC_START                 */
  41. /*   HID     hid         handler ID                                         */
  42. /*   HSTREAM hstream     handle of stream instance                          */
  43. /*                                                                          */
  44. /* EXIT-NORMAL: NO_ERROR (0)                                                */
  45. /*                                                                          */
  46. /* EXIT-ERROR:                                                              */
  47. /*   ERROR_INVALID_SPCBKEY                                                  */
  48. /*   ERROR_ALLOC_RESOURCES                                                  */
  49. /*   Errors from the external routines:                                     */
  50. /*     DosRequestMutexSem                                                   */
  51. /*                                                                          */
  52. /* SIDE EFFECTS:                                                            */
  53. /*   The IO thread is unblocked.                                            */
  54. /*                                                                          */
  55. /* EXTERNAL REFERENCES:                                                     */
  56. /*   ROUTINES:                                                              */
  57. /*     ShFindSib                                                            */
  58. /*     DosResumeThread                                                      */
  59. /*                                                                          */
  60. /*   DATA STRUCTURES:                                                       */
  61. /*                                                                          */
  62. /*************************** END OF SPECIFICATIONS **************************/
  63.  
  64. RC ShcStart(pstparm)
  65. PPARM_START pstparm;
  66.  
  67. { /* Start of ShcStart */
  68.  
  69. RC rc = NO_ERROR;                       // local return code
  70. PSIB psib;                              // Stream instance block
  71. BOOL bPaused;                           // Is stream paused?
  72.  
  73.   /*
  74.    * Find our Stream Instance Block
  75.    */
  76.   if (!(rc = ShFindSib(&psib, pstparm->hstream, pstparm->hid)))
  77.     { /* We have SIB */
  78.       /* error if we don't have something to stream */
  79.       if (psib->ulStatus < SIB_RUNNING)
  80.         {
  81.           rc = ERROR_DATA_ITEM_NOT_SPECIFIED;
  82.         }
  83.       else
  84.         {
  85.           if (psib->ulActionFlags & SIBACTFLG_THREAD_DEAD)
  86.             {
  87.               rc = ERROR_INVALID_SEQUENCE;
  88.             }
  89.           else
  90.             { /* command sequence ok */
  91.  
  92.               bPaused = (psib->ulStatus == SIB_PAUSED);
  93.               psib->ulStatus = SIB_RUNNING;
  94.               if (psib->ThreadID)
  95.                 {
  96.                   DosPostEventSem(psib->hevStop);
  97.                   if (bPaused)
  98.                     {
  99.                       DosResumeThread(psib->ThreadID);
  100.                     }
  101.                 }
  102.             } /* command sequence ok */
  103.         }
  104.     } /* We have SIB */
  105.  
  106.   return(rc);
  107.  
  108. } /* End of ShcStart */
  109.