xref: /aoo41x/main/store/source/storpage.hxx (revision 1a5fa39b)
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_STORPAGE_HXX_
25 #define _STORE_STORPAGE_HXX_ "$Revision: 1.6.8.2 $"
26 
27 #include "sal/types.h"
28 
29 #include "object.hxx"
30 #include "lockbyte.hxx"
31 
32 #include "storbase.hxx"
33 #include "storbios.hxx"
34 #include "stortree.hxx"
35 
36 namespace store
37 {
38 
39 struct OStoreDirectoryPageData;
40 class  OStoreDirectoryPageObject;
41 
42 /*========================================================================
43  *
44  * OStorePageManager interface.
45  *
46  *======================================================================*/
47 class OStorePageManager : public store::OStorePageBIOS
48 {
49 public:
50 	/** Construction.
51 	 */
52 	OStorePageManager (void);
53 
54 	/** Initialization (two-phase construction).
55 	 */
56     virtual storeError initialize (
57 		ILockBytes *    pLockBytes,
58 		storeAccessMode eAccessMode,
59 		sal_uInt16 &    rnPageSize);
60 
61 	/** isValid.
62 	 *  @return sal_True  upon successful initialization,
63 	 *          sal_False otherwise.
64 	 */
65 	inline sal_Bool isValid (void) const;
66 
67 	/** DirectoryPage I/O (managed).
68 	 */
69 	static storeError namei (
70 		const rtl_String *pPath,
71 		const rtl_String *pName,
72 		OStorePageKey    &rKey);
73 
74 	storeError iget (
75 		OStoreDirectoryPageObject & rPage, // [out]
76 		sal_uInt32                  nAttrib,
77 		const rtl_String *          pPath,
78 		const rtl_String *          pName,
79 		storeAccessMode             eMode);
80 
81 	storeError iterate (
82 		OStorePageKey &  rKey,
83 		OStorePageLink & rLink,
84 		sal_uInt32 &     rAttrib);
85 
86 	/** attrib [nAttrib = ((nAttrib & ~nMask1) | nMask2)].
87      *  @see store_attrib()
88 	 */
89 	storeError attrib (
90 		const OStorePageKey &rKey,
91 		sal_uInt32           nMask1,
92 		sal_uInt32           nMask2,
93 		sal_uInt32          &rAttrib);
94 
95 	/** link (insert Source Key as hardlink to Destination).
96      *  @see store_link()
97 	 */
98 	storeError link (
99 		const OStorePageKey &rSrcKey,
100 		const OStorePageKey &rDstKey);
101 
102 	/** symlink (insert Source DirectoryPage as symlink to Destination).
103      *  @see store_symlink()
104 	 */
105 	storeError symlink (
106 		const rtl_String    *pSrcPath,
107 		const rtl_String    *pSrcName,
108 		const OStorePageKey &rDstKey);
109 
110 	/** rename.
111      *  @see store_rename()
112 	 */
113 	storeError rename (
114 		const OStorePageKey &rSrcKey,
115 		const rtl_String    *pDstPath,
116 		const rtl_String    *pDstName);
117 
118 	/** remove.
119      *  @see store_remove()
120 	 */
121 	storeError remove (
122 		const OStorePageKey &rKey);
123 
124 	/** rebuild (combines recover and compact from 'Src' to 'Dst').
125 	 *  @param  pSrcLB [in] accessed readonly.
126 	 *  @param  pDstLB [in] truncated and accessed readwrite (as initialize()).
127 	 *  @return store_E_None upon success.
128      *
129      *  @see store_rebuildFile()
130 	 */
131 	storeError rebuild (
132 		ILockBytes *pSrcLB,
133 		ILockBytes *pDstLB);
134 
135 	/** IStoreHandle.
136 	 */
137 	virtual sal_Bool SAL_CALL isKindOf (sal_uInt32 nTypeId);
138 
139 protected:
140 	/** Destruction.
141 	*/
142 	virtual ~OStorePageManager (void);
143 
144 private:
145 	/** Implementation.
146 	*/
147 	typedef OStorePageBIOS            base;
148 	typedef OStorePageManager         self;
149 
150 	typedef OStoreBTreeEntry          entry;
151 	typedef OStoreBTreeNodeData       page;
152 	typedef OStoreBTreeNodeObject     node;
153 
154     typedef OStoreDirectoryPageData   inode;
155     typedef PageHolderObject< inode > inode_holder_type;
156 
157 	/** IStoreHandle TypeId.
158 	 */
159 	static const sal_uInt32 m_nTypeId;
160 
161 	/** IStoreHandle query() template function specialization.
162 	 */
163 	friend OStorePageManager*
164 	SAL_CALL query<> (IStoreHandle *pHandle, OStorePageManager*);
165 
166 	/** Representation.
167 	*/
168     OStoreBTreeRootObject m_aRoot;
169 
170 	/** DirectoryPage I/O (managed).
171 	 */
172 	storeError load_dirpage_Impl ( // @@@ => private: iget() @@@
173 		const OStorePageKey       &rKey,
174 		OStoreDirectoryPageObject &rPage);
175 
176 	storeError save_dirpage_Impl ( // @@@ => private: iget(), rebuild() @@@
177 		const OStorePageKey       &rKey,
178 		OStoreDirectoryPageObject &rPage);
179 
180 	/** find_lookup (node page and index, w/o split).
181 	*/
182 	storeError find_lookup (
183         OStoreBTreeNodeObject & rNode,
184         sal_uInt16 &            rIndex,
185         OStorePageKey const &   rKey);
186 
187 	/** remove (possibly down from root).
188 	*/
189 	storeError remove_Impl (entry & rEntry);
190 
191 	/** Not implemented.
192 	*/
193 	OStorePageManager (const OStorePageManager&);
194 	OStorePageManager& operator= (const OStorePageManager&);
195 };
196 
isValid(void) const197 inline sal_Bool OStorePageManager::isValid (void) const
198 {
199 	return (base::isValid() /* @@@ NYI && (m_aRoot.is()) */);
200 }
201 
202 template<> inline OStorePageManager*
query(IStoreHandle * pHandle,OStorePageManager *)203 SAL_CALL query (IStoreHandle *pHandle, OStorePageManager*)
204 {
205 	if (pHandle && pHandle->isKindOf (OStorePageManager::m_nTypeId))
206 	{
207 		// Handle is kind of OStorePageManager.
208 		return static_cast<OStorePageManager*>(pHandle);
209 	}
210 	return 0;
211 }
212 
213 /*========================================================================
214  *
215  * The End.
216  *
217  *======================================================================*/
218 
219 } // namespace store
220 
221 #endif /* !_STORE_STORPAGE_HXX_ */
222 
223