2002-03-28 02:08:05 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-07 22:22:14 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2002-03-28 02:08:05 -06:00
|
|
|
*
|
2005-09-07 22:22:14 -05:00
|
|
|
* $RCSfile: cachecontroller.hxx,v $
|
2002-03-28 02:08:05 -06:00
|
|
|
*
|
2007-11-23 07:35:21 -06:00
|
|
|
* $Revision: 1.11 $
|
2002-03-28 02:08:05 -06:00
|
|
|
*
|
2007-11-23 07:35:21 -06:00
|
|
|
* last change: $Author: ihi $ $Date: 2007-11-23 14:35:21 $
|
2002-03-28 02:08:05 -06:00
|
|
|
*
|
2005-09-07 22:22:14 -05:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2002-03-28 02:08:05 -06:00
|
|
|
*
|
|
|
|
*
|
2005-09-07 22:22:14 -05:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2002-03-28 02:08:05 -06:00
|
|
|
*
|
2005-09-07 22:22:14 -05:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2002-03-28 02:08:05 -06:00
|
|
|
*
|
2005-09-07 22:22:14 -05:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2002-03-28 02:08:05 -06:00
|
|
|
*
|
2005-09-07 22:22:14 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2002-03-28 02:08:05 -06:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/* PLEASE DON'T DELETE ANY COMMENT LINES, ALSO IT'S UNNECESSARY. */
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CONFIGMGR_BACKEND_CACHECONTROLLER_HXX
|
|
|
|
#define CONFIGMGR_BACKEND_CACHECONTROLLER_HXX
|
|
|
|
|
|
|
|
#ifndef CONFIGMGR_UTILITY_HXX_
|
|
|
|
#include "utility.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIGMGR_BACKEND_CACHEDDATAPROVIDER_HXX
|
|
|
|
#include "cacheddataprovider.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIGMGR_BACKEND_MERGEDDATAPROVIDER_HXX
|
|
|
|
#include "mergeddataprovider.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIGMGR_CACHEACCESS_HXX
|
|
|
|
#include "cacheaccess.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIGMGR_BACKEND_CACHEMULTICASTER_HXX
|
|
|
|
#include "cachemulticaster.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIGMGR_MISC_REQUESTOPTIONS_HXX_
|
|
|
|
#include "requestoptions.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIGMGR_AUTOREFERENCEMAP_HXX
|
|
|
|
#include "autoreferencemap.hxx"
|
|
|
|
#endif
|
|
|
|
|
2004-03-30 08:01:46 -06:00
|
|
|
#ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HPP_
|
|
|
|
#include <com/sun/star/uno/XComponentContext.hpp>
|
|
|
|
#endif
|
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
namespace configmgr
|
|
|
|
{
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
class OTreeDisposeScheduler;
|
|
|
|
class OCacheWriteScheduler;
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
namespace backend
|
|
|
|
{
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** manages a shared data cache for configuration data
|
|
|
|
trying to ensure consistency with a backend
|
|
|
|
and provides access to the data for clients
|
|
|
|
*/
|
|
|
|
class CacheController
|
2002-12-13 03:30:45 -06:00
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
: public ICachedDataProvider
|
|
|
|
, public IDirectDataProvider // Refcounted
|
2004-03-30 08:01:46 -06:00
|
|
|
, public INodeDataListener
|
2002-03-28 02:08:05 -06:00
|
|
|
{
|
|
|
|
typedef backend::IMergedDataProvider Backend;
|
|
|
|
typedef rtl::Reference< Backend > BackendRef;
|
2004-03-30 08:01:46 -06:00
|
|
|
typedef ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
|
|
|
|
CreationContext;
|
2002-03-28 02:08:05 -06:00
|
|
|
public:
|
|
|
|
/** ctor
|
|
|
|
*/
|
|
|
|
explicit
|
2004-03-30 08:01:46 -06:00
|
|
|
CacheController(BackendRef const & _xBackend,
|
|
|
|
const uno::Reference<uno::XComponentContext>& xContext);
|
2002-03-28 02:08:05 -06:00
|
|
|
|
|
|
|
// ICachedDataProvider implementation
|
|
|
|
public:
|
|
|
|
// disposing the cache before destroying
|
|
|
|
virtual void dispose() CFG_UNO_THROW_RTE();
|
|
|
|
|
|
|
|
/** locates data of a component in the cache.
|
|
|
|
|
|
|
|
<p> If the data isn't in the cache it is loaded from the backend. </p>
|
|
|
|
|
|
|
|
@param _aRequest
|
|
|
|
identifies the component to be loaded.
|
|
|
|
|
|
|
|
@returns
|
|
|
|
data that can be used to locate the loaded data in the cache.
|
|
|
|
|
|
|
|
@throws com::sun::star::uno::Exception
|
|
|
|
if loading the data fails.
|
|
|
|
The exact exception being thrown may depend on the underlying backend.
|
|
|
|
*/
|
|
|
|
virtual CacheLocation loadComponent(ComponentRequest const & _aRequest)
|
|
|
|
CFG_UNO_THROW_ALL();
|
|
|
|
|
|
|
|
/** releases data of a component from the cache.
|
|
|
|
|
|
|
|
<p> Should be called when a client is done with a component.
|
|
|
|
Each calls to <method>loadComponent</method> should
|
|
|
|
be balanced by exactly one call to <method>freeComponent</method>.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
@param _aRequest
|
|
|
|
identifies a component previously loaded via <method>loadComponent</method>.
|
|
|
|
|
|
|
|
@returns
|
|
|
|
data that can be used to locate the loaded data in the cache.
|
|
|
|
*/
|
|
|
|
virtual void freeComponent(ComponentRequest const & _aRequest)
|
|
|
|
CFG_NOTHROW();
|
|
|
|
|
|
|
|
/** refreshes data of an existing component from the backend
|
|
|
|
|
|
|
|
<p> If the data is in the cache already, it is refreshed from the
|
|
|
|
backend and the change are notified to all registered listeners.
|
|
|
|
</p>
|
|
|
|
<p> If the data isn't in the cache nothing is done and
|
|
|
|
a NULL location is returned.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p>Note: the caller <strong>must not</strong> hold any lock on the cache line affected.</p>
|
|
|
|
|
|
|
|
@param _aRequest
|
|
|
|
identifies the component to be refreshed.
|
|
|
|
|
|
|
|
@returns
|
|
|
|
data that can be used to locate the refreshed data in the cache.
|
|
|
|
|
|
|
|
<p>If there is no data to refresh a NULL location is returned.</p>
|
|
|
|
|
|
|
|
@throws com::sun::star::uno::Exception
|
|
|
|
if loading the data fails.
|
|
|
|
The exact exception being thrown may depend on the underlying backend.
|
|
|
|
*/
|
|
|
|
virtual CacheLocation refreshComponent(ComponentRequest const & _aRequest)
|
|
|
|
CFG_UNO_THROW_ALL();
|
2004-06-18 09:52:00 -05:00
|
|
|
/** refreshes data of all existing components from the backend
|
|
|
|
|
|
|
|
<p> If the data is in the cache already, it is refreshed from the
|
|
|
|
backend and the change are notified to all registered listeners.
|
|
|
|
</p>
|
|
|
|
<p> If the data isn't in the cache nothing is done and
|
|
|
|
a NULL location is returned.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p>Note: the caller <strong>must not</strong> hold any lock on the cache line affected.</p>
|
|
|
|
|
|
|
|
@throws com::sun::star::uno::Exception
|
|
|
|
if loading the data fails.
|
|
|
|
The exact exception being thrown may depend on the underlying backend.
|
|
|
|
*/
|
|
|
|
virtual void refreshAllComponents()
|
|
|
|
CFG_UNO_THROW_ALL();
|
2002-03-28 02:08:05 -06:00
|
|
|
|
|
|
|
/** locates a template in the cache.
|
|
|
|
|
|
|
|
<p> If the data isn't in the cache it is loaded from the backend. </p>
|
|
|
|
|
|
|
|
<p>Note: the caller <strong>must not</strong> hold any lock on the cache line affected.</p>
|
|
|
|
|
|
|
|
@param _aRequest
|
|
|
|
identifies the template to be loaded.
|
|
|
|
|
|
|
|
@returns
|
|
|
|
data that can be used to locate the template data in the cache.
|
|
|
|
|
|
|
|
@throws com::sun::star::uno::Exception
|
|
|
|
if loading the template data fails.
|
|
|
|
The exact exception being thrown may depend on the underlying backend.
|
|
|
|
*/
|
|
|
|
virtual CacheLocation loadTemplate(TemplateRequest const & _aRequest)
|
|
|
|
CFG_UNO_THROW_ALL();
|
|
|
|
|
|
|
|
/** saves changes to the backend and notifies them to registered listeners.
|
|
|
|
|
|
|
|
<p> Must be called after the changes have been applied to the cache
|
|
|
|
and before any subsequent changes to the same component.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p> Notifications are guaranteed to be delivered
|
|
|
|
before any subsequent changes to the same component are possible.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p> Note: the caller <strong>must</strong> hold a read lock (but no write lock)
|
|
|
|
on the cache line affected during the call.</p>
|
|
|
|
|
|
|
|
@param _anUpdate
|
|
|
|
identifies the node that changed and describes the changes.
|
|
|
|
|
|
|
|
@throws com::sun::star::uno::Exception
|
|
|
|
if saving the changes to the backend fails.
|
|
|
|
The exact exception being thrown may depend on the underlying backend.
|
|
|
|
*/
|
|
|
|
virtual void saveAndNotify(UpdateRequest const & _anUpdate)
|
|
|
|
CFG_UNO_THROW_ALL();
|
|
|
|
|
|
|
|
/** @returns
|
|
|
|
an object that can used to broadcast changes done through this object.
|
|
|
|
<p> The object returned is guaranteed to live as long
|
|
|
|
as this ICachedDataProvider lives.
|
|
|
|
</p>
|
|
|
|
*/
|
|
|
|
virtual ICachedDataNotifier & getNotifier() CFG_NOTHROW()
|
|
|
|
{ return m_aNotifier; }
|
|
|
|
|
|
|
|
/** @returns
|
|
|
|
an object that can be used to retrieve owned copies of the data,
|
|
|
|
defaults and templates.
|
|
|
|
<p> The object returned is guaranteed to live as long
|
|
|
|
as this ICachedDataProvider lives.
|
|
|
|
</p>
|
|
|
|
*/
|
|
|
|
virtual IDirectDataProvider & getDirectDataProvider() CFG_NOTHROW()
|
|
|
|
{ return *this; }
|
|
|
|
|
|
|
|
// IDirectDataProvider implementation
|
|
|
|
public:
|
|
|
|
/** loads merged data for a (complete) tree and returns it as return value.
|
|
|
|
|
|
|
|
@param _aRequest
|
|
|
|
identifies the component to be loaded
|
|
|
|
|
2004-03-30 08:01:46 -06:00
|
|
|
@param __bAddListenter
|
|
|
|
identifies is listener is to be registered to backend
|
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
@returns
|
2002-12-13 03:30:45 -06:00
|
|
|
A valid component instance for the given component.
|
2002-03-28 02:08:05 -06:00
|
|
|
|
|
|
|
@throws com::sun::star::uno::Exception
|
|
|
|
if the node cannot be retrieved.
|
|
|
|
The exact exception being thrown may depend on the underlying backend.
|
|
|
|
|
|
|
|
*/
|
2004-03-30 08:01:46 -06:00
|
|
|
virtual ComponentResult getComponentData(ComponentRequest const & _aRequest,
|
|
|
|
bool _bAddListenter)
|
2002-03-28 02:08:05 -06:00
|
|
|
CFG_UNO_THROW_ALL();
|
|
|
|
|
|
|
|
/** loads default data for a (partial) tree and returns it as return value
|
|
|
|
|
|
|
|
@param _aRequest
|
|
|
|
identifies the node to be loaded
|
|
|
|
|
|
|
|
@returns
|
|
|
|
A valid node instance for the default state of the given node.
|
|
|
|
|
|
|
|
<p>May be NULL, if the node exists but has no default equivalent.</p>
|
|
|
|
|
|
|
|
@throws com::sun::star::uno::Exception
|
|
|
|
if the default cannot be retrieved.
|
|
|
|
The exact exception being thrown may depend on the underlying backend.
|
|
|
|
*/
|
|
|
|
virtual NodeResult getDefaultData(NodeRequest const & _aRequest)
|
|
|
|
CFG_UNO_THROW_ALL();
|
|
|
|
|
|
|
|
/** loads a given template and returns it as return value
|
|
|
|
|
|
|
|
@param _aRequest
|
|
|
|
identifies the template to be loaded
|
|
|
|
|
|
|
|
@returns
|
|
|
|
A valid instance of the given template.
|
|
|
|
|
|
|
|
<p> Currently a request with empty template name
|
|
|
|
will retrieve a group node holding all templates
|
|
|
|
of a component.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
@throws com::sun::star::uno::Exception
|
|
|
|
if the template cannot be retrieved.
|
|
|
|
The exact exception being thrown may depend on the underlying backend.
|
|
|
|
*/
|
|
|
|
virtual TemplateResult getTemplateData(TemplateRequest const & _aRequest)
|
|
|
|
CFG_UNO_THROW_ALL();
|
2004-03-30 08:01:46 -06:00
|
|
|
//INodeDataListener Implementation
|
|
|
|
/** Triggered when component data is changed
|
2002-03-28 02:08:05 -06:00
|
|
|
|
2004-03-30 08:01:46 -06:00
|
|
|
@param _aRequest
|
|
|
|
identifies the data that changed
|
|
|
|
*/
|
|
|
|
virtual void dataChanged(const ComponentRequest& _aRequest) CFG_NOTHROW();
|
2002-03-28 02:08:05 -06:00
|
|
|
protected:
|
|
|
|
// ref counted, that's why no public dtor
|
|
|
|
~CacheController();
|
|
|
|
// implementation
|
|
|
|
private:
|
|
|
|
typedef CacheLoadingAccess Cache;
|
|
|
|
typedef rtl::Reference<Cache> CacheRef;
|
|
|
|
|
|
|
|
private:
|
|
|
|
AbsolutePath encodeTemplateLocation(const Name& _rName, const Name &_rModule) const;
|
|
|
|
|
|
|
|
AbsolutePath ensureTemplate(Name const& _rName, Name const& _rModule) CFG_UNO_THROW_ALL( );
|
|
|
|
|
|
|
|
// adjust a node result for locale, ...
|
2002-12-13 03:30:45 -06:00
|
|
|
bool normalizeResult(std::auto_ptr<ISubtree> & _aResult, RequestOptions const & _aOptions);
|
2002-03-28 02:08:05 -06:00
|
|
|
|
|
|
|
// reads data from the backend directly
|
2004-03-30 08:01:46 -06:00
|
|
|
ComponentResult loadDirectly(ComponentRequest const & _aRequest, bool _bAddListenter )
|
|
|
|
CFG_UNO_THROW_ALL( );
|
2002-03-28 02:08:05 -06:00
|
|
|
// reads default data from the backend directly
|
|
|
|
NodeResult loadDefaultsDirectly(NodeRequest const & _aRequest) CFG_UNO_THROW_ALL( );
|
|
|
|
// writes an update to the backend directly
|
|
|
|
void saveDirectly(UpdateRequest const & _anUpdate) CFG_UNO_THROW_ALL( );
|
|
|
|
|
|
|
|
// marks a component as invalid and initiates a (background ?) refresh on it
|
|
|
|
void invalidateComponent(ComponentRequest const & _aComponent) CFG_UNO_THROW_ALL( );
|
|
|
|
// writes updates for a component to the backend directly
|
|
|
|
void savePendingChanges(CacheRef const & _aCache, ComponentRequest const & _aComponent)
|
|
|
|
CFG_UNO_THROW_ALL( );
|
|
|
|
// saves all pending changes from a cache access to the backend
|
2002-07-12 05:42:50 -05:00
|
|
|
bool saveAllPendingChanges(CacheRef const & _aCache, RequestOptions const & _aOptions)
|
|
|
|
CFG_UNO_THROW_RTE( );
|
2002-12-16 05:49:26 -06:00
|
|
|
// load templates componentwise from backend
|
2002-12-13 03:30:45 -06:00
|
|
|
std::auto_ptr<ISubtree> loadTemplateData(TemplateRequest const & _aRequest)
|
|
|
|
CFG_UNO_THROW_ALL( );
|
2004-06-18 09:52:00 -05:00
|
|
|
|
2004-11-15 06:37:34 -06:00
|
|
|
void flushPendingUpdates() CFG_UNO_THROW_ALL();
|
|
|
|
|
|
|
|
void flushCacheWriter() CFG_NOTHROW();
|
2002-12-13 03:30:45 -06:00
|
|
|
// add templates componentwise to cache
|
2002-12-16 05:49:26 -06:00
|
|
|
data::TreeAddress addTemplates ( backend::ComponentData const & _aComponentInstance );
|
2002-03-28 02:08:05 -06:00
|
|
|
CacheRef getCacheAlways(RequestOptions const & _aOptions);
|
|
|
|
|
2004-03-30 08:01:46 -06:00
|
|
|
OTreeDisposeScheduler * createDisposer(const CreationContext& _xContext);
|
|
|
|
OCacheWriteScheduler * createCacheWriter(const CreationContext& _xContext);
|
2002-03-28 02:08:05 -06:00
|
|
|
|
2004-06-18 09:52:00 -05:00
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
|
|
|
|
// disposing
|
2002-07-12 05:42:50 -05:00
|
|
|
void disposeAll(bool _bFlushRemainingUpdates);
|
2002-03-28 02:08:05 -06:00
|
|
|
void disposeOne(RequestOptions const & _aOptions, bool _bFlushUpdates = true);
|
|
|
|
void disposeUser(RequestOptions const & _aUserOptions, bool _bFlushUpdates = true);
|
|
|
|
void implDisposeOne(CacheRef const & _aCache, RequestOptions const & _aOptions, bool _bFlushUpdates);
|
|
|
|
|
|
|
|
void closeModules(Cache::DisposeList & _aList, RequestOptions const & _aOptions);
|
|
|
|
private:
|
2007-11-23 07:35:21 -06:00
|
|
|
typedef AutoReferenceMap<RequestOptions,Cache,lessRequestOptions> CacheMap;
|
2002-12-13 03:30:45 -06:00
|
|
|
|
2002-03-28 02:08:05 -06:00
|
|
|
CacheChangeMulticaster m_aNotifier;
|
2007-11-23 07:35:21 -06:00
|
|
|
BackendRef m_xBackend;
|
|
|
|
CacheMap m_aCacheMap;
|
|
|
|
TemplateCacheData m_aTemplates;
|
2002-03-28 02:08:05 -06:00
|
|
|
|
|
|
|
OTreeDisposeScheduler* m_pDisposer;
|
|
|
|
OCacheWriteScheduler * m_pCacheWriter;
|
|
|
|
|
|
|
|
bool m_bDisposing; // disables async writing and automatic refresh
|
|
|
|
|
2002-10-24 02:36:59 -05:00
|
|
|
friend class configmgr::OTreeDisposeScheduler;
|
|
|
|
friend class configmgr::OCacheWriteScheduler;
|
2002-03-28 02:08:05 -06:00
|
|
|
friend class OInvalidateTreeThread;
|
|
|
|
|
|
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
} // namespace backend
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
} // namespace configmgr
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|