LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/misc - svtaccessiblefactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 8 71 11.3 %
Date: 2012-12-17 Functions: 4 26 15.4 %
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             : #include <osl/module.h>
      22             : 
      23             : // #define UNLOAD_ON_LAST_CLIENT_DYING
      24             :     // this is not recommended currently. If enabled, the implementation will log
      25             :     // the number of active clients, and unload the acc library when the last client
      26             :     // goes away.
      27             :     // Sounds like a good idea, unfortunately, there's no guarantee that all objects
      28             :     // implemented in this library are already dead.
      29             :     // Iow, just because an object implementing an XAccessible (implemented in this lib
      30             :     // here) died, it's not said that everybody released all references to the
      31             :     // XAccessibleContext used by this component, and implemented in the acc lib.
      32             :     // So we cannot really unload the lib.
      33             :     //
      34             :     // Alternatively, if the lib would us own "usage counting", i.e. every component
      35             :     // implemented therein would affect a static ref count, the acc lib could care
      36             :     // for unloading itself.
      37             : 
      38             : //........................................................................
      39             : namespace svt
      40             : {
      41             : //........................................................................
      42             : 
      43             :     using namespace ::com::sun::star::uno;
      44             :     using namespace ::com::sun::star::awt;
      45             :     using namespace ::com::sun::star::accessibility;
      46             : 
      47             :     namespace
      48             :     {
      49             : #ifdef UNLOAD_ON_LAST_CLIENT_DYING
      50             :         static oslInterlockedCount                      s_nAccessibleFactoryAccesss = 0;
      51             : #endif // UNLOAD_ON_LAST_CLIENT_DYING
      52             : #ifndef DISABLE_DYNLOADING
      53             :         static oslModule                                s_hAccessibleImplementationModule = NULL;
      54             : #endif
      55             :         static GetSvtAccessibilityComponentFactory      s_pAccessibleFactoryFunc = NULL;
      56         106 :         static ::rtl::Reference< IAccessibleFactory >   s_pFactory;
      57             : 
      58             :         //====================================================================
      59             :         //= AccessibleDummyFactory
      60             :         //====================================================================
      61             :         class AccessibleDummyFactory : public IAccessibleFactory
      62             :         {
      63             :         public:
      64             :             AccessibleDummyFactory();
      65             : 
      66             :         protected:
      67             :             virtual ~AccessibleDummyFactory();
      68             : 
      69             :         private:
      70             :             AccessibleDummyFactory( const AccessibleDummyFactory& );            // never implemented
      71             :             AccessibleDummyFactory& operator=( const AccessibleDummyFactory& ); // never implemented
      72             : 
      73             :             oslInterlockedCount m_refCount;
      74             : 
      75             :         public:
      76             :             // IReference
      77             :             virtual oslInterlockedCount SAL_CALL acquire();
      78             :             virtual oslInterlockedCount SAL_CALL release();
      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
      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
      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
     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
     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
     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*/, bool /*bCompoundControlChild*/
     128             :                 ) const
     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
     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
     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
     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
     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             :                     sal_Bool /*_bIsTriState*/
     186             :                 ) const
     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
     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             :                 )
     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             :                 )
     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          30 :     AccessibleFactoryAccess::AccessibleFactoryAccess()
     256          30 :         :m_bInitialized( false )
     257             :     {
     258          30 :     }
     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 ::rtl::OUString sModuleName( SVLIBRARY( "acc" ));
     283           0 :                 s_hAccessibleImplementationModule = osl_loadModuleRelative( &thisModule, sModuleName.pData, 0 );
     284           0 :                 if ( s_hAccessibleImplementationModule != NULL )
     285             :                 {
     286           0 :                     const ::rtl::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          26 :     AccessibleFactoryAccess::~AccessibleFactoryAccess()
     320             :     {
     321          26 :         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          26 :     }
     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         318 : }   // namespace svt
     350             : //........................................................................
     351             : 
     352             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10