DataSetsManager.cpp
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/gdal/DataSetsManager.cpp
22 
23  \brief GDAL data set manager.
24 */
25 
26 // TerraLib
27 #include "DataSetsManager.h"
28 
30 
32 
34  const AccessType aType )
35 {
36  if( uri.empty() )
37  {
38  return false;
39  }
40  else
41  {
42  m_mutex.lock();
43 
44  UrisInfoT::iterator it = m_openURIS.find( uri );
45 
46  if( it == m_openURIS.end() )
47  {
48  m_openURIS[ uri ] = std::pair< AccessType, unsigned long int >( aType, 1 ) ;
49  m_mutex.unlock();
50  return true;
51  }
52  else
53  {
54  if( aType == SingleAccessType )
55  {
56  m_mutex.unlock();
57  return false;
58  }
59  else
60  {
61  if( it->second.first == SingleAccessType )
62  {
63  m_mutex.unlock();
64  return false;
65  }
66  else
67  {
68  ++( it->second.second );
69  m_mutex.unlock();
70  return true;
71  }
72  }
73  }
74  }
75 }
76 
77 void te::gdal::DataSetsManager::decrementUseCounter( const std::string& uri )
78 {
79  if( ! uri.empty() )
80  {
81  m_mutex.lock();
82 
83  UrisInfoT::iterator it = m_openURIS.find( uri );
84 
85  if( it != m_openURIS.end() )
86  {
87  if( it->second.second == 1 )
88  {
89  m_openURIS.erase( uri );
90  }
91  else
92  {
93  --( it->second.second );
94  }
95  }
96 
97  m_mutex.unlock();
98  }
99 }
100 
UrisInfoT m_openURIS
Current open URIs.
void decrementUseCounter(const std::string &uri)
Decrement the use counter for the given raster URI.
bool incrementUseCounter(const std::string &uri, const AccessType aType)
Try to increment the use counter for the given raster URI.
boost::mutex m_mutex
Internal thread sync mutex.