merge the formfield patch from ooo-build
[ooovba.git] / comphelper / source / misc / documentiologring.cxx
blob7969b938e10808eb723954c9254849165773ae44
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: documentiologring.hxx,v $
10 * $Revision: 1.0 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_comphelper.hxx"
34 #include <com/sun/star/frame/DoubleInitializationException.hpp>
35 #include <com/sun/star/lang/IllegalArgumentException.hpp>
37 #include "documentiologring.hxx"
39 using namespace ::com::sun::star;
41 namespace comphelper
44 // ----------------------------------------------------------
45 OSimpleLogRing::OSimpleLogRing( const uno::Reference< uno::XComponentContext >& /*xContext*/ )
46 : m_aMessages( SIMPLELOGRING_SIZE )
47 , m_bInitialized( sal_False )
48 , m_bFull( sal_False )
49 , m_nPos( 0 )
53 // ----------------------------------------------------------
54 OSimpleLogRing::~OSimpleLogRing()
58 // ----------------------------------------------------------
59 uno::Sequence< ::rtl::OUString > SAL_CALL OSimpleLogRing::impl_staticGetSupportedServiceNames()
61 uno::Sequence< rtl::OUString > aResult( 1 );
62 aResult[0] = impl_staticGetServiceName();
63 return aResult;
66 // ----------------------------------------------------------
67 ::rtl::OUString SAL_CALL OSimpleLogRing::impl_staticGetImplementationName()
69 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.logging.SimpleLogRing" ) );
72 // ----------------------------------------------------------
73 ::rtl::OUString SAL_CALL OSimpleLogRing::impl_staticGetSingletonName()
75 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.DocumentIOLogRing" ) );
78 // ----------------------------------------------------------
79 ::rtl::OUString SAL_CALL OSimpleLogRing::impl_staticGetServiceName()
81 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.SimpleLogRing" ) );
84 // ----------------------------------------------------------
85 uno::Reference< uno::XInterface > SAL_CALL OSimpleLogRing::impl_staticCreateSelfInstance( const uno::Reference< uno::XComponentContext >& rxContext )
87 return static_cast< cppu::OWeakObject* >( new OSimpleLogRing( rxContext ) );
90 // XSimpleLogRing
91 // ----------------------------------------------------------
92 void SAL_CALL OSimpleLogRing::logString( const ::rtl::OUString& aMessage ) throw (uno::RuntimeException)
94 ::osl::MutexGuard aGuard( m_aMutex );
96 m_aMessages[m_nPos] = aMessage;
97 if ( ++m_nPos >= m_aMessages.getLength() )
99 m_nPos = 0;
100 m_bFull = sal_True;
103 // if used once then default initialized
104 m_bInitialized = sal_True;
107 // ----------------------------------------------------------
108 uno::Sequence< ::rtl::OUString > SAL_CALL OSimpleLogRing::getCollectedLog() throw (uno::RuntimeException)
110 ::osl::MutexGuard aGuard( m_aMutex );
112 sal_Int32 nResLen = m_bFull ? m_aMessages.getLength() : m_nPos;
113 sal_Int32 nStart = m_bFull ? m_nPos : 0;
114 uno::Sequence< ::rtl::OUString > aResult( nResLen );
116 for ( sal_Int32 nInd = 0; nInd < nResLen; nInd++ )
117 aResult[nInd] = m_aMessages[ ( nStart + nInd ) % m_aMessages.getLength() ];
119 // if used once then default initialized
120 m_bInitialized = sal_True;
122 return aResult;
125 // XInitialization
126 // ----------------------------------------------------------
127 void SAL_CALL OSimpleLogRing::initialize( const uno::Sequence< uno::Any >& aArguments ) throw (uno::Exception, uno::RuntimeException)
129 ::osl::MutexGuard aGuard( m_aMutex );
130 if ( m_bInitialized )
131 throw frame::DoubleInitializationException();
133 if ( !m_refCount )
134 throw uno::RuntimeException(); // the object must be refcounted already!
136 sal_Int32 nLen = 0;
137 if ( aArguments.getLength() == 1 && ( aArguments[0] >>= nLen ) && nLen )
138 m_aMessages.realloc( nLen );
139 else
140 throw lang::IllegalArgumentException(
141 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Nonnull size is expected as the first argument!" ) ),
142 uno::Reference< uno::XInterface >(),
143 0 );
145 m_bInitialized = sal_True;
148 // XServiceInfo
149 // ----------------------------------------------------------
150 ::rtl::OUString SAL_CALL OSimpleLogRing::getImplementationName() throw (uno::RuntimeException)
152 return impl_staticGetImplementationName();
155 // ----------------------------------------------------------
156 ::sal_Bool SAL_CALL OSimpleLogRing::supportsService( const ::rtl::OUString& aServiceName ) throw (uno::RuntimeException)
158 const uno::Sequence< rtl::OUString > & aSupportedNames = impl_staticGetSupportedServiceNames();
159 for ( sal_Int32 nInd = 0; nInd < aSupportedNames.getLength(); nInd++ )
161 if ( aSupportedNames[ nInd ].equals( aServiceName ) )
162 return sal_True;
165 return sal_False;
168 // ----------------------------------------------------------
169 uno::Sequence< ::rtl::OUString > SAL_CALL OSimpleLogRing::getSupportedServiceNames() throw (uno::RuntimeException)
171 return impl_staticGetSupportedServiceNames();
174 } // namespace comphelper