1*1a5fa39bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*1a5fa39bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*1a5fa39bSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*1a5fa39bSAndrew Rist * distributed with this work for additional information
6*1a5fa39bSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*1a5fa39bSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*1a5fa39bSAndrew Rist * "License"); you may not use this file except in compliance
9*1a5fa39bSAndrew Rist * with the License. You may obtain a copy of the License at
10*1a5fa39bSAndrew Rist *
11*1a5fa39bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*1a5fa39bSAndrew Rist *
13*1a5fa39bSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*1a5fa39bSAndrew Rist * software distributed under the License is distributed on an
15*1a5fa39bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1a5fa39bSAndrew Rist * KIND, either express or implied. See the License for the
17*1a5fa39bSAndrew Rist * specific language governing permissions and limitations
18*1a5fa39bSAndrew Rist * under the License.
19*1a5fa39bSAndrew Rist *
20*1a5fa39bSAndrew Rist *************************************************************/
21*1a5fa39bSAndrew Rist
22*1a5fa39bSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifndef _STORE_STORBIOS_HXX_
25cdf0e10cSrcweir #define _STORE_STORBIOS_HXX_
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "sal/types.h"
28cdf0e10cSrcweir #include "rtl/ref.hxx"
29cdf0e10cSrcweir #include "osl/mutex.hxx"
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "store/types.h"
32cdf0e10cSrcweir #include "object.hxx"
33cdf0e10cSrcweir #include "lockbyte.hxx"
34cdf0e10cSrcweir #include "storbase.hxx"
35cdf0e10cSrcweir #include "storcach.hxx"
36cdf0e10cSrcweir
37cdf0e10cSrcweir /*========================================================================
38cdf0e10cSrcweir *
39cdf0e10cSrcweir * OStorePageBIOS.
40cdf0e10cSrcweir *
41cdf0e10cSrcweir *======================================================================*/
42cdf0e10cSrcweir namespace store
43cdf0e10cSrcweir {
44cdf0e10cSrcweir
45cdf0e10cSrcweir struct SuperBlockPage;
46cdf0e10cSrcweir
47cdf0e10cSrcweir class OStorePageBIOS : public store::OStoreObject
48cdf0e10cSrcweir {
49cdf0e10cSrcweir public:
50cdf0e10cSrcweir /** Construction.
51cdf0e10cSrcweir */
52cdf0e10cSrcweir OStorePageBIOS (void);
53cdf0e10cSrcweir
54cdf0e10cSrcweir /** Conversion into Mutex&
55cdf0e10cSrcweir */
56cdf0e10cSrcweir inline operator osl::Mutex& (void) const;
57cdf0e10cSrcweir
58cdf0e10cSrcweir /** Initialization.
59cdf0e10cSrcweir * @param pLockBytes [in]
60cdf0e10cSrcweir * @param eAccessMode [in]
61cdf0e10cSrcweir * @param rnPageSize [inout]
62cdf0e10cSrcweir * @return store_E_None upon success
63cdf0e10cSrcweir */
64cdf0e10cSrcweir virtual storeError initialize (
65cdf0e10cSrcweir ILockBytes * pLockBytes,
66cdf0e10cSrcweir storeAccessMode eAccessMode,
67cdf0e10cSrcweir sal_uInt16 & rnPageSize);
68cdf0e10cSrcweir
allocator()69cdf0e10cSrcweir rtl::Reference< PageData::Allocator > & allocator()
70cdf0e10cSrcweir {
71cdf0e10cSrcweir return m_xAllocator;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
74cdf0e10cSrcweir /** read.
75cdf0e10cSrcweir */
76cdf0e10cSrcweir storeError read (
77cdf0e10cSrcweir sal_uInt32 nAddr, void *pData, sal_uInt32 nSize);
78cdf0e10cSrcweir
79cdf0e10cSrcweir /** write.
80cdf0e10cSrcweir */
81cdf0e10cSrcweir storeError write (
82cdf0e10cSrcweir sal_uInt32 nAddr, const void *pData, sal_uInt32 nSize);
83cdf0e10cSrcweir
84cdf0e10cSrcweir /** isWriteable.
85cdf0e10cSrcweir */
86cdf0e10cSrcweir inline bool isWriteable (void) const;
87cdf0e10cSrcweir
88cdf0e10cSrcweir /** isValid.
89cdf0e10cSrcweir */
90cdf0e10cSrcweir inline sal_Bool isValid (void) const;
91cdf0e10cSrcweir
92cdf0e10cSrcweir /** Page Access.
93cdf0e10cSrcweir */
94cdf0e10cSrcweir storeError acquirePage (
95cdf0e10cSrcweir const OStorePageDescriptor& rDescr, storeAccessMode eMode);
96cdf0e10cSrcweir
97cdf0e10cSrcweir storeError releasePage (
98cdf0e10cSrcweir const OStorePageDescriptor& rDescr, storeAccessMode eMode);
99cdf0e10cSrcweir
100cdf0e10cSrcweir sal_uInt32 getRefererCount (void);
101cdf0e10cSrcweir
102cdf0e10cSrcweir /** Page Allocation.
103cdf0e10cSrcweir */
104cdf0e10cSrcweir enum Allocation
105cdf0e10cSrcweir {
106cdf0e10cSrcweir ALLOCATE_FIRST = 0,
107cdf0e10cSrcweir ALLOCATE_BEST = 1,
108cdf0e10cSrcweir ALLOCATE_EOF = 2
109cdf0e10cSrcweir };
110cdf0e10cSrcweir
111cdf0e10cSrcweir storeError allocate (
112cdf0e10cSrcweir OStorePageObject& rPage, Allocation eAllocation = ALLOCATE_FIRST);
113cdf0e10cSrcweir
114cdf0e10cSrcweir storeError free (sal_uInt32 nAddr);
115cdf0e10cSrcweir
116cdf0e10cSrcweir /** Page I/O.
117cdf0e10cSrcweir */
118cdf0e10cSrcweir storeError loadObjectAt (
119cdf0e10cSrcweir OStorePageObject& rPage, sal_uInt32 nAddr);
120cdf0e10cSrcweir
121cdf0e10cSrcweir storeError saveObjectAt (
122cdf0e10cSrcweir OStorePageObject& rPage, sal_uInt32 nAddr);
123cdf0e10cSrcweir
124cdf0e10cSrcweir /** close.
125cdf0e10cSrcweir * @return store_E_None upon success.
126cdf0e10cSrcweir */
127cdf0e10cSrcweir storeError close (void);
128cdf0e10cSrcweir
129cdf0e10cSrcweir /** flush.
130cdf0e10cSrcweir * @return store_E_None upon success.
131cdf0e10cSrcweir */
132cdf0e10cSrcweir storeError flush (void);
133cdf0e10cSrcweir
134cdf0e10cSrcweir /** size.
135cdf0e10cSrcweir */
136cdf0e10cSrcweir storeError size (sal_uInt32 &rnSize);
137cdf0e10cSrcweir
138cdf0e10cSrcweir /** ScanContext.
139cdf0e10cSrcweir */
140cdf0e10cSrcweir struct ScanContext
141cdf0e10cSrcweir {
142cdf0e10cSrcweir /** Representation.
143cdf0e10cSrcweir */
144cdf0e10cSrcweir OStorePageDescriptor m_aDescr;
145cdf0e10cSrcweir sal_uInt32 m_nSize;
146cdf0e10cSrcweir sal_uInt32 m_nMagic;
147cdf0e10cSrcweir
148cdf0e10cSrcweir /** Construction.
149cdf0e10cSrcweir */
150cdf0e10cSrcweir inline ScanContext (void);
151cdf0e10cSrcweir
152cdf0e10cSrcweir /** isValid.
153cdf0e10cSrcweir */
154cdf0e10cSrcweir inline bool isValid (void) const;
155cdf0e10cSrcweir };
156cdf0e10cSrcweir
157cdf0e10cSrcweir /** scanBegin.
158cdf0e10cSrcweir */
159cdf0e10cSrcweir storeError scanBegin (
160cdf0e10cSrcweir ScanContext &rCtx,
161cdf0e10cSrcweir sal_uInt32 nMagic = 0);
162cdf0e10cSrcweir
163cdf0e10cSrcweir /** scanNext.
164cdf0e10cSrcweir */
165cdf0e10cSrcweir storeError scanNext (
166cdf0e10cSrcweir ScanContext &rCtx,
167cdf0e10cSrcweir OStorePageObject &rPage);
168cdf0e10cSrcweir
169cdf0e10cSrcweir protected:
170cdf0e10cSrcweir /** Destruction (OReference).
171cdf0e10cSrcweir */
172cdf0e10cSrcweir virtual ~OStorePageBIOS (void);
173cdf0e10cSrcweir
174cdf0e10cSrcweir private:
175cdf0e10cSrcweir /** Representation.
176cdf0e10cSrcweir */
177cdf0e10cSrcweir rtl::Reference<ILockBytes> m_xLockBytes;
178cdf0e10cSrcweir osl::Mutex m_aMutex;
179cdf0e10cSrcweir
180cdf0e10cSrcweir SuperBlockPage * m_pSuper;
181cdf0e10cSrcweir
182cdf0e10cSrcweir bool m_bWriteable;
183cdf0e10cSrcweir
184cdf0e10cSrcweir rtl::Reference< PageData::Allocator > m_xAllocator;
185cdf0e10cSrcweir rtl::Reference< PageCache > m_xCache;
186cdf0e10cSrcweir
187cdf0e10cSrcweir /** Page Access (control).
188cdf0e10cSrcweir */
189cdf0e10cSrcweir public:
190cdf0e10cSrcweir struct Ace
191cdf0e10cSrcweir {
192cdf0e10cSrcweir Ace * m_next;
193cdf0e10cSrcweir Ace * m_prev;
194cdf0e10cSrcweir
195cdf0e10cSrcweir sal_uInt32 m_addr;
196cdf0e10cSrcweir sal_uInt32 m_used;
197cdf0e10cSrcweir
198cdf0e10cSrcweir Ace();
199cdf0e10cSrcweir ~Ace();
200cdf0e10cSrcweir
201cdf0e10cSrcweir static int SAL_CALL constructor (void * obj, void * arg);
202cdf0e10cSrcweir
203cdf0e10cSrcweir static Ace * find (Ace * head, sal_uInt32 addr);
204cdf0e10cSrcweir static void insert (Ace * head, Ace * entry);
205cdf0e10cSrcweir };
206cdf0e10cSrcweir
207cdf0e10cSrcweir private:
208cdf0e10cSrcweir Ace m_ace_head;
209cdf0e10cSrcweir
210cdf0e10cSrcweir class AceCache;
211cdf0e10cSrcweir
212cdf0e10cSrcweir /** Initialization.
213cdf0e10cSrcweir */
214cdf0e10cSrcweir storeError initialize_Impl (
215cdf0e10cSrcweir ILockBytes * pLockBytes,
216cdf0e10cSrcweir storeAccessMode eAccessMode,
217cdf0e10cSrcweir sal_uInt16 & rnPageSize);
218cdf0e10cSrcweir void cleanup_Impl();
219cdf0e10cSrcweir
220cdf0e10cSrcweir /** Page Maintenance.
221cdf0e10cSrcweir */
222cdf0e10cSrcweir storeError loadObjectAt_Impl (
223cdf0e10cSrcweir OStorePageObject & rPage, sal_uInt32 nAddr);
224cdf0e10cSrcweir storeError saveObjectAt_Impl (
225cdf0e10cSrcweir OStorePageObject & rPage, sal_uInt32 nAddr);
226cdf0e10cSrcweir
227cdf0e10cSrcweir /** Not implemented.
228cdf0e10cSrcweir */
229cdf0e10cSrcweir OStorePageBIOS (const OStorePageBIOS&);
230cdf0e10cSrcweir OStorePageBIOS& operator= (const OStorePageBIOS&);
231cdf0e10cSrcweir };
232cdf0e10cSrcweir
operator osl::Mutex&(void) const233cdf0e10cSrcweir inline OStorePageBIOS::operator osl::Mutex& (void) const
234cdf0e10cSrcweir {
235cdf0e10cSrcweir return (osl::Mutex&)m_aMutex;
236cdf0e10cSrcweir }
isWriteable(void) const237cdf0e10cSrcweir inline bool OStorePageBIOS::isWriteable (void) const
238cdf0e10cSrcweir {
239cdf0e10cSrcweir return m_bWriteable;
240cdf0e10cSrcweir }
isValid(void) const241cdf0e10cSrcweir inline sal_Bool OStorePageBIOS::isValid (void) const
242cdf0e10cSrcweir {
243cdf0e10cSrcweir return m_xLockBytes.is();
244cdf0e10cSrcweir }
245cdf0e10cSrcweir
ScanContext(void)246cdf0e10cSrcweir inline OStorePageBIOS::ScanContext::ScanContext (void)
247cdf0e10cSrcweir : m_aDescr (0, 0, 0), m_nSize (0), m_nMagic (0)
248cdf0e10cSrcweir {
249cdf0e10cSrcweir }
isValid(void) const250cdf0e10cSrcweir inline bool OStorePageBIOS::ScanContext::isValid (void) const
251cdf0e10cSrcweir {
252cdf0e10cSrcweir return (m_aDescr.m_nAddr < m_nSize);
253cdf0e10cSrcweir }
254cdf0e10cSrcweir
255cdf0e10cSrcweir /*========================================================================
256cdf0e10cSrcweir *
257cdf0e10cSrcweir * The End.
258cdf0e10cSrcweir *
259cdf0e10cSrcweir *======================================================================*/
260cdf0e10cSrcweir
261cdf0e10cSrcweir } // namespace store
262cdf0e10cSrcweir
263cdf0e10cSrcweir #endif /* !_STORE_STORBIOS_HXX_ */
264