LCOV - code coverage report
Current view: top level - comphelper/source/misc - documentiologring.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 40 57 70.2 %
Date: 2015-06-13 12:38:46 Functions: 13 15 86.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             : 
      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         117 : OSimpleLogRing::OSimpleLogRing()
      37             : : m_aMessages( SIMPLELOGRING_SIZE )
      38             : , m_bInitialized( false )
      39             : , m_bFull( false )
      40         117 : , m_nPos( 0 )
      41             : {
      42         117 : }
      43             : 
      44             : 
      45         212 : OSimpleLogRing::~OSimpleLogRing()
      46             : {
      47         212 : }
      48             : 
      49             : 
      50         383 : uno::Sequence< OUString > SAL_CALL OSimpleLogRing::getSupportedServiceNames_static()
      51             : {
      52         383 :     uno::Sequence< OUString > aResult( 1 );
      53         383 :     aResult[0] = getServiceName_static();
      54         383 :     return aResult;
      55             : }
      56             : 
      57             : 
      58         383 : OUString SAL_CALL OSimpleLogRing::getImplementationName_static()
      59             : {
      60         383 :     return OUString( "com.sun.star.comp.logging.SimpleLogRing" );
      61             : }
      62             : 
      63             : 
      64         191 : OUString SAL_CALL OSimpleLogRing::getSingletonName_static()
      65             : {
      66         191 :     return OUString( "com.sun.star.logging.DocumentIOLogRing" );
      67             : }
      68             : 
      69             : 
      70         383 : OUString SAL_CALL OSimpleLogRing::getServiceName_static()
      71             : {
      72         383 :     return OUString( "com.sun.star.logging.SimpleLogRing" );
      73             : }
      74             : 
      75             : 
      76         117 : uno::Reference< uno::XInterface > SAL_CALL OSimpleLogRing::Create( SAL_UNUSED_PARAMETER const uno::Reference< uno::XComponentContext >& )
      77             : {
      78         117 :     return static_cast< cppu::OWeakObject* >( new OSimpleLogRing );
      79             : }
      80             : 
      81             : // XSimpleLogRing
      82             : 
      83       36381 : void SAL_CALL OSimpleLogRing::logString( const OUString& aMessage ) throw (uno::RuntimeException, std::exception)
      84             : {
      85       36381 :     ::osl::MutexGuard aGuard( m_aMutex );
      86             : 
      87       36381 :     m_aMessages[m_nPos] = aMessage;
      88       36381 :     if ( ++m_nPos >= m_aMessages.getLength() )
      89             :     {
      90         105 :         m_nPos = 0;
      91         105 :         m_bFull = true;
      92             :     }
      93             : 
      94             :     // if used once then default initialized
      95       36381 :     m_bInitialized = true;
      96       36381 : }
      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           1 : void SAL_CALL OSimpleLogRing::initialize( const uno::Sequence< uno::Any >& aArguments ) throw (uno::Exception, uno::RuntimeException, std::exception)
     119             : {
     120           1 :     ::osl::MutexGuard aGuard( m_aMutex );
     121           1 :     if ( m_bInitialized )
     122           0 :         throw frame::DoubleInitializationException();
     123             : 
     124           1 :     if ( !m_refCount )
     125           0 :         throw uno::RuntimeException(); // the object must be refcounted already!
     126             : 
     127           1 :     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           1 :     m_bInitialized = true;
     140           1 : }
     141             : 
     142             : // XServiceInfo
     143           1 : OUString SAL_CALL OSimpleLogRing::getImplementationName() throw (uno::RuntimeException, std::exception)
     144             : {
     145           1 :     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           1 : uno::Sequence< OUString > SAL_CALL OSimpleLogRing::getSupportedServiceNames() throw (uno::RuntimeException, std::exception)
     154             : {
     155           1 :     return getSupportedServiceNames_static();
     156             : }
     157             : 
     158             : } // namespace comphelper
     159             : 
     160         191 : void createRegistryInfo_OSimpleLogRing()
     161             : {
     162         191 :     static ::comphelper::module::OAutoRegistration< ::comphelper::OSimpleLogRing > aAutoRegistration;
     163         191 :     static ::comphelper::module::OSingletonRegistration< ::comphelper::OSimpleLogRing > aSingletonRegistration;
     164         191 : }
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11