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>
26 #include "documentiologring.hxx"
28 using namespace ::com::sun::star
;
33 // ----------------------------------------------------------
34 OSimpleLogRing::OSimpleLogRing()
35 : m_aMessages( SIMPLELOGRING_SIZE
)
36 , m_bInitialized( sal_False
)
37 , m_bFull( sal_False
)
42 // ----------------------------------------------------------
43 OSimpleLogRing::~OSimpleLogRing()
47 // ----------------------------------------------------------
48 uno::Sequence
< ::rtl::OUString
> SAL_CALL
OSimpleLogRing::getSupportedServiceNames_static()
50 uno::Sequence
< rtl::OUString
> aResult( 1 );
51 aResult
[0] = getServiceName_static();
55 // ----------------------------------------------------------
56 ::rtl::OUString SAL_CALL
OSimpleLogRing::getImplementationName_static()
58 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.logging.SimpleLogRing" ) );
61 // ----------------------------------------------------------
62 ::rtl::OUString SAL_CALL
OSimpleLogRing::getSingletonName_static()
64 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.DocumentIOLogRing" ) );
67 // ----------------------------------------------------------
68 ::rtl::OUString SAL_CALL
OSimpleLogRing::getServiceName_static()
70 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.SimpleLogRing" ) );
73 // ----------------------------------------------------------
74 uno::Reference
< uno::XInterface
> SAL_CALL
OSimpleLogRing::Create( SAL_UNUSED_PARAMETER
const uno::Reference
< uno::XComponentContext
>& )
76 return static_cast< cppu::OWeakObject
* >( new OSimpleLogRing
);
80 // ----------------------------------------------------------
81 void SAL_CALL
OSimpleLogRing::logString( const ::rtl::OUString
& aMessage
) throw (uno::RuntimeException
)
83 ::osl::MutexGuard
aGuard( m_aMutex
);
85 m_aMessages
[m_nPos
] = aMessage
;
86 if ( ++m_nPos
>= m_aMessages
.getLength() )
92 // if used once then default initialized
93 m_bInitialized
= sal_True
;
96 // ----------------------------------------------------------
97 uno::Sequence
< ::rtl::OUString
> SAL_CALL
OSimpleLogRing::getCollectedLog() throw (uno::RuntimeException
)
99 ::osl::MutexGuard
aGuard( m_aMutex
);
101 sal_Int32 nResLen
= m_bFull
? m_aMessages
.getLength() : m_nPos
;
102 sal_Int32 nStart
= m_bFull
? m_nPos
: 0;
103 uno::Sequence
< ::rtl::OUString
> aResult( nResLen
);
105 for ( sal_Int32 nInd
= 0; nInd
< nResLen
; nInd
++ )
106 aResult
[nInd
] = m_aMessages
[ ( nStart
+ nInd
) % m_aMessages
.getLength() ];
108 // if used once then default initialized
109 m_bInitialized
= sal_True
;
115 // ----------------------------------------------------------
116 void SAL_CALL
OSimpleLogRing::initialize( const uno::Sequence
< uno::Any
>& aArguments
) throw (uno::Exception
, uno::RuntimeException
)
118 ::osl::MutexGuard
aGuard( m_aMutex
);
119 if ( m_bInitialized
)
120 throw frame::DoubleInitializationException();
123 throw uno::RuntimeException(); // the object must be refcounted already!
126 if ( aArguments
.getLength() == 1 && ( aArguments
[0] >>= nLen
) && nLen
)
127 m_aMessages
.realloc( nLen
);
129 throw lang::IllegalArgumentException(
130 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Nonnull size is expected as the first argument!" ) ),
131 uno::Reference
< uno::XInterface
>(),
134 m_bInitialized
= sal_True
;
138 // ----------------------------------------------------------
139 ::rtl::OUString SAL_CALL
OSimpleLogRing::getImplementationName() throw (uno::RuntimeException
)
141 return getImplementationName_static();
144 // ----------------------------------------------------------
145 ::sal_Bool SAL_CALL
OSimpleLogRing::supportsService( const ::rtl::OUString
& aServiceName
) throw (uno::RuntimeException
)
147 const uno::Sequence
< rtl::OUString
> & aSupportedNames
= getSupportedServiceNames_static();
148 for ( sal_Int32 nInd
= 0; nInd
< aSupportedNames
.getLength(); nInd
++ )
150 if ( aSupportedNames
[ nInd
].equals( aServiceName
) )
157 // ----------------------------------------------------------
158 uno::Sequence
< ::rtl::OUString
> SAL_CALL
OSimpleLogRing::getSupportedServiceNames() throw (uno::RuntimeException
)
160 return getSupportedServiceNames_static();
163 } // namespace comphelper
165 void createRegistryInfo_OSimpleLogRing()
167 static ::comphelper::module::OAutoRegistration
< ::comphelper::OSimpleLogRing
> aAutoRegistration
;
168 static ::comphelper::module::OSingletonRegistration
< ::comphelper::OSimpleLogRing
> aSingletonRegistration
;
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */