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

Generated by: LCOV version 1.11