1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <com/sun/star/frame/DoubleInitializationException.hpp>
22 #include <com/sun/star/lang/IllegalArgumentException.hpp>
24 #include <comphelper_module.hxx>
25 #include <comphelper_services.hxx>
26 #include <cppuhelper/supportsservice.hxx>
28 #include "documentiologring.hxx"
30 using namespace ::com::sun::star
;
36 OSimpleLogRing::OSimpleLogRing()
37 : m_aMessages( SIMPLELOGRING_SIZE
)
38 , m_bInitialized( false )
45 OSimpleLogRing::~OSimpleLogRing()
50 uno::Sequence
< OUString
> SAL_CALL
OSimpleLogRing::getSupportedServiceNames_static()
52 uno::Sequence
< OUString
> aResult( 1 );
53 aResult
[0] = getServiceName_static();
58 OUString SAL_CALL
OSimpleLogRing::getImplementationName_static()
60 return OUString( "com.sun.star.comp.logging.SimpleLogRing" );
64 OUString SAL_CALL
OSimpleLogRing::getSingletonName_static()
66 return OUString( "com.sun.star.logging.DocumentIOLogRing" );
70 OUString SAL_CALL
OSimpleLogRing::getServiceName_static()
72 return OUString( "com.sun.star.logging.SimpleLogRing" );
76 uno::Reference
< uno::XInterface
> SAL_CALL
OSimpleLogRing::Create( SAL_UNUSED_PARAMETER
const uno::Reference
< uno::XComponentContext
>& )
78 return static_cast< cppu::OWeakObject
* >( new OSimpleLogRing
);
83 void SAL_CALL
OSimpleLogRing::logString( const OUString
& aMessage
) throw (uno::RuntimeException
, std::exception
)
85 ::osl::MutexGuard
aGuard( m_aMutex
);
87 m_aMessages
[m_nPos
] = aMessage
;
88 if ( ++m_nPos
>= m_aMessages
.getLength() )
94 // if used once then default initialized
95 m_bInitialized
= true;
99 uno::Sequence
< OUString
> SAL_CALL
OSimpleLogRing::getCollectedLog() throw (uno::RuntimeException
, std::exception
)
101 ::osl::MutexGuard
aGuard( m_aMutex
);
103 sal_Int32 nResLen
= m_bFull
? m_aMessages
.getLength() : m_nPos
;
104 sal_Int32 nStart
= m_bFull
? m_nPos
: 0;
105 uno::Sequence
< OUString
> aResult( nResLen
);
107 for ( sal_Int32 nInd
= 0; nInd
< nResLen
; nInd
++ )
108 aResult
[nInd
] = m_aMessages
[ ( nStart
+ nInd
) % m_aMessages
.getLength() ];
110 // if used once then default initialized
111 m_bInitialized
= true;
118 void SAL_CALL
OSimpleLogRing::initialize( const uno::Sequence
< uno::Any
>& aArguments
) throw (uno::Exception
, uno::RuntimeException
, std::exception
)
120 ::osl::MutexGuard
aGuard( m_aMutex
);
121 if ( m_bInitialized
)
122 throw frame::DoubleInitializationException();
125 throw uno::RuntimeException(); // the object must be refcounted already!
127 if (aArguments
.hasElements())
130 if ( aArguments
.getLength() == 1 && ( aArguments
[0] >>= nLen
) && nLen
)
131 m_aMessages
.realloc( nLen
);
133 throw lang::IllegalArgumentException(
134 "Nonnull size is expected as the first argument!",
135 uno::Reference
< uno::XInterface
>(),
139 m_bInitialized
= true;
143 OUString SAL_CALL
OSimpleLogRing::getImplementationName() throw (uno::RuntimeException
, std::exception
)
145 return getImplementationName_static();
148 sal_Bool SAL_CALL
OSimpleLogRing::supportsService( const OUString
& aServiceName
) throw (uno::RuntimeException
, std::exception
)
150 return cppu::supportsService(this, aServiceName
);
153 uno::Sequence
< OUString
> SAL_CALL
OSimpleLogRing::getSupportedServiceNames() throw (uno::RuntimeException
, std::exception
)
155 return getSupportedServiceNames_static();
158 } // namespace comphelper
160 void createRegistryInfo_OSimpleLogRing()
162 static ::comphelper::module::OAutoRegistration
< ::comphelper::OSimpleLogRing
> aAutoRegistration
;
163 static ::comphelper::module::OSingletonRegistration
< ::comphelper::OSimpleLogRing
> aSingletonRegistration
;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */