LCOV - code coverage report
Current view: top level - UnoControls/source/controls - OConnectionPointHelper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 60 0.0 %
Date: 2014-04-14 Functions: 0 13 0.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 "OConnectionPointHelper.hxx"
      21             : 
      22             : #include "OConnectionPointContainerHelper.hxx"
      23             : 
      24             : //  namespaces
      25             : 
      26             : using namespace ::rtl;
      27             : using namespace ::osl;
      28             : using namespace ::cppu;
      29             : using namespace ::com::sun::star::uno;
      30             : using namespace ::com::sun::star::lang;
      31             : 
      32             : namespace unocontrols{
      33             : 
      34             : //  construct/destruct
      35             : 
      36           0 : OConnectionPointHelper::OConnectionPointHelper(
      37             :     Mutex&                              aMutex                      ,
      38             :     OConnectionPointContainerHelper*    pContainerImplementation    ,
      39             :     Type                                aType
      40             : )   : m_aSharedMutex                ( aMutex                    )
      41             :     , m_oContainerWeakReference     ( pContainerImplementation  )
      42             :     , m_pContainerImplementation    ( pContainerImplementation  )
      43           0 :     , m_aInterfaceType              ( aType                     )
      44             : {
      45           0 : }
      46             : 
      47           0 : OConnectionPointHelper::~OConnectionPointHelper()
      48             : {
      49           0 : }
      50             : 
      51             : //  XInterface
      52             : 
      53           0 : Any SAL_CALL OConnectionPointHelper::queryInterface( const Type& aType ) throw( RuntimeException, std::exception )
      54             : {
      55             :     // Attention:
      56             :     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
      57             : 
      58             :     // Ask for my own supported interfaces ...
      59             :     Any aReturn ( ::cppu::queryInterface(   aType                                       ,
      60             :                                             static_cast< XConnectionPoint*  > ( this )
      61             :                                         )
      62           0 :                 );
      63             : 
      64             :     // If searched interface not supported by this class ...
      65           0 :     if ( !aReturn.hasValue() )
      66             :     {
      67             :         // ... ask baseclasses.
      68           0 :         aReturn = OWeakObject::queryInterface( aType );
      69             :     }
      70             : 
      71           0 :     return aReturn;
      72             : }
      73             : 
      74             : //  XInterface
      75             : 
      76           0 : void SAL_CALL OConnectionPointHelper::acquire() throw()
      77             : {
      78             :     // Attention:
      79             :     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
      80             : 
      81             :     // Forward to baseclass
      82           0 :     OWeakObject::acquire();
      83           0 : }
      84             : 
      85             : //  XInterface
      86             : 
      87           0 : void SAL_CALL OConnectionPointHelper::release() throw()
      88             : {
      89             :     // Attention:
      90             :     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
      91             : 
      92             :     // Forward to baseclass
      93           0 :     OWeakObject::release();
      94           0 : }
      95             : 
      96             : //  XConnectionPoint
      97             : 
      98           0 : Type SAL_CALL OConnectionPointHelper::getConnectionType() throw( RuntimeException, std::exception )
      99             : {
     100             :     // Ready for multithreading
     101           0 :     MutexGuard aGuard( m_aSharedMutex );
     102             : 
     103             :     // Set default return value, if method failed.
     104           0 :     if ( !impl_LockContainer() )
     105             :     {
     106             :         // Container not exist! Its an runtime error.
     107           0 :         throw RuntimeException();
     108             :     }
     109             : 
     110             :     // If container reference valid, return right type of supported interfaces of THIS connectionpoint.
     111           0 :     Type aReturnType = m_aInterfaceType;
     112             :     // Don't forget this!
     113           0 :     impl_UnlockContainer();
     114             : 
     115           0 :     return aReturnType;
     116             : }
     117             : 
     118             : //  XConnectionPoint
     119             : 
     120           0 : Reference< XConnectionPointContainer > SAL_CALL OConnectionPointHelper::getConnectionPointContainer() throw( RuntimeException, std::exception )
     121             : {
     122             :     // Ready for multithreading
     123           0 :     MutexGuard aGuard( m_aSharedMutex );
     124             :     // Convert weakreference to correct uno3-reference and return value. It can be NULL, if container destroyed!
     125           0 :     return Reference< XConnectionPointContainer >( m_oContainerWeakReference.get(), UNO_QUERY );
     126             : }
     127             : 
     128             : //  XConnectionPoint
     129             : 
     130           0 : void SAL_CALL OConnectionPointHelper::advise( const Reference< XInterface >& xListener ) throw( ListenerExistException      ,
     131             :                                                                                                 InvalidListenerException    ,
     132             :                                                                                                 RuntimeException, std::exception            )
     133             : {
     134             :     // Ready for multithreading
     135           0 :     MutexGuard aGuard( m_aSharedMutex );
     136             : 
     137             :     // If type of listener not the same for this special container ...
     138           0 :     Any aCheckType = xListener->queryInterface( m_aInterfaceType );
     139           0 :     if ( aCheckType.hasValue() )
     140             :     {
     141             :         // ... throw an exception.
     142           0 :         throw InvalidListenerException();
     143             :     }
     144             : 
     145             :     // ListenerExistException is obsolete!?
     146             :     // Its the same container for XConnectionPointContainer and XConnectionPoint. But only here we must control, if a listener already exist!?
     147             :     // You can add a listener more then one time at XConnectionPointContainer, but here only one ...
     148             : 
     149             :     // Operation is permitted only, if reference to container is valid!
     150           0 :     if ( !impl_LockContainer() )
     151             :     {
     152             :         // Container not exist! Its an runtime error.
     153           0 :         throw RuntimeException();
     154             :     }
     155             :     // Forward it to OConnectionPointHelperContainer!
     156           0 :     m_pContainerImplementation->advise( m_aInterfaceType, xListener );
     157             :     // Don't forget this!
     158           0 :     impl_UnlockContainer();
     159           0 : }
     160             : 
     161             : //  XConnectionPoint
     162             : 
     163           0 : void SAL_CALL OConnectionPointHelper::unadvise( const Reference< XInterface >& xListener ) throw( RuntimeException, std::exception )
     164             : {
     165             :     // Ready for multithreading
     166           0 :     MutexGuard aGuard( m_aSharedMutex );
     167             :     // Operation is permitted only, if reference to container is valid!
     168           0 :     if ( !impl_LockContainer() )
     169             :     {
     170             :         // Container not exist! Its an runtime error.
     171           0 :         throw RuntimeException();
     172             : 
     173             :     }
     174             :     // Forward it to OConnectionPointHelperContainer!
     175           0 :     m_pContainerImplementation->unadvise( m_aInterfaceType, xListener );
     176             :     // Don't forget this!
     177           0 :     impl_UnlockContainer();
     178           0 : }
     179             : 
     180             : //  XConnectionPoint
     181             : 
     182           0 : Sequence< Reference< XInterface > > SAL_CALL OConnectionPointHelper::getConnections() throw( RuntimeException, std::exception )
     183             : {
     184             :     // Ready for multithreading
     185           0 :     MutexGuard aGuard( m_aSharedMutex );
     186             :     // Operation is permitted only, if reference to container is valid!
     187           0 :     if ( !impl_LockContainer() )
     188             :     {
     189             :         // Container not exist! Its an runtime error.
     190           0 :         throw RuntimeException();
     191             :     }
     192             :     // Set default return value, if method failed.
     193           0 :     Sequence< Reference< XInterface > > seqReturnConnections = Sequence< Reference< XInterface > >();
     194             :     // Get reference to private member of OConnectionPointHelperContainer!
     195           0 :     OMultiTypeInterfaceContainerHelper& aSharedContainer = m_pContainerImplementation->impl_getMultiTypeContainer();
     196             :     // Get pointer to specialized container which hold all interfaces of searched type.
     197           0 :     OInterfaceContainerHelper* pSpecialContainer = aSharedContainer.getContainer( m_aInterfaceType );
     198             :     // Get elements of searched type, if somelse exist.
     199           0 :     if ( pSpecialContainer != NULL )
     200             :     {
     201           0 :         seqReturnConnections = pSpecialContainer->getElements();
     202             :     }
     203             :     // Don't forget this!
     204           0 :     impl_UnlockContainer();
     205             : 
     206           0 :     return seqReturnConnections;
     207             : }
     208             : 
     209             : //  private method
     210             : 
     211           0 : bool OConnectionPointHelper::impl_LockContainer()
     212             : {
     213             :     // Convert weakreference to hard uno3-reference and return state.
     214             :     // If this reference different from NULL, there exist a hard reference to container. Container-instance can't be destroyed.
     215             :     // Don't forget to "unlock" this reference!
     216           0 :     m_xLock = m_oContainerWeakReference.get();
     217           0 :     return m_xLock.is();
     218             : }
     219             : 
     220             : //  private method
     221             : 
     222           0 : void OConnectionPointHelper::impl_UnlockContainer()
     223             : {
     224             :     // Free hard uno3-reference to container.
     225             :     // see also "impl_LockContainer()"
     226           0 :     m_xLock.clear();
     227           0 : }
     228             : 
     229             : }   // namespace unocontrols
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10