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