LCOV - code coverage report
Current view: top level - svtools/source/misc - svtaccessiblefactory.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 2 71 2.8 %
Date: 2014-04-14 Functions: 2 26 7.7 %
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 "svtaccessiblefactory.hxx"
      21             : 
      22             : #include <boost/noncopyable.hpp>
      23             : #include <osl/module.h>
      24             : 
      25             : // #define UNLOAD_ON_LAST_CLIENT_DYING
      26             :     // this is not recommended currently. If enabled, the implementation will log
      27             :     // the number of active clients, and unload the acc library when the last client
      28             :     // goes away.
      29             :     // Sounds like a good idea, unfortunately, there's no guarantee that all objects
      30             :     // implemented in this library are already dead.
      31             :     // Iow, just because an object implementing an XAccessible (implemented in this lib
      32             :     // here) died, it's not said that everybody released all references to the
      33             :     // XAccessibleContext used by this component, and implemented in the acc lib.
      34             :     // So we cannot really unload the lib.
      35             : 
      36             :     // Alternatively, if the lib would us own "usage counting", i.e. every component
      37             :     // implemented therein would affect a static ref count, the acc lib could care
      38             :     // for unloading itself.
      39             : 
      40             : 
      41             : namespace svt
      42             : {
      43             : 
      44             : 
      45             :     using namespace ::com::sun::star::uno;
      46             :     using namespace ::com::sun::star::awt;
      47             :     using namespace ::com::sun::star::accessibility;
      48             : 
      49             :     namespace
      50             :     {
      51             : #ifdef UNLOAD_ON_LAST_CLIENT_DYING
      52             :         static oslInterlockedCount                      s_nAccessibleFactoryAccesss = 0;
      53             : #endif // UNLOAD_ON_LAST_CLIENT_DYING
      54             : #ifndef DISABLE_DYNLOADING
      55             :         static oslModule                                s_hAccessibleImplementationModule = NULL;
      56             : #endif
      57             :         static GetSvtAccessibilityComponentFactory      s_pAccessibleFactoryFunc = NULL;
      58           1 :         static ::rtl::Reference< IAccessibleFactory >   s_pFactory;
      59             : 
      60             : 
      61             :         //= AccessibleDummyFactory
      62             : 
      63             :         class AccessibleDummyFactory:
      64             :             public IAccessibleFactory, private boost::noncopyable
      65             :         {
      66             :         public:
      67             :             AccessibleDummyFactory();
      68             : 
      69             :         protected:
      70             :             virtual ~AccessibleDummyFactory();
      71             : 
      72             :         private:
      73             :             oslInterlockedCount m_refCount;
      74             : 
      75             :         public:
      76             :             // IReference
      77             :             virtual oslInterlockedCount SAL_CALL acquire() SAL_OVERRIDE;
      78             :             virtual oslInterlockedCount SAL_CALL release() SAL_OVERRIDE;
      79             : 
      80             :             // IAccessibleFactory
      81             :             virtual IAccessibleTabListBox*
      82           0 :                 createAccessibleTabListBox(
      83             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*rxParent*/,
      84             :                     SvHeaderTabListBox& /*rBox*/
      85             :                 ) const SAL_OVERRIDE
      86             :             {
      87           0 :                 return NULL;
      88             :             }
      89             : 
      90             :             virtual IAccessibleBrowseBox*
      91           0 :                 createAccessibleBrowseBox(
      92             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*_rxParent*/,
      93             :                     IAccessibleTableProvider& /*_rBrowseBox*/
      94             :                 ) const SAL_OVERRIDE
      95             :             {
      96           0 :                 return NULL;
      97             :             }
      98             : 
      99             :             virtual table::IAccessibleTableControl*
     100           0 :                 createAccessibleTableControl(
     101             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*_rxParent*/,
     102             :                     table::IAccessibleTable& /*_rTable*/
     103             :                 ) const SAL_OVERRIDE
     104             :             {
     105           0 :                 return NULL;
     106             :             }
     107             : 
     108             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     109           0 :                 createAccessibleIconChoiceCtrl(
     110             :                     SvtIconChoiceCtrl& /*_rIconCtrl*/,
     111             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*_xParent*/
     112             :                 ) const SAL_OVERRIDE
     113             :             {
     114           0 :                 return NULL;
     115             :             }
     116             : 
     117             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     118           0 :                 createAccessibleTabBar(
     119             :                     TabBar& /*_rTabBar*/
     120             :                 ) const SAL_OVERRIDE
     121             :             {
     122           0 :                 return NULL;
     123             :             }
     124             : 
     125             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     126           0 :                 createAccessibleTextWindowContext(
     127             :                     VCLXWindow* /*pVclXWindow*/, TextEngine& /*rEngine*/, TextView& /*rView*/
     128             :                 ) const SAL_OVERRIDE
     129             :             {
     130           0 :                 return NULL;
     131             :             }
     132             : 
     133             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     134           0 :                 createAccessibleTreeListBox(
     135             :                     SvTreeListBox& /*_rListBox*/,
     136             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*_xParent*/
     137             :                 ) const SAL_OVERRIDE
     138             :             {
     139           0 :                 return NULL;
     140             :             }
     141             : 
     142             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     143           0 :                 createAccessibleBrowseBoxHeaderBar(
     144             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*rxParent*/,
     145             :                     IAccessibleTableProvider& /*_rOwningTable*/,
     146             :                     AccessibleBrowseBoxObjType /*_eObjType*/
     147             :                 ) const SAL_OVERRIDE
     148             :             {
     149           0 :                 return NULL;
     150             :             }
     151             : 
     152             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     153           0 :                 createAccessibleBrowseBoxTableCell(
     154             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*_rxParent*/,
     155             :                     IAccessibleTableProvider& /*_rBrowseBox*/,
     156             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& /*_xFocusWindow*/,
     157             :                     sal_Int32 /*_nRowId*/,
     158             :                     sal_uInt16 /*_nColId*/,
     159             :                     sal_Int32 /*_nOffset*/
     160             :                 ) const SAL_OVERRIDE
     161             :             {
     162           0 :                 return NULL;
     163             :             }
     164             : 
     165             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     166           0 :                 createAccessibleBrowseBoxHeaderCell(
     167             :                     sal_Int32 /*_nColumnRowId*/,
     168             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*rxParent*/,
     169             :                     IAccessibleTableProvider& /*_rBrowseBox*/,
     170             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& /*_xFocusWindow*/,
     171             :                     AccessibleBrowseBoxObjType  /*_eObjType*/
     172             :                 ) const SAL_OVERRIDE
     173             :             {
     174           0 :                 return NULL;
     175             :             }
     176             : 
     177             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     178           0 :                 createAccessibleCheckBoxCell(
     179             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*_rxParent*/,
     180             :                     IAccessibleTableProvider& /*_rBrowseBox*/,
     181             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& /*_xFocusWindow*/,
     182             :                     sal_Int32 /*_nRowPos*/,
     183             :                     sal_uInt16 /*_nColPos*/,
     184             :                     const TriState& /*_eState*/,
     185             :                     bool /*_bIsTriState*/
     186             :                 ) const SAL_OVERRIDE
     187             :             {
     188           0 :                 return NULL;
     189             :             }
     190             : 
     191             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     192           0 :                 createEditBrowseBoxTableCellAccess(
     193             :                     const ::com::sun::star::uno::Reference< com::sun::star::accessibility::XAccessible >& /*_rxParent*/,
     194             :                     const ::com::sun::star::uno::Reference< com::sun::star::accessibility::XAccessible >& /*_rxControlAccessible*/,
     195             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& /*_rxFocusWindow*/,
     196             :                     IAccessibleTableProvider& /*_rBrowseBox*/,
     197             :                     sal_Int32 /*_nRowPos*/,
     198             :                     sal_uInt16 /*_nColPos*/
     199             :                 ) const SAL_OVERRIDE
     200             :             {
     201           0 :                 return NULL;
     202             :             }
     203             : 
     204             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     205           0 :                 createAccessibleToolPanelDeck(
     206             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*i_rAccessibleParent*/,
     207             :                     ::svt::ToolPanelDeck& /*i_rPanelDeck*/
     208             :                 ) SAL_OVERRIDE
     209             :             {
     210           0 :                 return NULL;
     211             :             }
     212             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     213           0 :                 createAccessibleToolPanelTabBar(
     214             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& /*i_rAccessibleParent*/,
     215             :                     ::svt::IToolPanelDeck& /*i_rPanelDeck*/,
     216             :                     ::svt::PanelTabBar& /*i_rTabBar*/
     217             :                 ) SAL_OVERRIDE
     218             :             {
     219           0 :                 return NULL;
     220             :             }
     221             :         };
     222             : 
     223             : 
     224           0 :         AccessibleDummyFactory::AccessibleDummyFactory()
     225             :         {
     226           0 :         }
     227             : 
     228             : 
     229           0 :         AccessibleDummyFactory::~AccessibleDummyFactory()
     230             :         {
     231           0 :         }
     232             : 
     233             : 
     234           0 :         oslInterlockedCount SAL_CALL AccessibleDummyFactory::acquire()
     235             :         {
     236           0 :             return osl_atomic_increment( &m_refCount );
     237             :         }
     238             : 
     239             : 
     240           0 :         oslInterlockedCount SAL_CALL AccessibleDummyFactory::release()
     241             :         {
     242           0 :             if ( 0 == osl_atomic_decrement( &m_refCount ) )
     243             :             {
     244           0 :                 delete this;
     245           0 :                 return 0;
     246             :             }
     247           0 :             return m_refCount;
     248             :         }
     249             :     }
     250             : 
     251             : 
     252             :     //= AccessibleFactoryAccess
     253             : 
     254             : 
     255           0 :     AccessibleFactoryAccess::AccessibleFactoryAccess()
     256           0 :         :m_bInitialized( false )
     257             :     {
     258           0 :     }
     259             : 
     260             : 
     261             : #ifndef DISABLE_DYNLOADING
     262           0 :     extern "C" { static void SAL_CALL thisModule() {} }
     263             : #else
     264             :     extern "C" void* getSvtAccessibilityComponentFactory();
     265             : #endif
     266             : 
     267           0 :     void AccessibleFactoryAccess::ensureInitialized()
     268             :     {
     269           0 :         if ( m_bInitialized )
     270           0 :             return;
     271             : 
     272           0 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     273             : 
     274             : #ifdef UNLOAD_ON_LAST_CLIENT_DYING
     275             :         if ( 1 == osl_atomic_increment( &s_nAccessibleFactoryAccesss ) )
     276             :         {   // the first client
     277             : #endif // UNLOAD_ON_LAST_CLIENT_DYING
     278             :             // load the library implementing the factory
     279           0 :             if ( !s_pFactory.get() )
     280             :             {
     281             : #ifndef DISABLE_DYNLOADING
     282           0 :                 const OUString sModuleName( SVLIBRARY( "acc" ));
     283           0 :                 s_hAccessibleImplementationModule = osl_loadModuleRelative( &thisModule, sModuleName.pData, 0 );
     284           0 :                 if ( s_hAccessibleImplementationModule != NULL )
     285             :                 {
     286           0 :                     const OUString sFactoryCreationFunc( "getSvtAccessibilityComponentFactory" );
     287             :                     s_pAccessibleFactoryFunc = (GetSvtAccessibilityComponentFactory)
     288           0 :                         osl_getFunctionSymbol( s_hAccessibleImplementationModule, sFactoryCreationFunc.pData );
     289             : 
     290             :                 }
     291             :                 OSL_ENSURE( s_pAccessibleFactoryFunc, "ac_registerClient: could not load the library, or not retrieve the needed symbol!" );
     292             : #else
     293             :                 s_pAccessibleFactoryFunc = getSvtAccessibilityComponentFactory;
     294             : #endif
     295             :                 // get a factory instance
     296           0 :                 if ( s_pAccessibleFactoryFunc )
     297             :                 {
     298           0 :                     IAccessibleFactory* pFactory = static_cast< IAccessibleFactory* >( (*s_pAccessibleFactoryFunc)() );
     299           0 :                     if ( pFactory )
     300             :                     {
     301           0 :                         s_pFactory = pFactory;
     302           0 :                         pFactory->release();
     303             :                     }
     304           0 :                 }
     305             :             }
     306             : 
     307           0 :             if ( !s_pFactory.get() )
     308             :                 // the attempt to load the lib, or to create the factory, failed
     309             :                 // -> fall back to a dummy factory
     310           0 :                 s_pFactory = new AccessibleDummyFactory;
     311             : #ifdef UNLOAD_ON_LAST_CLIENT_DYING
     312             :         }
     313             : #endif
     314             : 
     315           0 :         m_bInitialized = true;
     316             :     }
     317             : 
     318             : 
     319           0 :     AccessibleFactoryAccess::~AccessibleFactoryAccess()
     320             :     {
     321           0 :         if ( m_bInitialized )
     322             :         {
     323           0 :             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     324             : 
     325             : #ifdef UNLOAD_ON_LAST_CLIENT_DYING
     326             :             if( 0 == osl_atomic_decrement( &s_nAccessibleFactoryAccesss ) )
     327             :             {
     328             :                 s_pFactory = NULL;
     329             :                 s_pAccessibleFactoryFunc = NULL;
     330             :                 if ( s_hAccessibleImplementationModule )
     331             :                 {
     332             :                     osl_unloadModule( s_hAccessibleImplementationModule );
     333             :                     s_hAccessibleImplementationModule = NULL;
     334             :                 }
     335             :             }
     336             : #endif // UNLOAD_ON_LAST_CLIENT_DYING
     337             :         }
     338           0 :     }
     339             : 
     340             : 
     341           0 :     IAccessibleFactory& AccessibleFactoryAccess::getFactory()
     342             :     {
     343           0 :         ensureInitialized();
     344             :         DBG_ASSERT( s_pFactory.is(), "AccessibleFactoryAccess::getFactory: at least a dummy factory should have been created!" );
     345           0 :         return *s_pFactory;
     346             :     }
     347             : 
     348             : 
     349           3 : }   // namespace svt
     350             : 
     351             : 
     352             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10