1*dde7d3faSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*dde7d3faSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*dde7d3faSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*dde7d3faSAndrew Rist * distributed with this work for additional information 6*dde7d3faSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*dde7d3faSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*dde7d3faSAndrew Rist * "License"); you may not use this file except in compliance 9*dde7d3faSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*dde7d3faSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*dde7d3faSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*dde7d3faSAndrew Rist * software distributed under the License is distributed on an 15*dde7d3faSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*dde7d3faSAndrew Rist * KIND, either express or implied. See the License for the 17*dde7d3faSAndrew Rist * specific language governing permissions and limitations 18*dde7d3faSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*dde7d3faSAndrew Rist *************************************************************/ 21*dde7d3faSAndrew Rist 22*dde7d3faSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_comphelper.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/frame/DoubleInitializationException.hpp> 28cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <comphelper_module.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include "documentiologring.hxx" 33cdf0e10cSrcweir 34cdf0e10cSrcweir using namespace ::com::sun::star; 35cdf0e10cSrcweir 36cdf0e10cSrcweir namespace comphelper 37cdf0e10cSrcweir { 38cdf0e10cSrcweir 39cdf0e10cSrcweir // ---------------------------------------------------------- 40cdf0e10cSrcweir OSimpleLogRing::OSimpleLogRing( const uno::Reference< uno::XComponentContext >& /*xContext*/ ) 41cdf0e10cSrcweir : m_aMessages( SIMPLELOGRING_SIZE ) 42cdf0e10cSrcweir , m_bInitialized( sal_False ) 43cdf0e10cSrcweir , m_bFull( sal_False ) 44cdf0e10cSrcweir , m_nPos( 0 ) 45cdf0e10cSrcweir { 46cdf0e10cSrcweir } 47cdf0e10cSrcweir 48cdf0e10cSrcweir // ---------------------------------------------------------- 49cdf0e10cSrcweir OSimpleLogRing::~OSimpleLogRing() 50cdf0e10cSrcweir { 51cdf0e10cSrcweir } 52cdf0e10cSrcweir 53cdf0e10cSrcweir // ---------------------------------------------------------- 54cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OSimpleLogRing::getSupportedServiceNames_static() 55cdf0e10cSrcweir { 56cdf0e10cSrcweir uno::Sequence< rtl::OUString > aResult( 1 ); 57cdf0e10cSrcweir aResult[0] = getServiceName_static(); 58cdf0e10cSrcweir return aResult; 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir // ---------------------------------------------------------- 62cdf0e10cSrcweir ::rtl::OUString SAL_CALL OSimpleLogRing::getImplementationName_static() 63cdf0e10cSrcweir { 64cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.logging.SimpleLogRing" ) ); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir // ---------------------------------------------------------- 68cdf0e10cSrcweir ::rtl::OUString SAL_CALL OSimpleLogRing::getSingletonName_static() 69cdf0e10cSrcweir { 70cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.DocumentIOLogRing" ) ); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir // ---------------------------------------------------------- 74cdf0e10cSrcweir ::rtl::OUString SAL_CALL OSimpleLogRing::getServiceName_static() 75cdf0e10cSrcweir { 76cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.SimpleLogRing" ) ); 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir // ---------------------------------------------------------- 80cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OSimpleLogRing::Create( const uno::Reference< uno::XComponentContext >& rxContext ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir return static_cast< cppu::OWeakObject* >( new OSimpleLogRing( rxContext ) ); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir // XSimpleLogRing 86cdf0e10cSrcweir // ---------------------------------------------------------- 87cdf0e10cSrcweir void SAL_CALL OSimpleLogRing::logString( const ::rtl::OUString& aMessage ) throw (uno::RuntimeException) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 90cdf0e10cSrcweir 91cdf0e10cSrcweir m_aMessages[m_nPos] = aMessage; 92cdf0e10cSrcweir if ( ++m_nPos >= m_aMessages.getLength() ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir m_nPos = 0; 95cdf0e10cSrcweir m_bFull = sal_True; 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir // if used once then default initialized 99cdf0e10cSrcweir m_bInitialized = sal_True; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir // ---------------------------------------------------------- 103cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OSimpleLogRing::getCollectedLog() throw (uno::RuntimeException) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir sal_Int32 nResLen = m_bFull ? m_aMessages.getLength() : m_nPos; 108cdf0e10cSrcweir sal_Int32 nStart = m_bFull ? m_nPos : 0; 109cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aResult( nResLen ); 110cdf0e10cSrcweir 111cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < nResLen; nInd++ ) 112cdf0e10cSrcweir aResult[nInd] = m_aMessages[ ( nStart + nInd ) % m_aMessages.getLength() ]; 113cdf0e10cSrcweir 114cdf0e10cSrcweir // if used once then default initialized 115cdf0e10cSrcweir m_bInitialized = sal_True; 116cdf0e10cSrcweir 117cdf0e10cSrcweir return aResult; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir // XInitialization 121cdf0e10cSrcweir // ---------------------------------------------------------- 122cdf0e10cSrcweir void SAL_CALL OSimpleLogRing::initialize( const uno::Sequence< uno::Any >& aArguments ) throw (uno::Exception, uno::RuntimeException) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 125cdf0e10cSrcweir if ( m_bInitialized ) 126cdf0e10cSrcweir throw frame::DoubleInitializationException(); 127cdf0e10cSrcweir 128cdf0e10cSrcweir if ( !m_refCount ) 129cdf0e10cSrcweir throw uno::RuntimeException(); // the object must be refcounted already! 130cdf0e10cSrcweir 131cdf0e10cSrcweir sal_Int32 nLen = 0; 132cdf0e10cSrcweir if ( aArguments.getLength() == 1 && ( aArguments[0] >>= nLen ) && nLen ) 133cdf0e10cSrcweir m_aMessages.realloc( nLen ); 134cdf0e10cSrcweir else 135cdf0e10cSrcweir throw lang::IllegalArgumentException( 136cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Nonnull size is expected as the first argument!" ) ), 137cdf0e10cSrcweir uno::Reference< uno::XInterface >(), 138cdf0e10cSrcweir 0 ); 139cdf0e10cSrcweir 140cdf0e10cSrcweir m_bInitialized = sal_True; 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir // XServiceInfo 144cdf0e10cSrcweir // ---------------------------------------------------------- 145cdf0e10cSrcweir ::rtl::OUString SAL_CALL OSimpleLogRing::getImplementationName() throw (uno::RuntimeException) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir return getImplementationName_static(); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir // ---------------------------------------------------------- 151cdf0e10cSrcweir ::sal_Bool SAL_CALL OSimpleLogRing::supportsService( const ::rtl::OUString& aServiceName ) throw (uno::RuntimeException) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir const uno::Sequence< rtl::OUString > & aSupportedNames = getSupportedServiceNames_static(); 154cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aSupportedNames.getLength(); nInd++ ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir if ( aSupportedNames[ nInd ].equals( aServiceName ) ) 157cdf0e10cSrcweir return sal_True; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir return sal_False; 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir // ---------------------------------------------------------- 164cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OSimpleLogRing::getSupportedServiceNames() throw (uno::RuntimeException) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir return getSupportedServiceNames_static(); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir } // namespace comphelper 170cdf0e10cSrcweir 171cdf0e10cSrcweir void createRegistryInfo_OSimpleLogRing() 172cdf0e10cSrcweir { 173cdf0e10cSrcweir static ::comphelper::module::OAutoRegistration< ::comphelper::OSimpleLogRing > aAutoRegistration; 174cdf0e10cSrcweir static ::comphelper::module::OSingletonRegistration< ::comphelper::OSimpleLogRing > aSingletonRegistration; 175cdf0e10cSrcweir } 176