fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / fwi / jobs / configaccess.cxx
blobbacc8c15b1f869ad9d87d7661419ec7347b4a1d1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <jobs/configaccess.hxx>
21 #include <general.h>
22 #include <services.h>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/beans/XMultiHierarchicalPropertySet.hpp>
26 #include <com/sun/star/configuration/theDefaultProvider.hpp>
27 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <com/sun/star/beans/PropertyValue.hpp>
29 #include <com/sun/star/util/XChangesBatch.hpp>
31 #include <unotools/configpaths.hxx>
32 #include <rtl/ustrbuf.hxx>
34 namespace framework{
36 /**
37 @short open the configuration of this job
38 @descr We open the configuration of this job only. Not the whole package or the whole
39 job set. We are interested on our own properties only.
40 We set the opened configuration access as our member. So any following method,
41 which needs cfg access, can use it. That prevent us against multiple open/close requests.
42 But you can use this method to upgrade an already opened configuration too.
44 @param eMode
45 force opening of the configuration access in readonly or in read/write mode
47 ConfigAccess::ConfigAccess( /*IN*/ const css::uno::Reference< css::uno::XComponentContext >& rxContext,
48 /*IN*/ const OUString& sRoot )
49 : m_xContext ( rxContext)
50 , m_sRoot ( sRoot )
51 , m_eMode ( E_CLOSED )
55 /**
56 @short last chance to close an open configuration access point
57 @descr In case our user forgot to close this configuration point
58 in the right way, normally he will run into some trouble -
59 e.g. losing data.
61 ConfigAccess::~ConfigAccess()
63 close();
66 /**
67 @short return the internal mode of this instance
68 @descr May be the outside user need any information about successfully opened
69 or closed config access point objects. He can control the internal mode to do so.
71 @return The internal open state of this object.
73 ConfigAccess::EOpenMode ConfigAccess::getMode() const
75 osl::MutexGuard g(m_mutex);
76 return m_eMode;
79 /**
80 @short open the configuration access in the specified mode
81 @descr We set the opened configuration access as our member. So any following method,
82 which needs cfg access, can use it. That prevent us against multiple open/close requests.
83 But you can use this method to upgrade an already opened configuration too.
84 It's possible to open a config access in READONLY mode first and "open" it at a second
85 time within the mode READWRITE. Then we will upgrade it. Dowgrade will be possible too.
87 But note: closing will be done explicitly by calling method close() ... not by
88 downgrading with mode CLOSED!
90 @param eMode
91 force (re)opening of the configuration access in readonly or in read/write mode
93 void ConfigAccess::open( /*IN*/ EOpenMode eMode )
95 osl::MutexGuard g(m_mutex);
97 // check if configuration is already open in the right mode.
98 // By the way: Don't allow closing by using this method!
99 if (
100 (eMode !=E_CLOSED) &&
101 (m_eMode!=eMode )
104 // We have to close the old access point without any question here.
105 // It will be open again using the new mode.
106 // can be called without checks! It does the checks by itself ...
107 // e.g. for already closed or not opened configuration.
108 // Flushing of all made changes will be done here too.
109 close();
111 // create the configuration provider, which provides sub access points
112 css::uno::Reference< css::lang::XMultiServiceFactory > xConfigProvider = css::configuration::theDefaultProvider::get(m_xContext);
113 css::beans::PropertyValue aParam;
114 aParam.Name = "nodepath";
115 aParam.Value <<= m_sRoot;
117 css::uno::Sequence< css::uno::Any > lParams(1);
118 lParams[0] <<= aParam;
120 // open it
123 if (eMode==E_READONLY)
124 m_xConfig = xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGREADACCESS , lParams);
125 else
126 if (eMode==E_READWRITE)
127 m_xConfig = xConfigProvider->createInstanceWithArguments(SERVICENAME_CFGUPDATEACCESS, lParams);
129 catch(const css::uno::Exception& ex)
131 (void) ex; // avoid warning
132 SAL_INFO("fwk", "open config: " << ex.Message);
135 m_eMode = E_CLOSED;
136 if (m_xConfig.is())
137 m_eMode = eMode;
142 @short close the internal opened configuration access and flush all changes
143 @descr It checks, if the given access is valid and react in the right way.
144 It flushes all changes ... so nobody else must know this state.
146 void ConfigAccess::close()
148 osl::MutexGuard g(m_mutex);
149 // check already closed configuration
150 if (m_xConfig.is())
152 css::uno::Reference< css::util::XChangesBatch > xFlush(m_xConfig, css::uno::UNO_QUERY);
153 if (xFlush.is())
154 xFlush->commitChanges();
155 m_xConfig = css::uno::Reference< css::uno::XInterface >();
156 m_eMode = E_CLOSED;
161 @short provides an access to the internal wrapped configuration access
162 @descr It's not allowed to safe this c++ (!) reference outside. You have
163 to use it directly. Further you must use our public lock member m_aLock
164 to synchronize your code with our internal structures and our interface
165 methods. Acquire it before you call cfg() and release it afterwards immediately.
167 E.g.: ConfigAccess aAccess(...);
168 Guard aReadLock(aAccess.m_aLock);
169 Reference< XPropertySet > xSet(aAccess.cfg(), UNO_QUERY);
170 Any aProp = xSet->getPropertyValue("...");
171 aReadLock.unlock();
173 @attention During this time it's not allowed to call the methods open() or close()!
174 Otherwhise you will change your own referenced config access. Anything will
175 be possible then.
177 @return A c++(!) reference to the uno instance of the configuration access point.
179 const css::uno::Reference< css::uno::XInterface >& ConfigAccess::cfg()
181 // must be synchronized from outside!
182 // => no lock here ...
183 return m_xConfig;
186 } // namespace framework
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */