Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <com/sun/star/frame/DoubleInitializationException.hpp>
22 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
23 :
24 : #include <comphelper_module.hxx>
25 :
26 : #include "documentiologring.hxx"
27 :
28 : using namespace ::com::sun::star;
29 :
30 : namespace comphelper
31 : {
32 :
33 : // ----------------------------------------------------------
34 13 : OSimpleLogRing::OSimpleLogRing()
35 : : m_aMessages( SIMPLELOGRING_SIZE )
36 : , m_bInitialized( sal_False )
37 : , m_bFull( sal_False )
38 13 : , m_nPos( 0 )
39 : {
40 13 : }
41 :
42 : // ----------------------------------------------------------
43 6 : OSimpleLogRing::~OSimpleLogRing()
44 : {
45 6 : }
46 :
47 : // ----------------------------------------------------------
48 28 : uno::Sequence< ::rtl::OUString > SAL_CALL OSimpleLogRing::getSupportedServiceNames_static()
49 : {
50 28 : uno::Sequence< rtl::OUString > aResult( 1 );
51 28 : aResult[0] = getServiceName_static();
52 28 : return aResult;
53 : }
54 :
55 : // ----------------------------------------------------------
56 28 : ::rtl::OUString SAL_CALL OSimpleLogRing::getImplementationName_static()
57 : {
58 28 : return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.logging.SimpleLogRing" ) );
59 : }
60 :
61 : // ----------------------------------------------------------
62 14 : ::rtl::OUString SAL_CALL OSimpleLogRing::getSingletonName_static()
63 : {
64 14 : return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.DocumentIOLogRing" ) );
65 : }
66 :
67 : // ----------------------------------------------------------
68 28 : ::rtl::OUString SAL_CALL OSimpleLogRing::getServiceName_static()
69 : {
70 28 : return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.logging.SimpleLogRing" ) );
71 : }
72 :
73 : // ----------------------------------------------------------
74 13 : uno::Reference< uno::XInterface > SAL_CALL OSimpleLogRing::Create( SAL_UNUSED_PARAMETER const uno::Reference< uno::XComponentContext >& )
75 : {
76 13 : return static_cast< cppu::OWeakObject* >( new OSimpleLogRing );
77 : }
78 :
79 : // XSimpleLogRing
80 : // ----------------------------------------------------------
81 2654 : void SAL_CALL OSimpleLogRing::logString( const ::rtl::OUString& aMessage ) throw (uno::RuntimeException)
82 : {
83 2654 : ::osl::MutexGuard aGuard( m_aMutex );
84 :
85 2654 : m_aMessages[m_nPos] = aMessage;
86 2654 : if ( ++m_nPos >= m_aMessages.getLength() )
87 : {
88 7 : m_nPos = 0;
89 7 : m_bFull = sal_True;
90 : }
91 :
92 : // if used once then default initialized
93 2654 : m_bInitialized = sal_True;
94 2654 : }
95 :
96 : // ----------------------------------------------------------
97 0 : uno::Sequence< ::rtl::OUString > SAL_CALL OSimpleLogRing::getCollectedLog() throw (uno::RuntimeException)
98 : {
99 0 : ::osl::MutexGuard aGuard( m_aMutex );
100 :
101 0 : sal_Int32 nResLen = m_bFull ? m_aMessages.getLength() : m_nPos;
102 0 : sal_Int32 nStart = m_bFull ? m_nPos : 0;
103 0 : uno::Sequence< ::rtl::OUString > aResult( nResLen );
104 :
105 0 : for ( sal_Int32 nInd = 0; nInd < nResLen; nInd++ )
106 0 : aResult[nInd] = m_aMessages[ ( nStart + nInd ) % m_aMessages.getLength() ];
107 :
108 : // if used once then default initialized
109 0 : m_bInitialized = sal_True;
110 :
111 0 : return aResult;
112 : }
113 :
114 : // XInitialization
115 : // ----------------------------------------------------------
116 0 : void SAL_CALL OSimpleLogRing::initialize( const uno::Sequence< uno::Any >& aArguments ) throw (uno::Exception, uno::RuntimeException)
117 : {
118 0 : ::osl::MutexGuard aGuard( m_aMutex );
119 0 : if ( m_bInitialized )
120 0 : throw frame::DoubleInitializationException();
121 :
122 0 : if ( !m_refCount )
123 0 : throw uno::RuntimeException(); // the object must be refcounted already!
124 :
125 0 : sal_Int32 nLen = 0;
126 0 : if ( aArguments.getLength() == 1 && ( aArguments[0] >>= nLen ) && nLen )
127 0 : m_aMessages.realloc( nLen );
128 : else
129 : throw lang::IllegalArgumentException(
130 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Nonnull size is expected as the first argument!" ) ),
131 : uno::Reference< uno::XInterface >(),
132 0 : 0 );
133 :
134 0 : m_bInitialized = sal_True;
135 0 : }
136 :
137 : // XServiceInfo
138 : // ----------------------------------------------------------
139 0 : ::rtl::OUString SAL_CALL OSimpleLogRing::getImplementationName() throw (uno::RuntimeException)
140 : {
141 0 : return getImplementationName_static();
142 : }
143 :
144 : // ----------------------------------------------------------
145 0 : ::sal_Bool SAL_CALL OSimpleLogRing::supportsService( const ::rtl::OUString& aServiceName ) throw (uno::RuntimeException)
146 : {
147 0 : const uno::Sequence< rtl::OUString > & aSupportedNames = getSupportedServiceNames_static();
148 0 : for ( sal_Int32 nInd = 0; nInd < aSupportedNames.getLength(); nInd++ )
149 : {
150 0 : if ( aSupportedNames[ nInd ].equals( aServiceName ) )
151 0 : return sal_True;
152 : }
153 :
154 0 : return sal_False;
155 : }
156 :
157 : // ----------------------------------------------------------
158 0 : uno::Sequence< ::rtl::OUString > SAL_CALL OSimpleLogRing::getSupportedServiceNames() throw (uno::RuntimeException)
159 : {
160 0 : return getSupportedServiceNames_static();
161 : }
162 :
163 : } // namespace comphelper
164 :
165 14 : void createRegistryInfo_OSimpleLogRing()
166 : {
167 14 : static ::comphelper::module::OAutoRegistration< ::comphelper::OSimpleLogRing > aAutoRegistration;
168 14 : static ::comphelper::module::OSingletonRegistration< ::comphelper::OSimpleLogRing > aSingletonRegistration;
169 14 : }
170 :
171 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|