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

Generated by: LCOV version 1.11