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 // Boost
35 #include <boost/noncopyable.hpp>
36 #include <boost/thread/mutex.hpp>
37 #include <boost/thread/condition_variable.hpp>
38 
39 // STL
40 #include <vector>
41 
42 namespace te
43 {
44  namespace rst
45  {
46  class SynchronizedBandBlocksManager;
47  class SynchronizedBand;
48  class SynchronizedRaster;
49 
50  /*!
51  \class RasterSynchronizer
52 
53  \brief An access synchronizer to be used in SynchronizedRaster raster instances.
54 
55  \ingroup rst
56  */
57  class TERASTEREXPORT RasterSynchronizer: public boost::noncopyable
58  {
60  friend class SynchronizedBand;
61  friend class SynchronizedRaster;
62 
63  public:
64 
65  /*!
66  \brief Constructor.
67 
68  \param raster The raster to synchronize.
69 
70  \param policy The access policy to use on the given input raster.
71  */
72  RasterSynchronizer( Raster& raster, const te::common::AccessPolicy policy );
73 
75 
76  protected :
77 
78  /*!
79  \brief Blocks use counter type definition.
80  \note Indexed as [band][blockYIndex][blockXIndex]
81  */
82  typedef std::vector< std::vector< std::vector< unsigned int > > > BlocksUseCounterT;
83 
84  te::common::AccessPolicy m_policy; //!< The access policy used on the given input raster.
85 
86  Raster& m_raster; //!< The input raster.
87 
88  boost::mutex m_mutex; //!< General sync mutex;
89 
90  boost::condition_variable_any m_condVar; //!< Block use request sync variable.
91 
92  BlocksUseCounterT m_blocksUseCounters; //!< blocks use counter.
93 
94  /*!
95  \brief Acquire a raster data block.
96  \param bandIdx Block band index.
97  \param blockXIndex Block X index.
98  \param blockYIndex Block Y index.
99  \param blkDataPtr A pointer to a pre-allocated area where the block data will be written.
100  \return true if OK, false if the increment could not be done.
101  \note The block data will be read from the internal raster and the block use counter will be incremented.
102  */
103  bool acquireBlock( const unsigned int bandIdx,
104  const unsigned int blockXIndex, const unsigned int blockYIndex,
105  void* blkDataPtr );
106 
107  /*!
108  \brief Release a raster data block.
109  \param bandIdx Block band index.
110  \param blockXIndex Block X index.
111  \param blockYIndex Block Y index.
112  \param blkDataPtr A pointer where the block data will be read.
113  \note The block data will be writed to the internal raster and the block use counter will be decremented.
114  \return true if OK, false if the increment could not be done.
115  */
116  bool releaseBlock( const unsigned int bandIdx,
117  const unsigned int blockXIndex, const unsigned int blockYIndex,
118  void* blkDataPtr );
119 
120 
121 
122  };
123 
124  } // end namespace rst
125 } // end namespace te
126 
127 #endif //__TERRALIB_RASTER_INTERNAL_RASTEERSYNCHRONIZER_H
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:62
An adapter class to allow concurrent access to raster data by multiple threads.
An access synchronizer to be used in SynchronizedRaster raster instances.
boost::mutex m_mutex
General sync mutex;.
boost::condition_variable_any m_condVar
Block use request sync variable.
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
Raster & m_raster
The input raster.
An abstract class for raster data strucutures.
An abstract class for raster data strucutures.
Definition: Raster.h:71
Syncrhonized raster band.
std::vector< std::vector< std::vector< unsigned int > > > BlocksUseCounterT
Blocks use counter type definition.
URI C++ Library.
Synchronized raster raster band blocks manager.
Configuration flags for the Raster module of TerraLib.
te::common::AccessPolicy m_policy
The access policy used on the given input raster.
BlocksUseCounterT m_blocksUseCounters
blocks use counter.