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

Generated by: LCOV version 1.10