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