LCOV - code coverage report
Current view: top level - comphelper/source/misc - documentiologring.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 36 57 63.2 %
Date: 2014-11-03 Functions: 11 15 73.3 %
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             : #include <com/sun/star/frame/DoubleInitializationException.hpp>
      22             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      23             : 
      24             : #include <comphelper_module.hxx>
      25             : #include <comphelper_services.hxx>
      26             : #include <cppuhelper/supportsservice.hxx>
      27             : 
      28             : #include "documentiologring.hxx"
      29             : 
      30             : using namespace ::com::sun::star;
      31             : 
      32             : namespace comphelper
      33             : {
      34             : 
      35             : 
      36         176 : OSimpleLogRing::OSimpleLogRing()
      37             : : m_aMessages( SIMPLELOGRING_SIZE )
      38             : , m_bInitialized( false )
      39             : , m_bFull( false )
      40         176 : , m_nPos( 0 )
      41             : {
      42         176 : }
      43             : 
      44             : 
      45         342 : OSimpleLogRing::~OSimpleLogRing()
      46             : {
      47         342 : }
      48             : 
      49             : 
      50         568 : uno::Sequence< OUString > SAL_CALL OSimpleLogRing::getSupportedServiceNames_static()
      51             : {
      52         568 :     uno::Sequence< OUString > aResult( 1 );
      53         568 :     aResult[0] = getServiceName_static();
      54         568 :     return aResult;
      55             : }
      56             : 
      57             : 
      58         568 : OUString SAL_CALL OSimpleLogRing::getImplementationName_static()
      59             : {
      60         568 :     return OUString( "com.sun.star.comp.logging.SimpleLogRing" );
      61             : }
      62             : 
      63             : 
      64         284 : OUString SAL_CALL OSimpleLogRing::getSingletonName_static()
      65             : {
      66         284 :     return OUString( "com.sun.star.logging.DocumentIOLogRing" );
      67             : }
      68             : 
      69             : 
      70         568 : OUString SAL_CALL OSimpleLogRing::getServiceName_static()
      71             : {
      72         568 :     return OUString( "com.sun.star.logging.SimpleLogRing" );
      73             : }
      74             : 
      75             : 
      76         176 : uno::Reference< uno::XInterface > SAL_CALL OSimpleLogRing::Create( SAL_UNUSED_PARAMETER const uno::Reference< uno::XComponentContext >& )
      77             : {
      78         176 :     return static_cast< cppu::OWeakObject* >( new OSimpleLogRing );
      79             : }
      80             : 
      81             : // XSimpleLogRing
      82             : 
      83       61690 : void SAL_CALL OSimpleLogRing::logString( const OUString& aMessage ) throw (uno::RuntimeException, std::exception)
      84             : {
      85       61690 :     ::osl::MutexGuard aGuard( m_aMutex );
      86             : 
      87       61690 :     m_aMessages[m_nPos] = aMessage;
      88       61690 :     if ( ++m_nPos >= m_aMessages.getLength() )
      89             :     {
      90         190 :         m_nPos = 0;
      91         190 :         m_bFull = true;
      92             :     }
      93             : 
      94             :     // if used once then default initialized
      95       61690 :     m_bInitialized = true;
      96       61690 : }
      97             : 
      98             : 
      99           0 : uno::Sequence< OUString > SAL_CALL OSimpleLogRing::getCollectedLog() throw (uno::RuntimeException, std::exception)
     100             : {
     101           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     102             : 
     103           0 :     sal_Int32 nResLen = m_bFull ? m_aMessages.getLength() : m_nPos;
     104           0 :     sal_Int32 nStart = m_bFull ? m_nPos : 0;
     105           0 :     uno::Sequence< OUString > aResult( nResLen );
     106             : 
     107           0 :     for ( sal_Int32 nInd = 0; nInd < nResLen; nInd++ )
     108           0 :         aResult[nInd] = m_aMessages[ ( nStart + nInd ) % m_aMessages.getLength() ];
     109             : 
     110             :     // if used once then default initialized
     111           0 :     m_bInitialized = true;
     112             : 
     113           0 :     return aResult;
     114             : }
     115             : 
     116             : // XInitialization
     117             : 
     118           2 : void SAL_CALL OSimpleLogRing::initialize( const uno::Sequence< uno::Any >& aArguments ) throw (uno::Exception, uno::RuntimeException, std::exception)
     119             : {
     120           2 :     ::osl::MutexGuard aGuard( m_aMutex );
     121           2 :     if ( m_bInitialized )
     122           0 :         throw frame::DoubleInitializationException();
     123             : 
     124           2 :     if ( !m_refCount )
     125           0 :         throw uno::RuntimeException(); // the object must be refcounted already!
     126             : 
     127           2 :     if (aArguments.hasElements())
     128             :     {
     129           0 :         sal_Int32 nLen = 0;
     130           0 :         if ( aArguments.getLength() == 1 && ( aArguments[0] >>= nLen ) && nLen )
     131           0 :             m_aMessages.realloc( nLen );
     132             :         else
     133             :             throw lang::IllegalArgumentException(
     134             :                 "Nonnull size is expected as the first argument!",
     135             :                 uno::Reference< uno::XInterface >(),
     136           0 :                 0 );
     137             :     }
     138             : 
     139           2 :     m_bInitialized = true;
     140           2 : }
     141             : 
     142             : // XServiceInfo
     143           0 : OUString SAL_CALL OSimpleLogRing::getImplementationName() throw (uno::RuntimeException, std::exception)
     144             : {
     145           0 :     return getImplementationName_static();
     146             : }
     147             : 
     148           0 : sal_Bool SAL_CALL OSimpleLogRing::supportsService( const OUString& aServiceName ) throw (uno::RuntimeException, std::exception)
     149             : {
     150           0 :     return cppu::supportsService(this, aServiceName);
     151             : }
     152             : 
     153           0 : uno::Sequence< OUString > SAL_CALL OSimpleLogRing::getSupportedServiceNames() throw (uno::RuntimeException, std::exception)
     154             : {
     155           0 :     return getSupportedServiceNames_static();
     156             : }
     157             : 
     158             : } // namespace comphelper
     159             : 
     160         284 : void createRegistryInfo_OSimpleLogRing()
     161             : {
     162         284 :     static ::comphelper::module::OAutoRegistration< ::comphelper::OSimpleLogRing > aAutoRegistration;
     163         284 :     static ::comphelper::module::OSingletonRegistration< ::comphelper::OSimpleLogRing > aSingletonRegistration;
     164         284 : }
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10