1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlsCacheConfiguration.cxx,v $
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_sd.hxx"
34 #include "SlsCacheConfiguration.hxx"
35 #include <vos/mutex.hxx>
36 #include <vcl/svapp.hxx>
38 #include <comphelper/processfactory.hxx>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
41 #ifndef _COM_SUN_STAR_CONTAINER_PROPERTYVALUE_HPP_
42 #include <com/sun/star/beans/PropertyValue.hpp>
45 using namespace ::com::sun::star
;
46 using namespace ::com::sun::star::uno
;
48 namespace sd
{ namespace slidesorter
{ namespace cache
{
50 ::boost::shared_ptr
<CacheConfiguration
> CacheConfiguration::mpInstance
;
51 ::boost::weak_ptr
<CacheConfiguration
> CacheConfiguration::mpWeakInstance
;
52 Timer
CacheConfiguration::maReleaseTimer
;
56 ::boost::shared_ptr
<CacheConfiguration
> CacheConfiguration::Instance (void)
58 ::vos::OGuard
aSolarGuard (Application::GetSolarMutex());
59 if (mpInstance
.get() == NULL
)
61 // Maybe somebody else kept a previously created instance alive.
62 if ( ! mpWeakInstance
.expired())
63 mpInstance
= ::boost::shared_ptr
<CacheConfiguration
>(mpWeakInstance
);
64 if (mpInstance
.get() == NULL
)
66 // We have to create a new instance.
67 mpInstance
.reset(new CacheConfiguration());
68 mpWeakInstance
= mpInstance
;
69 // Prepare to release this instance in the near future.
70 maReleaseTimer
.SetTimeoutHdl(
71 LINK(mpInstance
.get(),CacheConfiguration
,TimerCallback
));
72 maReleaseTimer
.SetTimeout(5000 /* 5s */);
73 maReleaseTimer
.Start();
82 CacheConfiguration::CacheConfiguration (void)
84 // Get the cache size from configuration.
85 const ::rtl::OUString
sConfigurationProviderServiceName(
86 RTL_CONSTASCII_USTRINGPARAM(
87 "com.sun.star.configuration.ConfigurationProvider"));
88 const ::rtl::OUString
sPathToImpressConfigurationRoot(
89 RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Office.Impress/"));
90 const ::rtl::OUString
sPathToNode(
91 RTL_CONSTASCII_USTRINGPARAM(
92 "MultiPaneGUI/SlideSorter/PreviewCache"));
98 // Obtain access to the configuration.
99 Reference
<lang::XMultiServiceFactory
> xProvider (
100 ::comphelper::getProcessServiceFactory()->createInstance(
101 sConfigurationProviderServiceName
),
103 if ( ! xProvider
.is())
106 // Obtain access to Impress configuration.
107 Sequence
<Any
> aCreationArguments(3);
108 aCreationArguments
[0] = makeAny(beans::PropertyValue(
110 RTL_CONSTASCII_USTRINGPARAM("nodepath")),
112 makeAny(sPathToImpressConfigurationRoot
),
113 beans::PropertyState_DIRECT_VALUE
));
114 aCreationArguments
[1] = makeAny(beans::PropertyValue(
115 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("depth")),
117 makeAny((sal_Int32
)-1),
118 beans::PropertyState_DIRECT_VALUE
));
119 aCreationArguments
[2] = makeAny(beans::PropertyValue(
120 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("lazywrite")),
123 beans::PropertyState_DIRECT_VALUE
));
124 ::rtl::OUString
sAccessService (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
125 "com.sun.star.configuration.ConfigurationAccess")));
126 Reference
<XInterface
> xRoot (xProvider
->createInstanceWithArguments(
127 sAccessService
, aCreationArguments
));
130 Reference
<container::XHierarchicalNameAccess
> xHierarchy (xRoot
, UNO_QUERY
);
131 if ( ! xHierarchy
.is())
134 // Get the node for the slide sorter preview cache.
135 mxCacheNode
= Reference
<container::XNameAccess
>(
136 xHierarchy
->getByHierarchicalName(sPathToNode
),
141 catch (RuntimeException aException
)
145 catch (Exception aException
)
154 Any
CacheConfiguration::GetValue (const ::rtl::OUString
& rName
)
158 if (mxCacheNode
!= NULL
)
162 aResult
= mxCacheNode
->getByName(rName
);
164 catch (Exception aException
)
176 IMPL_LINK(CacheConfiguration
,TimerCallback
, Timer
*,EMPTYARG
)
178 // Release out reference to the instance.
184 } } } // end of namespace ::sd::slidesorter::cache