update credits
[LibreOffice.git] / store / source / storbios.hxx
blob37d9dc3854dbe34170cb27209a3ce5fc45f4b52b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _STORE_STORBIOS_HXX_
21 #define _STORE_STORBIOS_HXX_
23 #include "sal/types.h"
24 #include "rtl/ref.hxx"
25 #include "osl/mutex.hxx"
27 #include "store/types.h"
28 #include "object.hxx"
29 #include "lockbyte.hxx"
30 #include "storbase.hxx"
31 #include "storcach.hxx"
33 /*========================================================================
35 * OStorePageBIOS.
37 *======================================================================*/
38 namespace store
41 struct SuperBlockPage;
43 class OStorePageBIOS : public store::OStoreObject
45 public:
46 /** Construction.
48 OStorePageBIOS (void);
50 /** Conversion into Mutex&
52 inline operator osl::Mutex& (void) const;
54 /** Initialization.
55 * @param pLockBytes [in]
56 * @param eAccessMode [in]
57 * @param rnPageSize [inout]
58 * @return store_E_None upon success
60 virtual storeError initialize (
61 ILockBytes * pLockBytes,
62 storeAccessMode eAccessMode,
63 sal_uInt16 & rnPageSize);
65 rtl::Reference< PageData::Allocator > & allocator()
67 return m_xAllocator;
70 /** read.
72 storeError read (
73 sal_uInt32 nAddr, void *pData, sal_uInt32 nSize);
75 /** write.
77 storeError write (
78 sal_uInt32 nAddr, const void *pData, sal_uInt32 nSize);
80 /** isWriteable.
82 inline bool isWriteable (void) const;
84 /** isValid.
86 inline sal_Bool isValid (void) const;
88 /** Page Access.
90 storeError acquirePage (
91 const OStorePageDescriptor& rDescr, storeAccessMode eMode);
93 storeError releasePage (const OStorePageDescriptor& rDescr);
95 sal_uInt32 getRefererCount (void);
97 /** Page Allocation.
99 enum Allocation
101 ALLOCATE_FIRST = 0,
102 ALLOCATE_BEST = 1,
103 ALLOCATE_EOF = 2
106 storeError allocate (
107 OStorePageObject& rPage, Allocation eAllocation = ALLOCATE_FIRST);
109 storeError free (sal_uInt32 nAddr);
111 /** Page I/O.
113 storeError loadObjectAt (
114 OStorePageObject& rPage, sal_uInt32 nAddr);
116 storeError saveObjectAt (
117 OStorePageObject& rPage, sal_uInt32 nAddr);
119 /** close.
120 * @return store_E_None upon success.
122 storeError close (void);
124 /** flush.
125 * @return store_E_None upon success.
127 storeError flush (void);
129 /** size.
131 storeError size (sal_uInt32 &rnSize);
133 /** ScanContext.
135 struct ScanContext
137 /** Representation.
139 OStorePageDescriptor m_aDescr;
140 sal_uInt32 m_nSize;
141 sal_uInt32 m_nMagic;
143 /** Construction.
145 inline ScanContext (void);
147 /** isValid.
149 inline bool isValid (void) const;
152 /** scanBegin.
154 storeError scanBegin (
155 ScanContext &rCtx,
156 sal_uInt32 nMagic = 0);
158 /** scanNext.
160 storeError scanNext (
161 ScanContext &rCtx,
162 OStorePageObject &rPage);
164 protected:
165 /** Destruction (OReference).
167 virtual ~OStorePageBIOS (void);
169 private:
170 /** Representation.
172 rtl::Reference<ILockBytes> m_xLockBytes;
173 osl::Mutex m_aMutex;
175 SuperBlockPage * m_pSuper;
177 bool m_bWriteable;
179 rtl::Reference< PageData::Allocator > m_xAllocator;
180 rtl::Reference< PageCache > m_xCache;
182 /** Page Access (control).
184 public:
185 struct Ace
187 Ace * m_next;
188 Ace * m_prev;
190 sal_uInt32 m_addr;
191 sal_uInt32 m_used;
193 Ace();
194 ~Ace();
196 static int SAL_CALL constructor (void * obj, void * arg);
198 static Ace * find (Ace * head, sal_uInt32 addr);
199 static void insert (Ace * head, Ace * entry);
202 private:
203 Ace m_ace_head;
205 class AceCache;
207 /** Initialization.
209 storeError initialize_Impl (
210 ILockBytes * pLockBytes,
211 storeAccessMode eAccessMode,
212 sal_uInt16 & rnPageSize);
213 void cleanup_Impl();
215 /** Page Maintenance.
217 storeError loadObjectAt_Impl (
218 OStorePageObject & rPage, sal_uInt32 nAddr);
219 storeError saveObjectAt_Impl (
220 OStorePageObject & rPage, sal_uInt32 nAddr);
222 /** Not implemented.
224 OStorePageBIOS (const OStorePageBIOS&);
225 OStorePageBIOS& operator= (const OStorePageBIOS&);
228 inline OStorePageBIOS::operator osl::Mutex& (void) const
230 return (osl::Mutex&)m_aMutex;
232 inline bool OStorePageBIOS::isWriteable (void) const
234 return m_bWriteable;
236 inline sal_Bool OStorePageBIOS::isValid (void) const
238 return m_xLockBytes.is();
241 inline OStorePageBIOS::ScanContext::ScanContext (void)
242 : m_aDescr (0, 0, 0), m_nSize (0), m_nMagic (0)
245 inline bool OStorePageBIOS::ScanContext::isValid (void) const
247 return (m_aDescr.m_nAddr < m_nSize);
250 /*========================================================================
252 * The End.
254 *======================================================================*/
256 } // namespace store
258 #endif /* !_STORE_STORBIOS_HXX_ */
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */