~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to gcore/gdaldefaultasync.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
GDALAsyncReader::GDALAsyncReader()
 
57
{
 
58
}
 
59
 
 
60
/************************************************************************/
 
61
/*                         ~GDALAsyncReader()                           */
 
62
/************************************************************************/
 
63
GDALAsyncReader::~GDALAsyncReader()
 
64
{
 
65
}
 
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
GDALARGetNextUpdatedRegion(GDALAsyncReaderH hARIO, double timeout,
 
116
                           int* pnxbufoff, int* pnybufoff, 
 
117
                           int* pnxbufsize, int* pnybufsize)
 
118
{
 
119
    VALIDATE_POINTER1(hARIO, "GDALARGetNextUpdatedRegion", GARIO_ERROR);
 
120
    return ((GDALAsyncReader *)hARIO)->GetNextUpdatedRegion(
 
121
        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
int GDALAsyncReader::LockBuffer( double dfTimeout )
 
144
 
 
145
{
 
146
    return TRUE;
 
147
}
 
148
 
 
149
 
 
150
/************************************************************************/
 
151
/*                          GDALARLockBuffer()                          */
 
152
/************************************************************************/
 
153
int CPL_STDCALL GDALARLockBuffer(GDALAsyncReaderH hARIO, double dfTimeout )
 
154
{
 
155
    VALIDATE_POINTER1(hARIO, "GDALARLockBuffer",FALSE);
 
156
    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
void GDALAsyncReader::UnlockBuffer()
 
170
 
 
171
{
 
172
}
 
173
 
 
174
/************************************************************************/
 
175
/*                          GDALARUnlockBuffer()                          */
 
176
/************************************************************************/
 
177
void CPL_STDCALL GDALARUnlockBuffer(GDALAsyncReaderH hARIO)
 
178
{
 
179
    VALIDATE_POINTER0(hARIO, "GDALARUnlockBuffer");
 
180
    ((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
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
                                         papszOptions );
 
235
}
 
236
 
 
237
/************************************************************************/
 
238
/*                       GDALDefaultAsyncReader()                       */
 
239
/************************************************************************/
 
240
 
 
241
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
                          int nBandSpace, char **papszOptions) 
 
251
 
 
252
{
 
253
    this->poDS = poDS;
 
254
    this->nXOff = nXOff;
 
255
    this->nYOff = nYOff;
 
256
    this->nXSize = nXSize;
 
257
    this->nYSize = nYSize;
 
258
    this->pBuf = pBuf;
 
259
    this->nBufXSize = nBufXSize;
 
260
    this->nBufYSize = nBufYSize;
 
261
    this->eBufType = eBufType;
 
262
    this->nBandCount = nBandCount;
 
263
    this->panBandMap = (int *) CPLMalloc(sizeof(int)*nBandCount);
 
264
 
 
265
    if( panBandMap != NULL )
 
266
        memcpy( this->panBandMap, panBandMap, sizeof(int)*nBandCount );
 
267
    else
 
268
    {
 
269
        for( int i = 0; i < nBandCount; i++ )
 
270
            this->panBandMap[i] = i+1;
 
271
    }
 
272
    
 
273
    this->nPixelSpace = nPixelSpace;
 
274
    this->nLineSpace = nLineSpace;
 
275
    this->nBandSpace = nBandSpace;
 
276
 
 
277
    this->papszOptions = CSLDuplicate(papszOptions);
 
278
}
 
279
 
 
280
/************************************************************************/
 
281
/*                      ~GDALDefaultAsyncReader()                       */
 
282
/************************************************************************/
 
283
 
 
284
GDALDefaultAsyncReader::~GDALDefaultAsyncReader()
 
285
 
 
286
{
 
287
    CPLFree( panBandMap );
 
288
    CSLDestroy( papszOptions );
 
289
}
 
290
 
 
291
/************************************************************************/
 
292
/*                        GetNextUpdatedRegion()                        */
 
293
/************************************************************************/
 
294
 
 
295
GDALAsyncStatusType
 
296
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
                           nPixelSpace, nLineSpace, nBandSpace );
 
309
 
 
310
    *pnBufXOff = 0;
 
311
    *pnBufYOff = 0;
 
312
    *pnBufXSize = nBufXSize;
 
313
    *pnBufYSize = nBufYSize;
 
314
 
 
315
    if( eErr == CE_None )
 
316
        return GARIO_COMPLETE;
 
317
    else
 
318
        return GARIO_ERROR;
 
319
}
 
320