Branch libreoffice-5-0-4
[LibreOffice.git] / store / source / storbios.hxx
blob0380b134485e70fe237e77302a8e00335deb4c43
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 INCLUDED_STORE_SOURCE_STORBIOS_HXX
21 #define INCLUDED_STORE_SOURCE_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();
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() const;
84 /** isValid.
86 inline bool isValid() const;
88 /** Page Access.
90 storeError acquirePage (
91 const OStorePageDescriptor& rDescr, storeAccessMode eMode);
93 storeError releasePage (const OStorePageDescriptor& rDescr);
95 sal_uInt32 getRefererCount();
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();
124 /** flush.
125 * @return store_E_None upon success.
127 storeError flush();
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();
147 /** isValid.
149 inline bool isValid() 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();
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 OStorePageBIOS (const OStorePageBIOS&) SAL_DELETED_FUNCTION;
223 OStorePageBIOS& operator= (const OStorePageBIOS&) SAL_DELETED_FUNCTION;
226 inline OStorePageBIOS::operator osl::Mutex& (void) const
228 return (osl::Mutex&)m_aMutex;
230 inline bool OStorePageBIOS::isWriteable() const
232 return m_bWriteable;
234 inline bool OStorePageBIOS::isValid() const
236 return m_xLockBytes.is();
239 inline OStorePageBIOS::ScanContext::ScanContext()
240 : m_aDescr (0, 0, 0), m_nSize (0), m_nMagic (0)
243 inline bool OStorePageBIOS::ScanContext::isValid() const
245 return (m_aDescr.m_nAddr < m_nSize);
248 /*========================================================================
250 * The End.
252 *======================================================================*/
254 } // namespace store
256 #endif // INCLUDED_STORE_SOURCE_STORBIOS_HXX
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */