LCOV - code coverage report
Current view: top level - dbaccess/source/ui/misc - moduledbu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 31 31 100.0 %
Date: 2012-08-25 Functions: 9 9 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 25 40 62.5 %

           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                 :            : 
      21                 :            : #include "moduledbu.hxx"
      22                 :            : 
      23                 :            : #include <tools/resmgr.hxx>
      24                 :            : #include <svl/solar.hrc>
      25                 :            : #include <tools/debug.hxx>
      26                 :            : 
      27                 :            : #define ENTER_MOD_METHOD()  \
      28                 :            :     ::osl::MutexGuard aGuard(s_aMutex); \
      29                 :            :     ensureImpl()
      30                 :            : 
      31                 :            : //.........................................................................
      32                 :            : namespace dbaui
      33                 :            : {
      34                 :            : //.........................................................................
      35                 :            : 
      36                 :            : //=========================================================================
      37                 :            : //= OModuleImpl
      38                 :            : //=========================================================================
      39                 :            : /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner
      40                 :            : */
      41                 :            : class OModuleImpl
      42                 :            : {
      43                 :            :     ResMgr* m_pResources;
      44                 :            : 
      45                 :            : public:
      46                 :            :     /// ctor
      47                 :            :     OModuleImpl();
      48                 :            :     ~OModuleImpl();
      49                 :            : 
      50                 :            :     /// get the manager for the resources of the module
      51                 :            :     ResMgr* getResManager();
      52                 :            : };
      53                 :            : 
      54                 :            : DBG_NAME(OModuleImpl)
      55                 :            : //-------------------------------------------------------------------------
      56                 :          2 : OModuleImpl::OModuleImpl()
      57                 :          2 :     :m_pResources(NULL)
      58                 :            : {
      59                 :            :     DBG_CTOR(OModuleImpl,NULL);
      60                 :            : 
      61                 :          2 : }
      62                 :            : 
      63                 :            : //-------------------------------------------------------------------------
      64                 :          2 : OModuleImpl::~OModuleImpl()
      65                 :            : {
      66         [ +  - ]:          2 :     if (m_pResources)
      67         [ +  - ]:          2 :         delete m_pResources;
      68                 :            : 
      69                 :            :     DBG_DTOR(OModuleImpl,NULL);
      70                 :          2 : }
      71                 :            : 
      72                 :            : //-------------------------------------------------------------------------
      73                 :         30 : ResMgr* OModuleImpl::getResManager()
      74                 :            : {
      75                 :            :     // note that this method is not threadsafe, which counts for the whole class !
      76                 :            : 
      77         [ +  + ]:         30 :     if (!m_pResources)
      78                 :            :     {
      79                 :            :         // create a manager with a fixed prefix
      80         [ +  - ]:          2 :         m_pResources = ResMgr::CreateResMgr(rtl::OString("dbu").getStr());
      81                 :            :     }
      82                 :         30 :     return m_pResources;
      83                 :            : }
      84                 :            : 
      85                 :            : //=========================================================================
      86                 :            : //= OModule
      87                 :            : //=========================================================================
      88                 :         14 : ::osl::Mutex    OModule::s_aMutex;
      89                 :            : sal_Int32       OModule::s_nClients = 0;
      90                 :            : OModuleImpl*    OModule::s_pImpl = NULL;
      91                 :            : //-------------------------------------------------------------------------
      92                 :         30 : ResMgr* OModule::getResManager()
      93                 :            : {
      94 [ +  - ][ +  - ]:         30 :     ENTER_MOD_METHOD();
      95 [ +  - ][ +  - ]:         30 :     return s_pImpl->getResManager();
      96                 :            : }
      97                 :            : 
      98                 :            : //-------------------------------------------------------------------------
      99                 :         16 : void OModule::registerClient()
     100                 :            : {
     101         [ +  - ]:         16 :     ::osl::MutexGuard aGuard(s_aMutex);
     102         [ +  - ]:         16 :     ++s_nClients;
     103                 :         16 : }
     104                 :            : 
     105                 :            : //-------------------------------------------------------------------------
     106                 :         16 : void OModule::revokeClient()
     107                 :            : {
     108         [ +  - ]:         16 :     ::osl::MutexGuard aGuard(s_aMutex);
     109 [ +  + ][ +  + ]:         16 :     if (!--s_nClients && s_pImpl)
                 [ +  + ]
     110                 :            :     {
     111 [ +  - ][ +  - ]:          2 :         delete s_pImpl;
     112                 :          2 :         s_pImpl = NULL;
     113         [ +  - ]:         16 :     }
     114                 :         16 : }
     115                 :            : 
     116                 :            : //-------------------------------------------------------------------------
     117                 :         30 : void OModule::ensureImpl()
     118                 :            : {
     119         [ +  + ]:         30 :     if (s_pImpl)
     120                 :         30 :         return;
     121                 :          2 :     s_pImpl = new OModuleImpl();
     122                 :            : }
     123                 :            : 
     124                 :            : //.........................................................................
     125 [ +  - ][ +  - ]:         42 : }   // namespace dbaui
     126                 :            : //.........................................................................
     127                 :            : 
     128                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10