xref: /aoo42x/main/store/source/storbios.hxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _STORE_STORBIOS_HXX_
29*cdf0e10cSrcweir #define _STORE_STORBIOS_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "sal/types.h"
32*cdf0e10cSrcweir #include "rtl/ref.hxx"
33*cdf0e10cSrcweir #include "osl/mutex.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "store/types.h"
36*cdf0e10cSrcweir #include "object.hxx"
37*cdf0e10cSrcweir #include "lockbyte.hxx"
38*cdf0e10cSrcweir #include "storbase.hxx"
39*cdf0e10cSrcweir #include "storcach.hxx"
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir /*========================================================================
42*cdf0e10cSrcweir  *
43*cdf0e10cSrcweir  * OStorePageBIOS.
44*cdf0e10cSrcweir  *
45*cdf0e10cSrcweir  *======================================================================*/
46*cdf0e10cSrcweir namespace store
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir struct SuperBlockPage;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir class OStorePageBIOS : public store::OStoreObject
52*cdf0e10cSrcweir {
53*cdf0e10cSrcweir public:
54*cdf0e10cSrcweir 	/** Construction.
55*cdf0e10cSrcweir 	 */
56*cdf0e10cSrcweir 	OStorePageBIOS (void);
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 	/** Conversion into Mutex&
59*cdf0e10cSrcweir 	 */
60*cdf0e10cSrcweir 	inline operator osl::Mutex& (void) const;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir 	/** Initialization.
63*cdf0e10cSrcweir 	 *  @param  pLockBytes [in]
64*cdf0e10cSrcweir 	 *  @param  eAccessMode [in]
65*cdf0e10cSrcweir 	 *  @param  rnPageSize [inout]
66*cdf0e10cSrcweir 	 *  @return store_E_None upon success
67*cdf0e10cSrcweir 	 */
68*cdf0e10cSrcweir 	virtual storeError initialize (
69*cdf0e10cSrcweir 		ILockBytes *    pLockBytes,
70*cdf0e10cSrcweir 		storeAccessMode eAccessMode,
71*cdf0e10cSrcweir 		sal_uInt16 &    rnPageSize);
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir     rtl::Reference< PageData::Allocator > & allocator()
74*cdf0e10cSrcweir     {
75*cdf0e10cSrcweir         return m_xAllocator;
76*cdf0e10cSrcweir     }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 	/** read.
79*cdf0e10cSrcweir 	 */
80*cdf0e10cSrcweir 	storeError read (
81*cdf0e10cSrcweir 		sal_uInt32 nAddr, void *pData, sal_uInt32 nSize);
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 	/** write.
84*cdf0e10cSrcweir 	 */
85*cdf0e10cSrcweir 	storeError write (
86*cdf0e10cSrcweir 		sal_uInt32 nAddr, const void *pData, sal_uInt32 nSize);
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 	/** isWriteable.
89*cdf0e10cSrcweir 	 */
90*cdf0e10cSrcweir 	inline bool isWriteable (void) const;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	/** isValid.
93*cdf0e10cSrcweir 	 */
94*cdf0e10cSrcweir 	inline sal_Bool isValid (void) const;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir 	/** Page Access.
97*cdf0e10cSrcweir 	 */
98*cdf0e10cSrcweir 	storeError acquirePage (
99*cdf0e10cSrcweir 		const OStorePageDescriptor& rDescr, storeAccessMode eMode);
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 	storeError releasePage (
102*cdf0e10cSrcweir 		const OStorePageDescriptor& rDescr, storeAccessMode eMode);
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 	sal_uInt32 getRefererCount (void);
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 	/** Page Allocation.
107*cdf0e10cSrcweir 	 */
108*cdf0e10cSrcweir 	enum Allocation
109*cdf0e10cSrcweir 	{
110*cdf0e10cSrcweir 		ALLOCATE_FIRST = 0,
111*cdf0e10cSrcweir 		ALLOCATE_BEST  = 1,
112*cdf0e10cSrcweir 		ALLOCATE_EOF   = 2
113*cdf0e10cSrcweir 	};
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	storeError allocate (
116*cdf0e10cSrcweir 		OStorePageObject& rPage, Allocation eAllocation = ALLOCATE_FIRST);
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	storeError free (sal_uInt32 nAddr);
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 	/** Page I/O.
121*cdf0e10cSrcweir 	 */
122*cdf0e10cSrcweir 	storeError loadObjectAt (
123*cdf0e10cSrcweir 		OStorePageObject& rPage, sal_uInt32 nAddr);
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 	storeError saveObjectAt (
126*cdf0e10cSrcweir 		OStorePageObject& rPage, sal_uInt32 nAddr);
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 	/** close.
129*cdf0e10cSrcweir 	 *  @return store_E_None upon success.
130*cdf0e10cSrcweir 	 */
131*cdf0e10cSrcweir 	storeError close (void);
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	/** flush.
134*cdf0e10cSrcweir 	 *  @return store_E_None upon success.
135*cdf0e10cSrcweir 	 */
136*cdf0e10cSrcweir 	storeError flush (void);
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	/** size.
139*cdf0e10cSrcweir 	 */
140*cdf0e10cSrcweir 	storeError size (sal_uInt32 &rnSize);
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 	/** ScanContext.
143*cdf0e10cSrcweir 	 */
144*cdf0e10cSrcweir 	struct ScanContext
145*cdf0e10cSrcweir 	{
146*cdf0e10cSrcweir 		/** Representation.
147*cdf0e10cSrcweir 		 */
148*cdf0e10cSrcweir 		OStorePageDescriptor m_aDescr;
149*cdf0e10cSrcweir 		sal_uInt32           m_nSize;
150*cdf0e10cSrcweir 		sal_uInt32           m_nMagic;
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 		/** Construction.
153*cdf0e10cSrcweir 		 */
154*cdf0e10cSrcweir 		inline ScanContext (void);
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 		/** isValid.
157*cdf0e10cSrcweir 		 */
158*cdf0e10cSrcweir 		inline bool isValid (void) const;
159*cdf0e10cSrcweir 	};
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 	/** scanBegin.
162*cdf0e10cSrcweir 	 */
163*cdf0e10cSrcweir 	storeError scanBegin (
164*cdf0e10cSrcweir 		ScanContext &rCtx,
165*cdf0e10cSrcweir 		sal_uInt32   nMagic = 0);
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 	/** scanNext.
168*cdf0e10cSrcweir 	 */
169*cdf0e10cSrcweir 	storeError scanNext (
170*cdf0e10cSrcweir 		ScanContext      &rCtx,
171*cdf0e10cSrcweir 		OStorePageObject &rPage);
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir protected:
174*cdf0e10cSrcweir 	/** Destruction (OReference).
175*cdf0e10cSrcweir 	 */
176*cdf0e10cSrcweir 	virtual ~OStorePageBIOS (void);
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir private:
179*cdf0e10cSrcweir 	/** Representation.
180*cdf0e10cSrcweir 	 */
181*cdf0e10cSrcweir 	rtl::Reference<ILockBytes>    m_xLockBytes;
182*cdf0e10cSrcweir 	osl::Mutex                    m_aMutex;
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 	SuperBlockPage *              m_pSuper;
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 	bool                          m_bWriteable;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir     rtl::Reference< PageData::Allocator > m_xAllocator;
189*cdf0e10cSrcweir     rtl::Reference< PageCache >   m_xCache;
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 	/** Page Access (control).
192*cdf0e10cSrcweir 	 */
193*cdf0e10cSrcweir public:
194*cdf0e10cSrcweir     struct Ace
195*cdf0e10cSrcweir 	{
196*cdf0e10cSrcweir         Ace *      m_next;
197*cdf0e10cSrcweir         Ace *      m_prev;
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir         sal_uInt32 m_addr;
200*cdf0e10cSrcweir         sal_uInt32 m_used;
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir         Ace();
203*cdf0e10cSrcweir         ~Ace();
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir         static int SAL_CALL constructor (void * obj, void * arg);
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir         static Ace * find   (Ace * head, sal_uInt32 addr);
208*cdf0e10cSrcweir         static void  insert (Ace * head, Ace * entry);
209*cdf0e10cSrcweir 	};
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir private:
212*cdf0e10cSrcweir     Ace m_ace_head;
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir     class AceCache;
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 	/** Initialization.
217*cdf0e10cSrcweir      */
218*cdf0e10cSrcweir 	storeError initialize_Impl (
219*cdf0e10cSrcweir 		ILockBytes *    pLockBytes,
220*cdf0e10cSrcweir 		storeAccessMode eAccessMode,
221*cdf0e10cSrcweir 		sal_uInt16 &    rnPageSize);
222*cdf0e10cSrcweir     void cleanup_Impl();
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 	/** Page Maintenance.
225*cdf0e10cSrcweir 	 */
226*cdf0e10cSrcweir 	storeError loadObjectAt_Impl (
227*cdf0e10cSrcweir 		OStorePageObject & rPage, sal_uInt32 nAddr);
228*cdf0e10cSrcweir 	storeError saveObjectAt_Impl (
229*cdf0e10cSrcweir 		OStorePageObject & rPage, sal_uInt32 nAddr);
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 	/** Not implemented.
232*cdf0e10cSrcweir 	 */
233*cdf0e10cSrcweir 	OStorePageBIOS (const OStorePageBIOS&);
234*cdf0e10cSrcweir 	OStorePageBIOS& operator= (const OStorePageBIOS&);
235*cdf0e10cSrcweir };
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir inline OStorePageBIOS::operator osl::Mutex& (void) const
238*cdf0e10cSrcweir {
239*cdf0e10cSrcweir 	return (osl::Mutex&)m_aMutex;
240*cdf0e10cSrcweir }
241*cdf0e10cSrcweir inline bool OStorePageBIOS::isWriteable (void) const
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir 	return m_bWriteable;
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir inline sal_Bool OStorePageBIOS::isValid (void) const
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir 	return m_xLockBytes.is();
248*cdf0e10cSrcweir }
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir inline OStorePageBIOS::ScanContext::ScanContext (void)
251*cdf0e10cSrcweir 	: m_aDescr (0, 0, 0), m_nSize (0), m_nMagic (0)
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir }
254*cdf0e10cSrcweir inline bool OStorePageBIOS::ScanContext::isValid (void) const
255*cdf0e10cSrcweir {
256*cdf0e10cSrcweir 	return (m_aDescr.m_nAddr < m_nSize);
257*cdf0e10cSrcweir }
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir /*========================================================================
260*cdf0e10cSrcweir  *
261*cdf0e10cSrcweir  * The End.
262*cdf0e10cSrcweir  *
263*cdf0e10cSrcweir  *======================================================================*/
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir } // namespace store
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir #endif /* !_STORE_STORBIOS_HXX_ */
268