1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*5b190011SAndrew Rist * distributed with this work for additional information
6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at
10*5b190011SAndrew Rist *
11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist *
13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist * software distributed under the License is distributed on an
15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the
17*5b190011SAndrew Rist * specific language governing permissions and limitations
18*5b190011SAndrew Rist * under the License.
19*5b190011SAndrew Rist *
20*5b190011SAndrew Rist *************************************************************/
21*5b190011SAndrew Rist
22*5b190011SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "SlsCacheConfiguration.hxx"
28cdf0e10cSrcweir #include <vos/mutex.hxx>
29cdf0e10cSrcweir #include <vcl/svapp.hxx>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
32cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
34cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_PROPERTYVALUE_HPP_
35cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir
38cdf0e10cSrcweir using namespace ::com::sun::star;
39cdf0e10cSrcweir using namespace ::com::sun::star::uno;
40cdf0e10cSrcweir
41cdf0e10cSrcweir namespace sd { namespace slidesorter { namespace cache {
42cdf0e10cSrcweir
43cdf0e10cSrcweir ::boost::shared_ptr<CacheConfiguration> CacheConfiguration::mpInstance;
44cdf0e10cSrcweir ::boost::weak_ptr<CacheConfiguration> CacheConfiguration::mpWeakInstance;
45cdf0e10cSrcweir Timer CacheConfiguration::maReleaseTimer;
46cdf0e10cSrcweir
47cdf0e10cSrcweir
48cdf0e10cSrcweir
Instance(void)49cdf0e10cSrcweir ::boost::shared_ptr<CacheConfiguration> CacheConfiguration::Instance (void)
50cdf0e10cSrcweir {
51cdf0e10cSrcweir ::vos::OGuard aSolarGuard (Application::GetSolarMutex());
52cdf0e10cSrcweir if (mpInstance.get() == NULL)
53cdf0e10cSrcweir {
54cdf0e10cSrcweir // Maybe somebody else kept a previously created instance alive.
55cdf0e10cSrcweir if ( ! mpWeakInstance.expired())
56cdf0e10cSrcweir mpInstance = ::boost::shared_ptr<CacheConfiguration>(mpWeakInstance);
57cdf0e10cSrcweir if (mpInstance.get() == NULL)
58cdf0e10cSrcweir {
59cdf0e10cSrcweir // We have to create a new instance.
60cdf0e10cSrcweir mpInstance.reset(new CacheConfiguration());
61cdf0e10cSrcweir mpWeakInstance = mpInstance;
62cdf0e10cSrcweir // Prepare to release this instance in the near future.
63cdf0e10cSrcweir maReleaseTimer.SetTimeoutHdl(
64cdf0e10cSrcweir LINK(mpInstance.get(),CacheConfiguration,TimerCallback));
65cdf0e10cSrcweir maReleaseTimer.SetTimeout(5000 /* 5s */);
66cdf0e10cSrcweir maReleaseTimer.Start();
67cdf0e10cSrcweir }
68cdf0e10cSrcweir }
69cdf0e10cSrcweir return mpInstance;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
72cdf0e10cSrcweir
73cdf0e10cSrcweir
74cdf0e10cSrcweir
CacheConfiguration(void)75cdf0e10cSrcweir CacheConfiguration::CacheConfiguration (void)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir // Get the cache size from configuration.
78cdf0e10cSrcweir const ::rtl::OUString sConfigurationProviderServiceName(
79cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
80cdf0e10cSrcweir "com.sun.star.configuration.ConfigurationProvider"));
81cdf0e10cSrcweir const ::rtl::OUString sPathToImpressConfigurationRoot(
82cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Office.Impress/"));
83cdf0e10cSrcweir const ::rtl::OUString sPathToNode(
84cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
85cdf0e10cSrcweir "MultiPaneGUI/SlideSorter/PreviewCache"));
86cdf0e10cSrcweir
87cdf0e10cSrcweir try
88cdf0e10cSrcweir {
89cdf0e10cSrcweir do
90cdf0e10cSrcweir {
91cdf0e10cSrcweir // Obtain access to the configuration.
92cdf0e10cSrcweir Reference<lang::XMultiServiceFactory> xProvider (
93cdf0e10cSrcweir ::comphelper::getProcessServiceFactory()->createInstance(
94cdf0e10cSrcweir sConfigurationProviderServiceName),
95cdf0e10cSrcweir UNO_QUERY);
96cdf0e10cSrcweir if ( ! xProvider.is())
97cdf0e10cSrcweir break;
98cdf0e10cSrcweir
99cdf0e10cSrcweir // Obtain access to Impress configuration.
100cdf0e10cSrcweir Sequence<Any> aCreationArguments(3);
101cdf0e10cSrcweir aCreationArguments[0] = makeAny(beans::PropertyValue(
102cdf0e10cSrcweir ::rtl::OUString(
103cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("nodepath")),
104cdf0e10cSrcweir 0,
105cdf0e10cSrcweir makeAny(sPathToImpressConfigurationRoot),
106cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE));
107cdf0e10cSrcweir aCreationArguments[1] = makeAny(beans::PropertyValue(
108cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("depth")),
109cdf0e10cSrcweir 0,
110cdf0e10cSrcweir makeAny((sal_Int32)-1),
111cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE));
112cdf0e10cSrcweir aCreationArguments[2] = makeAny(beans::PropertyValue(
113cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("lazywrite")),
114cdf0e10cSrcweir 0,
115cdf0e10cSrcweir makeAny(true),
116cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE));
117cdf0e10cSrcweir ::rtl::OUString sAccessService (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
118cdf0e10cSrcweir "com.sun.star.configuration.ConfigurationAccess")));
119cdf0e10cSrcweir Reference<XInterface> xRoot (xProvider->createInstanceWithArguments(
120cdf0e10cSrcweir sAccessService, aCreationArguments));
121cdf0e10cSrcweir if ( ! xRoot.is())
122cdf0e10cSrcweir break;
123cdf0e10cSrcweir Reference<container::XHierarchicalNameAccess> xHierarchy (xRoot, UNO_QUERY);
124cdf0e10cSrcweir if ( ! xHierarchy.is())
125cdf0e10cSrcweir break;
126cdf0e10cSrcweir
127cdf0e10cSrcweir // Get the node for the slide sorter preview cache.
128cdf0e10cSrcweir mxCacheNode = Reference<container::XNameAccess>(
129cdf0e10cSrcweir xHierarchy->getByHierarchicalName(sPathToNode),
130cdf0e10cSrcweir UNO_QUERY);
131cdf0e10cSrcweir }
132cdf0e10cSrcweir while (false);
133cdf0e10cSrcweir }
134cdf0e10cSrcweir catch (RuntimeException aException)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir (void)aException;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir catch (Exception aException)
139cdf0e10cSrcweir {
140cdf0e10cSrcweir (void)aException;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir }
143cdf0e10cSrcweir
144cdf0e10cSrcweir
145cdf0e10cSrcweir
146cdf0e10cSrcweir
GetValue(const::rtl::OUString & rName)147cdf0e10cSrcweir Any CacheConfiguration::GetValue (const ::rtl::OUString& rName)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir Any aResult;
150cdf0e10cSrcweir
151cdf0e10cSrcweir if (mxCacheNode != NULL)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir try
154cdf0e10cSrcweir {
155cdf0e10cSrcweir aResult = mxCacheNode->getByName(rName);
156cdf0e10cSrcweir }
157cdf0e10cSrcweir catch (Exception aException)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir (void)aException;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir }
162cdf0e10cSrcweir
163cdf0e10cSrcweir return aResult;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
166cdf0e10cSrcweir
167cdf0e10cSrcweir
168cdf0e10cSrcweir
IMPL_LINK(CacheConfiguration,TimerCallback,Timer *,EMPTYARG)169cdf0e10cSrcweir IMPL_LINK(CacheConfiguration,TimerCallback, Timer*,EMPTYARG)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir // Release out reference to the instance.
172cdf0e10cSrcweir mpInstance.reset();
173cdf0e10cSrcweir return 0;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
176cdf0e10cSrcweir
177cdf0e10cSrcweir } } } // end of namespace ::sd::slidesorter::cache
178