LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/generic - ogrmutexeddatasource.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 76 132 57.6 %
Date: 2025-02-20 10:14:44 Functions: 19 33 57.6 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  Implements OGRMutexedDataSource class
       5             :  * Author:   Even Rouault, even dot rouault at spatialys.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2013, Even Rouault <even dot rouault at spatialys.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #ifndef DOXYGEN_SKIP
      14             : 
      15             : #include "ogrmutexeddatasource.h"
      16             : #include "cpl_multiproc.h"
      17             : 
      18          36 : OGRMutexedDataSource::OGRMutexedDataSource(GDALDataset *poBaseDataSource,
      19             :                                            int bTakeOwnership,
      20             :                                            CPLMutex *hMutexIn,
      21          36 :                                            int bWrapLayersInMutexedLayer)
      22             :     : m_poBaseDataSource(poBaseDataSource), m_bHasOwnership(bTakeOwnership),
      23             :       m_hGlobalMutex(hMutexIn),
      24          36 :       m_bWrapLayersInMutexedLayer(bWrapLayersInMutexedLayer)
      25             : {
      26          36 :     SetDescription(poBaseDataSource->GetDescription());
      27          36 :     poDriver = poBaseDataSource->GetDriver();
      28          36 : }
      29             : 
      30          72 : OGRMutexedDataSource::~OGRMutexedDataSource()
      31             : {
      32             :     std::map<OGRLayer *, OGRMutexedLayer *>::iterator oIter =
      33          36 :         m_oMapLayers.begin();
      34          99 :     for (; oIter != m_oMapLayers.end(); ++oIter)
      35          63 :         delete oIter->second;
      36             : 
      37          36 :     if (m_bHasOwnership)
      38          36 :         delete m_poBaseDataSource;
      39          72 : }
      40             : 
      41          24 : int OGRMutexedDataSource::GetLayerCount()
      42             : {
      43          48 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
      44          48 :     return m_poBaseDataSource->GetLayerCount();
      45             : }
      46             : 
      47         191 : OGRLayer *OGRMutexedDataSource::WrapLayerIfNecessary(OGRLayer *poLayer)
      48             : {
      49         191 :     if (poLayer && m_bWrapLayersInMutexedLayer)
      50             :     {
      51         183 :         OGRLayer *poWrappedLayer = m_oMapLayers[poLayer];
      52         183 :         if (poWrappedLayer)
      53           0 :             poLayer = poWrappedLayer;
      54             :         else
      55             :         {
      56             :             OGRMutexedLayer *poMutexedLayer =
      57         183 :                 new OGRMutexedLayer(poLayer, FALSE, m_hGlobalMutex);
      58         183 :             m_oMapLayers[poLayer] = poMutexedLayer;
      59         183 :             m_oReverseMapLayers[poMutexedLayer] = poLayer;
      60         183 :             poLayer = poMutexedLayer;
      61             :         }
      62             :     }
      63         191 :     return poLayer;
      64             : }
      65             : 
      66          42 : OGRLayer *OGRMutexedDataSource::GetLayer(int iIndex)
      67             : {
      68          84 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
      69          84 :     return WrapLayerIfNecessary(m_poBaseDataSource->GetLayer(iIndex));
      70             : }
      71             : 
      72          24 : OGRLayer *OGRMutexedDataSource::GetLayerByName(const char *pszName)
      73             : {
      74          48 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
      75          48 :     return WrapLayerIfNecessary(m_poBaseDataSource->GetLayerByName(pszName));
      76             : }
      77             : 
      78           0 : OGRErr OGRMutexedDataSource::DeleteLayer(int iIndex)
      79             : {
      80           0 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
      81             :     OGRLayer *poLayer =
      82           0 :         m_bWrapLayersInMutexedLayer ? GetLayer(iIndex) : nullptr;
      83           0 :     OGRErr eErr = m_poBaseDataSource->DeleteLayer(iIndex);
      84           0 :     if (eErr == OGRERR_NONE && poLayer)
      85             :     {
      86             :         std::map<OGRLayer *, OGRMutexedLayer *>::iterator oIter =
      87           0 :             m_oMapLayers.find(poLayer);
      88           0 :         if (oIter != m_oMapLayers.end())
      89             :         {
      90           0 :             delete oIter->second;
      91           0 :             m_oReverseMapLayers.erase(oIter->second);
      92           0 :             m_oMapLayers.erase(oIter);
      93             :         }
      94             :     }
      95           0 :     return eErr;
      96             : }
      97             : 
      98           1 : bool OGRMutexedDataSource::IsLayerPrivate(int iLayer) const
      99             : {
     100           2 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     101           2 :     return m_poBaseDataSource->IsLayerPrivate(iLayer);
     102             : }
     103             : 
     104          89 : int OGRMutexedDataSource::TestCapability(const char *pszCap)
     105             : {
     106         178 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     107         178 :     return m_poBaseDataSource->TestCapability(pszCap);
     108             : }
     109             : 
     110             : OGRLayer *
     111           0 : OGRMutexedDataSource::ICreateLayer(const char *pszName,
     112             :                                    const OGRGeomFieldDefn *poGeomFieldDefn,
     113             :                                    CSLConstList papszOptions)
     114             : {
     115           0 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     116           0 :     return WrapLayerIfNecessary(m_poBaseDataSource->CreateLayer(
     117           0 :         pszName, poGeomFieldDefn, papszOptions));
     118             : }
     119             : 
     120           0 : OGRLayer *OGRMutexedDataSource::CopyLayer(OGRLayer *poSrcLayer,
     121             :                                           const char *pszNewName,
     122             :                                           char **papszOptions)
     123             : {
     124           0 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     125           0 :     return WrapLayerIfNecessary(
     126           0 :         m_poBaseDataSource->CopyLayer(poSrcLayer, pszNewName, papszOptions));
     127             : }
     128             : 
     129           1 : OGRStyleTable *OGRMutexedDataSource::GetStyleTable()
     130             : {
     131           2 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     132           2 :     return m_poBaseDataSource->GetStyleTable();
     133             : }
     134             : 
     135           0 : void OGRMutexedDataSource::SetStyleTableDirectly(OGRStyleTable *poStyleTable)
     136             : {
     137           0 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     138           0 :     m_poBaseDataSource->SetStyleTableDirectly(poStyleTable);
     139           0 : }
     140             : 
     141           0 : void OGRMutexedDataSource::SetStyleTable(OGRStyleTable *poStyleTable)
     142             : {
     143           0 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     144           0 :     m_poBaseDataSource->SetStyleTable(poStyleTable);
     145           0 : }
     146             : 
     147         125 : OGRLayer *OGRMutexedDataSource::ExecuteSQL(const char *pszStatement,
     148             :                                            OGRGeometry *poSpatialFilter,
     149             :                                            const char *pszDialect)
     150             : {
     151         250 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     152         125 :     return WrapLayerIfNecessary(m_poBaseDataSource->ExecuteSQL(
     153         375 :         pszStatement, poSpatialFilter, pszDialect));
     154             : }
     155             : 
     156         120 : void OGRMutexedDataSource::ReleaseResultSet(OGRLayer *poResultsSet)
     157             : {
     158         240 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     159         120 :     if (poResultsSet && m_bWrapLayersInMutexedLayer)
     160             :     {
     161             :         std::map<OGRMutexedLayer *, OGRLayer *>::iterator oIter =
     162             :             m_oReverseMapLayers.find(
     163         120 :                 dynamic_cast<OGRMutexedLayer *>(poResultsSet));
     164         120 :         CPLAssert(oIter != m_oReverseMapLayers.end());
     165         120 :         delete poResultsSet;
     166         120 :         poResultsSet = oIter->second;
     167         120 :         m_oMapLayers.erase(poResultsSet);
     168         120 :         m_oReverseMapLayers.erase(oIter);
     169             :     }
     170             : 
     171         120 :     m_poBaseDataSource->ReleaseResultSet(poResultsSet);
     172         120 : }
     173             : 
     174           0 : CPLErr OGRMutexedDataSource::FlushCache(bool bAtClosing)
     175             : {
     176           0 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     177           0 :     return m_poBaseDataSource->FlushCache(bAtClosing);
     178             : }
     179             : 
     180           0 : OGRErr OGRMutexedDataSource::StartTransaction(int bForce)
     181             : {
     182           0 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     183           0 :     return m_poBaseDataSource->StartTransaction(bForce);
     184             : }
     185             : 
     186           0 : OGRErr OGRMutexedDataSource::CommitTransaction()
     187             : {
     188           0 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     189           0 :     return m_poBaseDataSource->CommitTransaction();
     190             : }
     191             : 
     192           0 : OGRErr OGRMutexedDataSource::RollbackTransaction()
     193             : {
     194           0 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     195           0 :     return m_poBaseDataSource->RollbackTransaction();
     196             : }
     197             : 
     198           1 : char **OGRMutexedDataSource::GetMetadata(const char *pszDomain)
     199             : {
     200           2 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     201           2 :     return m_poBaseDataSource->GetMetadata(pszDomain);
     202             : }
     203             : 
     204           0 : CPLErr OGRMutexedDataSource::SetMetadata(char **papszMetadata,
     205             :                                          const char *pszDomain)
     206             : {
     207           0 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     208           0 :     return m_poBaseDataSource->SetMetadata(papszMetadata, pszDomain);
     209             : }
     210             : 
     211           1 : const char *OGRMutexedDataSource::GetMetadataItem(const char *pszName,
     212             :                                                   const char *pszDomain)
     213             : {
     214           2 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     215           2 :     return m_poBaseDataSource->GetMetadataItem(pszName, pszDomain);
     216             : }
     217             : 
     218           0 : CPLErr OGRMutexedDataSource::SetMetadataItem(const char *pszName,
     219             :                                              const char *pszValue,
     220             :                                              const char *pszDomain)
     221             : {
     222           0 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     223           0 :     return m_poBaseDataSource->SetMetadataItem(pszName, pszValue, pszDomain);
     224             : }
     225             : 
     226             : std::vector<std::string>
     227           1 : OGRMutexedDataSource::GetFieldDomainNames(CSLConstList papszOptions) const
     228             : {
     229           2 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     230           2 :     return m_poBaseDataSource->GetFieldDomainNames(papszOptions);
     231             : }
     232             : 
     233             : const OGRFieldDomain *
     234           3 : OGRMutexedDataSource::GetFieldDomain(const std::string &name) const
     235             : {
     236           6 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     237           6 :     return m_poBaseDataSource->GetFieldDomain(name);
     238             : }
     239             : 
     240           0 : bool OGRMutexedDataSource::AddFieldDomain(
     241             :     std::unique_ptr<OGRFieldDomain> &&domain, std::string &failureReason)
     242             : {
     243           0 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     244           0 :     return m_poBaseDataSource->AddFieldDomain(std::move(domain), failureReason);
     245             : }
     246             : 
     247           0 : bool OGRMutexedDataSource::DeleteFieldDomain(const std::string &name,
     248             :                                              std::string &failureReason)
     249             : {
     250           0 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     251           0 :     return m_poBaseDataSource->DeleteFieldDomain(name, failureReason);
     252             : }
     253             : 
     254           0 : bool OGRMutexedDataSource::UpdateFieldDomain(
     255             :     std::unique_ptr<OGRFieldDomain> &&domain, std::string &failureReason)
     256             : {
     257           0 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     258           0 :     return m_poBaseDataSource->UpdateFieldDomain(std::move(domain),
     259           0 :                                                  failureReason);
     260             : }
     261             : 
     262             : std::vector<std::string>
     263           3 : OGRMutexedDataSource::GetRelationshipNames(CSLConstList papszOptions) const
     264             : {
     265           6 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     266           6 :     return m_poBaseDataSource->GetRelationshipNames(papszOptions);
     267             : }
     268             : 
     269             : const GDALRelationship *
     270           8 : OGRMutexedDataSource::GetRelationship(const std::string &name) const
     271             : {
     272          16 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     273          16 :     return m_poBaseDataSource->GetRelationship(name);
     274             : }
     275             : 
     276           1 : std::shared_ptr<GDALGroup> OGRMutexedDataSource::GetRootGroup() const
     277             : {
     278           2 :     CPLMutexHolderOptionalLockD(m_hGlobalMutex);
     279           2 :     return m_poBaseDataSource->GetRootGroup();
     280             : }
     281             : 
     282             : #endif /* #ifndef DOXYGEN_SKIP */

Generated by: LCOV version 1.14