1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
31 #include <com/sun/star/frame/DoubleInitializationException.hpp>
32 #include <com/sun/star/lang/IllegalArgumentException.hpp>
34 #include <comphelper_module.hxx>
36 #include "documentiologring.hxx"
38 using namespace ::com::sun::star
;
43 // ----------------------------------------------------------
44 OSimpleLogRing::OSimpleLogRing( const uno::Reference
< uno::XComponentContext
>& /*xContext*/ )
45 : m_aMessages( SIMPLELOGRING_SIZE
)
46 , m_bInitialized( sal_False
)
47 , m_bFull( sal_False
)
52 // ----------------------------------------------------------
53 OSimpleLogRing::~OSimpleLogRing()
57 // ----------------------------------------------------------
58 uno::Sequence
< ::rtl::OUString
> SAL_CALL
OSimpleLogRing::getSupportedServiceNames_static()
60 uno::Sequence
< rtl::OUString
> aResult( 1 );
61 aResult
[0] = getServiceName_static();
65 // ----------------------------------------------------------
66 ::rtl::OUString SAL_CALL
OSimpleLogRing::getImplementationName_static()
68 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.logging.SimpleLogRing" ) );
71 // ----------------------------------------------------------
72 ::rtl::OUString SAL_CALL
OSimpleLogRing::getSingletonName_static()
74 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.DocumentIOLogRing" ) );
77 // ----------------------------------------------------------
78 ::rtl::OUString SAL_CALL
OSimpleLogRing::getServiceName_static()
80 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.SimpleLogRing" ) );
83 // ----------------------------------------------------------
84 uno::Reference
< uno::XInterface
> SAL_CALL
OSimpleLogRing::Create( const uno::Reference
< uno::XComponentContext
>& rxContext
)
86 return static_cast< cppu::OWeakObject
* >( new OSimpleLogRing( rxContext
) );
90 // ----------------------------------------------------------
91 void SAL_CALL
OSimpleLogRing::logString( const ::rtl::OUString
& aMessage
) throw (uno::RuntimeException
)
93 ::osl::MutexGuard
aGuard( m_aMutex
);
95 m_aMessages
[m_nPos
] = aMessage
;
96 if ( ++m_nPos
>= m_aMessages
.getLength() )
102 // if used once then default initialized
103 m_bInitialized
= sal_True
;
106 // ----------------------------------------------------------
107 uno::Sequence
< ::rtl::OUString
> SAL_CALL
OSimpleLogRing::getCollectedLog() throw (uno::RuntimeException
)
109 ::osl::MutexGuard
aGuard( m_aMutex
);
111 sal_Int32 nResLen
= m_bFull
? m_aMessages
.getLength() : m_nPos
;
112 sal_Int32 nStart
= m_bFull
? m_nPos
: 0;
113 uno::Sequence
< ::rtl::OUString
> aResult( nResLen
);
115 for ( sal_Int32 nInd
= 0; nInd
< nResLen
; nInd
++ )
116 aResult
[nInd
] = m_aMessages
[ ( nStart
+ nInd
) % m_aMessages
.getLength() ];
118 // if used once then default initialized
119 m_bInitialized
= sal_True
;
125 // ----------------------------------------------------------
126 void SAL_CALL
OSimpleLogRing::initialize( const uno::Sequence
< uno::Any
>& aArguments
) throw (uno::Exception
, uno::RuntimeException
)
128 ::osl::MutexGuard
aGuard( m_aMutex
);
129 if ( m_bInitialized
)
130 throw frame::DoubleInitializationException();
133 throw uno::RuntimeException(); // the object must be refcounted already!
136 if ( aArguments
.getLength() == 1 && ( aArguments
[0] >>= nLen
) && nLen
)
137 m_aMessages
.realloc( nLen
);
139 throw lang::IllegalArgumentException(
140 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Nonnull size is expected as the first argument!" ) ),
141 uno::Reference
< uno::XInterface
>(),
144 m_bInitialized
= sal_True
;
148 // ----------------------------------------------------------
149 ::rtl::OUString SAL_CALL
OSimpleLogRing::getImplementationName() throw (uno::RuntimeException
)
151 return getImplementationName_static();
154 // ----------------------------------------------------------
155 ::sal_Bool SAL_CALL
OSimpleLogRing::supportsService( const ::rtl::OUString
& aServiceName
) throw (uno::RuntimeException
)
157 const uno::Sequence
< rtl::OUString
> & aSupportedNames
= getSupportedServiceNames_static();
158 for ( sal_Int32 nInd
= 0; nInd
< aSupportedNames
.getLength(); nInd
++ )
160 if ( aSupportedNames
[ nInd
].equals( aServiceName
) )
167 // ----------------------------------------------------------
168 uno::Sequence
< ::rtl::OUString
> SAL_CALL
OSimpleLogRing::getSupportedServiceNames() throw (uno::RuntimeException
)
170 return getSupportedServiceNames_static();
173 } // namespace comphelper
175 void createRegistryInfo_OSimpleLogRing()
177 static ::comphelper::module::OAutoRegistration
< ::comphelper::OSimpleLogRing
> aAutoRegistration
;
178 static ::comphelper::module::OSingletonRegistration
< ::comphelper::OSimpleLogRing
> aSingletonRegistration
;