LCOV - code coverage report
Current view: top level - dbaccess/source/ui/misc - moduledbu.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 31 31 100.0 %
Date: 2015-06-13 12:38:46 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11