LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/unotools - ucblockbytes.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 18 24 75.0 %
Date: 2013-07-09 Functions: 19 24 79.2 %
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             : #ifndef _UNTOOLS_UCBLOCKBYTES_HXX
      20             : #define _UNTOOLS_UCBLOCKBYTES_HXX
      21             : 
      22             : #include <com/sun/star/uno/Reference.hxx>
      23             : #include <com/sun/star/uno/Sequence.hxx>
      24             : #include <com/sun/star/ucb/XContent.hpp>
      25             : #include <com/sun/star/beans/PropertyValue.hpp>
      26             : #include "unotools/unotoolsdllapi.h"
      27             : 
      28             : #include <osl/thread.hxx>
      29             : #include <osl/conditn.hxx>
      30             : #include <osl/mutex.hxx>
      31             : #include <rtl/ustring.hxx>
      32             : #include <tools/stream.hxx>
      33             : #include <tools/link.hxx>
      34             : #include <tools/errcode.hxx>
      35             : #include <tools/datetime.hxx>
      36             : 
      37             : namespace com
      38             : {
      39             :     namespace sun
      40             :     {
      41             :         namespace star
      42             :         {
      43             :             namespace task
      44             :             {
      45             :                 class XInteractionHandler;
      46             :             }
      47             :             namespace io
      48             :             {
      49             :                 class XStream;
      50             :                 class XInputStream;
      51             :                 class XOutputStream;
      52             :                 class XSeekable;
      53             :             }
      54             :             namespace ucb
      55             :             {
      56             :                 class XContent;
      57             :             }
      58             :             namespace beans
      59             :             {
      60             :                 struct PropertyValue;
      61             :             }
      62             :         }
      63             :     }
      64             : }
      65             : 
      66             : namespace utl
      67             : {
      68      140064 : SV_DECL_REF( UcbLockBytes )
      69             : 
      70             : class UcbLockBytesHandler : public SvRefBase
      71             : {
      72             :     bool            m_bActive;
      73             : public:
      74             :     enum LoadHandlerItem
      75             :     {
      76             :         DATA_AVAILABLE,
      77             :         DONE,
      78             :         CANCEL
      79             :     };
      80             : 
      81             :                     UcbLockBytesHandler()
      82             :                         : m_bActive( sal_True )
      83             :                     {}
      84             : 
      85             :     virtual void    Handle( LoadHandlerItem nWhich, UcbLockBytesRef xLockBytes ) = 0;
      86             :     void            Activate( bool bActivate = true ) { m_bActive = bActivate; }
      87             :     bool            IsActive() const { return m_bActive; }
      88             : };
      89             : 
      90       78500 : SV_DECL_IMPL_REF( UcbLockBytesHandler )
      91             : 
      92             : class UNOTOOLS_DLLPUBLIC UcbLockBytes : public virtual SvLockBytes
      93             : {
      94             :     osl::Condition          m_aInitialized;
      95             :     osl::Condition          m_aTerminated;
      96             :     osl::Mutex              m_aMutex;
      97             : 
      98             :     OUString                m_aContentType;
      99             :     OUString                m_aRealURL;
     100             :     DateTime                m_aExpireDate;
     101             : 
     102             :     ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >  m_xInputStream;
     103             :     ::com::sun::star::uno::Reference < ::com::sun::star::io::XOutputStream > m_xOutputStream;
     104             :     ::com::sun::star::uno::Reference < ::com::sun::star::io::XSeekable >     m_xSeekable;
     105             :     void*                   m_pCommandThread; // is alive only for compatibility reasons
     106             :     UcbLockBytesHandlerRef  m_xHandler;
     107             : 
     108             :     sal_uInt32              m_nRead;
     109             :     sal_uInt32              m_nSize;
     110             :     ErrCode                 m_nError;
     111             : 
     112             :     bool                    m_bTerminated;
     113             :     bool                    m_bDontClose;
     114             :     bool                    m_bStreamValid;
     115             : 
     116             :     DECL_LINK(              DataAvailHdl, void * );
     117             : 
     118             :                             UcbLockBytes( UcbLockBytesHandler* pHandler=NULL );
     119             : protected:
     120             :     virtual                 ~UcbLockBytes (void);
     121             : 
     122             : public:
     123             :                             // properties: Referer, PostMimeType
     124             :     static UcbLockBytesRef  CreateLockBytes( const ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XContent >& xContent,
     125             :                                             const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >& rProps,
     126             :                                             StreamMode eMode,
     127             :                                             const ::com::sun::star::uno::Reference < ::com::sun::star::task::XInteractionHandler >& xInter,
     128             :                                             UcbLockBytesHandler* pHandler=0 );
     129             : 
     130             :     static UcbLockBytesRef  CreateInputLockBytes( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xContent );
     131             :     static UcbLockBytesRef  CreateLockBytes( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream >& xContent );
     132             : 
     133             :     // SvLockBytes
     134             :     virtual void            SetSynchronMode (bool bSynchron);
     135             :     virtual ErrCode         ReadAt ( sal_uLong nPos, void *pBuffer, sal_uLong nCount, sal_uLong *pRead) const;
     136             :     virtual ErrCode         WriteAt ( sal_uLong, const void*, sal_uLong, sal_uLong *pWritten);
     137             :     virtual ErrCode         Flush (void) const;
     138             :     virtual ErrCode         SetSize (sal_uLong);
     139             :     virtual ErrCode         Stat ( SvLockBytesStat *pStat, SvLockBytesStatFlag) const;
     140             : 
     141         127 :     void                    SetError( ErrCode nError )
     142         127 :                             { m_nError = nError; }
     143             : 
     144       38072 :     ErrCode                 GetError() const
     145       38072 :                             { return m_nError; }
     146             : 
     147             :     // the following properties are available when and after the first DataAvailable callback has been executed
     148             :     OUString                GetContentType() const;
     149             :     OUString                GetRealURL() const;
     150             :     DateTime                GetExpireDate() const;
     151             : 
     152             :     // calling this method delegates the responsibility to call closeinput to the caller!
     153             :     ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > getInputStream();
     154             : 
     155             :     bool                    setInputStream_Impl( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > &rxInputStream,
     156             :                                                  bool bSetXSeekable = true );
     157             :     bool                    setStream_Impl( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream > &rxStream );
     158             :     void                    terminate_Impl (void);
     159             : 
     160       72543 :     ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > getInputStream_Impl() const
     161             :                             {
     162       72543 :                                 osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
     163       72543 :                                 return m_xInputStream;
     164             :                             }
     165             : 
     166       34670 :     ::com::sun::star::uno::Reference < ::com::sun::star::io::XOutputStream > getOutputStream_Impl() const
     167             :                             {
     168       34670 :                                 osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
     169       34670 :                                 return m_xOutputStream;
     170             :                             }
     171             : 
     172       90740 :     ::com::sun::star::uno::Reference < ::com::sun::star::io::XSeekable > getSeekable_Impl() const
     173             :                             {
     174       90740 :                                 osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
     175       90740 :                                 return m_xSeekable;
     176             :                             }
     177             : 
     178           0 :     bool                    hasInputStream_Impl() const
     179             :                             {
     180           0 :                                 osl::MutexGuard aGuard( (const_cast< UcbLockBytes* >(this))->m_aMutex );
     181           0 :                                 return m_xInputStream.is();
     182             :                             }
     183             : 
     184        6463 :     void                    setDontClose_Impl()
     185        6463 :                             { m_bDontClose = sal_True; }
     186             : 
     187           0 :     void                    SetContentType_Impl( const OUString& rType ) { m_aContentType = rType; }
     188           0 :     void                    SetRealURL_Impl( const OUString& rURL )  { m_aRealURL = rURL; }
     189           0 :     void                    SetExpireDate_Impl( const DateTime& rDateTime )  { m_aExpireDate = rDateTime; }
     190             :     void                    SetStreamValid_Impl();
     191             : };
     192             : 
     193      161324 : SV_IMPL_REF( UcbLockBytes );
     194             : 
     195             : }
     196             : 
     197             : #endif
     198             : 
     199             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10