Changeset 1738 for trunk


Ignore:
Timestamp:
07/11/11 13:42:20 (7 months ago)
Author:
Freddie Akeroyd
Message:

Add NXreopen() function to create a second NXhandle referencing the same file that can be used by e.g. a second thread
Refs #298

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/napi.h

    r1735 r1738  
    198198 
    199199#    define NXopen              MANGLE(nxiopen) 
     200#    define NXreopen            MANGLE(nxireopen) 
    200201#    define NXclose             MANGLE(nxiclose) 
    201202#    define NXmakegroup         MANGLE(nximakegroup) 
     
    298299extern  NXstatus  NXopen(CONSTCHAR * filename, NXaccess access_method, NXhandle* pHandle); 
    299300 
     301  /**  
     302   * Opens an existing NeXus file a second time for e.g. access from another thread. 
     303   * \return NX_OK on success, NX_ERROR in the case of an error.    
     304   * \ingroup c_init 
     305   */ 
     306extern  NXstatus  NXreopen(NXhandle pOrigHandle, NXhandle* pNewHandle); 
     307 
    300308  /** 
    301309   * close a NeXus file 
     
    888896        NXhandle pNexusData;    
    889897        int stripFlag; 
     898        NXstatus ( *nxreopen)(NXhandle pOrigHandle, NXhandle* pNewHandle); 
    890899        NXstatus ( *nxclose)(NXhandle* pHandle); 
    891900        NXstatus ( *nxflush)(NXhandle* pHandle); 
  • trunk/include/napi5.h

    r1736 r1738  
    99 
    1010extern  NXstatus  NX5open(CONSTCHAR *filename, NXaccess access_method, NXhandle* pHandle); 
     11extern  NXstatus  NX5reopen(NXhandle pOrigHandle, NXhandle* pNewHandle); 
     12 
    1113extern  NXstatus  NX5close(NXhandle* pHandle); 
    1214extern  NXstatus  NX5flush(NXhandle* pHandle); 
  • trunk/src/napi.c

    r1735 r1738  
    567567} 
    568568 
     569 
     570NXstatus  NXreopen(NXhandle pOrigHandle, NXhandle* pNewHandle) 
     571{ 
     572      pFileStack newFileStack; 
     573          pFileStack origFileStack = (pFileStack)pOrigHandle; 
     574        pNexusFunction fOrigHandle = NULL, fNewHandle = NULL; 
     575          *pNewHandle = NULL; 
     576          newFileStack = makeFileStack(); 
     577          if(newFileStack == NULL){ 
     578          NXReportError ("ERROR: no memory to create filestack"); 
     579          return NX_ERROR; 
     580      } 
     581          // The code below will only open the last file on a stack 
     582          // for the moment raise an error, but this behaviour may be OK 
     583          if (fileStackDepth(origFileStack) > 0)     
     584          { 
     585                NXReportError ( 
     586          "ERROR: handle stack referes to many files - cannot reopen"); 
     587                  return NX_ERROR; 
     588          } 
     589          fOrigHandle = peekFileOnStack(origFileStack); 
     590          if (fOrigHandle->nxreopen == NULL) 
     591          { 
     592                NXReportError ( 
     593          "ERROR: NXreopen not implemented for this underlying file format"); 
     594                  return NX_ERROR; 
     595          } 
     596          fNewHandle = (NexusFunction*)malloc(sizeof(NexusFunction)); 
     597          memcpy(fNewHandle, fOrigHandle, sizeof(NexusFunction)); 
     598          LOCKED_CALL(fNewHandle->nxreopen( fOrigHandle->pNexusData, &(fNewHandle->pNexusData) )); 
     599          pushFileStack( newFileStack, fNewHandle, peekFilenameOnStack(origFileStack) ); 
     600          *pNewHandle = newFileStack; 
     601          return NX_OK; 
     602} 
     603 
     604 
    569605/* ------------------------------------------------------------------------- */ 
    570606 
  • trunk/src/napi4.c

    r1735 r1738  
    19501950{ 
    19511951      fHandle->nxclose=NX4close; 
     1952          fHandle->nxreopen=NULL; 
    19521953      fHandle->nxflush=NX4flush; 
    19531954      fHandle->nxmakegroup=NX4makegroup; 
  • trunk/src/napi5.c

    r1737 r1738  
    115115   ---------------------------------------------------------------------*/ 
    116116 
    117   NXstatus  NX5open(CONSTCHAR *filename, NXaccess am,  
     117  NXstatus  NX5reopen(NXhandle pOrigHandle, NXhandle* pNewHandle)   
     118{ 
     119        pNexusFile5 pNew = NULL, pOrig = NULL; 
     120    *pNewHandle = NULL; 
     121       pOrig = (pNexusFile5)pOrigHandle; 
     122    pNew = (pNexusFile5) malloc (sizeof (NexusFile5)); 
     123    if (!pNew) { 
     124      NXReportError ("ERROR: no memory to create File datastructure"); 
     125      return NX_ERROR; 
     126    } 
     127    memset (pNew, 0, sizeof (NexusFile5)); 
     128    pNew->iFID = H5Freopen (pOrig->iFID); 
     129    if (pNew->iFID <= 0) { 
     130        NXReportError ("cannot clone file"); 
     131                free (pNew); 
     132      return NX_ERROR; 
     133       } 
     134       strcpy(pNew->iAccess, pOrig->iAccess); 
     135    pNew->iNXID = NX5SIGNATURE; 
     136    pNew->iStack5[0].iVref = 0;    /* root! */ 
     137    *pNewHandle = (NXhandle)pNew; 
     138    return NX_OK; 
     139} 
     140 
     141NXstatus  NX5open(CONSTCHAR *filename, NXaccess am,  
    118142                                 NXhandle* pHandle) 
    119143  { 
     
    21992223void NX5assignFunctions(pNexusFunction fHandle) 
    22002224{ 
    2201  
     2225                 
    22022226      fHandle->nxclose=NX5close; 
     2227      fHandle->nxreopen=NX5reopen; 
    22032228      fHandle->nxflush=NX5flush; 
    22042229      fHandle->nxmakegroup=NX5makegroup; 
  • trunk/src/nxxml.c

    r1735 r1738  
    19391939void NXXassignFunctions(pNexusFunction fHandle){ 
    19401940      fHandle->nxclose=NXXclose; 
     1941          fHandle->nxreopen=NULL; 
    19411942      fHandle->nxflush=NXXflush; 
    19421943      fHandle->nxmakegroup=NXXmakegroup; 
Note: See TracChangeset for help on using the changeset viewer.