merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / config / cacheoptions.cxx
blob34a18f7ecb2e6faacdea4156db0bef2221eef110
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: cacheoptions.cxx,v $
10 * $Revision: 1.8 $
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_svtools.hxx"
33 #ifndef GCC
34 #endif
36 //_________________________________________________________________________________________________________________
37 // includes
38 //_________________________________________________________________________________________________________________
40 #include "cacheoptions.hxx"
41 #include <unotools/configmgr.hxx>
42 #include <unotools/configitem.hxx>
43 #include <tools/debug.hxx>
44 #include <com/sun/star/uno/Any.hxx>
45 #include <com/sun/star/uno/Sequence.hxx>
47 //_________________________________________________________________________________________________________________
48 // namespaces
49 //_________________________________________________________________________________________________________________
51 using namespace ::utl;
52 using namespace ::rtl;
53 using namespace ::osl;
54 using namespace ::com::sun::star::uno;
56 //_________________________________________________________________________________________________________________
57 // const
58 //_________________________________________________________________________________________________________________
60 #define ROOTNODE_START OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Cache" ))
61 #define DEFAULT_WRITEROLE 20
62 #define DEFAULT_DRAWINGOLE 20
63 #define DEFAULT_GRFMGR_TOTALSIZE 10000000
64 #define DEFAULT_GRFMGR_OBJECTSIZE 2400000
65 #define DEFAULT_GRFMGR_OBJECTRELEASE 600
67 #define PROPERTYNAME_WRITEROLE OUString(RTL_CONSTASCII_USTRINGPARAM("Writer/OLE_Objects"))
68 #define PROPERTYNAME_DRAWINGOLE OUString(RTL_CONSTASCII_USTRINGPARAM("DrawingEngine/OLE_Objects"))
69 #define PROPERTYNAME_GRFMGR_TOTALSIZE OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicManager/TotalCacheSize"))
70 #define PROPERTYNAME_GRFMGR_OBJECTSIZE OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicManager/ObjectCacheSize"))
71 #define PROPERTYNAME_GRFMGR_OBJECTRELEASE OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicManager/ObjectReleaseTime"))
73 #define PROPERTYHANDLE_WRITEROLE 0
74 #define PROPERTYHANDLE_DRAWINGOLE 1
75 #define PROPERTYHANDLE_GRFMGR_TOTALSIZE 2
76 #define PROPERTYHANDLE_GRFMGR_OBJECTSIZE 3
77 #define PROPERTYHANDLE_GRFMGR_OBJECTRELEASE 4
79 #define PROPERTYCOUNT 5
81 class SvtCacheOptions_Impl : public ConfigItem
83 public:
85 //---------------------------------------------------------------------------------------------------------
86 // constructor / destructor
87 //---------------------------------------------------------------------------------------------------------
89 SvtCacheOptions_Impl();
90 ~SvtCacheOptions_Impl();
92 //---------------------------------------------------------------------------------------------------------
93 // overloaded methods of baseclass
94 //---------------------------------------------------------------------------------------------------------
96 virtual void Commit();
98 //---------------------------------------------------------------------------------------------------------
99 // public interface
100 //---------------------------------------------------------------------------------------------------------
102 sal_Int32 GetWriterOLE_Objects() const;
103 sal_Int32 GetDrawingEngineOLE_Objects() const;
104 sal_Int32 GetGraphicManagerTotalCacheSize() const;
105 sal_Int32 GetGraphicManagerObjectCacheSize() const;
106 sal_Int32 GetGraphicManagerObjectReleaseTime() const;
108 void SetWriterOLE_Objects( sal_Int32 nObjects );
109 void SetDrawingEngineOLE_Objects( sal_Int32 nObjects );
110 void SetGraphicManagerTotalCacheSize( sal_Int32 nTotalCacheSize );
111 void SetGraphicManagerObjectCacheSize( sal_Int32 nObjectCacheSize );
112 void SetGraphicManagerObjectReleaseTime( sal_Int32 nReleaseTimeSeconds );
114 //-------------------------------------------------------------------------------------------------------------
115 // private methods
116 //-------------------------------------------------------------------------------------------------------------
118 private:
120 static Sequence< OUString > impl_GetPropertyNames();
122 //-------------------------------------------------------------------------------------------------------------
123 // private member
124 //-------------------------------------------------------------------------------------------------------------
126 private:
128 sal_Int32 mnWriterOLE;
129 sal_Int32 mnDrawingOLE;
130 sal_Int32 mnGrfMgrTotalSize;
131 sal_Int32 mnGrfMgrObjectSize;
132 sal_Int32 mnGrfMgrObjectRelease;
135 //_________________________________________________________________________________________________________________
136 // definitions
137 //_________________________________________________________________________________________________________________
139 //*****************************************************************************************************************
140 // constructor
141 //*****************************************************************************************************************
142 SvtCacheOptions_Impl::SvtCacheOptions_Impl() :
143 ConfigItem( ROOTNODE_START ),
144 mnWriterOLE( DEFAULT_WRITEROLE ),
145 mnDrawingOLE( DEFAULT_DRAWINGOLE ),
146 mnGrfMgrTotalSize( DEFAULT_GRFMGR_TOTALSIZE ),
147 mnGrfMgrObjectSize( DEFAULT_GRFMGR_OBJECTSIZE ),
148 mnGrfMgrObjectRelease( DEFAULT_GRFMGR_OBJECTRELEASE )
150 Sequence< OUString > seqNames( impl_GetPropertyNames() );
151 Sequence< Any > seqValues = GetProperties( seqNames ) ;
153 DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtCacheOptions_Impl::SvtCacheOptions_Impl()\nI miss some values of configuration keys!\n" );
155 // Copy values from list in right order to ouer internal member.
156 sal_Int32 nPropertyCount = seqValues.getLength();
157 sal_Int32 nProperty = 0;
159 for( nProperty=0; nProperty<nPropertyCount; ++nProperty )
161 if( seqValues[ nProperty ].hasValue() )
163 switch( nProperty )
165 case PROPERTYHANDLE_WRITEROLE:
167 if( seqValues[ nProperty ].getValueTypeClass() == TypeClass_LONG )
168 seqValues[nProperty] >>= mnWriterOLE;
170 break;
172 case PROPERTYHANDLE_DRAWINGOLE:
174 if( seqValues[ nProperty ].getValueTypeClass() == TypeClass_LONG )
175 seqValues[nProperty] >>= mnDrawingOLE;
177 break;
179 case PROPERTYHANDLE_GRFMGR_TOTALSIZE:
181 if( seqValues[ nProperty ].getValueTypeClass() == TypeClass_LONG )
182 seqValues[nProperty] >>= mnGrfMgrTotalSize;
184 break;
186 case PROPERTYHANDLE_GRFMGR_OBJECTSIZE:
188 if( seqValues[ nProperty ].getValueTypeClass() == TypeClass_LONG )
189 seqValues[nProperty] >>= mnGrfMgrObjectSize;
191 break;
193 case PROPERTYHANDLE_GRFMGR_OBJECTRELEASE:
195 if( seqValues[ nProperty ].getValueTypeClass() == TypeClass_LONG )
196 seqValues[nProperty] >>= mnGrfMgrObjectRelease;
198 break;
204 //*****************************************************************************************************************
205 // destructor
206 //*****************************************************************************************************************
207 SvtCacheOptions_Impl::~SvtCacheOptions_Impl()
209 if( IsModified() )
210 Commit();
213 //*****************************************************************************************************************
214 // Commit
215 //*****************************************************************************************************************
216 void SvtCacheOptions_Impl::Commit()
218 Sequence< OUString > aSeqNames( impl_GetPropertyNames() );
219 Sequence< Any > aSeqValues( aSeqNames.getLength() );
221 for( sal_Int32 nProperty = 0, nCount = aSeqNames.getLength(); nProperty < nCount; ++nProperty )
223 switch( nProperty )
225 case PROPERTYHANDLE_WRITEROLE:
226 aSeqValues[nProperty] <<= mnWriterOLE;
227 break;
229 case PROPERTYHANDLE_DRAWINGOLE:
230 aSeqValues[nProperty] <<= mnDrawingOLE;
231 break;
233 case PROPERTYHANDLE_GRFMGR_TOTALSIZE:
234 aSeqValues[nProperty] <<= mnGrfMgrTotalSize;
235 break;
237 case PROPERTYHANDLE_GRFMGR_OBJECTSIZE:
238 aSeqValues[nProperty] <<= mnGrfMgrObjectSize;
239 break;
241 case PROPERTYHANDLE_GRFMGR_OBJECTRELEASE:
242 aSeqValues[nProperty] <<= mnGrfMgrObjectRelease;
243 break;
247 PutProperties( aSeqNames, aSeqValues );
250 //*****************************************************************************************************************
251 // public method
252 //*****************************************************************************************************************
253 sal_Int32 SvtCacheOptions_Impl::GetWriterOLE_Objects() const
255 return mnWriterOLE;
258 //*****************************************************************************************************************
259 // public method
260 //*****************************************************************************************************************
261 sal_Int32 SvtCacheOptions_Impl::GetDrawingEngineOLE_Objects() const
263 return mnDrawingOLE;
266 //*****************************************************************************************************************
267 // public method
268 //*****************************************************************************************************************
269 sal_Int32 SvtCacheOptions_Impl::GetGraphicManagerTotalCacheSize() const
271 return mnGrfMgrTotalSize;
274 //*****************************************************************************************************************
275 // public method
276 //*****************************************************************************************************************
277 sal_Int32 SvtCacheOptions_Impl::GetGraphicManagerObjectCacheSize() const
279 return mnGrfMgrObjectSize;
282 //*****************************************************************************************************************
283 // public method
284 //*****************************************************************************************************************
285 sal_Int32 SvtCacheOptions_Impl::GetGraphicManagerObjectReleaseTime() const
287 return mnGrfMgrObjectRelease;
290 //*****************************************************************************************************************
291 // public method
292 //*****************************************************************************************************************
293 void SvtCacheOptions_Impl::SetWriterOLE_Objects( sal_Int32 nWriterOLE )
295 mnWriterOLE = nWriterOLE;
296 SetModified();
299 //*****************************************************************************************************************
300 // public method
301 //*****************************************************************************************************************
302 void SvtCacheOptions_Impl::SetDrawingEngineOLE_Objects( sal_Int32 nDrawingOLE )
304 mnDrawingOLE = nDrawingOLE;
305 SetModified();
308 //*****************************************************************************************************************
309 // public method
310 //*****************************************************************************************************************
311 void SvtCacheOptions_Impl::SetGraphicManagerTotalCacheSize( sal_Int32 nGrfMgrTotalSize )
313 mnGrfMgrTotalSize = nGrfMgrTotalSize;
314 SetModified();
317 //*****************************************************************************************************************
318 // public method
319 //*****************************************************************************************************************
320 void SvtCacheOptions_Impl::SetGraphicManagerObjectCacheSize( sal_Int32 nGrfMgrObjectSize )
322 mnGrfMgrObjectSize = nGrfMgrObjectSize;
323 SetModified();
326 //*****************************************************************************************************************
327 // public method
328 //*****************************************************************************************************************
329 void SvtCacheOptions_Impl::SetGraphicManagerObjectReleaseTime( sal_Int32 nGrfMgrObjectReleaseTime )
331 mnGrfMgrObjectRelease = nGrfMgrObjectReleaseTime;
332 SetModified();
335 //*****************************************************************************************************************
336 // private method
337 //*****************************************************************************************************************
338 Sequence< OUString > SvtCacheOptions_Impl::impl_GetPropertyNames()
340 // Build static list of configuration key names.
341 static const OUString pProperties[] =
343 PROPERTYNAME_WRITEROLE,
344 PROPERTYNAME_DRAWINGOLE,
345 PROPERTYNAME_GRFMGR_TOTALSIZE,
346 PROPERTYNAME_GRFMGR_OBJECTSIZE,
347 PROPERTYNAME_GRFMGR_OBJECTRELEASE
349 // Initialize return sequence with these list ...
350 static const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
351 // ... and return it.
352 return seqPropertyNames;
355 //*****************************************************************************************************************
356 // initialize static member
357 // DON'T DO IT IN YOUR HEADER!
358 // see definition for further informations
359 //*****************************************************************************************************************
360 SvtCacheOptions_Impl* SvtCacheOptions::m_pDataContainer = NULL;
361 sal_Int32 SvtCacheOptions::m_nRefCount = 0;
363 //*****************************************************************************************************************
364 // constructor
365 //*****************************************************************************************************************
366 SvtCacheOptions::SvtCacheOptions()
368 // Global access, must be guarded (multithreading!).
369 MutexGuard aGuard( GetOwnStaticMutex() );
370 // Increase ouer refcount ...
371 ++m_nRefCount;
372 // ... and initialize ouer data container only if it not already!
373 if( m_pDataContainer == NULL )
375 m_pDataContainer = new SvtCacheOptions_Impl();
379 //*****************************************************************************************************************
380 // destructor
381 //*****************************************************************************************************************
382 SvtCacheOptions::~SvtCacheOptions()
384 // Global access, must be guarded (multithreading!)
385 MutexGuard aGuard( GetOwnStaticMutex() );
386 // Decrease ouer refcount.
387 --m_nRefCount;
388 // If last instance was deleted ...
389 // we must destroy ouer static data container!
390 if( m_nRefCount <= 0 )
392 delete m_pDataContainer;
393 m_pDataContainer = NULL;
397 //*****************************************************************************************************************
398 // public method
399 //*****************************************************************************************************************
400 sal_Int32 SvtCacheOptions::GetWriterOLE_Objects() const
402 MutexGuard aGuard( GetOwnStaticMutex() );
403 return m_pDataContainer->GetWriterOLE_Objects();
406 //*****************************************************************************************************************
407 // public method
408 //*****************************************************************************************************************
409 sal_Int32 SvtCacheOptions::GetDrawingEngineOLE_Objects() const
411 MutexGuard aGuard( GetOwnStaticMutex() );
412 return m_pDataContainer->GetDrawingEngineOLE_Objects();
415 //*****************************************************************************************************************
416 // public method
417 //*****************************************************************************************************************
418 sal_Int32 SvtCacheOptions::GetGraphicManagerTotalCacheSize() const
420 MutexGuard aGuard( GetOwnStaticMutex() );
421 return m_pDataContainer->GetGraphicManagerTotalCacheSize();
424 //*****************************************************************************************************************
425 // public method
426 //*****************************************************************************************************************
427 sal_Int32 SvtCacheOptions::GetGraphicManagerObjectCacheSize() const
429 MutexGuard aGuard( GetOwnStaticMutex() );
430 return m_pDataContainer->GetGraphicManagerObjectCacheSize();
433 //*****************************************************************************************************************
434 // public method
435 //*****************************************************************************************************************
436 sal_Int32 SvtCacheOptions::GetGraphicManagerObjectReleaseTime() const
438 MutexGuard aGuard( GetOwnStaticMutex() );
439 return m_pDataContainer->GetGraphicManagerObjectReleaseTime();
442 //*****************************************************************************************************************
443 // public method
444 //*****************************************************************************************************************
445 void SvtCacheOptions::SetWriterOLE_Objects( sal_Int32 nWriterOLE )
447 MutexGuard aGuard( GetOwnStaticMutex() );
448 m_pDataContainer->SetWriterOLE_Objects( nWriterOLE );
451 //*****************************************************************************************************************
452 // public method
453 //*****************************************************************************************************************
454 void SvtCacheOptions::SetDrawingEngineOLE_Objects( sal_Int32 nDrawingOLE )
456 MutexGuard aGuard( GetOwnStaticMutex() );
457 m_pDataContainer->SetDrawingEngineOLE_Objects( nDrawingOLE );
460 //*****************************************************************************************************************
461 // public method
462 //*****************************************************************************************************************
463 void SvtCacheOptions::SetGraphicManagerTotalCacheSize( sal_Int32 nGrfMgrTotalSize )
465 MutexGuard aGuard( GetOwnStaticMutex() );
466 m_pDataContainer->SetGraphicManagerTotalCacheSize( nGrfMgrTotalSize );
469 //*****************************************************************************************************************
470 // public method
471 //*****************************************************************************************************************
472 void SvtCacheOptions::SetGraphicManagerObjectCacheSize( sal_Int32 nGrfMgrObjectSize )
474 MutexGuard aGuard( GetOwnStaticMutex() );
475 m_pDataContainer->SetGraphicManagerObjectCacheSize( nGrfMgrObjectSize );
478 //*****************************************************************************************************************
479 // public method
480 //*****************************************************************************************************************
481 void SvtCacheOptions::SetGraphicManagerObjectReleaseTime( sal_Int32 nGrfMgrObjectReleaseTime )
483 MutexGuard aGuard( GetOwnStaticMutex() );
484 m_pDataContainer->SetGraphicManagerObjectReleaseTime( nGrfMgrObjectReleaseTime );
487 //*****************************************************************************************************************
488 // private method
489 //*****************************************************************************************************************
490 Mutex& SvtCacheOptions::GetOwnStaticMutex()
492 // Initialize static mutex only for one time!
493 static Mutex* pMutex = NULL;
494 // If these method first called (Mutex not already exist!) ...
495 if( pMutex == NULL )
497 // ... we must create a new one. Protect follow code with the global mutex -
498 // It must be - we create a static variable!
499 MutexGuard aGuard( Mutex::getGlobalMutex() );
500 // We must check our pointer again - because it can be that another instance of ouer class will be fastr then these!
501 if( pMutex == NULL )
503 // Create the new mutex and set it for return on static variable.
504 static Mutex aMutex;
505 pMutex = &aMutex;
508 // Return new created or already existing mutex object.
509 return *pMutex;