Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "SlsCacheConfiguration.hxx"
31 : : #include <osl/mutex.hxx>
32 : : #include <rtl/instance.hxx>
33 : : #include <vcl/svapp.hxx>
34 : :
35 : : #include <comphelper/processfactory.hxx>
36 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 : : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
38 : : #include <com/sun/star/beans/PropertyValue.hpp>
39 : :
40 : : using namespace ::com::sun::star;
41 : : using namespace ::com::sun::star::uno;
42 : :
43 : : namespace sd { namespace slidesorter { namespace cache {
44 : :
45 : : namespace
46 : : {
47 : : typedef ::boost::shared_ptr<CacheConfiguration> CacheConfigSharedPtr;
48 : : class theInstance :
49 : : public rtl::Static<CacheConfigSharedPtr, theInstance> {};
50 : : }
51 : :
52 : 25 : ::boost::weak_ptr<CacheConfiguration> CacheConfiguration::mpWeakInstance;
53 : 25 : Timer CacheConfiguration::maReleaseTimer;
54 : :
55 : 756 : ::boost::shared_ptr<CacheConfiguration> CacheConfiguration::Instance (void)
56 : : {
57 [ + - ]: 756 : SolarMutexGuard aSolarGuard;
58 [ + - ]: 756 : CacheConfigSharedPtr &rInstancePtr = theInstance::get();
59 [ + + ]: 756 : if (rInstancePtr.get() == NULL)
60 : : {
61 : : // Maybe somebody else kept a previously created instance alive.
62 [ - + ]: 93 : if ( ! mpWeakInstance.expired())
63 [ # # ][ # # ]: 0 : rInstancePtr = ::boost::shared_ptr<CacheConfiguration>(mpWeakInstance);
[ # # ]
64 [ + - ]: 93 : if (rInstancePtr.get() == NULL)
65 : : {
66 : : // We have to create a new instance.
67 [ + - ][ + - ]: 93 : rInstancePtr.reset(new CacheConfiguration());
[ + - ]
68 [ + - ]: 93 : mpWeakInstance = rInstancePtr;
69 : : // Prepare to release this instance in the near future.
70 : : maReleaseTimer.SetTimeoutHdl(
71 [ + - ]: 93 : LINK(rInstancePtr.get(),CacheConfiguration,TimerCallback));
72 [ + - ]: 93 : maReleaseTimer.SetTimeout(5000 /* 5s */);
73 [ + - ]: 93 : maReleaseTimer.Start();
74 : : }
75 : : }
76 [ + - ][ + - ]: 756 : return rInstancePtr;
77 : : }
78 : :
79 : :
80 : :
81 : :
82 : 93 : CacheConfiguration::CacheConfiguration (void)
83 : : {
84 : : // Get the cache size from configuration.
85 : 93 : const ::rtl::OUString sConfigurationProviderServiceName("com.sun.star.configuration.ConfigurationProvider");
86 : 93 : const ::rtl::OUString sPathToImpressConfigurationRoot("/org.openoffice.Office.Impress/");
87 : 93 : const ::rtl::OUString sPathToNode("MultiPaneGUI/SlideSorter/PreviewCache");
88 : :
89 : : try
90 : : {
91 : : // Obtain access to the configuration.
92 : : Reference<lang::XMultiServiceFactory> xProvider (
93 [ + - ][ + - ]: 186 : ::comphelper::getProcessServiceFactory()->createInstance(
94 : 93 : sConfigurationProviderServiceName),
95 [ + - ][ + - ]: 93 : UNO_QUERY);
96 [ - + ]: 93 : if ( ! xProvider.is())
97 : : return;
98 : :
99 : : // Obtain access to Impress configuration.
100 [ + - ]: 93 : Sequence<Any> aCreationArguments(3);
101 [ + - ]: 93 : aCreationArguments[0] = makeAny(beans::PropertyValue(
102 : : "nodepath",
103 : : 0,
104 : : makeAny(sPathToImpressConfigurationRoot),
105 [ + - ][ + - ]: 186 : beans::PropertyState_DIRECT_VALUE));
106 [ + - ]: 93 : aCreationArguments[1] = makeAny(beans::PropertyValue(
107 : : "depth",
108 : : 0,
109 : : makeAny((sal_Int32)-1),
110 [ + - ][ + - ]: 186 : beans::PropertyState_DIRECT_VALUE));
111 [ + - ]: 93 : aCreationArguments[2] = makeAny(beans::PropertyValue(
112 : : "lazywrite",
113 : : 0,
114 : : makeAny(true),
115 [ + - ][ + - ]: 186 : beans::PropertyState_DIRECT_VALUE));
116 : :
117 [ + - ]: 93 : Reference<XInterface> xRoot (xProvider->createInstanceWithArguments(
118 : : "com.sun.star.configuration.ConfigurationAccess",
119 [ + - ]: 93 : aCreationArguments));
120 [ - + ]: 93 : if ( ! xRoot.is())
121 : : return;
122 [ + - ]: 93 : Reference<container::XHierarchicalNameAccess> xHierarchy (xRoot, UNO_QUERY);
123 [ - + ]: 93 : if ( ! xHierarchy.is())
124 : : return;
125 : :
126 : : // Get the node for the slide sorter preview cache.
127 : : mxCacheNode = Reference<container::XNameAccess>(
128 [ + - ]: 93 : xHierarchy->getByHierarchicalName(sPathToNode),
129 [ - + ][ # # ]: 186 : UNO_QUERY);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ - - + ]
130 : : }
131 [ # # ]: 0 : catch (RuntimeException &)
132 : : {
133 : : }
134 [ + - ]: 93 : catch (Exception &)
135 : : {
136 [ - + ][ - + ]: 93 : }
[ + - ]
137 : : }
138 : :
139 : :
140 : :
141 : :
142 : 756 : Any CacheConfiguration::GetValue (const ::rtl::OUString& rName)
143 : : {
144 : 756 : Any aResult;
145 : :
146 [ - + ][ + - ]: 756 : if (mxCacheNode != NULL)
147 : : {
148 : : try
149 : : {
150 [ # # ][ # # ]: 0 : aResult = mxCacheNode->getByName(rName);
151 : : }
152 [ # # ]: 0 : catch (Exception &)
153 : : {
154 : : }
155 : : }
156 : :
157 [ # # ]: 756 : return aResult;
158 : : }
159 : :
160 : :
161 : :
162 : :
163 : 85 : IMPL_LINK_NOARG(CacheConfiguration, TimerCallback)
164 : : {
165 : 85 : CacheConfigSharedPtr &rInstancePtr = theInstance::get();
166 : : // Release out reference to the instance.
167 : 85 : rInstancePtr.reset();
168 : 85 : return 0;
169 : : }
170 : :
171 : :
172 [ + - ][ + - ]: 75 : } } } // end of namespace ::sd::slidesorter::cache
173 : :
174 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|