RasterSynchronizer.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/raster/RasterSynchronizer.h
22 
23  \brief An access synchronizer to be used in SynchronizedRaster raster instances.
24 */
25 
26 #ifndef __TERRALIB_RASTER_INTERNAL_RASTEERSYNCHRONIZER_H
27 #define __TERRALIB_RASTER_INTERNAL_RASTEERSYNCHRONIZER_H
28 
29 // TerraLib
30 #include "Raster.h"
31 #include "Config.h"
32 #include "../common/Enums.h"
33 
34 // STL
35 #include <vector>
36 #include <mutex>
37 #include <condition_variable>
38 
39 namespace te
40 {
41  namespace rst
42  {
43  class SynchronizedBandBlocksManager;
44  class SynchronizedBand;
45  class SynchronizedRaster;
46 
47  /*!
48  \class RasterSynchronizer
49 
50  \brief An access synchronizer to be used in SynchronizedRaster raster instances.
51 
52  \ingroup rst
53  */
55  {
57  friend class SynchronizedBand;
58  friend class SynchronizedRaster;
59 
60  public:
61 
62  /*!
63  \brief Constructor.
64 
65  \param raster The raster to synchronize.
66 
67  \param policy The access policy to use on the given input raster.
68  */
70 
72 
73  protected :
74 
75  /*!
76  \brief Blocks use counter type definition.
77  \note Indexed as [band][blockYIndex][blockXIndex]
78  */
79  typedef std::vector< std::vector< std::vector< unsigned int > > > BlocksUseCounterT;
80 
81  te::common::AccessPolicy m_policy; //!< The access policy used on the given input raster.
82 
83  Raster* m_rasterPtr; //!< The input raster.
84 
85  std::mutex m_mutex; //!< General sync mutex;
86 
87  std::condition_variable_any m_condVar; //!< Block use request sync variable.
88 
89  BlocksUseCounterT m_blocksUseCounters; //!< blocks use counter.
90 
91  /*!
92  \brief Acquire a raster data block.
93  \param bandIdx Block band index.
94  \param blockXIndex Block X index.
95  \param blockYIndex Block Y index.
96  \param blkDataPtr A pointer to a pre-allocated area where the block data will be written.
97  \return true if OK, false if the increment could not be done.
98  \note The block data will be read from the internal raster and the block use counter will be incremented.
99  */
100  bool acquireBlock( const unsigned int bandIdx,
101  const unsigned int blockXIndex, const unsigned int blockYIndex,
102  void* blkDataPtr );
103 
104  /*!
105  \brief Release a raster data block.
106  \param bandIdx Block band index.
107  \param blockXIndex Block X index.
108  \param blockYIndex Block Y index.
109  \param blkDataPtr A pointer where the block data will be read.
110  \note The block data will be writed to the internal raster and the block use counter will be decremented.
111  \return true if OK, false if the increment could not be done.
112  */
113  bool releaseBlock( const unsigned int bandIdx,
114  const unsigned int blockXIndex, const unsigned int blockYIndex,
115  void* blkDataPtr );
116 
117  private:
118 
121 
122  };
123 
124  } // end namespace rst
125 } // end namespace te
126 
127 #endif //__TERRALIB_RASTER_INTERNAL_RASTEERSYNCHRONIZER_H
Raster.h
Raster implementaton for TerraLib 4.x.
te::rst::RasterSynchronizer::acquireBlock
bool acquireBlock(const unsigned int bandIdx, const unsigned int blockXIndex, const unsigned int blockYIndex, void *blkDataPtr)
Acquire a raster data block.
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::rst::RasterSynchronizer::RasterSynchronizer
RasterSynchronizer(Raster &raster, const te::common::AccessPolicy policy)
Constructor.
te::rst::Raster
An abstract class for raster data strucutures.
Definition: Raster.h:72
te::rst::RasterSynchronizer::releaseBlock
bool releaseBlock(const unsigned int bandIdx, const unsigned int blockXIndex, const unsigned int blockYIndex, void *blkDataPtr)
Release a raster data block.
te::rst::SynchronizedBand
Syncrhonized raster band.
Definition: SynchronizedBand.h:52
te::rst::RasterSynchronizer
An access synchronizer to be used in SynchronizedRaster raster instances.
Definition: RasterSynchronizer.h:55
te::rst::RasterSynchronizer::m_rasterPtr
Raster * m_rasterPtr
The input raster.
Definition: RasterSynchronizer.h:83
te::rst::RasterSynchronizer::m_policy
te::common::AccessPolicy m_policy
The access policy used on the given input raster.
Definition: RasterSynchronizer.h:81
TERASTEREXPORT
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
te::rst::RasterSynchronizer::~RasterSynchronizer
~RasterSynchronizer()
te::rst::RasterSynchronizer::RasterSynchronizer
RasterSynchronizer()
Definition: RasterSynchronizer.h:119
te::rst::RasterSynchronizer::m_mutex
std::mutex m_mutex
General sync mutex;.
Definition: RasterSynchronizer.h:85
te::rst::SynchronizedRaster
An adapter class to allow concurrent access to raster data by multiple threads.
Definition: SynchronizedRaster.h:52
te::rst::RasterSynchronizer::RasterSynchronizer
RasterSynchronizer(const RasterSynchronizer &other)
Definition: RasterSynchronizer.h:120
te::rst::SynchronizedBandBlocksManager
Synchronized raster raster band blocks manager.
Definition: SynchronizedBandBlocksManager.h:48
te::rst::RasterSynchronizer::m_blocksUseCounters
BlocksUseCounterT m_blocksUseCounters
blocks use counter.
Definition: RasterSynchronizer.h:89
te::rst::RasterSynchronizer::m_condVar
std::condition_variable_any m_condVar
Block use request sync variable.
Definition: RasterSynchronizer.h:87
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::common::AccessPolicy
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:41
te::rst::RasterSynchronizer::BlocksUseCounterT
std::vector< std::vector< std::vector< unsigned int > > > BlocksUseCounterT
Blocks use counter type definition.
Definition: RasterSynchronizer.h:79