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: cacheline.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 CONFIGMGR_CACHELINE_HXX
32 #define CONFIGMGR_CACHELINE_HXX
34 #include "configpath.hxx"
35 #include "requesttypes.hxx"
36 #include "utility.hxx"
37 #include "treefragment.hxx"
38 #include <osl/interlck.h>
39 #include <rtl/ref.hxx>
40 #include <salhelper/simplereferenceobject.hxx>
44 /** This object represents a cache line for a single configuration tree
46 class CacheLine
: public salhelper::SimpleReferenceObject
49 // create a new CacheLine for the given component name
50 static rtl::Reference
<CacheLine
>
51 createNew( rtl::OUString
const & _aModuleName
);
53 // create a new CacheLine attached to the given memory location
54 static rtl::Reference
<CacheLine
>
55 createAttached( rtl::OUString
const & _aModuleName
, sharable::TreeFragment
* _aLocation
);
57 bool hasDefaults() const;
59 bool isEmpty() const { return m_base
== NULL
; }
60 sharable::TreeFragment
* getTreeAddress() const { return m_base
; }
61 sharable::TreeFragment
* getPartialTree(configuration::AbsolutePath
const & _aTemplatePath
) const;
62 sharable::Node
* getNode(configuration::AbsolutePath
const & _aPath
) const;
64 sharable::TreeFragment
* setComponentData( backend::ComponentDataStruct
const & _aComponentInstance
,
66 ) SAL_THROW((com::sun::star::uno::RuntimeException
));
68 sharable::TreeFragment
* insertDefaults( backend::NodeInstance
const & _aDefaultInstance
69 ) SAL_THROW((com::sun::star::uno::RuntimeException
));
71 // get the module name for this component
72 rtl::OUString
getModuleName() const;
74 /// add a client for this module's data
75 oslInterlockedCount
clientReferences() const { return m_nDataRefs
; }
76 /// add a client for this modules data
77 oslInterlockedCount
clientAcquire() { return osl_incrementInterlockedCount(&m_nDataRefs
); }
78 /// subtract a client for this modules data
79 oslInterlockedCount
clientRelease() { return osl_decrementInterlockedCount(&m_nDataRefs
); }
82 // create a new CacheLine attached to the given memory location
84 CacheLine( rtl::OUString
const & _aModuleName
, sharable::TreeFragment
* _pLocation
);
86 // create a new empty CacheLine for the given component name
88 CacheLine( rtl::OUString
const & _aModuleName
);
90 sharable::Node
* internalGetNode(configuration::AbsolutePath
const & _rPath
) const;
92 sharable::TreeFragment
* base() const { return m_base
; }
93 void setBase(sharable::TreeFragment
* _base
);
96 sharable::TreeFragment
* m_base
;
99 oslInterlockedCount m_nDataRefs
; /// the number of clients on this modules data
102 ////////////////////////////////////////////////////////////////////////////////
103 /** This object represents a cache line and associated data for a single configuration tree
105 class ExtendedCacheLine
: public CacheLine
108 // create a new CacheLine for the given component name
109 static rtl::Reference
<ExtendedCacheLine
>
110 createNew( rtl::OUString
const & _aModuleName
);
112 // create a new CacheLine attached to the given memory location
113 static rtl::Reference
<ExtendedCacheLine
>
114 createAttached( rtl::OUString
const & _aModuleName
,
115 sharable::TreeFragment
* _aLocation
);
117 // management of pending changes
118 bool hasPending() const {return m_pPending
.get() != NULL
;}
120 void addPending(backend::ConstUpdateInstance
const & _anUpdate
) SAL_THROW((com::sun::star::uno::RuntimeException
));
121 std::auto_ptr
<SubtreeChange
> releasePending() {return m_pPending
;}
124 // create a new empty CacheLine for the given component name
126 ExtendedCacheLine( rtl::OUString
const & _aModuleName
);
128 // create a new CacheLine attached to the given memory location
130 ExtendedCacheLine( rtl::OUString
const & _aModuleName
,
131 sharable::TreeFragment
* _aLocation
);
134 std::auto_ptr
<SubtreeChange
> m_pPending
;
137 } // namespace configmgr