⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogrfmecacheindex.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        }        if( iDir < (int) oUserDirectives.entries() || !bMatch             || (psDirective != NULL && psDirective->psNext != NULL) )            continue;        return psCDS;    }    return NULL;}/************************************************************************//*                               Touch()                                *//*                                                                      *//*      Update the LastUseTime on the passed datasource.                *//************************************************************************/void OGRFMECacheIndex::Touch( CPLXMLNode *psDSNode ){    if( psDSNode == NULL || !EQUAL(psDSNode->pszValue,"DataSource") )        return;/* -------------------------------------------------------------------- *//*      Prepare the new time value to use.                              *//* -------------------------------------------------------------------- */    char      szNewTime[32];    sprintf( szNewTime, "%lu", (unsigned long) time(NULL) );/* -------------------------------------------------------------------- *//*      Set or insert LastUseTime into dataset.                         *//* -------------------------------------------------------------------- */    CPLSetXMLValue( psDSNode, "LastUseTime", szNewTime );}/************************************************************************//*                             Reference()                              *//************************************************************************/void OGRFMECacheIndex::Reference( CPLXMLNode *psDSNode ){    if( psDSNode == NULL || !EQUAL(psDSNode->pszValue,"DataSource") )        return;    char szNewRefCount[32];    sprintf( szNewRefCount, "%d",              atoi(CPLGetXMLValue(psDSNode, "RefCount", "0")) + 1 );    CPLSetXMLValue( psDSNode, "RefCount", szNewRefCount );    Touch( psDSNode );}/************************************************************************//*                            Dereference()                             *//************************************************************************/void OGRFMECacheIndex::Dereference( CPLXMLNode *psDSNode ){    if( psDSNode == NULL         || !EQUAL(psDSNode->pszValue,"DataSource")         || CPLGetXMLNode(psDSNode,"RefCount") == NULL )        return;    char szNewRefCount[32];    int  nRefCount = atoi(CPLGetXMLValue(psDSNode, "RefCount", "1"));    if( nRefCount < 1 )        nRefCount = 1;    sprintf( szNewRefCount, "%d", nRefCount-1 );    CPLSetXMLValue( psDSNode, "RefCount", szNewRefCount );    Touch( psDSNode );}/************************************************************************//*                                Add()                                 *//*                                                                      *//*      Note that Add() takes over ownership of the passed tree.        *//************************************************************************/void OGRFMECacheIndex::Add( CPLXMLNode *psDSNode ){    CPLAssert( psTree != NULL );    psDSNode->psNext = psTree->psChild;    psTree->psChild = psDSNode;    if( psDSNode == NULL || !EQUAL(psDSNode->pszValue,"DataSource") )        return;/* -------------------------------------------------------------------- *//*      Prepare the creation time value to use.                         *//* -------------------------------------------------------------------- */    char      szNewTime[32];    sprintf( szNewTime, "%lu", (unsigned long) time(NULL) );/* -------------------------------------------------------------------- *//*      Set or insert CreationTime into dataset.                        *//* -------------------------------------------------------------------- */    CPLSetXMLValue( psDSNode, "CreationTime", szNewTime );}/************************************************************************//*                          ExpireOldCaches()                           *//*                                                                      *//*      Make a pass over all the cache index entries.  Remove (and      *//*      free the associated FME spatial caches) for any entries that    *//*      haven't been touched for a long time.  Note that two            *//*      different timeouts apply.  One is for layers with a RefCount    *//*      of 0 and the other (longer time) is for those with a            *//*      non-zero refcount.  Even if the RefCount is non-zero we         *//*      assume this may because a program crashed during it's run.      *//************************************************************************/int OGRFMECacheIndex::ExpireOldCaches( IFMESession *poSession ){    CPLXMLNode *psDSNode, *psLastDSNode = NULL;    unsigned long nCurTime = time(NULL);    int  bChangeMade = FALSE;    if( psTree == NULL )        return FALSE;    for( psLastDSNode = NULL; TRUE; psLastDSNode = psDSNode )    {        if( psLastDSNode != NULL )            psDSNode = psLastDSNode->psNext;        else            psDSNode = psTree->psChild;        if( psDSNode == NULL )            break;        if( !EQUAL(psDSNode->pszValue,"DataSource") )            continue;        /* -------------------------------------------------------------------- *//*      When was this datasource last accessed?                         *//* -------------------------------------------------------------------- */        unsigned long nLastUseTime = 0;        sscanf( CPLGetXMLValue( psDSNode, "LastUseTime", "0" ),                 "%lu", &nLastUseTime );        /* -------------------------------------------------------------------- *//*      When was this datasource created.                               *//* -------------------------------------------------------------------- */        unsigned long nCreationTime = 0;        sscanf( CPLGetXMLValue( psDSNode, "CreationTime", "0" ),                 "%lu", &nCreationTime );/* -------------------------------------------------------------------- *//*      Do we want to delete this datasource according to our           *//*      retention and ref timeout rules?                                *//* -------------------------------------------------------------------- */        int bCleanup = FALSE;        // Do we want to cleanup this node?         if( atoi(CPLGetXMLValue( psDSNode, "RefCount", "0" )) > 0              && nLastUseTime + FMECACHE_REF_TIMEOUT < nCurTime )            bCleanup = TRUE;        if( atoi(CPLGetXMLValue( psDSNode, "RefCount", "0" )) < 1             && nLastUseTime + FMECACHE_RETENTION < nCurTime )            bCleanup = TRUE;        if( atoi(CPLGetXMLValue( psDSNode, "RefCount", "0" )) < 1             && nCreationTime + FMECACHE_MAX_RETENTION < nCurTime )            bCleanup = TRUE;        if( !bCleanup )            continue;        bChangeMade = TRUE;        CPLDebug( "OGRFMECacheIndex",                   "ExpireOldCaches() cleaning up data source %s - %ds since last use, %ds old.",                  CPLGetXMLValue( psDSNode, "DSName", "<missing name>" ),                  nCurTime - nLastUseTime,                  nCurTime - nCreationTime );/* -------------------------------------------------------------------- *//*      Loop over all the layers, to delete the spatial caches on       *//*      disk.                                                           *//* -------------------------------------------------------------------- */        CPLXMLNode *psLayerN;        for( psLayerN = psDSNode->psChild;              psLayerN != NULL;             psLayerN = psLayerN->psNext )        {            IFMESpatialIndex   *poIndex;            if( !EQUAL(psLayerN->pszValue,"OGRLayer") )                continue;            const char *pszBase;            pszBase = CPLGetXMLValue( psLayerN, "SpatialCacheName", "" );            if( EQUAL(pszBase,"") )                continue;            // open, and then delete the index on close.            poIndex = poSession->createSpatialIndex( pszBase, "READ", NULL );            if( poIndex == NULL )                continue;            if( poIndex->open() != 0 )            {                CPLDebug( "OGRFMECacheIndex", "Failed to open FME index %s.",                          pszBase );                                          poSession->destroySpatialIndex( poIndex );                continue;            }                     poIndex->close( FME_TRUE );            poSession->destroySpatialIndex( poIndex );        }/* -------------------------------------------------------------------- *//*      Remove the datasource from the tree.                            *//* -------------------------------------------------------------------- */        if( psLastDSNode == NULL )            psTree->psChild = psDSNode->psNext;        else            psLastDSNode->psNext = psDSNode->psNext;        psDSNode->psNext = NULL;        CPLDestroyXMLNode( psDSNode );        psDSNode = psLastDSNode;    }    return bChangeMade;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -