LCOV - code coverage report
Current view: directory - gcore - gdaldefaultasync.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 54 41 75.9 %
Date: 2012-12-26 Functions: 17 7 41.2 %

       1                 : /******************************************************************************
       2                 :  * $Id: gdaldataset.cpp 16796 2009-04-17 23:35:04Z normanb $
       3                 :  *
       4                 :  * Project:  GDAL Core
       5                 :  * Purpose:  Implementation of GDALDefaultAsyncReader and the 
       6                 :  *           GDALAsyncReader base class.
       7                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       8                 :  *
       9                 :  ******************************************************************************
      10                 :  * Copyright (c) 2010, Frank Warmerdam
      11                 :  *
      12                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      13                 :  * copy of this software and associated documentation files (the "Software"),
      14                 :  * to deal in the Software without restriction, including without limitation
      15                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      16                 :  * and/or sell copies of the Software, and to permit persons to whom the
      17                 :  * Software is furnished to do so, subject to the following conditions:
      18                 :  *
      19                 :  * The above copyright notice and this permission notice shall be included
      20                 :  * in all copies or substantial portions of the Software.
      21                 :  *
      22                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      23                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      24                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      25                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      26                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      27                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      28                 :  * DEALINGS IN THE SOFTWARE.
      29                 :  ****************************************************************************/
      30                 : 
      31                 : #include "gdal_priv.h"
      32                 : 
      33                 : CPL_CVSID("$Id: gdaldataset.cpp 16796 2009-04-17 23:35:04Z normanb $");
      34                 : 
      35                 : CPL_C_START
      36                 : GDALAsyncReader *
      37                 : GDALGetDefaultAsyncReader( GDALDataset* poDS,
      38                 :                            int nXOff, int nYOff, int nXSize, int nYSize,
      39                 :                            void *pBuf, int nBufXSize, int nBufYSize,
      40                 :                            GDALDataType eBufType,
      41                 :                            int nBandCount, int* panBandMap,
      42                 :                            int nPixelSpace, int nLineSpace,
      43                 :                            int nBandSpace, char **papszOptions );
      44                 : CPL_C_END
      45                 : 
      46                 : /************************************************************************/
      47                 : /* ==================================================================== */
      48                 : /*                         GDALAsyncReader                              */
      49                 : /* ==================================================================== */
      50                 : /************************************************************************/
      51                 : 
      52                 : /************************************************************************/
      53                 : /*                          GDALAsyncReader()                           */
      54                 : /************************************************************************/
      55                 : 
      56               1 : GDALAsyncReader::GDALAsyncReader()
      57                 : {
      58               1 : }
      59                 : 
      60                 : /************************************************************************/
      61                 : /*                         ~GDALAsyncReader()                           */
      62                 : /************************************************************************/
      63               1 : GDALAsyncReader::~GDALAsyncReader()
      64                 : {
      65               1 : }
      66                 : 
      67                 : /************************************************************************/
      68                 : /*                        GetNextUpdatedRegion()                        */
      69                 : /************************************************************************/
      70                 : 
      71                 : /**
      72                 :  * \fn GDALAsyncStatusType GDALAsyncReader::GetNextUpdatedRegion( double dfTimeout, int* pnBufXOff, int* pnBufYOff, int* pnBufXSize, int* pnBufXSize) = 0;
      73                 :  * 
      74                 :  * \brief Get async IO update
      75                 :  *
      76                 :  * Provide an opportunity for an asynchronous IO request to update the
      77                 :  * image buffer and return an indication of the area of the buffer that
      78                 :  * has been updated.  
      79                 :  *
      80                 :  * The dfTimeout parameter can be used to wait for additional data to 
      81                 :  * become available.  The timeout does not limit the amount
      82                 :  * of time this method may spend actually processing available data.
      83                 :  *
      84                 :  * The following return status are possible.
      85                 :  * - GARIO_PENDING: No imagery was altered in the buffer, but there is still 
      86                 :  * activity pending, and the application should continue to call 
      87                 :  * GetNextUpdatedRegion() as time permits.
      88                 :  * - GARIO_UPDATE: Some of the imagery has been updated, but there is still 
      89                 :  * activity pending.
      90                 :  * - GARIO_ERROR: Something has gone wrong. The asynchronous request should 
      91                 :  * be ended.
      92                 :  * - GARIO_COMPLETE: An update has occured and there is no more pending work 
      93                 :  * on this request. The request should be ended and the buffer used. 
      94                 :  *
      95                 :  * @param dfTimeout the number of seconds to wait for additional updates.  Use 
      96                 :  * -1 to wait indefinately, or zero to not wait at all if there is no data
      97                 :  * available.
      98                 :  * @param pnBufXOff location to return the X offset of the area of the
      99                 :  * request buffer that has been updated.
     100                 :  * @param pnBufYOff location to return the Y offset of the area of the
     101                 :  * request buffer that has been updated.
     102                 :  * @param pnBufXSize location to return the X size of the area of the
     103                 :  * request buffer that has been updated.
     104                 :  * @param pnBufYSize location to return the Y size of the area of the
     105                 :  * request buffer that has been updated.
     106                 :  * 
     107                 :  * @return GARIO_ status, details described above. 
     108                 :  */
     109                 : 
     110                 : /************************************************************************/
     111                 : /*                     GDALARGetNextUpdatedRegion()                     */
     112                 : /************************************************************************/
     113                 : 
     114                 : GDALAsyncStatusType CPL_STDCALL 
     115               1 : GDALARGetNextUpdatedRegion(GDALAsyncReaderH hARIO, double timeout,
     116                 :                            int* pnxbufoff, int* pnybufoff, 
     117                 :                            int* pnxbufsize, int* pnybufsize)
     118                 : {
     119               1 :     VALIDATE_POINTER1(hARIO, "GDALARGetNextUpdatedRegion", GARIO_ERROR);
     120                 :     return ((GDALAsyncReader *)hARIO)->GetNextUpdatedRegion(
     121               1 :         timeout, pnxbufoff, pnybufoff, pnxbufsize, pnybufsize);
     122                 : }
     123                 : 
     124                 : /************************************************************************/
     125                 : /*                             LockBuffer()                             */
     126                 : /************************************************************************/
     127                 : 
     128                 : /**
     129                 :  * \brief Lock image buffer.
     130                 :  *
     131                 :  * Locks the image buffer passed into GDALDataset::BeginAsyncReader(). 
     132                 :  * This is useful to ensure the image buffer is not being modified while
     133                 :  * it is being used by the application.  UnlockBuffer() should be used
     134                 :  * to release this lock when it is no longer needed.
     135                 :  *
     136                 :  * @param dfTimeout the time in seconds to wait attempting to lock the buffer.
     137                 :  * -1.0 to wait indefinately and 0 to not wait at all if it can't be
     138                 :  * acquired immediately.  Default is -1.0 (infinite wait).
     139                 :  *
     140                 :  * @return TRUE if successful, or FALSE on an error.
     141                 :  */
     142                 : 
     143               0 : int GDALAsyncReader::LockBuffer( double dfTimeout )
     144                 : 
     145                 : {
     146               0 :     return TRUE;
     147                 : }
     148                 : 
     149                 : 
     150                 : /************************************************************************/
     151                 : /*                          GDALARLockBuffer()                          */
     152                 : /************************************************************************/
     153               0 : int CPL_STDCALL GDALARLockBuffer(GDALAsyncReaderH hARIO, double dfTimeout )
     154                 : {
     155               0 :     VALIDATE_POINTER1(hARIO, "GDALARLockBuffer",FALSE);
     156               0 :     return ((GDALAsyncReader *)hARIO)->LockBuffer( dfTimeout );
     157                 : }
     158                 : 
     159                 : /************************************************************************/
     160                 : /*                            UnlockBuffer()                            */
     161                 : /************************************************************************/
     162                 : 
     163                 : /**
     164                 :  * \brief Unlock image buffer.
     165                 :  *
     166                 :  * Releases a lock on the image buffer previously taken with LockBuffer().
     167                 :  */
     168                 : 
     169               0 : void GDALAsyncReader::UnlockBuffer()
     170                 : 
     171                 : {
     172               0 : }
     173                 : 
     174                 : /************************************************************************/
     175                 : /*                          GDALARUnlockBuffer()                          */
     176                 : /************************************************************************/
     177               0 : void CPL_STDCALL GDALARUnlockBuffer(GDALAsyncReaderH hARIO)
     178                 : {
     179               0 :     VALIDATE_POINTER0(hARIO, "GDALARUnlockBuffer");
     180               0 :     ((GDALAsyncReader *)hARIO)->UnlockBuffer();
     181                 : }
     182                 : 
     183                 : /************************************************************************/
     184                 : /* ==================================================================== */
     185                 : /*                     GDALDefaultAsyncReader                           */
     186                 : /* ==================================================================== */
     187                 : /************************************************************************/
     188                 : 
     189                 : class GDALDefaultAsyncReader : public GDALAsyncReader
     190                 : {
     191                 :   private:
     192                 :     char **         papszOptions;
     193                 : 
     194                 :   public:
     195                 :     GDALDefaultAsyncReader(GDALDataset* poDS,
     196                 :                              int nXOff, int nYOff,
     197                 :                              int nXSize, int nYSize,
     198                 :                              void *pBuf,
     199                 :                              int nBufXSize, int nBufYSize,
     200                 :                              GDALDataType eBufType,
     201                 :                              int nBandCount, int* panBandMap,
     202                 :                              int nPixelSpace, int nLineSpace,
     203                 :                              int nBandSpace, char **papszOptions);
     204                 :     ~GDALDefaultAsyncReader();
     205                 : 
     206                 :     virtual GDALAsyncStatusType GetNextUpdatedRegion(double dfTimeout,
     207                 :                                                      int* pnBufXOff,
     208                 :                                                      int* pnBufYOff,
     209                 :                                                      int* pnBufXSize,
     210                 :                                                      int* pnBufYSize);
     211                 : };
     212                 : 
     213                 : /************************************************************************/
     214                 : /*                     GDALGetDefaultAsyncReader()                      */
     215                 : /************************************************************************/
     216                 : 
     217                 : GDALAsyncReader *
     218               1 : GDALGetDefaultAsyncReader( GDALDataset* poDS,
     219                 :                              int nXOff, int nYOff,
     220                 :                              int nXSize, int nYSize,
     221                 :                              void *pBuf,
     222                 :                              int nBufXSize, int nBufYSize,
     223                 :                              GDALDataType eBufType,
     224                 :                              int nBandCount, int* panBandMap,
     225                 :                              int nPixelSpace, int nLineSpace,
     226                 :                              int nBandSpace, char **papszOptions)
     227                 : 
     228                 : {
     229                 :     return new GDALDefaultAsyncReader( poDS,
     230                 :                                          nXOff, nYOff, nXSize, nYSize,
     231                 :                                          pBuf, nBufXSize, nBufYSize, eBufType,
     232                 :                                          nBandCount, panBandMap,
     233                 :                                          nPixelSpace, nLineSpace, nBandSpace,
     234               1 :                                          papszOptions );
     235                 : }
     236                 : 
     237                 : /************************************************************************/
     238                 : /*                       GDALDefaultAsyncReader()                       */
     239                 : /************************************************************************/
     240                 : 
     241               1 : GDALDefaultAsyncReader::
     242                 : GDALDefaultAsyncReader( GDALDataset* poDS,
     243                 :                           int nXOff, int nYOff,
     244                 :                           int nXSize, int nYSize,
     245                 :                           void *pBuf,
     246                 :                           int nBufXSize, int nBufYSize,
     247                 :                           GDALDataType eBufType,
     248                 :                           int nBandCount, int* panBandMap,
     249                 :                           int nPixelSpace, int nLineSpace,
     250               1 :                           int nBandSpace, char **papszOptions) 
     251                 : 
     252                 : {
     253               1 :     this->poDS = poDS;
     254               1 :     this->nXOff = nXOff;
     255               1 :     this->nYOff = nYOff;
     256               1 :     this->nXSize = nXSize;
     257               1 :     this->nYSize = nYSize;
     258               1 :     this->pBuf = pBuf;
     259               1 :     this->nBufXSize = nBufXSize;
     260               1 :     this->nBufYSize = nBufYSize;
     261               1 :     this->eBufType = eBufType;
     262               1 :     this->nBandCount = nBandCount;
     263               1 :     this->panBandMap = (int *) CPLMalloc(sizeof(int)*nBandCount);
     264                 : 
     265               1 :     if( panBandMap != NULL )
     266               1 :         memcpy( this->panBandMap, panBandMap, sizeof(int)*nBandCount );
     267                 :     else
     268                 :     {
     269               0 :         for( int i = 0; i < nBandCount; i++ )
     270               0 :             this->panBandMap[i] = i+1;
     271                 :     }
     272                 :     
     273               1 :     this->nPixelSpace = nPixelSpace;
     274               1 :     this->nLineSpace = nLineSpace;
     275               1 :     this->nBandSpace = nBandSpace;
     276                 : 
     277               1 :     this->papszOptions = CSLDuplicate(papszOptions);
     278               1 : }
     279                 : 
     280                 : /************************************************************************/
     281                 : /*                      ~GDALDefaultAsyncReader()                       */
     282                 : /************************************************************************/
     283                 : 
     284               1 : GDALDefaultAsyncReader::~GDALDefaultAsyncReader()
     285                 : 
     286                 : {
     287               1 :     CPLFree( panBandMap );
     288               1 :     CSLDestroy( papszOptions );
     289               1 : }
     290                 : 
     291                 : /************************************************************************/
     292                 : /*                        GetNextUpdatedRegion()                        */
     293                 : /************************************************************************/
     294                 : 
     295                 : GDALAsyncStatusType
     296               1 : GDALDefaultAsyncReader::GetNextUpdatedRegion(double dfTimeout,
     297                 :                                              int* pnBufXOff,
     298                 :                                              int* pnBufYOff,
     299                 :                                              int* pnBufXSize,
     300                 :                                              int* pnBufYSize )
     301                 : 
     302                 : {
     303                 :     CPLErr eErr;
     304                 : 
     305                 :     eErr = poDS->RasterIO( GF_Read, nXOff, nYOff, nXSize, nYSize, 
     306                 :                            pBuf, nBufXSize, nBufYSize, eBufType, 
     307                 :                            nBandCount, panBandMap, 
     308               1 :                            nPixelSpace, nLineSpace, nBandSpace );
     309                 : 
     310               1 :     *pnBufXOff = 0;
     311               1 :     *pnBufYOff = 0;
     312               1 :     *pnBufXSize = nBufXSize;
     313               1 :     *pnBufYSize = nBufYSize;
     314                 : 
     315               1 :     if( eErr == CE_None )
     316               1 :         return GARIO_COMPLETE;
     317                 :     else
     318               0 :         return GARIO_ERROR;
     319                 : }
     320                 : 

Generated by: LCOV version 1.7