LCOV - code coverage report
Current view: top level - ucbhelper/source/provider - resultsethelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 26 88 29.5 %
Date: 2015-06-13 12:38:46 Functions: 6 21 28.6 %
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             : 
      21             : /**************************************************************************
      22             :                                 TODO
      23             :  **************************************************************************
      24             : 
      25             :  - This implementation is far away from completion. It has no interface
      26             :    for changes notifications etc.
      27             : 
      28             :  *************************************************************************/
      29             : #include <com/sun/star/ucb/ListActionType.hpp>
      30             : #include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp>
      31             : #include <com/sun/star/ucb/CachedDynamicResultSetStubFactory.hpp>
      32             : #include <com/sun/star/ucb/XSourceInitialization.hpp>
      33             : #include <cppuhelper/interfacecontainer.hxx>
      34             : #include <ucbhelper/resultsethelper.hxx>
      35             : #include <ucbhelper/getcomponentcontext.hxx>
      36             : 
      37             : #include "osl/diagnose.h"
      38             : 
      39             : using namespace com::sun::star;
      40             : 
      41             : 
      42             : 
      43             : 
      44             : // ResultSetImplHelper Implementation.
      45             : 
      46             : 
      47             : 
      48             : 
      49             : namespace ucbhelper {
      50             : 
      51             : 
      52          55 : ResultSetImplHelper::ResultSetImplHelper(
      53             :     const uno::Reference< uno::XComponentContext >& rxContext,
      54             :     const com::sun::star::ucb::OpenCommandArgument2& rCommand )
      55             : : m_pDisposeEventListeners( 0 ),
      56             :   m_bStatic( false ),
      57             :   m_bInitDone( false ),
      58             :   m_aCommand( rCommand ),
      59          55 :   m_xContext( rxContext )
      60             : {
      61          55 : }
      62             : 
      63             : 
      64             : // virtual
      65         110 : ResultSetImplHelper::~ResultSetImplHelper()
      66             : {
      67          55 :     delete m_pDisposeEventListeners;
      68          55 : }
      69             : 
      70             : 
      71             : 
      72             : // XInterface methods.
      73         220 : void SAL_CALL ResultSetImplHelper::acquire()
      74             :     throw()
      75             : {
      76         220 :     OWeakObject::acquire();
      77         220 : }
      78             : 
      79         220 : void SAL_CALL ResultSetImplHelper::release()
      80             :     throw()
      81             : {
      82         220 :     OWeakObject::release();
      83         220 : }
      84             : 
      85           0 : css::uno::Any SAL_CALL ResultSetImplHelper::queryInterface( const css::uno::Type & rType )
      86             :     throw( css::uno::RuntimeException, std::exception )
      87             : {
      88             :     css::uno::Any aRet = cppu::queryInterface( rType,
      89             :                                                (static_cast< lang::XTypeProvider* >(this)),
      90             :                                                (static_cast< lang::XServiceInfo* >(this)),
      91             :                                                (static_cast< lang::XComponent* >(this)),
      92             :                                                (static_cast< css::ucb::XDynamicResultSet* >(this))
      93           0 :                                                );
      94           0 :     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
      95             : }
      96             : 
      97             : // XTypeProvider methods.
      98             : 
      99             : 
     100             : 
     101           0 : XTYPEPROVIDER_IMPL_3( ResultSetImplHelper,
     102             :                       lang::XTypeProvider,
     103             :                          lang::XServiceInfo,
     104             :                       com::sun::star::ucb::XDynamicResultSet );
     105             : 
     106             : 
     107             : 
     108             : // XServiceInfo methods.
     109             : 
     110             : 
     111             : 
     112           0 : XSERVICEINFO_NOFACTORY_IMPL_1( ResultSetImplHelper,
     113             :                                OUString(
     114             :                                    "ResultSetImplHelper" ),
     115             :                                DYNAMICRESULTSET_SERVICE_NAME );
     116             : 
     117             : 
     118             : 
     119             : // XComponent methods.
     120             : 
     121             : 
     122             : 
     123             : // virtual
     124           0 : void SAL_CALL ResultSetImplHelper::dispose()
     125             :     throw( uno::RuntimeException, std::exception )
     126             : {
     127           0 :     osl::MutexGuard aGuard( m_aMutex );
     128             : 
     129           0 :     if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
     130             :     {
     131           0 :         lang::EventObject aEvt;
     132           0 :         aEvt.Source = static_cast< lang::XComponent * >( this );
     133           0 :         m_pDisposeEventListeners->disposeAndClear( aEvt );
     134           0 :     }
     135           0 : }
     136             : 
     137             : 
     138             : // virtual
     139           0 : void SAL_CALL ResultSetImplHelper::addEventListener(
     140             :         const uno::Reference< lang::XEventListener >& Listener )
     141             :     throw( uno::RuntimeException, std::exception )
     142             : {
     143           0 :     osl::MutexGuard aGuard( m_aMutex );
     144             : 
     145           0 :     if ( !m_pDisposeEventListeners )
     146             :         m_pDisposeEventListeners
     147           0 :             = new cppu::OInterfaceContainerHelper( m_aMutex );
     148             : 
     149           0 :     m_pDisposeEventListeners->addInterface( Listener );
     150           0 : }
     151             : 
     152             : 
     153             : // virtual
     154           0 : void SAL_CALL ResultSetImplHelper::removeEventListener(
     155             :         const uno::Reference< lang::XEventListener >& Listener )
     156             :     throw( uno::RuntimeException, std::exception )
     157             : {
     158           0 :     osl::MutexGuard aGuard( m_aMutex );
     159             : 
     160           0 :     if ( m_pDisposeEventListeners )
     161           0 :         m_pDisposeEventListeners->removeInterface( Listener );
     162           0 : }
     163             : 
     164             : 
     165             : 
     166             : // XDynamicResultSet methods.
     167             : 
     168             : 
     169             : 
     170             : // virtual
     171             : uno::Reference< sdbc::XResultSet > SAL_CALL
     172          55 : ResultSetImplHelper::getStaticResultSet()
     173             :     throw( com::sun::star::ucb::ListenerAlreadySetException,
     174             :            uno::RuntimeException, std::exception )
     175             : {
     176          55 :     osl::MutexGuard aGuard( m_aMutex );
     177             : 
     178          55 :     if ( m_xListener.is() )
     179           0 :         throw com::sun::star::ucb::ListenerAlreadySetException();
     180             : 
     181          55 :     init( true );
     182          55 :     return m_xResultSet1;
     183             : }
     184             : 
     185             : 
     186             : // virtual
     187           0 : void SAL_CALL ResultSetImplHelper::setListener(
     188             :         const uno::Reference< com::sun::star::ucb::XDynamicResultSetListener >&
     189             :             Listener )
     190             :     throw( com::sun::star::ucb::ListenerAlreadySetException,
     191             :            uno::RuntimeException, std::exception )
     192             : {
     193           0 :     osl::ClearableMutexGuard aGuard( m_aMutex );
     194             : 
     195           0 :     if ( m_bStatic || m_xListener.is() )
     196           0 :         throw com::sun::star::ucb::ListenerAlreadySetException();
     197             : 
     198           0 :     m_xListener = Listener;
     199             : 
     200             : 
     201             :     // Create "welcome event" and send it to listener.
     202             : 
     203             : 
     204             :     // Note: We only have the implementation for a static result set at the
     205             :     //       moment (src590). The dynamic result sets passed to the listener
     206             :     //       are a fake. This implementation will never call "notify" at the
     207             :     //       listener to propagate any changes!!!
     208             : 
     209           0 :     init( false );
     210             : 
     211           0 :     uno::Any aInfo;
     212           0 :     aInfo <<= com::sun::star::ucb::WelcomeDynamicResultSetStruct(
     213             :         m_xResultSet1 /* "old" */,
     214           0 :         m_xResultSet2 /* "new" */ );
     215             : 
     216           0 :     uno::Sequence< com::sun::star::ucb::ListAction > aActions( 1 );
     217             :     aActions.getArray()[ 0 ]
     218           0 :         = com::sun::star::ucb::ListAction(
     219             :             0, // Position; not used
     220             :             0, // Count; not used
     221             :             com::sun::star::ucb::ListActionType::WELCOME,
     222           0 :             aInfo );
     223           0 :     aGuard.clear();
     224             : 
     225           0 :     Listener->notify(
     226             :         com::sun::star::ucb::ListEvent(
     227           0 :             static_cast< cppu::OWeakObject * >( this ), aActions ) );
     228           0 : }
     229             : 
     230             : 
     231             : // virtual
     232           0 : sal_Int16 SAL_CALL ResultSetImplHelper::getCapabilities()
     233             :     throw( uno::RuntimeException, std::exception )
     234             : {
     235             :     // ! com::sun::star::ucb::ContentResultSetCapability::SORTED
     236           0 :     return 0;
     237             : }
     238             : 
     239             : 
     240             : // virtual
     241           0 : void SAL_CALL ResultSetImplHelper::connectToCache(
     242             :         const uno::Reference< com::sun::star::ucb::XDynamicResultSet > &
     243             :             xCache )
     244             :     throw( com::sun::star::ucb::ListenerAlreadySetException,
     245             :            com::sun::star::ucb::AlreadyInitializedException,
     246             :            com::sun::star::ucb::ServiceNotFoundException,
     247             :            uno::RuntimeException, std::exception )
     248             : {
     249           0 :     if ( m_xListener.is() )
     250           0 :         throw com::sun::star::ucb::ListenerAlreadySetException();
     251             : 
     252           0 :     if ( m_bStatic )
     253           0 :         throw com::sun::star::ucb::ListenerAlreadySetException();
     254             : 
     255             :     uno::Reference< com::sun::star::ucb::XSourceInitialization >
     256           0 :         xTarget( xCache, uno::UNO_QUERY );
     257           0 :     if ( xTarget.is() )
     258             :     {
     259             :         uno::Reference<
     260             :             com::sun::star::ucb::XCachedDynamicResultSetStubFactory >
     261           0 :                 xStubFactory;
     262             :         try
     263             :         {
     264             :             xStubFactory
     265           0 :                 = com::sun::star::ucb::CachedDynamicResultSetStubFactory::create(
     266           0 :                       m_xContext );
     267             :         }
     268           0 :         catch ( uno::Exception const & )
     269             :         {
     270             :         }
     271             : 
     272           0 :         if ( xStubFactory.is() )
     273             :         {
     274           0 :             xStubFactory->connectToCache(
     275           0 :                                   this, xCache, m_aCommand.SortingInfo, 0 );
     276           0 :             return;
     277           0 :         }
     278             :     }
     279           0 :     throw com::sun::star::ucb::ServiceNotFoundException();
     280             : }
     281             : 
     282             : 
     283             : 
     284             : // Non-interface methods.
     285             : 
     286             : 
     287             : 
     288          55 : void ResultSetImplHelper::init( bool bStatic )
     289             : {
     290          55 :     osl::MutexGuard aGuard( m_aMutex );
     291             : 
     292          55 :     if ( !m_bInitDone )
     293             :     {
     294          55 :         if ( bStatic )
     295             :         {
     296             :             // virtual... derived class fills m_xResultSet1
     297          55 :             initStatic();
     298             : 
     299             :             OSL_ENSURE( m_xResultSet1.is(),
     300             :                         "ResultSetImplHelper::init - No 1st result set!" );
     301          55 :             m_bStatic = true;
     302             :         }
     303             :         else
     304             :         {
     305             :             // virtual... derived class fills m_xResultSet1 and m_xResultSet2
     306           0 :             initDynamic();
     307             : 
     308             :             OSL_ENSURE( m_xResultSet1.is(),
     309             :                         "ResultSetImplHelper::init - No 1st result set!" );
     310             :             OSL_ENSURE( m_xResultSet2.is(),
     311             :                         "ResultSetImplHelper::init - No 2nd result set!" );
     312           0 :             m_bStatic = false;
     313             :         }
     314          55 :         m_bInitDone = true;
     315          55 :     }
     316          55 : }
     317             : 
     318             : } // namespace ucbhelper
     319             : 
     320             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11