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: gconfbackend.hxx,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 #ifndef GCONFBACKEND_HXX_
32 #define GCONFBACKEND_HXX_
34 #ifndef _COM_SUN_STAR_CONFIGURATION_BACKEND_XSCHEMASUPPLIER_HPP_
35 #include <com/sun/star/configuration/backend/XSingleLayerStratum.hpp>
37 #include <com/sun/star/lang/XInitialization.hpp>
38 #include <com/sun/star/uno/XComponentContext.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
41 //#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
42 //#include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 //#endif // _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
44 #include <com/sun/star/configuration/InvalidBootstrapFileException.hpp>
45 #include <com/sun/star/configuration/backend/CannotConnectException.hpp>
46 #include <com/sun/star/configuration/backend/XBackendChangesNotifier.hpp>
47 #include <cppuhelper/compbase3.hxx>
53 //#ifndef _VOS_THREAD_HXX_
54 //#include <vos/thread.hxx>
57 #include <gconf/gconf-client.h>
60 namespace css
= com::sun::star
;
61 namespace uno
= css::uno
;
62 namespace lang
= css::lang
;
63 namespace backend
= css::configuration::backend
;
66 /** Structure containing the mapping between OOffice and Gconf keys.
67 AlOO specifies whether the key is protected, if key is protected it
68 can not be over riden in subsequent higher layers
73 rtl::OUString mOOName
;
74 rtl::OUString mOOType
;
75 rtl::OUString mGconfName
;
79 typedef keyMapping KeyMappingInfo
;
80 typedef std::multimap
<rtl::OUString
, KeyMappingInfo
> KeyMappingTable
;
82 /*Time Stamp mapping table used to store timestamps of updated components
83 when a notification is recieved. It is needed as you cannot access gconf key
84 timestamps via the Gconf api */
86 typedef std::multimap
<rtl::OUString
, rtl::OUString
> TSMappingTable
;
88 //------------------------------------------------------------------------------
91 class ONotificationThread: public vos::OThread
99 ~ONotificationThread()
101 g_main_loop_quit(mLoop);
105 virtual void SAL_CALL onTerminated()
110 virtual void SAL_CALL run();
116 //------------------------------------------------------------------------------
117 typedef cppu::WeakComponentImplHelper3
<backend::XSingleLayerStratum
,
118 backend::XBackendChangesNotifier
,
119 lang::XServiceInfo
> BackendBase
;
122 Implements the SingleLayerStratum service for gconf access.
124 class GconfBackend
: public BackendBase
{
127 static GconfBackend
* createInstance(const uno::Reference
<uno::XComponentContext
>& xContext
);
130 virtual rtl::OUString SAL_CALL
getImplementationName( )
131 throw (uno::RuntimeException
) ;
133 virtual sal_Bool SAL_CALL
supportsService( const rtl::OUString
& aServiceName
)
134 throw (uno::RuntimeException
) ;
136 virtual uno::Sequence
<rtl::OUString
> SAL_CALL
getSupportedServiceNames( )
137 throw (uno::RuntimeException
) ;
140 Provides the implementation name.
142 @return implementation name
144 static rtl::OUString SAL_CALL
getBackendName(void) ;
147 Provides the supported services names
149 @return service names
151 static uno::Sequence
<rtl::OUString
> SAL_CALL
getBackendServiceNames(void) ;
153 /* returns a GconfClient */
154 static GConfClient
* getGconfClient();
156 //XSingleLayerStratum
157 virtual uno::Reference
<backend::XLayer
> SAL_CALL
158 getLayer( const rtl::OUString
& aLayerId
, const rtl::OUString
& aTimestamp
)
159 throw (backend::BackendAccessException
, lang::IllegalArgumentException
) ;
161 virtual uno::Reference
<backend::XUpdatableLayer
> SAL_CALL
162 getUpdatableLayer( const rtl::OUString
& aLayerId
)
163 throw (backend::BackendAccessException
, lang::NoSupportException
,
164 lang::IllegalArgumentException
) ;
166 // XBackendChangesNotifier
167 virtual void SAL_CALL
addChangesListener(
168 const uno::Reference
<backend::XBackendChangesListener
>& xListener
,
169 const rtl::OUString
& aComponent
)
170 throw (::com::sun::star::uno::RuntimeException
);
173 virtual void SAL_CALL
removeChangesListener(
174 const uno::Reference
<backend::XBackendChangesListener
>& xListener
,
175 const rtl::OUString
& aComponent
)
176 throw (::com::sun::star::uno::RuntimeException
);
178 //Notify all listener of component change
179 void notifyListeners(const rtl::OUString
& aGconfKey
);
183 Service constructor from a service factory.
185 @param xContext component context
187 GconfBackend(const uno::Reference
<uno::XComponentContext
>& xContext
)
188 throw (backend::BackendAccessException
);
191 ~GconfBackend(void) ;
195 typedef uno::Reference
<backend::XBackendChangesListener
> ListenerRef
;
196 typedef std::multimap
<rtl::OUString
,ListenerRef
> ListenerList
;
198 /** Build Gconf/OO mapping table */
199 void initializeMappingTable ();
202 /** The component context */
203 uno::Reference
<uno::XComponentContext
> m_xContext
;
205 /** Mutex for reOOurces protection */
208 KeyMappingTable mKeyMap
;
210 /** List of component TimeStamps */
211 TSMappingTable mTSMap
;
213 static GconfBackend
* mInstance
;
215 /** List of listener */
216 ListenerList mListenerList
;
218 /**Connection to Gconf */
219 static GConfClient
* mClient
;
221 // ONotificationThread* mNotificationThread;
225 #endif // CONFIGMGR_LOCALBE_LOCALSINGLESTRATUM_HXX_