LCOV - code coverage report
Current view: top level - ucbhelper/source/provider - resultsethelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 26 88 29.5 %
Date: 2014-11-03 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          76 : 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          76 :   m_xContext( rxContext )
      60             : {
      61          76 : }
      62             : 
      63             : 
      64             : // virtual
      65         152 : ResultSetImplHelper::~ResultSetImplHelper()
      66             : {
      67          76 :     delete m_pDisposeEventListeners;
      68          76 : }
      69             : 
      70             : 
      71             : 
      72             : // XInterface methods.
      73         302 : void SAL_CALL ResultSetImplHelper::acquire()
      74             :     throw()
      75             : {
      76         302 :     OWeakObject::acquire();
      77         302 : }
      78             : 
      79         302 : void SAL_CALL ResultSetImplHelper::release()
      80             :     throw()
      81             : {
      82         302 :     OWeakObject::release();
      83         302 : }
      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             :                                OUString(
     116             :                                    DYNAMICRESULTSET_SERVICE_NAME ) );
     117             : 
     118             : 
     119             : 
     120             : // XComponent methods.
     121             : 
     122             : 
     123             : 
     124             : // virtual
     125           0 : void SAL_CALL ResultSetImplHelper::dispose()
     126             :     throw( uno::RuntimeException, std::exception )
     127             : {
     128           0 :     osl::MutexGuard aGuard( m_aMutex );
     129             : 
     130           0 :     if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
     131             :     {
     132           0 :         lang::EventObject aEvt;
     133           0 :         aEvt.Source = static_cast< lang::XComponent * >( this );
     134           0 :         m_pDisposeEventListeners->disposeAndClear( aEvt );
     135           0 :     }
     136           0 : }
     137             : 
     138             : 
     139             : // virtual
     140           0 : void SAL_CALL ResultSetImplHelper::addEventListener(
     141             :         const uno::Reference< lang::XEventListener >& Listener )
     142             :     throw( uno::RuntimeException, std::exception )
     143             : {
     144           0 :     osl::MutexGuard aGuard( m_aMutex );
     145             : 
     146           0 :     if ( !m_pDisposeEventListeners )
     147             :         m_pDisposeEventListeners
     148           0 :             = new cppu::OInterfaceContainerHelper( m_aMutex );
     149             : 
     150           0 :     m_pDisposeEventListeners->addInterface( Listener );
     151           0 : }
     152             : 
     153             : 
     154             : // virtual
     155           0 : void SAL_CALL ResultSetImplHelper::removeEventListener(
     156             :         const uno::Reference< lang::XEventListener >& Listener )
     157             :     throw( uno::RuntimeException, std::exception )
     158             : {
     159           0 :     osl::MutexGuard aGuard( m_aMutex );
     160             : 
     161           0 :     if ( m_pDisposeEventListeners )
     162           0 :         m_pDisposeEventListeners->removeInterface( Listener );
     163           0 : }
     164             : 
     165             : 
     166             : 
     167             : // XDynamicResultSet methods.
     168             : 
     169             : 
     170             : 
     171             : // virtual
     172             : uno::Reference< sdbc::XResultSet > SAL_CALL
     173          76 : ResultSetImplHelper::getStaticResultSet()
     174             :     throw( com::sun::star::ucb::ListenerAlreadySetException,
     175             :            uno::RuntimeException, std::exception )
     176             : {
     177          76 :     osl::MutexGuard aGuard( m_aMutex );
     178             : 
     179          76 :     if ( m_xListener.is() )
     180           0 :         throw com::sun::star::ucb::ListenerAlreadySetException();
     181             : 
     182          76 :     init( true );
     183          76 :     return m_xResultSet1;
     184             : }
     185             : 
     186             : 
     187             : // virtual
     188           0 : void SAL_CALL ResultSetImplHelper::setListener(
     189             :         const uno::Reference< com::sun::star::ucb::XDynamicResultSetListener >&
     190             :             Listener )
     191             :     throw( com::sun::star::ucb::ListenerAlreadySetException,
     192             :            uno::RuntimeException, std::exception )
     193             : {
     194           0 :     osl::ClearableMutexGuard aGuard( m_aMutex );
     195             : 
     196           0 :     if ( m_bStatic || m_xListener.is() )
     197           0 :         throw com::sun::star::ucb::ListenerAlreadySetException();
     198             : 
     199           0 :     m_xListener = Listener;
     200             : 
     201             : 
     202             :     // Create "welcome event" and send it to listener.
     203             : 
     204             : 
     205             :     // Note: We only have the implementation for a static result set at the
     206             :     //       moment (src590). The dynamic result sets passed to the listener
     207             :     //       are a fake. This implementation will never call "notify" at the
     208             :     //       listener to propagate any changes!!!
     209             : 
     210           0 :     init( false );
     211             : 
     212           0 :     uno::Any aInfo;
     213           0 :     aInfo <<= com::sun::star::ucb::WelcomeDynamicResultSetStruct(
     214             :         m_xResultSet1 /* "old" */,
     215           0 :         m_xResultSet2 /* "new" */ );
     216             : 
     217           0 :     uno::Sequence< com::sun::star::ucb::ListAction > aActions( 1 );
     218             :     aActions.getArray()[ 0 ]
     219           0 :         = com::sun::star::ucb::ListAction(
     220             :             0, // Position; not used
     221             :             0, // Count; not used
     222             :             com::sun::star::ucb::ListActionType::WELCOME,
     223           0 :             aInfo );
     224           0 :     aGuard.clear();
     225             : 
     226           0 :     Listener->notify(
     227             :         com::sun::star::ucb::ListEvent(
     228           0 :             static_cast< cppu::OWeakObject * >( this ), aActions ) );
     229           0 : }
     230             : 
     231             : 
     232             : // virtual
     233           0 : sal_Int16 SAL_CALL ResultSetImplHelper::getCapabilities()
     234             :     throw( uno::RuntimeException, std::exception )
     235             : {
     236             :     // ! com::sun::star::ucb::ContentResultSetCapability::SORTED
     237           0 :     return 0;
     238             : }
     239             : 
     240             : 
     241             : // virtual
     242           0 : void SAL_CALL ResultSetImplHelper::connectToCache(
     243             :         const uno::Reference< com::sun::star::ucb::XDynamicResultSet > &
     244             :             xCache )
     245             :     throw( com::sun::star::ucb::ListenerAlreadySetException,
     246             :            com::sun::star::ucb::AlreadyInitializedException,
     247             :            com::sun::star::ucb::ServiceNotFoundException,
     248             :            uno::RuntimeException, std::exception )
     249             : {
     250           0 :     if ( m_xListener.is() )
     251           0 :         throw com::sun::star::ucb::ListenerAlreadySetException();
     252             : 
     253           0 :     if ( m_bStatic )
     254           0 :         throw com::sun::star::ucb::ListenerAlreadySetException();
     255             : 
     256             :     uno::Reference< com::sun::star::ucb::XSourceInitialization >
     257           0 :         xTarget( xCache, uno::UNO_QUERY );
     258           0 :     if ( xTarget.is() )
     259             :     {
     260             :         uno::Reference<
     261             :             com::sun::star::ucb::XCachedDynamicResultSetStubFactory >
     262           0 :                 xStubFactory;
     263             :         try
     264             :         {
     265             :             xStubFactory
     266           0 :                 = com::sun::star::ucb::CachedDynamicResultSetStubFactory::create(
     267           0 :                       m_xContext );
     268             :         }
     269           0 :         catch ( uno::Exception const & )
     270             :         {
     271             :         }
     272             : 
     273           0 :         if ( xStubFactory.is() )
     274             :         {
     275           0 :             xStubFactory->connectToCache(
     276           0 :                                   this, xCache, m_aCommand.SortingInfo, 0 );
     277           0 :             return;
     278           0 :         }
     279             :     }
     280           0 :     throw com::sun::star::ucb::ServiceNotFoundException();
     281             : }
     282             : 
     283             : 
     284             : 
     285             : // Non-interface methods.
     286             : 
     287             : 
     288             : 
     289          76 : void ResultSetImplHelper::init( bool bStatic )
     290             : {
     291          76 :     osl::MutexGuard aGuard( m_aMutex );
     292             : 
     293          76 :     if ( !m_bInitDone )
     294             :     {
     295          76 :         if ( bStatic )
     296             :         {
     297             :             // virtual... derived class fills m_xResultSet1
     298          76 :             initStatic();
     299             : 
     300             :             OSL_ENSURE( m_xResultSet1.is(),
     301             :                         "ResultSetImplHelper::init - No 1st result set!" );
     302          76 :             m_bStatic = true;
     303             :         }
     304             :         else
     305             :         {
     306             :             // virtual... derived class fills m_xResultSet1 and m_xResultSet2
     307           0 :             initDynamic();
     308             : 
     309             :             OSL_ENSURE( m_xResultSet1.is(),
     310             :                         "ResultSetImplHelper::init - No 1st result set!" );
     311             :             OSL_ENSURE( m_xResultSet2.is(),
     312             :                         "ResultSetImplHelper::init - No 2nd result set!" );
     313           0 :             m_bStatic = false;
     314             :         }
     315          76 :         m_bInitDone = true;
     316          76 :     }
     317          76 : }
     318             : 
     319             : } // namespace ucbhelper
     320             : 
     321             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10