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

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                    Copyright (c) IBM Corporation 1992, 1993              */
  4. /*                           All Rights Reserved                            */
  5. /*                                                                          */
  6. /* SOURCE FILE NAME: SHMISC.C                                               */
  7. /*                                                                          */
  8. /* DESCRIPTIVE NAME:  Stream Handler Misc. routines                         */
  9. /*                                                                          */
  10. /* FUNCTION: This file contains the supporting routines for the stream      */
  11. /*           handlers.                                                      */
  12. /*                                                                          */
  13. /* ENTRY POINTS: ShFindSib                                                  */
  14. /*               ShFindEspcb                                                */
  15. /*               ShFindESPCB  - handles generic cases                       */
  16. /*               ShSearchESPCBList - search list for match                  */
  17. /*               DestroySIB                                                 */
  18. /*************************** END OF SPECIFICATIONS **************************/
  19. #define  INCL_NOPMAPI                  /* no PM include files required */
  20. #define  INCL_DOSSEMAPHORES
  21. #define  INCL_DOSERRORS
  22. #define  INCL_DOSPROCESS
  23. #include <os2.h>
  24. #include <os2me.h>
  25. #include <hhpheap.h>
  26. #include <shi.h>
  27.  
  28. /************************** START OF SPECIFICATIONS *************************/
  29. /*                                                                          */
  30. /* SUBROUTINE NAME: ShFindSib                                               */
  31. /*                                                                          */
  32. /* DESCRIPTIVE NAME: Stream Handler Find Stream Instance Block              */
  33. /*                                                                          */
  34. /* FUNCTION: Finds the SIB associated with the stream handle, and handler   */
  35. /*           ID passed.                                                     */
  36. /* NOTES:                                                                   */
  37. /*                                                                          */
  38. /* ENTRY POINT: ShFindSib                                                   */
  39. /*   LINKAGE:   CALL NEAR (0:32)                                            */
  40. /*                                                                          */
  41. /* INPUT:                                                                   */
  42. /*   psib       - stream instance block                                     */
  43. /*   hstream    - stream handle                                             */
  44. /*   hid        - handler id                                                */
  45. /*                                                                          */
  46. /* EXIT-NORMAL: NO_ERROR (0)                                                */
  47. /*                                                                          */
  48. /* EXIT-ERROR:                                                              */
  49. /*        ERROR_INVALID_STREAM                                              */
  50. /*                                                                          */
  51. /* SIDE EFFECTS:                                                            */
  52. /*                                                                          */
  53. /* INTERNAL REFERENCES:                                                     */
  54. /*        ROUTINES: None                                                    */
  55. /*                                                                          */
  56. /* EXTERNAL REFERENCES:                                                     */
  57. /*   ROUTINES: None                                                         */
  58. /*                                                                          */
  59. /*   DATA STRUCTURES:                                                       */
  60. /*     sib                                                                  */
  61. /*                                                                          */
  62. /*************************** END OF SPECIFICATIONS **************************/
  63.  
  64. RC ShFindSib(psib, hstream, hid)
  65. PSIB *psib;                               /* Output - pointer to SIB */
  66. HSTREAM hstream;                          /* Input - stream handle */
  67. HID hid;                                  /* Handler ID to identify */
  68.                                           /*  source or target */
  69.  
  70. { /* Start of ShFindSib */
  71.  
  72. RC rc = NO_ERROR;                       /* local return code */
  73. PSIB psibtemp;                          /* Stream instance block */
  74.  
  75.   /*
  76.    * Find our Stream Instance Block by searching the SIB list.  It is
  77.    *  under semaphore control, so get it first.
  78.    */
  79.   ENTERCRITX(rc);
  80.   psibtemp = pSIB_list_head;
  81.   while ((psibtemp) &&
  82.          !((psibtemp->hStream == hstream) && (psibtemp->HandlerID == hid)))
  83.     {
  84.       psibtemp = psibtemp->pnxtSIB;
  85.     }
  86.   if (psibtemp)
  87.     {
  88.       *psib = psibtemp;
  89.     }
  90.   else
  91.     {
  92.       rc = ERROR_INVALID_STREAM;
  93.     }
  94.  
  95.   EXITCRIT;
  96.   return(rc);
  97.  
  98. } /* End of ShFindSib */
  99.  
  100.  
  101. /************************** START OF SPECIFICATIONS *************************/
  102. /*                                                                          */
  103. /* SUBROUTINE NAME: ShFindEspcb                                             */
  104. /*                                                                          */
  105. /* DESCRIPTIVE NAME: Stream Handler Find Extended Stream Protocol Control   */
  106. /*                   Block                                                  */
  107. /*                                                                          */
  108. /* FUNCTION: Finds the ESPCB described by the spcbkey passed.               */
  109. /*                                                                          */
  110. /* NOTES: The hmtxGlobalData semaphore must be obtained before calling      */
  111. /*        this routine.                                                     */
  112. /*                                                                          */
  113. /* ENTRY POINT: ShFindEspcb                                                 */
  114. /*   LINKAGE:   CALL NEAR (0:32)                                            */
  115. /*                                                                          */
  116. /* INPUT:                                                                   */
  117. /*   spcbkey    - SPCB key                                                  */
  118. /*                                                                          */
  119. /* EXIT-NORMAL: NO_ERROR (0)                                                */
  120. /*                                                                          */
  121. /* EXIT-ERROR:                                                              */
  122. /*        Return from SHSearchESPCBList                                     */
  123. /*                                                                          */
  124. /* SIDE EFFECTS:                                                            */
  125. /*                                                                          */
  126. /* INTERNAL REFERENCES:                                                     */
  127. /*        ROUTINES: None                                                    */
  128. /*                                                                          */
  129. /* EXTERNAL REFERENCES:                                                     */
  130. /*   ROUTINES: None                                                         */
  131. /*        SHSearchESPCBList                                                 */
  132. /*                                                                          */
  133. /*   DATA STRUCTURES:                                                       */
  134. /*     ESPCB                                                                */
  135. /*                                                                          */
  136. /*************************** END OF SPECIFICATIONS **************************/
  137.  
  138. PESPCB ShFindEspcb(spcbkey)
  139. SPCBKEY spcbkey;                          /* Input - key of espcb to find */
  140.  
  141. { /* Start of ShFindEspcb */
  142.  
  143.   return (ShSearchESPCBList(&spcbkey,0L, NULL));
  144.  
  145. } /* End of ShFindEspcb */
  146.  
  147.  
  148. /************************** START OF SPECIFICATIONS *************************/
  149. /*                                                                          */
  150. /* SUBROUTINE NAME: ShFindESPCB                                             */
  151. /*                                                                          */
  152. /* DESCRIPTIVE NAME: Stream Handler Find Extended Stream Protocol Control   */
  153. /*                   Block with defaults specified.                         */
  154. /*                                                                          */
  155. /* FUNCTION: Finds the ESPCB described by the spcbkey passed.               */
  156. /*                                                                          */
  157. /* NOTES: The hmtxGlobalData semaphore must be obtained before calling      */
  158. /*        this routine.                                                     */
  159. /*                                                                          */
  160. /* ENTRY POINT: ShFindESPCB                                                 */
  161. /*   LINKAGE:   CALL NEAR (0:32)                                            */
  162. /*                                                                          */
  163. /* INPUT:                                                                   */
  164. /*   spcbkey    - SPCB key                                                  */
  165. /*   ulDefaults - defaults flags                                            */
  166. /*                                                                          */
  167. /* EXIT-NORMAL: NO_ERROR (0)                                                */
  168. /*                                                                          */
  169. /* EXIT-ERROR:                                                              */
  170. /*        None                                                              */
  171. /*                                                                          */
  172. /* SIDE EFFECTS:                                                            */
  173. /*                                                                          */
  174. /* INTERNAL REFERENCES:                                                     */
  175. /*        ROUTINES: None                                                    */
  176. /*                                                                          */
  177. /* EXTERNAL REFERENCES:                                                     */
  178. /*   ROUTINES: None                                                         */
  179. /*        SHSearchESPCBList                                                 */
  180. /*                                                                          */
  181. /*   DATA STRUCTURES:                                                       */
  182. /*     ESPCB                                                                */
  183. /*                                                                          */
  184. /*************************** END OF SPECIFICATIONS **************************/
  185.  
  186. PESPCB ShFindESPCB(spcbkey,ulDefaults)
  187. SPCBKEY spcbkey;                          /* Input - key of espcb to find */
  188. ULONG   ulDefaults;
  189.  
  190. { /* Start of ShFindESPCB */
  191.  
  192. PESPCB pTempEspcb;
  193.  
  194.   /*
  195.    * Find our Extended SPCB by searching the ESPCB list.
  196.    */
  197.  
  198.     { /* Search ESPCB list */
  199.       pTempEspcb = ShSearchESPCBList(&spcbkey,ulDefaults,NULL);
  200.  
  201.       /*
  202.        * If espcb not found then get the last generic spcb installed and use it if
  203.        * ulDefaults flag is set to use it. (last = head of list)
  204.        */
  205.       if (!pTempEspcb)
  206.         { /* Get Generic spcb */
  207.  
  208.           if (ulDefaults & ESPCB_DEFAULT_LAST_GENERIC)
  209.             {
  210.               spcbkey.ulDataType = DATATYPE_GENERIC;
  211.               pTempEspcb = ShSearchESPCBList(&spcbkey,ESPCB_IGNORE_INTKEY | ESPCB_IGNORE_DATASUBTYPE,NULL);
  212.             }
  213.         }
  214.     } /* Search ESPCB list */
  215.  
  216.   return(pTempEspcb);
  217.  
  218. } /* End of ShFindESPCB */
  219.  
  220.  
  221. /************************** START OF SPECIFICATIONS *************************/
  222. /*                                                                          */
  223. /* SUBROUTINE NAME: ShSearchESPCBList                                       */
  224. /*                                                                          */
  225. /* DESCRIPTIVE NAME: Stream Handler Find Extended Stream Protocol Control   */
  226. /*                   Block with defaults specified.                         */
  227. /*                                                                          */
  228. /* FUNCTION: Finds the ESPCB described by the spcbkey passed.               */
  229. /*                                                                          */
  230. /* NOTES: The hmtxGlobalData semaphore must be obtained before calling      */
  231. /*        this routine.                                                     */
  232. /*                                                                          */
  233. /* ENTRY POINT: ShFindESPCB                                                 */
  234. /*   LINKAGE:   CALL NEAR (0:32)                                            */
  235. /*                                                                          */
  236. /* INPUT:                                                                   */
  237. /*   pspcbkey   - pointer to SPCB key                                       */
  238. /*   ulDefaults - defaults flags                                            */
  239. /*   pespcbPrevRtn - pointer to an ESPCB                                    */
  240. /*                                                                          */
  241. /* EXIT-NORMAL: NO_ERROR (0)                                                */
  242. /*                                                                          */
  243. /* EXIT-ERROR:                                                              */
  244. /*        None                                                              */
  245. /*                                                                          */
  246. /* SIDE EFFECTS:                                                            */
  247. /*                                                                          */
  248. /* INTERNAL REFERENCES:                                                     */
  249. /*        ROUTINES: None                                                    */
  250. /*                                                                          */
  251. /* EXTERNAL REFERENCES:                                                     */
  252. /*   ROUTINES: None                                                         */
  253. /*                                                                          */
  254. /*   DATA STRUCTURES:                                                       */
  255. /*     ESPCB                                                                */
  256. /*                                                                          */
  257. /*************************** END OF SPECIFICATIONS **************************/
  258.  
  259. PESPCB ShSearchESPCBList(pspcbkey,ulDefaults,pespcbPrevRtn)
  260.  
  261. PSPCBKEY pspcbkey;                         /* Input - key of espcb to find */
  262. ULONG    ulDefaults;
  263. PESPCB   pespcbPrevRtn;
  264.  
  265. { /* Start of ShFindEspcb */
  266.  
  267. PESPCB pespcbTemp;
  268. PESPCB pespcbPrev;
  269. BOOL fMatchDataType;
  270. BOOL fMatchDataSubType;
  271. BOOL fMatchIntKey;
  272.  
  273.   /*
  274.    * Find our Extended SPCB by searching the ESPCB list.
  275.    */
  276.  
  277.     { /* Search ESPCB list */
  278.  
  279.       for (pespcbTemp = pESPCB_ListHead, pespcbPrev = NULL;
  280.            pespcbTemp;
  281.            pespcbPrev = pespcbTemp, pespcbTemp = pespcbTemp->pnxtESPCB)
  282.         { /* Loop thru espcbs */
  283.  
  284.           fMatchDataType = (pspcbkey->ulDataType == pespcbTemp->spcb.spcbkey.ulDataType);
  285.           fMatchDataSubType = ((pspcbkey->ulDataSubType == pespcbTemp->spcb.spcbkey.ulDataSubType) ||
  286.                                (ulDefaults & ESPCB_IGNORE_INTKEY));
  287.           fMatchIntKey = ((pspcbkey->ulIntKey == pespcbTemp->spcb.spcbkey.ulIntKey) ||
  288.                           (ulDefaults & ESPCB_IGNORE_INTKEY));
  289.  
  290.           if (fMatchDataSubType && fMatchDataType && fMatchIntKey)
  291.             {
  292.               if (pespcbPrevRtn)
  293.                 pespcbPrevRtn = pespcbPrev;
  294.               break;
  295.             }
  296.         } /* Loop thru espcbs */
  297.  
  298.     } /* Search ESPCB list */
  299.  
  300.   return(pespcbTemp);
  301.  
  302. } /* End of ShSearchEspcb */
  303.  
  304.  
  305.  
  306. /************************** START OF SPECIFICATIONS *************************/
  307. /*                                                                          */
  308. /* SUBROUTINE NAME: DestroySIB                                              */
  309. /*                                                                          */
  310. /* DESCRIPTIVE NAME: Deallocate the SIB and all other structures            */
  311. /*                                                                          */
  312. /* FUNCTION: Deallocate the SIB and other associated structures.            */
  313. /*                                                                          */
  314. /* ENTRY POINT: DestroySIB                                                  */
  315. /*   LINKAGE:   CALL NEAR (0:32)                                            */
  316. /*                                                                          */
  317. /* INPUT:                                                                   */
  318. /*         PSIB   psib      - Pointer to stream instance control block.     */
  319. /*                                                                          */
  320. /* EXIT-NORMAL: 0 NO_ERROR                                                  */
  321. /*                                                                          */
  322. /* EXIT-ERROR:                                                              */
  323. /*   ERROR_INVALID_STREAM                                                   */
  324. /*   Errors from:                                                           */
  325. /*     DosRequestMutexSem                                                   */
  326. /*                                                                          */
  327. /* NOTES:                                                                   */
  328. /*                                                                          */
  329. /* SIDE EFFECTS:                                                            */
  330. /*                                                                          */
  331. /* INTERNAL REFERENCES:                                                     */
  332. /*        ROUTINES: None                                                    */
  333. /*                                                                          */
  334. /* EXTERNAL REFERENCES:                                                     */
  335. /*   ROUTINES: None                                                         */
  336. /*                                                                          */
  337. /*   DATA STRUCTURES:                                                       */
  338. /*     ESPCB                                                                */
  339. /*                                                                          */
  340. /*************************** END OF SPECIFICATIONS **************************/
  341.  
  342. RC DestroySIB ( PSIB psib )
  343.  
  344. {
  345. RC    rc = NO_ERROR;                       /* local return code */
  346.  
  347.    if (psib->ThreadID)
  348.      {
  349.        psib->ulActionFlags |= SIBACTFLG_KILL;
  350.        SEND_MSG(psib,SIBACTFLG_KILL,0L);     /* Tell IO thread to kill itself */
  351.        WAIT_FOR_DEAD_IO(psib)                /* Wait until IO thread is dead. */
  352.      }
  353.  
  354.    if (psib->hevStop)
  355.      {
  356.        DosCloseEventSem(psib->hevStop);
  357.      }
  358.  
  359.    if (psib->hevCmdSync)
  360.      {
  361.        DosCloseEventSem(psib->hevCmdSync);
  362.      }
  363.  
  364.    ENTERCRIT(rc);
  365.    HhpFreeMem(hHeap, psib);
  366.    EXITCRIT;
  367.  
  368.    return (rc);
  369. }
  370.