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