LCOV - code coverage report
Current view: top level - libreoffice/toolkit/source/helper - accessibilityclient.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 8 67 11.9 %
Date: 2012-12-27 Functions: 4 24 16.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 <toolkit/helper/accessibilityclient.hxx>
      21             : #include <toolkit/helper/accessiblefactory.hxx>
      22             : #include <osl/module.h>
      23             : #include <osl/diagnose.h>
      24             : #include <tools/solar.h>
      25             : 
      26             : // #define UNLOAD_ON_LAST_CLIENT_DYING
      27             :     // this is not recommended currently. If enabled, the implementation will log
      28             :     // the number of active clients, and unload the acc library when the last client
      29             :     // goes away.
      30             :     // Sounds like a good idea, unfortunately, there's no guarantee that all objects
      31             :     // implemented in this library are already dead.
      32             :     // Iow, just because an object implementing an XAccessible (implemented in this lib
      33             :     // here) died, it's not said that everybody released all references to the
      34             :     // XAccessibleContext used by this component, and implemented in the acc lib.
      35             :     // So we cannot really unload the lib.
      36             :     //
      37             :     // Alternatively, if the lib would us own "usage counting", i.e. every component
      38             :     // implemented therein would affect a static ref count, the acc lib could care
      39             :     // for unloading itself.
      40             : 
      41             : //........................................................................
      42             : namespace toolkit
      43             : {
      44             : //........................................................................
      45             : 
      46             :     using namespace ::com::sun::star::uno;
      47             :     using namespace ::com::sun::star::accessibility;
      48             : 
      49             :     namespace
      50             :     {
      51             : #ifdef UNLOAD_ON_LAST_CLIENT_DYING
      52             :         static oslInterlockedCount                      s_nAccessibilityClients = 0;
      53             : #endif // UNLOAD_ON_LAST_CLIENT_DYING
      54             : #ifndef DISABLE_DYNLOADING
      55             :         static oslModule                                s_hAccessibleImplementationModule = NULL;
      56             : #endif
      57             :         static GetStandardAccComponentFactory           s_pAccessibleFactoryFunc = NULL;
      58          36 :         static ::rtl::Reference< IAccessibleFactory >   s_pFactory;
      59             :     }
      60             : 
      61             :     //====================================================================
      62             :     //= AccessibleDummyFactory
      63             :     //====================================================================
      64             :     class AccessibleDummyFactory : public IAccessibleFactory
      65             :     {
      66             :     public:
      67             :         AccessibleDummyFactory();
      68             : 
      69             :     protected:
      70             :         virtual ~AccessibleDummyFactory();
      71             : 
      72             :     private:
      73             :         AccessibleDummyFactory( const AccessibleDummyFactory& );            // never implemented
      74             :         AccessibleDummyFactory& operator=( const AccessibleDummyFactory& ); // never implemented
      75             : 
      76             :         oslInterlockedCount m_refCount;
      77             : 
      78             :     public:
      79             :         // IReference
      80             :         virtual oslInterlockedCount SAL_CALL acquire();
      81             :         virtual oslInterlockedCount SAL_CALL release();
      82             : 
      83             :         // IAccessibleFactory
      84             :         ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
      85           0 :                 createAccessibleContext( VCLXButton* /*_pXWindow*/ )
      86             :         {
      87           0 :             return NULL;
      88             :         }
      89             :         ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
      90           0 :                 createAccessibleContext( VCLXCheckBox* /*_pXWindow*/ )
      91             :         {
      92           0 :             return NULL;
      93             :         }
      94             :         ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
      95           0 :                 createAccessibleContext( VCLXRadioButton* /*_pXWindow*/ )
      96             :         {
      97           0 :             return NULL;
      98             :         }
      99             :         ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     100           0 :                 createAccessibleContext( VCLXListBox* /*_pXWindow*/ )
     101             :         {
     102           0 :             return NULL;
     103             :         }
     104             :         ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     105           0 :                 createAccessibleContext( VCLXFixedHyperlink* /*_pXWindow*/ )
     106             :         {
     107           0 :             return NULL;
     108             :         }
     109             :         ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     110           0 :                 createAccessibleContext( VCLXFixedText* /*_pXWindow*/ )
     111             :         {
     112           0 :             return NULL;
     113             :         }
     114             :         ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     115           0 :                 createAccessibleContext( VCLXScrollBar* /*_pXWindow*/ )
     116             :         {
     117           0 :             return NULL;
     118             :         }
     119             :         ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     120           0 :                 createAccessibleContext( VCLXEdit* /*_pXWindow*/ )
     121             :         {
     122           0 :             return NULL;
     123             :         }
     124             :         ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     125           0 :                 createAccessibleContext( VCLXComboBox* /*_pXWindow*/ )
     126             :         {
     127           0 :             return NULL;
     128             :         }
     129             :         ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     130           0 :                 createAccessibleContext( VCLXToolBox* /*_pXWindow*/ )
     131             :         {
     132           0 :             return NULL;
     133             :         }
     134             :         ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
     135           0 :                 createAccessibleContext( VCLXWindow* /*_pXWindow*/ )
     136             :         {
     137           0 :             return NULL;
     138             :         }
     139             :         ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
     140           0 :                 createAccessible( Menu* /*_pMenu*/, sal_Bool /*_bIsMenuBar*/ )
     141             :         {
     142           0 :             return NULL;
     143             :         }
     144             :     };
     145             : 
     146             :     //--------------------------------------------------------------------
     147           0 :     AccessibleDummyFactory::AccessibleDummyFactory()
     148             :     {
     149           0 :     }
     150             : 
     151             :     //--------------------------------------------------------------------
     152           0 :     AccessibleDummyFactory::~AccessibleDummyFactory()
     153             :     {
     154           0 :     }
     155             : 
     156             :     //--------------------------------------------------------------------
     157           0 :     oslInterlockedCount SAL_CALL AccessibleDummyFactory::acquire()
     158             :     {
     159           0 :         return osl_atomic_increment( &m_refCount );
     160             :     }
     161             : 
     162             :     //--------------------------------------------------------------------
     163           0 :     oslInterlockedCount SAL_CALL AccessibleDummyFactory::release()
     164             :     {
     165           0 :         if ( 0 == osl_atomic_decrement( &m_refCount ) )
     166             :         {
     167           0 :             delete this;
     168           0 :             return 0;
     169             :         }
     170           0 :         return m_refCount;
     171             :     }
     172             : 
     173             :     //====================================================================
     174             :     //= AccessibilityClient
     175             :     //====================================================================
     176             :     //--------------------------------------------------------------------
     177        3781 :     AccessibilityClient::AccessibilityClient()
     178        3781 :         :m_bInitialized( false )
     179             :     {
     180        3781 :     }
     181             : 
     182             :     //--------------------------------------------------------------------
     183             : #ifndef DISABLE_DYNLOADING
     184           0 :     extern "C" { static void SAL_CALL thisModule() {} }
     185             : #else
     186             :     extern "C" void *getStandardAccessibleFactory();
     187             : #endif
     188             : 
     189           0 :     void AccessibilityClient::ensureInitialized()
     190             :     {
     191           0 :         if ( m_bInitialized )
     192           0 :             return;
     193             : 
     194           0 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     195             : 
     196             : #ifdef UNLOAD_ON_LAST_CLIENT_DYING
     197             :         if ( 1 == osl_atomic_increment( &s_nAccessibilityClients ) )
     198             :         {   // the first client
     199             : #endif // UNLOAD_ON_LAST_CLIENT_DYING
     200             :             // load the library implementing the factory
     201           0 :             if ( !s_pFactory.get() )
     202             :             {
     203             : #ifndef DISABLE_DYNLOADING
     204           0 :                 const ::rtl::OUString sModuleName( SVLIBRARY( "acc" ) );
     205           0 :                 s_hAccessibleImplementationModule = osl_loadModuleRelative( &thisModule, sModuleName.pData, 0 );
     206           0 :                 if ( s_hAccessibleImplementationModule != NULL )
     207             :                 {
     208             :                     const ::rtl::OUString sFactoryCreationFunc =
     209           0 :                         ::rtl::OUString("getStandardAccessibleFactory");
     210             :                     s_pAccessibleFactoryFunc = (GetStandardAccComponentFactory)
     211           0 :                         osl_getFunctionSymbol( s_hAccessibleImplementationModule, sFactoryCreationFunc.pData );
     212             : 
     213             :                 }
     214             :                 OSL_ENSURE( s_pAccessibleFactoryFunc, "AccessibilityClient::ensureInitialized: could not load the library, or not retrieve the needed symbol!" );
     215             : #else
     216             :                 s_pAccessibleFactoryFunc = getStandardAccessibleFactory;
     217             : #endif
     218             : 
     219             :                 // get a factory instance
     220           0 :                 if ( s_pAccessibleFactoryFunc )
     221             :                 {
     222           0 :                     IAccessibleFactory* pFactory = static_cast< IAccessibleFactory* >( (*s_pAccessibleFactoryFunc)() );
     223             :                     OSL_ENSURE( pFactory, "AccessibilityClient::ensureInitialized: no factory provided by the A11Y lib!" );
     224           0 :                     if ( pFactory )
     225             :                     {
     226           0 :                         s_pFactory = pFactory;
     227           0 :                         pFactory->release();
     228             :                     }
     229           0 :                 }
     230             :             }
     231             : 
     232           0 :             if ( !s_pFactory.get() )
     233             :                 // the attempt to load the lib, or to create the factory, failed
     234             :                 // -> fall back to a dummy factory
     235           0 :                 s_pFactory = new AccessibleDummyFactory;
     236             : #ifdef UNLOAD_ON_LAST_CLIENT_DYING
     237             :         }
     238             : #endif
     239             : 
     240           0 :         m_bInitialized = true;
     241             :     }
     242             : 
     243             :     //--------------------------------------------------------------------
     244         359 :     AccessibilityClient::~AccessibilityClient()
     245             :     {
     246         359 :         if ( m_bInitialized )
     247             :         {
     248           0 :             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     249             : 
     250             : #ifdef UNLOAD_ON_LAST_CLIENT_DYING
     251             :             if( 0 == osl_atomic_decrement( &s_nAccessibilityClients ) )
     252             :             {
     253             :                 s_pFactory = NULL;
     254             :                 s_pAccessibleFactoryFunc = NULL;
     255             :                 if ( s_hAccessibleImplementationModule )
     256             :                 {
     257             :                     osl_unloadModule( s_hAccessibleImplementationModule );
     258             :                     s_hAccessibleImplementationModule = NULL;
     259             :                 }
     260             :             }
     261             : #endif // UNLOAD_ON_LAST_CLIENT_DYING
     262             :         }
     263         359 :     }
     264             : 
     265             :     //--------------------------------------------------------------------
     266           0 :     IAccessibleFactory& AccessibilityClient::getFactory()
     267             :     {
     268           0 :         ensureInitialized();
     269             :         OSL_ENSURE( s_pFactory.is(), "AccessibilityClient::getFactory: at least a dummy factory should have been created!" );
     270           0 :         return *s_pFactory;
     271             :     }
     272             : 
     273             : //........................................................................
     274         108 : }   // namespace toolkit
     275             : //........................................................................
     276             : 
     277             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10