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

Generated by: LCOV version 1.10