LCOV - code coverage report
Current view: top level - rdbmaker/source/codemaker - typemanager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 63 121 52.1 %
Date: 2012-08-25 Functions: 13 16 81.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 46 192 24.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #include    <rtl/alloc.h>
      21                 :            : #include    <osl/file.hxx>
      22                 :            : #include    <codemaker/typemanager.hxx>
      23                 :            : 
      24                 :            : using ::rtl::OUString;
      25                 :            : using ::rtl::OString;
      26                 :            : using ::rtl::OStringToOUString;
      27                 :          4 : TypeManager::TypeManager()
      28                 :            : {
      29                 :          4 :     m_pImpl = new TypeManagerImpl();
      30                 :          4 :     acquire();
      31                 :          4 : }
      32                 :            : 
      33                 :          2 : TypeManager::~TypeManager()
      34                 :            : {
      35                 :          2 :     release();
      36         [ -  + ]:          2 : }
      37                 :            : 
      38                 :          8 : sal_Int32 TypeManager::acquire()
      39                 :            : {
      40                 :          8 :     return osl_incrementInterlockedCount(&m_pImpl->m_refCount);
      41                 :            : }
      42                 :            : 
      43                 :          4 : sal_Int32 TypeManager::release()
      44                 :            : {
      45                 :          4 :     sal_Int32 refCount = 0;
      46         [ +  + ]:          4 :     if (0 == (refCount = osl_decrementInterlockedCount(&m_pImpl->m_refCount)) )
      47                 :            :     {
      48                 :          2 :         delete m_pImpl;
      49                 :            :     }
      50                 :          4 :     return refCount;
      51                 :            : }
      52                 :            : 
      53                 :          4 : RegistryTypeManager::RegistryTypeManager()
      54                 :            : {
      55 [ +  - ][ +  - ]:          4 :     m_pImpl = new RegistryTypeManagerImpl();
      56         [ +  - ]:          4 :     acquire();
      57                 :          4 : }
      58                 :            : 
      59                 :          2 : RegistryTypeManager::~RegistryTypeManager()
      60                 :            : {
      61         [ +  - ]:          2 :     release();
      62         [ -  + ]:          4 : }
      63                 :            : 
      64                 :          4 : void RegistryTypeManager::acquire()
      65                 :            : {
      66                 :          4 :     TypeManager::acquire();
      67                 :          4 : }
      68                 :            : 
      69                 :          2 : void RegistryTypeManager::release()
      70                 :            : {
      71         [ -  + ]:          2 :     if (0 == TypeManager::release())
      72                 :            :     {
      73         [ #  # ]:          0 :         if (m_pImpl->m_pMergedRegistry)
      74                 :            :         {
      75         [ #  # ]:          0 :             if (m_pImpl->m_pMergedRegistry->isValid())
      76                 :            :             {
      77         [ #  # ]:          0 :                 m_pImpl->m_pMergedRegistry->destroy(OUString());
      78                 :            :             }
      79                 :            : 
      80         [ #  # ]:          0 :             delete m_pImpl->m_pMergedRegistry;
      81                 :            :         }
      82                 :            : 
      83         [ #  # ]:          0 :         if (m_pImpl->m_registries.size() > 0)
      84                 :            :         {
      85                 :          0 :             freeRegistries();
      86                 :            :         }
      87                 :            : 
      88         [ #  # ]:          0 :         delete m_pImpl;
      89                 :            :     }
      90                 :          2 : }
      91                 :            : 
      92                 :          2 : sal_Bool RegistryTypeManager::init(sal_Bool bMerged, const StringVector& regFiles)
      93                 :            : {
      94 [ -  + ][ #  # ]:          2 :     m_pImpl->m_isMerged = bMerged && (regFiles.size() > 1);
      95                 :            : 
      96         [ -  + ]:          2 :     if (regFiles.empty())
      97                 :          0 :         return sal_False;
      98                 :            : 
      99                 :          2 :     StringVector::const_iterator iter = regFiles.begin();
     100                 :            : 
     101         [ +  - ]:          2 :     Registry tmpReg;
     102 [ +  - ][ +  + ]:          4 :     while (iter != regFiles.end())
     103                 :            :     {
     104 [ +  - ][ +  - ]:          2 :         if (!tmpReg.open( convertToFileUrl(*iter), REG_READONLY))
                 [ +  - ]
     105 [ +  - ][ +  - ]:          2 :             m_pImpl->m_registries.push_back(new Registry(tmpReg));
                 [ +  - ]
     106                 :            :         else
     107                 :            :         {
     108         [ #  # ]:          0 :             freeRegistries();
     109                 :          0 :             return sal_False;
     110                 :            :         }
     111                 :          2 :         ++iter;
     112                 :            :     }
     113                 :            : 
     114         [ -  + ]:          2 :     if (m_pImpl->m_isMerged)
     115                 :            :     {
     116 [ #  # ][ #  # ]:          0 :         Registry *pTmpReg = new Registry;
     117                 :          0 :         OUString tmpName;
     118         [ #  # ]:          0 :         osl::FileBase::createTempFile(0, 0, &tmpName);
     119 [ #  # ][ #  # ]:          0 :         if (!pTmpReg->create(tmpName))
     120                 :            :         {
     121         [ #  # ]:          0 :             RegistryKey rootKey;
     122                 :          0 :             RegError ret = REG_NO_ERROR;
     123         [ #  # ]:          0 :             OUString aRoot( RTL_CONSTASCII_USTRINGPARAM("/") );
     124                 :          0 :             iter = regFiles.begin();
     125         [ #  # ]:          0 :             pTmpReg->openRootKey(rootKey);
     126                 :            : 
     127 [ #  # ][ #  # ]:          0 :             while (iter != regFiles.end())
     128                 :            :             {
     129 [ #  # ][ #  # ]:          0 :                 if ( (ret = pTmpReg->mergeKey(rootKey, aRoot, convertToFileUrl( *iter ))) )
                 [ #  # ]
     130                 :            :                 {
     131         [ #  # ]:          0 :                     if (ret != REG_MERGE_CONFLICT)
     132                 :            :                     {
     133         [ #  # ]:          0 :                         freeRegistries();
     134         [ #  # ]:          0 :                         rootKey.closeKey();
     135         [ #  # ]:          0 :                         pTmpReg->destroy( OUString() );
     136 [ #  # ][ #  # ]:          0 :                         delete pTmpReg;
     137                 :          0 :                         return sal_False;
     138                 :            :                     }
     139                 :            :                 }
     140                 :          0 :                 ++iter;
     141                 :            :             }
     142                 :            : 
     143                 :          0 :             m_pImpl->m_pMergedRegistry = pTmpReg;
     144 [ #  # ][ #  # ]:          0 :             freeRegistries();
         [ #  # ][ #  # ]
     145                 :            :         } else
     146                 :            :         {
     147 [ #  # ][ #  # ]:          0 :             delete pTmpReg;
     148         [ #  # ]:          0 :             freeRegistries();
     149                 :          0 :             return sal_False;
     150         [ #  # ]:          0 :         }
     151                 :            :     }
     152                 :            : 
     153         [ +  - ]:          2 :     return sal_True;
     154                 :            : }
     155                 :            : 
     156                 :        444 : TypeReader RegistryTypeManager::getTypeReader(const OString& name)
     157                 :            : {
     158                 :        444 :     TypeReader reader;
     159         [ +  - ]:        444 :     RegistryKey key(searchTypeKey(name));
     160                 :            : 
     161         [ +  - ]:        444 :     if (key.isValid())
     162                 :            :     {
     163                 :            :         RegValueType    valueType;
     164                 :            :         sal_uInt32      valueSize;
     165                 :            : 
     166 [ +  - ][ +  - ]:        444 :         if (!key.getValueInfo(OUString(), &valueType, &valueSize))
     167                 :            :         {
     168                 :        444 :             sal_uInt8*  pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
     169 [ +  - ][ +  - ]:        444 :             if (!key.getValue(OUString(), pBuffer))
     170                 :            :             {
     171 [ +  - ][ +  - ]:        444 :                 reader = TypeReader(pBuffer, valueSize, sal_True);
                 [ +  - ]
     172                 :            :             }
     173                 :        444 :             rtl_freeMemory(pBuffer);
     174                 :            :         }
     175                 :            :     }
     176         [ +  - ]:        444 :     return reader;
     177                 :            : }
     178                 :            : 
     179                 :          0 : RTTypeClass RegistryTypeManager::getTypeClass(const OString& name)
     180                 :            : {
     181         [ #  # ]:          0 :     if (m_pImpl->m_t2TypeClass.count(name) > 0)
     182                 :            :     {
     183                 :          0 :         return m_pImpl->m_t2TypeClass[name];
     184                 :            :     } else
     185                 :            :     {
     186         [ #  # ]:          0 :         RegistryKey key(searchTypeKey(name));
     187                 :            : 
     188         [ #  # ]:          0 :         if (key.isValid())
     189                 :            :         {
     190                 :            :             RegValueType    valueType;
     191                 :            :             sal_uInt32      valueSize;
     192                 :            : 
     193 [ #  # ][ #  # ]:          0 :             if (!key.getValueInfo(OUString(), &valueType, &valueSize))
     194                 :            :             {
     195                 :          0 :                 sal_uInt8*  pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
     196 [ #  # ][ #  # ]:          0 :                 if (!key.getValue(OUString(), pBuffer))
     197                 :            :                 {
     198         [ #  # ]:          0 :                     TypeReader reader(pBuffer, valueSize, sal_False);
     199                 :            : 
     200                 :          0 :                     RTTypeClass ret = reader.getTypeClass();
     201                 :            : 
     202                 :          0 :                     rtl_freeMemory(pBuffer);
     203                 :            : 
     204         [ #  # ]:          0 :                     m_pImpl->m_t2TypeClass[name] = ret;
     205         [ #  # ]:          0 :                     return ret;
     206                 :            :                 }
     207                 :          0 :                 rtl_freeMemory(pBuffer);
     208                 :            :             }
     209 [ #  # ][ #  # ]:          0 :         }
     210                 :            :     }
     211                 :            : 
     212                 :          0 :     return RT_TYPE_INVALID;
     213                 :            : }
     214                 :            : 
     215                 :          2 : void RegistryTypeManager::setBase(const OString& base)
     216                 :            : {
     217                 :          2 :     m_pImpl->m_base = base;
     218                 :            : 
     219         [ +  - ]:          2 :     if (base.lastIndexOf('/') != (base.getLength() - 1))
     220                 :            :     {
     221                 :          2 :         m_pImpl->m_base += "/";
     222                 :            :     }
     223                 :          2 : }
     224                 :            : 
     225                 :          0 : void RegistryTypeManager::freeRegistries()
     226                 :            : {
     227                 :          0 :     RegistryList::const_iterator iter = m_pImpl->m_registries.begin();
     228                 :            : 
     229         [ #  # ]:          0 :     while (iter != m_pImpl->m_registries.end())
     230                 :            :     {
     231 [ #  # ][ #  # ]:          0 :         delete *iter;
     232                 :            : 
     233                 :          0 :         ++iter;
     234                 :            :     }
     235                 :            : 
     236                 :          0 : }
     237                 :            : 
     238                 :       1756 : RegistryKey RegistryTypeManager::searchTypeKey(const OString& name)
     239                 :            : {
     240 [ +  - ][ +  - ]:       1756 :     RegistryKey key, rootKey;
     241                 :            : 
     242         [ -  + ]:       1756 :     if (m_pImpl->m_isMerged)
     243                 :            :     {
     244 [ #  # ][ #  # ]:          0 :         if (!m_pImpl->m_pMergedRegistry->openRootKey(rootKey))
     245                 :            :         {
     246 [ #  # ][ #  # ]:          0 :             rootKey.openKey(OStringToOUString(m_pImpl->m_base + name, RTL_TEXTENCODING_UTF8), key);
     247                 :            :         }
     248                 :            :     } else
     249                 :            :     {
     250                 :       1756 :         RegistryList::const_iterator iter = m_pImpl->m_registries.begin();
     251                 :            : 
     252         [ +  + ]:       3512 :         while (iter != m_pImpl->m_registries.end())
     253                 :            :         {
     254 [ +  - ][ +  - ]:       1756 :             if (!(*iter)->openRootKey(rootKey))
     255                 :            :             {
     256 [ +  - ][ +  - ]:       1756 :                 if (!rootKey.openKey(OStringToOUString(m_pImpl->m_base + name, RTL_TEXTENCODING_UTF8), key))
                 [ +  + ]
     257                 :       1268 :                     break;
     258                 :            :             }
     259                 :            : 
     260                 :        488 :             ++iter;
     261                 :            :         }
     262                 :            :     }
     263                 :            : 
     264         [ +  - ]:       1756 :     return key;
     265                 :            : }
     266                 :            : 
     267                 :            : 
     268                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10