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

Generated by: LCOV version 1.10