LCOV - code coverage report
Current view: top level - sw/source/core/docnode - retrievedinputstreamdata.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 48 0.0 %
Date: 2014-04-14 Functions: 0 6 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 <retrievedinputstreamdata.hxx>
      21             : #include <retrieveinputstreamconsumer.hxx>
      22             : #include <vcl/svapp.hxx>
      23             : 
      24             : // #i73788#
      25             : 
      26             : SwRetrievedInputStreamDataManager::tDataKey SwRetrievedInputStreamDataManager::mnNextKeyValue = 1;
      27             : 
      28             : namespace
      29             : {
      30             :     class theSwRetrievedInputStreamDataManager :
      31             :         public rtl::Static< SwRetrievedInputStreamDataManager, theSwRetrievedInputStreamDataManager>
      32             :     {
      33             :     };
      34             : }
      35             : 
      36           0 : SwRetrievedInputStreamDataManager& SwRetrievedInputStreamDataManager::GetManager()
      37             : {
      38           0 :     return theSwRetrievedInputStreamDataManager::get();
      39             : }
      40             : 
      41           0 : SwRetrievedInputStreamDataManager::tDataKey SwRetrievedInputStreamDataManager::ReserveData(
      42             :                         boost::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > pThreadConsumer )
      43             : {
      44           0 :     osl::MutexGuard aGuard(maMutex);
      45             : 
      46             :     // create empty data container for given thread Consumer
      47           0 :     tDataKey nDataKey( mnNextKeyValue );
      48           0 :     tData aNewEntry( pThreadConsumer );
      49           0 :     maInputStreamData[ nDataKey ] = aNewEntry;
      50             : 
      51             :     // prepare next data key value
      52           0 :     if ( mnNextKeyValue < SAL_MAX_UINT64 )
      53             :     {
      54           0 :         ++mnNextKeyValue;
      55             :     }
      56             :     else
      57             :     {
      58           0 :         mnNextKeyValue = 1;
      59             :     }
      60             : 
      61           0 :     return nDataKey;
      62             : }
      63             : 
      64           0 : void SwRetrievedInputStreamDataManager::PushData(
      65             :         const tDataKey nDataKey,
      66             :         com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream,
      67             :         const sal_Bool bIsStreamReadOnly )
      68             : {
      69           0 :     osl::MutexGuard aGuard(maMutex);
      70             : 
      71           0 :     std::map< tDataKey, tData >::iterator aIter = maInputStreamData.find( nDataKey );
      72             : 
      73           0 :     if ( aIter != maInputStreamData.end() )
      74             :     {
      75             :         // Fill data container.
      76           0 :         (*aIter).second.mxInputStream = xInputStream;
      77           0 :         (*aIter).second.mbIsStreamReadOnly = bIsStreamReadOnly;
      78             : 
      79             :         // post user event to process the retrieved input stream data
      80           0 :         if ( GetpApp() )
      81             :         {
      82             : 
      83           0 :             tDataKey* pDataKey = new tDataKey;
      84           0 :             *pDataKey = nDataKey;
      85           0 :             GetpApp()->PostUserEvent( LINK( this, SwRetrievedInputStreamDataManager, LinkedInputStreamReady ), pDataKey );
      86             :         }
      87             :         else
      88             :         {
      89             :             // no application available -> discard data
      90           0 :             maInputStreamData.erase( aIter );
      91             :         }
      92           0 :     }
      93           0 : }
      94             : 
      95           0 : bool SwRetrievedInputStreamDataManager::PopData( const tDataKey nDataKey,
      96             :                                                  tData& rData )
      97             : {
      98           0 :     osl::MutexGuard aGuard(maMutex);
      99             : 
     100           0 :     bool bDataProvided( false );
     101             : 
     102           0 :     std::map< tDataKey, tData >::iterator aIter = maInputStreamData.find( nDataKey );
     103             : 
     104           0 :     if ( aIter != maInputStreamData.end() )
     105             :     {
     106           0 :         rData.mpThreadConsumer = (*aIter).second.mpThreadConsumer;
     107           0 :         rData.mxInputStream = (*aIter).second.mxInputStream;
     108           0 :         rData.mbIsStreamReadOnly = (*aIter).second.mbIsStreamReadOnly;
     109             : 
     110           0 :         maInputStreamData.erase( aIter );
     111             : 
     112           0 :         bDataProvided = true;
     113             :     }
     114             : 
     115           0 :     return bDataProvided;
     116             : }
     117             : 
     118             : /** callback function, which is triggered by input stream data manager on
     119             :     filling of the data container to provide retrieved input stream to the
     120             :     thread Consumer using <Application::PostUserEvent(..)>
     121             : 
     122             :     #i73788#
     123             :     Note: This method has to be run in the main thread.
     124             : */
     125           0 : IMPL_LINK( SwRetrievedInputStreamDataManager,
     126             :            LinkedInputStreamReady,
     127             :            SwRetrievedInputStreamDataManager::tDataKey*,
     128             :            pDataKey )
     129             : {
     130           0 :     if ( !pDataKey )
     131             :     {
     132           0 :         return 0;
     133             :     }
     134             : 
     135           0 :     osl::MutexGuard aGuard(maMutex);
     136             : 
     137             :     SwRetrievedInputStreamDataManager& rDataManager =
     138           0 :                             SwRetrievedInputStreamDataManager::GetManager();
     139           0 :     SwRetrievedInputStreamDataManager::tData aInputStreamData;
     140           0 :     if ( rDataManager.PopData( *pDataKey, aInputStreamData ) )
     141             :     {
     142             :         boost::shared_ptr< SwAsyncRetrieveInputStreamThreadConsumer > pThreadConsumer =
     143           0 :                                     aInputStreamData.mpThreadConsumer.lock();
     144           0 :         if ( pThreadConsumer )
     145             :         {
     146             :             pThreadConsumer->ApplyInputStream( aInputStreamData.mxInputStream,
     147           0 :                                                aInputStreamData.mbIsStreamReadOnly );
     148           0 :         }
     149             :     }
     150           0 :     delete pDataKey;
     151             : 
     152           0 :     return 0;
     153             : }
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10