home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v6.zip / MMPM2TK / TK / ULIOT / IOCLOSE.C < prev    next >
C/C++ Source or Header  |  1993-04-08  |  11KB  |  234 lines

  1. /*************************START OF SPECIFICATIONS *************************/
  2. /* SOURCE FILE NAME:  IOCLOSE.C                                           */
  3. /*                                                                        */
  4. /* DESCRIPTIVE NAME: File Format IO Proc routine for MMIOM_CLOSE          */
  5. /*                                                                        */
  6. /* COPYRIGHT:     IBM - International Business Machines                   */
  7. /*            Copyright (c) IBM Corporation  1991, 1992, 1993             */
  8. /*                        All Rights Reserved                             */
  9. /*                                                                        */
  10. /* STATUS: OS/2 Release 2.0                                               */
  11. /*                                                                        */
  12. /* FUNCTION: This source module contains the close routine.               */
  13. /*                                                                        */
  14. /* NOTES:                                                                 */
  15. /*    DEPENDENCIES: none                                                  */
  16. /*    RESTRICTIONS: Runs in 32 bit protect mode (OS/2 2.0)                */
  17. /*                                                                        */
  18. /* ENTRY POINTS:                                                          */
  19. /*      IOProcClose                                                       */
  20. /*      ioCleanUp                                                         */
  21. /*                                                                        */
  22. /************************* END OF SPECIFICATIONS **************************/
  23.  
  24. #include        <stdio.h>
  25. #include        <string.h>
  26. #include        <stdlib.h>
  27. #include        <memory.h>
  28.  
  29. #define         INCL_DOS                        /* #define  INCL_DOSPROCESS.*/
  30. #define         INCL_ERRORS
  31. #define         INCL_WIN
  32. #define         INCL_GPI
  33. #include        <os2.h>                         /* OS/2 headers.*/
  34. #include        <pmbitmap.h>
  35.  
  36. #define         INCL_OS2MM
  37. #define         INCL_MMIO_CODEC
  38. #define         INCL_MMIO_DOSIOPROC
  39. #include        <os2me.h>                       /* Multi-Media IO extensions.*/
  40. #include        <hhpheap.h>
  41. #include        <ioi.h>
  42.  
  43.    extern HHUGEHEAP hheap;
  44.    extern HMTX hmtxGlobalHeap;
  45.  
  46. /************************** START OF SPECIFICATIONS *************************/
  47. /*                                                                          */
  48. /* SUBROUTINE NAME:  IOProcClose                                            */
  49. /*                                                                          */
  50. /* DESCRIPTIVE NAME: close file.                                            */
  51. /*                                                                          */
  52. /* FUNCTION: This function closes Digital Video file if opened,             */
  53. /*           free allocated buffers.                                        */
  54. /*                                                                          */
  55. /* NOTES: None                                                              */
  56. /*                                                                          */
  57. /* ENTRY POINT: IOProcClose                                                 */
  58. /*   LINKAGE:   CALL FAR (00:32)                                            */
  59. /*                                                                          */
  60. /* INPUT:    PMMIOINFO  pmmioinfo - pointer to MMIOINFO instance structure. */
  61. /*                                                                          */
  62. /*                                                                          */
  63. /* EXIT-NORMAL:                                                             */
  64. /*              MMIO_SUCCESS                                                */
  65. /*                                                                          */
  66. /* EXIT-ERROR:                                                              */
  67. /*              MMIO_ERROR                                                  */
  68. /*                                                                          */
  69. /* SIDE EFFECTS:                                                            */
  70. /*                                                                          */
  71. /*************************** END OF SPECIFICATIONS **************************/
  72.  
  73. LONG IOProcClose (PMMIOINFO pmmioinfo) {
  74.    LONG rc;
  75.    PINSTANCE  pinstance;
  76.  
  77.    if (rc = ioGetPtrInstance(pmmioinfo,&pinstance))
  78.       return(rc);
  79.  
  80.    pmmioinfo->ulErrorRet = 0L;
  81.  
  82.    ioCleanUp(pmmioinfo); /* mmioClose is called in CleanUp */
  83.  
  84.    if (pmmioinfo->ulErrorRet != 0L) return MMIO_ERROR;
  85.  
  86.    return MMIO_SUCCESS;
  87. }
  88.  
  89. /************************** START OF SPECIFICATIONS *************************/
  90. /*                                                                          */
  91. /* SUBROUTINE NAME: ioCleanUp                                               */
  92. /*                                                                          */
  93. /* DESCRIPTIVE NAME: Clean up on error or before closing file.              */
  94. /*                                                                          */
  95. /* FUNCTION: Close any open file and free allocated instance control        */
  96. /*           blocks and any temporary buffers created.                      */
  97. /*                                                                          */
  98. /* NOTES: None                                                              */
  99. /*                                                                          */
  100. /* ENTRY POINT: ioCleanUp                                                   */
  101. /*   LINKAGE:   CALL FAR (00:32)                                            */
  102. /*                                                                          */
  103. /* INPUT:                                                                   */
  104. /*              PMMIOINFO pmmioinfo - pointer to MMIOINFO status structure. */
  105. /*                                                                          */
  106. /* EXIT-NORMAL:                                                             */
  107. /*              (none)                                                      */
  108. /*                                                                          */
  109. /* EXIT-ERROR:                                                              */
  110. /*              (none)                                                      */
  111. /*                                                                          */
  112. /* SIDE EFFECTS:                                                            */
  113. /*                                                                          */
  114. /*************************** END OF SPECIFICATIONS **************************/
  115.  
  116. VOID ioCleanUp ( PMMIOINFO pmmioinfo ) {
  117.    LONG            rc;                            /* Return code.           */
  118.    PINSTANCE       pinstance;                     /* Local work structure.  */
  119.    PTRACKI         ptracki;                       /* Pointer to track list. */
  120.    PCCB            pccb;                          /* Pointer to CCB list.   */
  121.    PMMVIDEOHEADER  pmmVideoHdr;                   /* Video header node.      */
  122.  
  123.    /**************************************************************************/
  124.    /* Make sure the instant structure has been allocated, no memory need to  */
  125.    /* be freed otherwise.                                                    */
  126.    /**************************************************************************/
  127.  
  128.    if (pmmioinfo->pExtraInfoStruct) {
  129.       pinstance = (PINSTANCE)pmmioinfo->pExtraInfoStruct;
  130.       if (!pinstance) {
  131.          pmmioinfo->ulErrorRet |= MMIOERR_INVALID_STRUCTURE;
  132.          return;
  133.       }
  134.    }
  135.    else {
  136.       pmmioinfo->ulErrorRet |= MMIOERR_INVALID_STRUCTURE;
  137.       return;
  138.    }
  139.  
  140.    // Call File Format specific clean up routine
  141.  
  142.    ffCleanUp(pinstance);
  143.  
  144.    /**************************************************************************/
  145.    /* If file is opened, close it.                                           */
  146.    /**************************************************************************/
  147.    if (pinstance->hmmioFileHandle) {
  148.       rc = (LONG)mmioClose(pinstance->hmmioFileHandle,(WORD)0L);
  149.  
  150.       if (rc != MMIO_SUCCESS) {
  151.          pmmioinfo->ulErrorRet |= rc;
  152.          }
  153.       pinstance->hmmioFileHandle = 0;
  154.       }
  155.    pmmioinfo->hmmio = 0L;
  156.  
  157.   if (ENTERCRIT(rc)) {
  158.      return;
  159.      }
  160.  
  161.    /**************************************************************************/
  162.    /* Free pTempBuffer in instant structure.                                 */
  163.    /**************************************************************************/
  164.    if(pinstance->pTempBuffer) {
  165.       HhpFreeMem(hheap,pinstance->pTempBuffer);
  166.       pinstance->pTempBuffer = NULL;
  167.       }
  168.  
  169.    /**************************************************************************/
  170.    /* pccbList is a link list, CleanUp free every node of link list.  .      */
  171.    /**************************************************************************/
  172.    while (pinstance->pccbList) {
  173.       pccb = pinstance->pccbList;
  174.       if (pccb) {
  175.          pinstance->pccbList = pccb->pccbNext;
  176.          ioCloseCodec(pccb);
  177.          }
  178.       } /* end loop */
  179.  
  180.    /**************************************************************************/
  181.    /* ptrackiList is a link list, CleanUp free every node of link list.      */
  182.    /**************************************************************************/
  183.    while (pinstance->ptrackiList) {
  184.       ptracki = pinstance->ptrackiList;
  185.  
  186.       if (ptracki) {
  187.  
  188.          if (ptracki->pTrackHeader) {
  189.  
  190.             /* Delete movie video track specific data */
  191.             if (IS_VIDEO_TRACK(ptracki->ulMediaType)) {
  192.                pmmVideoHdr = (PMMVIDEOHEADER)ptracki->pTrackHeader;
  193.  
  194.                if (pmmVideoHdr->pmmXDIBHeader) {
  195.                   HhpFreeMem(hheap,(PVOID)pmmVideoHdr->pmmXDIBHeader);
  196.                   }
  197.  
  198.                if (pmmVideoHdr->genpalVideo.prgb2Entries) {
  199.                   HhpFreeMem(hheap,(PVOID)pmmVideoHdr->genpalVideo.prgb2Entries);
  200.                   }
  201.                }
  202.             HhpFreeMem(hheap,(PVOID)ptracki->pTrackHeader);
  203.             }
  204.  
  205.          if (ptracki->pRawHdr) {
  206.             HhpFreeMem(hheap,(PVOID)ptracki->pRawHdr);
  207.             }
  208.  
  209.          pinstance->ptrackiList = ptracki->ptrackiNext;
  210.          HhpFreeMem(hheap,(PVOID)ptracki);
  211.          }
  212.       } /* end loop */
  213.  
  214.    if (pinstance->pRawHdr) {
  215.       HhpFreeMem(hheap,(PVOID) pinstance->pRawHdr);       /* Free header */
  216.       pinstance->pRawHdr = NULL;
  217.       }
  218.  
  219.    if (pinstance->pmmhdr) {
  220.       HhpFreeMem(hheap, (PVOID)pinstance->pmmhdr);        /* Free header */
  221.       pinstance->pmmhdr = NULL;
  222.    }
  223.  
  224. #ifdef WORKSHOP
  225.       ioEditCleanup(pinstance);                // free clipboard editing control blocks
  226. #endif
  227.  
  228.    HhpFreeMem(hheap, (PVOID)pinstance);       /* Free instance structure.*/
  229.    pmmioinfo->pExtraInfoStruct = (PVOID)NULL;
  230.    EXITCRIT;
  231.  
  232.    return;
  233. }
  234.