1*73d9b18aSAndrew Rist /**************************************************************
2*73d9b18aSAndrew Rist *
3*73d9b18aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*73d9b18aSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*73d9b18aSAndrew Rist * distributed with this work for additional information
6*73d9b18aSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*73d9b18aSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*73d9b18aSAndrew Rist * "License"); you may not use this file except in compliance
9*73d9b18aSAndrew Rist * with the License. You may obtain a copy of the License at
10*73d9b18aSAndrew Rist *
11*73d9b18aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*73d9b18aSAndrew Rist *
13*73d9b18aSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*73d9b18aSAndrew Rist * software distributed under the License is distributed on an
15*73d9b18aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*73d9b18aSAndrew Rist * KIND, either express or implied. See the License for the
17*73d9b18aSAndrew Rist * specific language governing permissions and limitations
18*73d9b18aSAndrew Rist * under the License.
19*73d9b18aSAndrew Rist *
20*73d9b18aSAndrew Rist *************************************************************/
21*73d9b18aSAndrew Rist
22cdf0e10cSrcweir /*
23cdf0e10cSrcweir * t_page.cxx
24cdf0e10cSrcweir */
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include "osl/diagnose.h"
27cdf0e10cSrcweir #include "rtl/alloc.h"
28cdf0e10cSrcweir #include "rtl/ref.hxx"
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include "storbase.hxx"
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include "osl/file.h"
33cdf0e10cSrcweir #include "rtl/ustring.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir /*========================================================================
36cdf0e10cSrcweir *
37cdf0e10cSrcweir * OTest...
38cdf0e10cSrcweir *
39cdf0e10cSrcweir *======================================================================*/
40cdf0e10cSrcweir
swap(T & lhs,T & rhs)41cdf0e10cSrcweir template< class T > void swap (T & lhs, T & rhs)
42cdf0e10cSrcweir {
43cdf0e10cSrcweir T tmp = rhs; rhs = lhs; lhs = tmp;
44cdf0e10cSrcweir }
45cdf0e10cSrcweir
46cdf0e10cSrcweir /*======================================================================*/
47cdf0e10cSrcweir
48cdf0e10cSrcweir class SharedCount
49cdf0e10cSrcweir {
50cdf0e10cSrcweir long * m_pCount;
51cdf0e10cSrcweir
52cdf0e10cSrcweir class Allocator
53cdf0e10cSrcweir {
54cdf0e10cSrcweir rtl_cache_type * m_cache;
55cdf0e10cSrcweir
56cdf0e10cSrcweir public:
57cdf0e10cSrcweir static Allocator & get();
58cdf0e10cSrcweir
alloc()59cdf0e10cSrcweir long * alloc()
60cdf0e10cSrcweir {
61cdf0e10cSrcweir return static_cast<long*>(rtl_cache_alloc (m_cache));
62cdf0e10cSrcweir }
free(long * pCount)63cdf0e10cSrcweir void free (long * pCount)
64cdf0e10cSrcweir {
65cdf0e10cSrcweir rtl_cache_free (m_cache, pCount);
66cdf0e10cSrcweir }
67cdf0e10cSrcweir
68cdf0e10cSrcweir protected:
69cdf0e10cSrcweir Allocator();
70cdf0e10cSrcweir ~Allocator();
71cdf0e10cSrcweir };
72cdf0e10cSrcweir
73cdf0e10cSrcweir public:
SharedCount()74cdf0e10cSrcweir SharedCount()
75cdf0e10cSrcweir : m_pCount(Allocator::get().alloc())
76cdf0e10cSrcweir {
77cdf0e10cSrcweir if (m_pCount != 0) (*m_pCount) = 1;
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
~SharedCount()80cdf0e10cSrcweir ~SharedCount()
81cdf0e10cSrcweir {
82cdf0e10cSrcweir if (m_pCount != 0)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir long new_count = --(*m_pCount);
85cdf0e10cSrcweir if (new_count == 0)
86cdf0e10cSrcweir Allocator::get().free(m_pCount);
87cdf0e10cSrcweir }
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
operator ==(long count) const90cdf0e10cSrcweir bool operator== (long count) const
91cdf0e10cSrcweir {
92cdf0e10cSrcweir return (m_pCount != 0) ? *m_pCount == count : false;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
95cdf0e10cSrcweir friend void swap<> (SharedCount & lhs, SharedCount & rhs); // nothrow
96cdf0e10cSrcweir
97cdf0e10cSrcweir SharedCount (SharedCount const & rhs); // nothrow
98cdf0e10cSrcweir SharedCount & operator= (SharedCount const & rhs); // nothrow
99cdf0e10cSrcweir };
100cdf0e10cSrcweir
101cdf0e10cSrcweir template<>
swap(SharedCount & lhs,SharedCount & rhs)102cdf0e10cSrcweir inline void swap (SharedCount & lhs, SharedCount & rhs) // nothrow
103cdf0e10cSrcweir {
104cdf0e10cSrcweir swap<long*>(lhs.m_pCount, rhs.m_pCount);
105cdf0e10cSrcweir }
106cdf0e10cSrcweir
SharedCount(SharedCount const & rhs)107cdf0e10cSrcweir SharedCount::SharedCount (SharedCount const & rhs) // nothrow
108cdf0e10cSrcweir : m_pCount (rhs.m_pCount)
109cdf0e10cSrcweir {
110cdf0e10cSrcweir if (m_pCount != 0) ++(*m_pCount);
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
113cdf0e10cSrcweir SharedCount &
operator =(SharedCount const & rhs)114cdf0e10cSrcweir SharedCount::operator= (SharedCount const & rhs) // nothrow
115cdf0e10cSrcweir {
116cdf0e10cSrcweir SharedCount tmp(rhs);
117cdf0e10cSrcweir swap<SharedCount>(tmp, *this);
118cdf0e10cSrcweir return *this;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
121cdf0e10cSrcweir SharedCount::Allocator &
get()122cdf0e10cSrcweir SharedCount::Allocator::get()
123cdf0e10cSrcweir {
124cdf0e10cSrcweir static Allocator g_aSharedCountAllocator;
125cdf0e10cSrcweir return g_aSharedCountAllocator;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir
Allocator()128cdf0e10cSrcweir SharedCount::Allocator::Allocator()
129cdf0e10cSrcweir {
130cdf0e10cSrcweir m_cache = rtl_cache_create (
131cdf0e10cSrcweir "store_shared_count_cache",
132cdf0e10cSrcweir sizeof(long),
133cdf0e10cSrcweir 0, // objalign
134cdf0e10cSrcweir 0, // constructor
135cdf0e10cSrcweir 0, // destructor
136cdf0e10cSrcweir 0, // reclaim
137cdf0e10cSrcweir 0, // userarg
138cdf0e10cSrcweir 0, // default source
139cdf0e10cSrcweir 0 // flags
140cdf0e10cSrcweir );
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
~Allocator()143cdf0e10cSrcweir SharedCount::Allocator::~Allocator()
144cdf0e10cSrcweir {
145cdf0e10cSrcweir rtl_cache_destroy (m_cache), m_cache = 0;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir /*======================================================================*/
149cdf0e10cSrcweir
150cdf0e10cSrcweir #if 0 /* OLD */
151cdf0e10cSrcweir
152cdf0e10cSrcweir typedef store::OStorePageData PageData;
153cdf0e10cSrcweir
154cdf0e10cSrcweir #else /* NEW */
155cdf0e10cSrcweir
156cdf0e10cSrcweir #if defined(OSL_BIGENDIAN)
157cdf0e10cSrcweir #define STORE_DWORD(dword) OSL_SWAPDWORD((dword))
158cdf0e10cSrcweir #else
159cdf0e10cSrcweir #define STORE_DWORD(dword) (dword)
160cdf0e10cSrcweir #endif
161cdf0e10cSrcweir
162cdf0e10cSrcweir struct PageData
163cdf0e10cSrcweir {
164cdf0e10cSrcweir typedef store::OStorePageGuard G;
165cdf0e10cSrcweir typedef store::OStorePageDescriptor D;
166cdf0e10cSrcweir typedef store::OStorePageLink L;
167cdf0e10cSrcweir
168cdf0e10cSrcweir /** Representation.
169cdf0e10cSrcweir */
170cdf0e10cSrcweir G m_aGuard;
171cdf0e10cSrcweir D m_aDescr;
172cdf0e10cSrcweir L m_aMarked;
173cdf0e10cSrcweir L m_aUnused;
174cdf0e10cSrcweir
175cdf0e10cSrcweir /** theSize.
176cdf0e10cSrcweir */
177cdf0e10cSrcweir static const size_t theSize = sizeof(G) + sizeof(D) + 2 * sizeof(L);
178cdf0e10cSrcweir static const sal_uInt16 thePageSize = theSize;
179cdf0e10cSrcweir STORE_STATIC_ASSERT(STORE_MINIMUM_PAGESIZE >= thePageSize);
180cdf0e10cSrcweir
181cdf0e10cSrcweir /** type.
182cdf0e10cSrcweir */
typePageData183cdf0e10cSrcweir sal_uInt32 type() const { return m_aGuard.m_nMagic; /* @@@ */ }
184cdf0e10cSrcweir
185cdf0e10cSrcweir /** offset.
186cdf0e10cSrcweir */
offsetPageData187cdf0e10cSrcweir sal_uInt32 offset() const { return m_aDescr.m_nAddr; /* @@@ */ }
offsetPageData188cdf0e10cSrcweir void offset (sal_uInt32 nOffset) { m_aDescr.m_nAddr = nOffset; }
189cdf0e10cSrcweir
190cdf0e10cSrcweir /** size.
191cdf0e10cSrcweir */
sizePageData192cdf0e10cSrcweir sal_uInt16 size() const { return m_aDescr.m_nSize; /* @@@ */ }
193cdf0e10cSrcweir
194cdf0e10cSrcweir /** Allocation.
195cdf0e10cSrcweir */
196cdf0e10cSrcweir class Allocator : public rtl::IReference
197cdf0e10cSrcweir {
198cdf0e10cSrcweir public:
construct()199cdf0e10cSrcweir template< class T > T * construct()
200cdf0e10cSrcweir {
201cdf0e10cSrcweir void * page = 0; sal_uInt16 size = 0;
202cdf0e10cSrcweir if (allocate (&page, &size))
203cdf0e10cSrcweir {
204cdf0e10cSrcweir return new(page) T(size);
205cdf0e10cSrcweir }
206cdf0e10cSrcweir return 0;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
209cdf0e10cSrcweir virtual bool allocate (void ** ppPage, sal_uInt16 * pnSize) = 0;
210cdf0e10cSrcweir virtual void deallocate (void * pPage) = 0;
211cdf0e10cSrcweir };
212cdf0e10cSrcweir
operator newPageData213cdf0e10cSrcweir static void * operator new (size_t, void * p) { return p; }
operator deletePageData214cdf0e10cSrcweir static void operator delete (void *, void *) {}
215cdf0e10cSrcweir
216cdf0e10cSrcweir /** Construction.
217cdf0e10cSrcweir */
PageDataPageData218cdf0e10cSrcweir explicit PageData (sal_uInt16 nPageSize = thePageSize)
219cdf0e10cSrcweir : m_aDescr (STORE_PAGE_NULL, nPageSize, thePageSize)
220cdf0e10cSrcweir {}
221cdf0e10cSrcweir
222cdf0e10cSrcweir /** ...
223cdf0e10cSrcweir */
guardPageData224cdf0e10cSrcweir void guard()
225cdf0e10cSrcweir {}
226cdf0e10cSrcweir
verifyPageData227cdf0e10cSrcweir storeError verify() const
228cdf0e10cSrcweir {
229cdf0e10cSrcweir return store_E_None;
230cdf0e10cSrcweir }
231cdf0e10cSrcweir };
232cdf0e10cSrcweir
233cdf0e10cSrcweir #endif /* NEW */
234cdf0e10cSrcweir
235cdf0e10cSrcweir class IPageAllocator
236cdf0e10cSrcweir {
237cdf0e10cSrcweir public:
238cdf0e10cSrcweir virtual void deallocate (void * p) = 0;
239cdf0e10cSrcweir };
240cdf0e10cSrcweir
241cdf0e10cSrcweir class PageAllocator
242cdf0e10cSrcweir {
243cdf0e10cSrcweir rtl_cache_type * m_cache;
244cdf0e10cSrcweir SharedCount m_refcount;
245cdf0e10cSrcweir
246cdf0e10cSrcweir public:
PageAllocator()247cdf0e10cSrcweir PageAllocator()
248cdf0e10cSrcweir : m_cache(0), m_refcount()
249cdf0e10cSrcweir {}
250cdf0e10cSrcweir
~PageAllocator()251cdf0e10cSrcweir ~PageAllocator()
252cdf0e10cSrcweir {
253cdf0e10cSrcweir // NYI
254cdf0e10cSrcweir if (m_refcount == 1)
255cdf0e10cSrcweir {
256cdf0e10cSrcweir }
257cdf0e10cSrcweir }
258cdf0e10cSrcweir
259cdf0e10cSrcweir friend void swap<>(PageAllocator & lhs, PageAllocator & rhs);
260cdf0e10cSrcweir
261cdf0e10cSrcweir PageAllocator (PageAllocator const & rhs);
262cdf0e10cSrcweir PageAllocator & operator= (PageAllocator const & rhs);
263cdf0e10cSrcweir };
264cdf0e10cSrcweir
265cdf0e10cSrcweir template<>
swap(PageAllocator & lhs,PageAllocator & rhs)266cdf0e10cSrcweir inline void swap (PageAllocator & lhs, PageAllocator & rhs)
267cdf0e10cSrcweir {
268cdf0e10cSrcweir swap<rtl_cache_type*>(lhs.m_cache, rhs.m_cache);
269cdf0e10cSrcweir swap<SharedCount>(lhs.m_refcount, rhs.m_refcount);
270cdf0e10cSrcweir }
271cdf0e10cSrcweir
PageAllocator(PageAllocator const & rhs)272cdf0e10cSrcweir PageAllocator::PageAllocator (PageAllocator const & rhs)
273cdf0e10cSrcweir : m_cache (rhs.m_cache),
274cdf0e10cSrcweir m_refcount (rhs.m_refcount)
275cdf0e10cSrcweir {
276cdf0e10cSrcweir }
277cdf0e10cSrcweir
278cdf0e10cSrcweir PageAllocator &
operator =(PageAllocator const & rhs)279cdf0e10cSrcweir PageAllocator::operator= (PageAllocator const & rhs)
280cdf0e10cSrcweir {
281cdf0e10cSrcweir PageAllocator tmp (rhs);
282cdf0e10cSrcweir swap<PageAllocator>(tmp, *this);
283cdf0e10cSrcweir return *this;
284cdf0e10cSrcweir }
285cdf0e10cSrcweir
286cdf0e10cSrcweir /*======================================================================*/
287cdf0e10cSrcweir
288cdf0e10cSrcweir class PageHolder
289cdf0e10cSrcweir {
290cdf0e10cSrcweir SharedCount m_refcount;
291cdf0e10cSrcweir PageData * m_pagedata;
292cdf0e10cSrcweir
293cdf0e10cSrcweir typedef rtl::Reference< PageData::Allocator > allocator_type;
294cdf0e10cSrcweir allocator_type m_allocator;
295cdf0e10cSrcweir
296cdf0e10cSrcweir public:
PageHolder(PageData * pagedata=0,allocator_type const & allocator=allocator_type ())297cdf0e10cSrcweir explicit PageHolder (PageData * pagedata = 0, allocator_type const & allocator = allocator_type())
298cdf0e10cSrcweir : m_refcount (),
299cdf0e10cSrcweir m_pagedata (pagedata),
300cdf0e10cSrcweir m_allocator(allocator)
301cdf0e10cSrcweir {}
302cdf0e10cSrcweir
~PageHolder()303cdf0e10cSrcweir ~PageHolder()
304cdf0e10cSrcweir {
305cdf0e10cSrcweir if ((m_refcount == 1) && (m_pagedata != 0) && m_allocator.is())
306cdf0e10cSrcweir {
307cdf0e10cSrcweir // free pagedata.
308cdf0e10cSrcweir m_allocator->deallocate (m_pagedata);
309cdf0e10cSrcweir }
310cdf0e10cSrcweir }
311cdf0e10cSrcweir
get()312cdf0e10cSrcweir PageData * get() { return m_pagedata; }
get() const313cdf0e10cSrcweir PageData const * get() const { return m_pagedata; }
314cdf0e10cSrcweir
operator ->()315cdf0e10cSrcweir PageData * operator->() { return m_pagedata; }
operator ->() const316cdf0e10cSrcweir PageData const * operator->() const { return m_pagedata; }
317cdf0e10cSrcweir
318cdf0e10cSrcweir friend void swap<> (PageHolder & lhs, PageHolder & rhs); // nothrow
319cdf0e10cSrcweir
320cdf0e10cSrcweir PageHolder (PageHolder const & rhs); // nothrow
321cdf0e10cSrcweir PageHolder & operator= (PageHolder const & rhs); // nothrow
322cdf0e10cSrcweir };
323cdf0e10cSrcweir
324cdf0e10cSrcweir template<>
swap(PageHolder & lhs,PageHolder & rhs)325cdf0e10cSrcweir inline void swap (PageHolder & lhs, PageHolder & rhs) // nothrow
326cdf0e10cSrcweir {
327cdf0e10cSrcweir swap<SharedCount>(lhs.m_refcount, rhs.m_refcount);
328cdf0e10cSrcweir swap<PageData*>(lhs.m_pagedata, rhs.m_pagedata);
329cdf0e10cSrcweir swap<PageHolder::allocator_type>(lhs.m_allocator, rhs.m_allocator);
330cdf0e10cSrcweir }
331cdf0e10cSrcweir
PageHolder(PageHolder const & rhs)332cdf0e10cSrcweir PageHolder::PageHolder (PageHolder const & rhs) // nothrow
333cdf0e10cSrcweir : m_refcount (rhs.m_refcount),
334cdf0e10cSrcweir m_pagedata (rhs.m_pagedata),
335cdf0e10cSrcweir m_allocator(rhs.m_allocator)
336cdf0e10cSrcweir {}
337cdf0e10cSrcweir
338cdf0e10cSrcweir PageHolder &
operator =(PageHolder const & rhs)339cdf0e10cSrcweir PageHolder::operator= (PageHolder const & rhs) // nothrow
340cdf0e10cSrcweir {
341cdf0e10cSrcweir PageHolder tmp (rhs);
342cdf0e10cSrcweir swap<PageHolder>(tmp, *this);
343cdf0e10cSrcweir return *this;
344cdf0e10cSrcweir }
345cdf0e10cSrcweir
346cdf0e10cSrcweir /*======================================================================*/
347cdf0e10cSrcweir
348cdf0e10cSrcweir template< class T >
349cdf0e10cSrcweir class PageHolderObject
350cdf0e10cSrcweir {
351cdf0e10cSrcweir protected:
352cdf0e10cSrcweir /** Representation.
353cdf0e10cSrcweir */
354cdf0e10cSrcweir PageHolder m_xPage;
355cdf0e10cSrcweir
356cdf0e10cSrcweir /** Checked cast.
357cdf0e10cSrcweir */
358cdf0e10cSrcweir template< class U >
isA(PageData const * p)359cdf0e10cSrcweir static bool isA (PageData const * p)
360cdf0e10cSrcweir {
361cdf0e10cSrcweir return ((p != 0) && (p->type() == U::theTypeId));
362cdf0e10cSrcweir }
363cdf0e10cSrcweir
364cdf0e10cSrcweir template< class U >
dynamic_page_cast(PageData * p)365cdf0e10cSrcweir static U * dynamic_page_cast (PageData * p)
366cdf0e10cSrcweir {
367cdf0e10cSrcweir return isA<U>(p) ? static_cast<U*>(p) : 0;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir
370cdf0e10cSrcweir template< class U >
dynamic_page_cast(PageData const * p)371cdf0e10cSrcweir static U const * dynamic_page_cast (PageData const * p)
372cdf0e10cSrcweir {
373cdf0e10cSrcweir return isA<U>(p) ? static_cast<U const *>(p) : 0;
374cdf0e10cSrcweir }
375cdf0e10cSrcweir
376cdf0e10cSrcweir public:
construct(rtl::Reference<PageData::Allocator> const & rxAllocator)377cdf0e10cSrcweir static PageHolderObject<T> construct (rtl::Reference< PageData::Allocator > const & rxAllocator)
378cdf0e10cSrcweir {
379cdf0e10cSrcweir PageHolderObject<T> tmp;
380cdf0e10cSrcweir if (rxAllocator.is())
381cdf0e10cSrcweir {
382cdf0e10cSrcweir PageHolder xPage (rxAllocator->construct<T>(), rxAllocator);
383cdf0e10cSrcweir store::swap<PageHolder>(tmp.m_xPage, xPage);
384cdf0e10cSrcweir }
385cdf0e10cSrcweir return tmp;
386cdf0e10cSrcweir }
387cdf0e10cSrcweir
PageHolderObject(PageHolder const & rxPage=PageHolder ())388cdf0e10cSrcweir explicit PageHolderObject (PageHolder const & rxPage = PageHolder())
389cdf0e10cSrcweir : m_xPage (rxPage)
390cdf0e10cSrcweir {}
391cdf0e10cSrcweir
swap(PageHolderObject<T> & rhs)392cdf0e10cSrcweir void swap (PageHolderObject<T> & rhs)
393cdf0e10cSrcweir {
394cdf0e10cSrcweir store::swap<PageHolder>(m_xPage, rhs.m_xPage);
395cdf0e10cSrcweir }
396cdf0e10cSrcweir
PageHolderObject(PageHolderObject<T> const & rhs)397cdf0e10cSrcweir PageHolderObject (PageHolderObject<T> const & rhs)
398cdf0e10cSrcweir : m_xPage (rhs.m_xPage)
399cdf0e10cSrcweir {
400cdf0e10cSrcweir }
401cdf0e10cSrcweir
operator =(PageHolderObject<T> const & rhs)402cdf0e10cSrcweir PageHolderObject<T> & operator= (PageHolderObject<T> const & rhs)
403cdf0e10cSrcweir {
404cdf0e10cSrcweir PageHolderObject<T> tmp (rhs);
405cdf0e10cSrcweir this->swap(tmp);
406cdf0e10cSrcweir return *this;
407cdf0e10cSrcweir }
408cdf0e10cSrcweir
operator ->()409cdf0e10cSrcweir T * operator->()
410cdf0e10cSrcweir {
411cdf0e10cSrcweir T * pImpl = dynamic_page_cast<T>(m_xPage.get());
412cdf0e10cSrcweir OSL_PRECOND(pImpl != 0, "store::PageHolder<T>::operator->(): Null pointer");
413cdf0e10cSrcweir return pImpl;
414cdf0e10cSrcweir }
operator ->() const415cdf0e10cSrcweir T const * operator->() const
416cdf0e10cSrcweir {
417cdf0e10cSrcweir T const * pImpl = dynamic_page_cast<T>(m_xPage.get());
418cdf0e10cSrcweir OSL_PRECOND(pImpl != 0, "store::PageHolder<T>::operator->(): Null pointer");
419cdf0e10cSrcweir return pImpl;
420cdf0e10cSrcweir }
421cdf0e10cSrcweir
operator *()422cdf0e10cSrcweir T & operator*()
423cdf0e10cSrcweir {
424cdf0e10cSrcweir T * pImpl = dynamic_page_cast<T>(m_xPage.get());
425cdf0e10cSrcweir OSL_PRECOND(pImpl != 0, "store::PageHolder<T>::operator*(): Null pointer");
426cdf0e10cSrcweir return *pImpl;
427cdf0e10cSrcweir }
operator *() const428cdf0e10cSrcweir T const & operator*() const
429cdf0e10cSrcweir {
430cdf0e10cSrcweir T const * pImpl = dynamic_page_cast<T>(m_xPage.get());
431cdf0e10cSrcweir OSL_PRECOND(pImpl != 0, "store::PageHolder<T>::operator*(): Null pointer");
432cdf0e10cSrcweir return *pImpl;
433cdf0e10cSrcweir }
434cdf0e10cSrcweir
guard(PageHolder & rxPage)435cdf0e10cSrcweir static storeError guard (PageHolder & rxPage)
436cdf0e10cSrcweir {
437cdf0e10cSrcweir T * pImpl = dynamic_page_cast<T>(rxPage.get());
438cdf0e10cSrcweir if (pImpl != 0)
439cdf0e10cSrcweir { pImpl->guard(); return store_E_None; }
440cdf0e10cSrcweir else if (rxPage.get() != 0)
441cdf0e10cSrcweir return store_E_WrongVersion;
442cdf0e10cSrcweir else
443cdf0e10cSrcweir return store_E_InvalidAccess;
444cdf0e10cSrcweir }
verify(PageHolder const & rxPage)445cdf0e10cSrcweir static storeError verify (PageHolder const & rxPage)
446cdf0e10cSrcweir {
447cdf0e10cSrcweir T const * pImpl = dynamic_page_cast<T>(rxPage.get());
448cdf0e10cSrcweir if (pImpl != 0)
449cdf0e10cSrcweir return pImpl->verify();
450cdf0e10cSrcweir else if (rxPage.get() != 0)
451cdf0e10cSrcweir return store_E_WrongVersion;
452cdf0e10cSrcweir else
453cdf0e10cSrcweir return store_E_InvalidAccess;
454cdf0e10cSrcweir }
455cdf0e10cSrcweir };
456cdf0e10cSrcweir
457cdf0e10cSrcweir /*======================================================================*/
458cdf0e10cSrcweir
459cdf0e10cSrcweir class PageObject
460cdf0e10cSrcweir {
461cdf0e10cSrcweir public:
PageObject(PageHolder const & rxPage=PageHolder ())462cdf0e10cSrcweir explicit PageObject (PageHolder const & rxPage = PageHolder())
463cdf0e10cSrcweir : m_xPage (rxPage)
464cdf0e10cSrcweir {}
465cdf0e10cSrcweir
466cdf0e10cSrcweir virtual ~PageObject();
467cdf0e10cSrcweir
get()468cdf0e10cSrcweir PageHolder & get() { return m_xPage; }
get() const469cdf0e10cSrcweir PageHolder const & get() const { return m_xPage; }
470cdf0e10cSrcweir
operator ->()471cdf0e10cSrcweir PageData * operator->()
472cdf0e10cSrcweir {
473cdf0e10cSrcweir PageData * pImpl = m_xPage.get();
474cdf0e10cSrcweir OSL_PRECOND(pImpl != 0, "store::PageObject::operator->(): Null pointer");
475cdf0e10cSrcweir return pImpl;
476cdf0e10cSrcweir }
operator *()477cdf0e10cSrcweir PageData & operator*()
478cdf0e10cSrcweir {
479cdf0e10cSrcweir PageData * pImpl = m_xPage.get();
480cdf0e10cSrcweir OSL_PRECOND(pImpl != 0, "store::PageObject::operator*(): Null pointer");
481cdf0e10cSrcweir return *pImpl;
482cdf0e10cSrcweir }
483cdf0e10cSrcweir
484cdf0e10cSrcweir virtual void guard();
485cdf0e10cSrcweir virtual storeError verify() const;
486cdf0e10cSrcweir
487cdf0e10cSrcweir protected:
488cdf0e10cSrcweir PageHolder m_xPage;
489cdf0e10cSrcweir };
490cdf0e10cSrcweir
~PageObject()491cdf0e10cSrcweir PageObject::~PageObject()
492cdf0e10cSrcweir {}
guard()493cdf0e10cSrcweir void PageObject::guard()
494cdf0e10cSrcweir {
495cdf0e10cSrcweir PageData * p = m_xPage.get();
496cdf0e10cSrcweir p->guard();
497cdf0e10cSrcweir }
verify() const498cdf0e10cSrcweir storeError PageObject::verify() const
499cdf0e10cSrcweir {
500cdf0e10cSrcweir PageData const * p = m_xPage.get();
501cdf0e10cSrcweir return p->verify();
502cdf0e10cSrcweir }
503cdf0e10cSrcweir
504cdf0e10cSrcweir /*======================================================================*/
505cdf0e10cSrcweir
506cdf0e10cSrcweir template< class T >
dynamic_page_cast(PageData * pagedata)507cdf0e10cSrcweir T * dynamic_page_cast (PageData * pagedata)
508cdf0e10cSrcweir {
509cdf0e10cSrcweir if ((pagedata != 0) && (pagedata->type() == T::theTypeId))
510cdf0e10cSrcweir return static_cast<T*>(pagedata);
511cdf0e10cSrcweir return 0;
512cdf0e10cSrcweir }
513cdf0e10cSrcweir
514cdf0e10cSrcweir template< class T >
dynamic_page_cast(PageData const * pagedata)515cdf0e10cSrcweir T * dynamic_page_cast (PageData const * pagedata)
516cdf0e10cSrcweir {
517cdf0e10cSrcweir if ((pagedata != 0) && (pagedata->type() == T::theTypeId))
518cdf0e10cSrcweir return static_cast<T*>(pagedata);
519cdf0e10cSrcweir return 0;
520cdf0e10cSrcweir }
521cdf0e10cSrcweir
522cdf0e10cSrcweir /*======================================================================*/
523cdf0e10cSrcweir
524cdf0e10cSrcweir class TestBIOS
525cdf0e10cSrcweir {
526cdf0e10cSrcweir public:
loadPageAt(PageHolder & rPage,storeError (* pfnVerify)(PageHolder const &))527cdf0e10cSrcweir storeError loadPageAt (PageHolder & rPage, storeError (*pfnVerify)(PageHolder const &))
528cdf0e10cSrcweir {
529cdf0e10cSrcweir return (pfnVerify)(rPage);
530cdf0e10cSrcweir }
531cdf0e10cSrcweir
allocate(PageHolder & rxPage,...)532cdf0e10cSrcweir storeError allocate (PageHolder & rxPage, ...)
533cdf0e10cSrcweir {
534cdf0e10cSrcweir // NYI: PageObject.save(nAddr, *this);
535cdf0e10cSrcweir (void)rxPage; // NYI
536cdf0e10cSrcweir return store_E_Unknown; // NYI
537cdf0e10cSrcweir }
538cdf0e10cSrcweir
loadAt(PageHolder & rPage,sal_uInt32 nOffset)539cdf0e10cSrcweir storeError loadAt (PageHolder & rPage, sal_uInt32 nOffset)
540cdf0e10cSrcweir {
541cdf0e10cSrcweir (void)rPage; // NYI
542cdf0e10cSrcweir (void)nOffset; // NYI
543cdf0e10cSrcweir return store_E_Unknown; // NYI
544cdf0e10cSrcweir }
saveAt(PageHolder const & rPage,sal_uInt32 nOffset)545cdf0e10cSrcweir storeError saveAt (PageHolder const & rPage, sal_uInt32 nOffset)
546cdf0e10cSrcweir {
547cdf0e10cSrcweir (void)rPage; // NYI
548cdf0e10cSrcweir (void)nOffset; // NYI
549cdf0e10cSrcweir return store_E_Unknown; // NYI
550cdf0e10cSrcweir }
551cdf0e10cSrcweir
552cdf0e10cSrcweir template< class T >
save(PageHolder & rxPage,sal_uInt32 nOffset)553cdf0e10cSrcweir storeError save (PageHolder & rxPage, sal_uInt32 nOffset)
554cdf0e10cSrcweir {
555cdf0e10cSrcweir storeError result = PageHolderObject<T>::guard (rxPage);
556cdf0e10cSrcweir if (result != store_E_None)
557cdf0e10cSrcweir return result;
558cdf0e10cSrcweir return saveAt (rxPage, nOffset);
559cdf0e10cSrcweir }
560cdf0e10cSrcweir
lookupAt(PageHolder & rPage,sal_uInt32 nOffset)561cdf0e10cSrcweir storeError lookupAt (PageHolder & rPage, sal_uInt32 nOffset)
562cdf0e10cSrcweir {
563cdf0e10cSrcweir (void)rPage; // NYI
564cdf0e10cSrcweir (void)nOffset; // NYI
565cdf0e10cSrcweir return store_E_NotExists;
566cdf0e10cSrcweir }
replaceAt(PageHolder const & rPage,sal_uInt32 nOffset)567cdf0e10cSrcweir storeError replaceAt (PageHolder const & rPage, sal_uInt32 nOffset)
568cdf0e10cSrcweir {
569cdf0e10cSrcweir (void)rPage; // NYI
570cdf0e10cSrcweir (void)nOffset; // NYI
571cdf0e10cSrcweir return store_E_None;
572cdf0e10cSrcweir }
573cdf0e10cSrcweir };
574cdf0e10cSrcweir
575cdf0e10cSrcweir struct TestDataV1 : public PageData
576cdf0e10cSrcweir {
577cdf0e10cSrcweir static const sal_uInt32 theTypeId = 6 * 9;
578cdf0e10cSrcweir };
579cdf0e10cSrcweir struct TestData : public PageData
580cdf0e10cSrcweir {
581cdf0e10cSrcweir typedef PageData base;
582cdf0e10cSrcweir typedef TestData self;
583cdf0e10cSrcweir
584cdf0e10cSrcweir static const sal_uInt32 theTypeId = 42;
585cdf0e10cSrcweir
guardTestData586cdf0e10cSrcweir void guard()
587cdf0e10cSrcweir {
588cdf0e10cSrcweir base::guard();
589cdf0e10cSrcweir // self::m_aGuard = ...;
590cdf0e10cSrcweir }
verifyTestData591cdf0e10cSrcweir storeError verify() const
592cdf0e10cSrcweir {
593cdf0e10cSrcweir storeError result = base::verify();
594cdf0e10cSrcweir if (result != store_E_None)
595cdf0e10cSrcweir return result;
596cdf0e10cSrcweir if (!(base::type() == self::theTypeId))
597cdf0e10cSrcweir return store_E_WrongVersion;
598cdf0e10cSrcweir return store_E_None;
599cdf0e10cSrcweir }
600cdf0e10cSrcweir
dwimTestData601cdf0e10cSrcweir storeError dwim() const
602cdf0e10cSrcweir {
603cdf0e10cSrcweir return store_E_None;
604cdf0e10cSrcweir }
605cdf0e10cSrcweir };
606cdf0e10cSrcweir class TestObject : public PageObject
607cdf0e10cSrcweir {
608cdf0e10cSrcweir typedef PageObject base;
609cdf0e10cSrcweir
610cdf0e10cSrcweir public:
611cdf0e10cSrcweir
dwim()612cdf0e10cSrcweir void dwim()
613cdf0e10cSrcweir {
614cdf0e10cSrcweir PageHolderObject< TestData > xPage (m_xPage);
615cdf0e10cSrcweir xPage->guard();
616cdf0e10cSrcweir }
617cdf0e10cSrcweir
guard()618cdf0e10cSrcweir virtual void guard()
619cdf0e10cSrcweir {
620cdf0e10cSrcweir TestData * pagedata = dynamic_page_cast< TestData >(m_xPage.get());
621cdf0e10cSrcweir if (pagedata != 0)
622cdf0e10cSrcweir {}
623cdf0e10cSrcweir }
verify() const624cdf0e10cSrcweir virtual storeError verify() const
625cdf0e10cSrcweir {
626cdf0e10cSrcweir storeError result = base::verify();
627cdf0e10cSrcweir if (result != store_E_None)
628cdf0e10cSrcweir return result;
629cdf0e10cSrcweir
630cdf0e10cSrcweir TestData const * pagedata = dynamic_page_cast< TestData const >(m_xPage.get());
631cdf0e10cSrcweir if (!pagedata)
632cdf0e10cSrcweir return store_E_WrongVersion;
633cdf0e10cSrcweir
634cdf0e10cSrcweir return pagedata->verify();
635cdf0e10cSrcweir }
636cdf0e10cSrcweir
verify(PageHolder const & rPage)637cdf0e10cSrcweir static storeError verify (PageHolder const & rPage)
638cdf0e10cSrcweir {
639cdf0e10cSrcweir return PageHolderObject< TestData >::verify (rPage);
640cdf0e10cSrcweir }
641cdf0e10cSrcweir
loadAt(sal_uInt32 nOffset,TestBIOS & rBIOS)642cdf0e10cSrcweir storeError loadAt (sal_uInt32 nOffset, TestBIOS & rBIOS)
643cdf0e10cSrcweir {
644cdf0e10cSrcweir storeError result = rBIOS.lookupAt (m_xPage, nOffset); // cache lookup
645cdf0e10cSrcweir if (result == store_E_NotExists)
646cdf0e10cSrcweir {
647cdf0e10cSrcweir result = rBIOS.loadAt (m_xPage, nOffset);
648cdf0e10cSrcweir if (result != store_E_None)
649cdf0e10cSrcweir return result;
650cdf0e10cSrcweir
651cdf0e10cSrcweir result = PageHolderObject< TestData >::verify (m_xPage);
652cdf0e10cSrcweir if (result != store_E_None)
653cdf0e10cSrcweir return result;
654cdf0e10cSrcweir
655cdf0e10cSrcweir result = rBIOS.replaceAt (m_xPage, nOffset); // cache insert
656cdf0e10cSrcweir }
657cdf0e10cSrcweir return result;
658cdf0e10cSrcweir }
saveAt(sal_uInt32 nOffset,TestBIOS & rBIOS)659cdf0e10cSrcweir storeError saveAt (sal_uInt32 nOffset, TestBIOS & rBIOS)
660cdf0e10cSrcweir {
661cdf0e10cSrcweir if (!m_xPage.get())
662cdf0e10cSrcweir return store_E_InvalidAccess;
663cdf0e10cSrcweir m_xPage->m_aDescr.m_nAddr = store::htonl(nOffset); // m_xPage->location (nOffset);
664cdf0e10cSrcweir
665cdf0e10cSrcweir storeError result = PageHolderObject< TestData >::guard (m_xPage);
666cdf0e10cSrcweir if (result != store_E_None)
667cdf0e10cSrcweir return result;
668cdf0e10cSrcweir
669cdf0e10cSrcweir result = rBIOS.saveAt (m_xPage, nOffset);
670cdf0e10cSrcweir if (result != store_E_None)
671cdf0e10cSrcweir return result;
672cdf0e10cSrcweir
673cdf0e10cSrcweir return rBIOS.replaceAt (m_xPage, nOffset); // cache update
674cdf0e10cSrcweir }
675cdf0e10cSrcweir };
676cdf0e10cSrcweir
677cdf0e10cSrcweir class TestObjectV2 : public PageHolderObject< TestData >
678cdf0e10cSrcweir {
679cdf0e10cSrcweir typedef PageHolderObject< TestData > base;
680cdf0e10cSrcweir
681cdf0e10cSrcweir public:
saveAt(sal_uInt32 nOffset,TestBIOS & rBIOS)682cdf0e10cSrcweir storeError saveAt (sal_uInt32 nOffset, TestBIOS & rBIOS)
683cdf0e10cSrcweir {
684cdf0e10cSrcweir m_xPage->offset(nOffset);
685cdf0e10cSrcweir
686cdf0e10cSrcweir storeError result = PageHolderObject< TestData >::guard (m_xPage);
687cdf0e10cSrcweir if (result != store_E_None)
688cdf0e10cSrcweir return result;
689cdf0e10cSrcweir
690cdf0e10cSrcweir result = rBIOS.saveAt (m_xPage, nOffset);
691cdf0e10cSrcweir if (result != store_E_None)
692cdf0e10cSrcweir return result;
693cdf0e10cSrcweir
694cdf0e10cSrcweir return rBIOS.replaceAt (m_xPage, nOffset);
695cdf0e10cSrcweir }
696cdf0e10cSrcweir #if 1
dwim() const697cdf0e10cSrcweir storeError dwim() const
698cdf0e10cSrcweir {
699cdf0e10cSrcweir TestData const * pImpl1 = operator->();
700cdf0e10cSrcweir
701cdf0e10cSrcweir PageHolderObject< TestData > xImpl (m_xPage);
702cdf0e10cSrcweir
703cdf0e10cSrcweir TestData const * pImpl2 = &*xImpl;
704cdf0e10cSrcweir OSL_ASSERT(pImpl1 == pImpl2);
705cdf0e10cSrcweir
706cdf0e10cSrcweir return xImpl->dwim();
707cdf0e10cSrcweir }
708cdf0e10cSrcweir #endif
709cdf0e10cSrcweir };
710cdf0e10cSrcweir
711cdf0e10cSrcweir class TestClient
712cdf0e10cSrcweir {
713cdf0e10cSrcweir public:
dwim(TestBIOS & rBIOS)714cdf0e10cSrcweir void dwim(TestBIOS & rBIOS)
715cdf0e10cSrcweir {
716cdf0e10cSrcweir TestObject aObj;
717cdf0e10cSrcweir
718cdf0e10cSrcweir rBIOS.loadPageAt(aObj.get(), aObj.verify);
719cdf0e10cSrcweir rBIOS.loadPageAt(aObj.get(), TestObject::verify);
720cdf0e10cSrcweir rBIOS.loadPageAt(aObj.get(), PageHolderObject<TestData>::verify);
721cdf0e10cSrcweir
722cdf0e10cSrcweir aObj.loadAt (1024, rBIOS);
723cdf0e10cSrcweir
724cdf0e10cSrcweir TestObjectV2 aObj2;
725cdf0e10cSrcweir aObj2.dwim();
726cdf0e10cSrcweir aObj2->dwim();
727cdf0e10cSrcweir }
728cdf0e10cSrcweir };
729cdf0e10cSrcweir
730cdf0e10cSrcweir /*======================================================================*/
731cdf0e10cSrcweir #if 0 /* NYI */
732cdf0e10cSrcweir BIOS::load (PageObject & rPage, sal_uInt32 nOffset)
733cdf0e10cSrcweir {
734cdf0e10cSrcweir result = m_xCache->readPageAt (rPage.get(), nOffset);
735cdf0e10cSrcweir if (result == NotExists)
736cdf0e10cSrcweir {
737cdf0e10cSrcweir result = m_xLockBytes->readPageAt (rPage.get(), nOffset);
738cdf0e10cSrcweir if (result != None)
739cdf0e10cSrcweir return result;
740cdf0e10cSrcweir
741cdf0e10cSrcweir result = rPage.verify();
742cdf0e10cSrcweir if (result != None)
743cdf0e10cSrcweir return result;
744cdf0e10cSrcweir
745cdf0e10cSrcweir result = m_xCache->writePageAt (rPage.get(), nOffset);
746cdf0e10cSrcweir }
747cdf0e10cSrcweir return result;
748cdf0e10cSrcweir }
749cdf0e10cSrcweir BIOS::save (PageObject & rPage, sal_uInt32 nOffset)
750cdf0e10cSrcweir {
751cdf0e10cSrcweir rPage.guard();
752cdf0e10cSrcweir result = m_xLockBytes->writePageAt (rPage.get(), nOffset);
753cdf0e10cSrcweir if (result != None)
754cdf0e10cSrcweir return result;
755cdf0e10cSrcweir
756cdf0e10cSrcweir return m_xCache->writePageAt (rPage.get(), nOffset);
757cdf0e10cSrcweir }
758cdf0e10cSrcweir BIOS::init (rxLockBytes, eAccessMode, nPageSize)
759cdf0e10cSrcweir {
760cdf0e10cSrcweir SuperPage super;
761cdf0e10cSrcweir if (eAccessMode == store_AccessCreate)
762cdf0e10cSrcweir {
763cdf0e10cSrcweir sal_uInt16 pagesize = nPageSize;
764cdf0e10cSrcweir if ((STORE_MINIMUM_PAGESIZE > pagesize) || (pagesize > STORE_MAXIMUM_PAGESIZE))
765cdf0e10cSrcweir return store_E_InvalidParameter;
766cdf0e10cSrcweir
767cdf0e10cSrcweir pagesize = ((pagesize + STORE_MINIMUM_PAGESIZE - 1) & ~(STORE_MINIMUM_PAGESIZE - 1));
768cdf0e10cSrcweir rxLockBytes->init (pagesize);
769cdf0e10cSrcweir
770cdf0e10cSrcweir super = allocator->construct<SuperPage>();
771cdf0e10cSrcweir super->guard();
772cdf0e10cSrcweir
773cdf0e10cSrcweir rxLockBytes->writeAt (0, super, super->size());
774cdf0e10cSrcweir
775cdf0e10cSrcweir }
776cdf0e10cSrcweir if (eAccessMode != store_AccessCreate)
777cdf0e10cSrcweir {
778cdf0e10cSrcweir rxLockBytes->readAt (0, &super, super::theSize);
779cdf0e10cSrcweir
780cdf0e10cSrcweir super.verify();
781cdf0e10cSrcweir }
782cdf0e10cSrcweir if (eErrCode != store_E_NotExists)
783cdf0e10cSrcweir
784cdf0e10cSrcweir
785cdf0e10cSrcweir }
786cdf0e10cSrcweir #endif /* NYI */
787cdf0e10cSrcweir /*======================================================================*/
788cdf0e10cSrcweir
789cdf0e10cSrcweir #if 0 /* NYI */
790cdf0e10cSrcweir class PageCache
791cdf0e10cSrcweir {
792cdf0e10cSrcweir std::set<const sal_uInt32, PageObject> m_pages;
793cdf0e10cSrcweir public:
794cdf0e10cSrcweir storeError readPageAt (PageObject & rPage, sal_uInt32 nOffset);
795cdf0e10cSrcweir storeError writePageAt (PageObject const & rPage, sal_uInt32 nOffset);
796cdf0e10cSrcweir };
797cdf0e10cSrcweir #endif /* NYI */
798cdf0e10cSrcweir
799cdf0e10cSrcweir /*======================================================================*/
800cdf0e10cSrcweir
801cdf0e10cSrcweir class IPageAllocator;
802cdf0e10cSrcweir class IPageAccess
803cdf0e10cSrcweir {
804cdf0e10cSrcweir public:
805cdf0e10cSrcweir virtual storeError initialize (storeAccessMode eAccessMode, sal_uInt16 nPageSize) = 0;
806cdf0e10cSrcweir virtual IPageAllocator & getAllocator () = 0;
807cdf0e10cSrcweir
808cdf0e10cSrcweir public:
readPageAt(PageHolder & rPage,sal_uInt32 nOffset)809cdf0e10cSrcweir storeError readPageAt (PageHolder & rPage, sal_uInt32 nOffset)
810cdf0e10cSrcweir {
811cdf0e10cSrcweir return readPageAt_Impl (rPage, nOffset);
812cdf0e10cSrcweir }
writePageAt(PageHolder const & rPage,sal_uInt32 nOffset)813cdf0e10cSrcweir storeError writePageAt (PageHolder const & rPage, sal_uInt32 nOffset)
814cdf0e10cSrcweir {
815cdf0e10cSrcweir // [SECURITY:ValInput]
816cdf0e10cSrcweir PageData const * pagedata = rPage.get();
817cdf0e10cSrcweir OSL_PRECOND(!(pagedata == 0), "invalid Page");
818cdf0e10cSrcweir if (pagedata == 0)
819cdf0e10cSrcweir return store_E_InvalidParameter;
820cdf0e10cSrcweir
821cdf0e10cSrcweir sal_uInt32 const offset = pagedata->offset();
822cdf0e10cSrcweir OSL_PRECOND(!(nOffset != offset), "inconsistent Offset");
823cdf0e10cSrcweir if (nOffset != offset)
824cdf0e10cSrcweir return store_E_InvalidParameter;
825cdf0e10cSrcweir
826cdf0e10cSrcweir OSL_PRECOND(!(nOffset == STORE_PAGE_NULL), "store::IPageAccess::writePageAt(): invalid Offset");
827cdf0e10cSrcweir if (nOffset == STORE_PAGE_NULL)
828cdf0e10cSrcweir return store_E_CantSeek;
829cdf0e10cSrcweir
830cdf0e10cSrcweir return writePageAt_Impl (rPage, nOffset);
831cdf0e10cSrcweir }
832cdf0e10cSrcweir
peekAt(sal_uInt32 nOffset,void * pBuffer,sal_uInt32 nBytes)833cdf0e10cSrcweir storeError peekAt (sal_uInt32 nOffset, void * pBuffer, sal_uInt32 nBytes)
834cdf0e10cSrcweir {
835cdf0e10cSrcweir // [SECURITY:ValInput]
836cdf0e10cSrcweir sal_uInt8 * dst_lo = static_cast<sal_uInt8*>(pBuffer);
837cdf0e10cSrcweir if (!(dst_lo != 0))
838cdf0e10cSrcweir return store_E_InvalidParameter;
839cdf0e10cSrcweir
840cdf0e10cSrcweir sal_uInt8 * dst_hi = dst_lo + nBytes;
841cdf0e10cSrcweir if (!(dst_lo < dst_hi))
842cdf0e10cSrcweir return (dst_lo > dst_hi) ? store_E_InvalidParameter : store_E_None;
843cdf0e10cSrcweir
844cdf0e10cSrcweir sal_uInt64 const dst_size = nOffset + nBytes;
845cdf0e10cSrcweir if (dst_size > SAL_MAX_UINT32)
846cdf0e10cSrcweir return store_E_CantSeek;
847cdf0e10cSrcweir
848cdf0e10cSrcweir return peekAt_Impl (nOffset, dst_lo, (dst_hi - dst_lo));
849cdf0e10cSrcweir }
850cdf0e10cSrcweir
pokeAt(sal_uInt32 nOffset,void const * pBuffer,sal_uInt32 nBytes)851cdf0e10cSrcweir storeError pokeAt (sal_uInt32 nOffset, void const * pBuffer, sal_uInt32 nBytes)
852cdf0e10cSrcweir {
853cdf0e10cSrcweir // [SECURITY:ValInput]
854cdf0e10cSrcweir sal_uInt8 const * src_lo = static_cast<sal_uInt8 const*>(pBuffer);
855cdf0e10cSrcweir if (!(src_lo != 0))
856cdf0e10cSrcweir return store_E_InvalidParameter;
857cdf0e10cSrcweir
858cdf0e10cSrcweir sal_uInt8 const * src_hi = src_lo + nBytes;
859cdf0e10cSrcweir if (!(src_lo < src_hi))
860cdf0e10cSrcweir return (src_lo > src_hi) ? store_E_InvalidParameter : store_E_None;
861cdf0e10cSrcweir
862cdf0e10cSrcweir sal_uInt64 const dst_size = nOffset + nBytes;
863cdf0e10cSrcweir if (dst_size > SAL_MAX_UINT32)
864cdf0e10cSrcweir return store_E_CantSeek;
865cdf0e10cSrcweir
866cdf0e10cSrcweir return pokeAt_Impl (nOffset, src_lo, (src_hi - src_lo));
867cdf0e10cSrcweir }
868cdf0e10cSrcweir
getSize(sal_uInt32 & rnSize)869cdf0e10cSrcweir storeError getSize (sal_uInt32 & rnSize)
870cdf0e10cSrcweir {
871cdf0e10cSrcweir rnSize = 0;
872cdf0e10cSrcweir return getSize_Impl (rnSize);
873cdf0e10cSrcweir }
874cdf0e10cSrcweir
setSize(sal_uInt32 nSize)875cdf0e10cSrcweir storeError setSize (sal_uInt32 nSize)
876cdf0e10cSrcweir {
877cdf0e10cSrcweir return setSize_Impl (nSize);
878cdf0e10cSrcweir }
879cdf0e10cSrcweir
880cdf0e10cSrcweir private:
881cdf0e10cSrcweir virtual storeError readPageAt_Impl (PageHolder & rPage, sal_uInt32 nOffset) = 0;
882cdf0e10cSrcweir virtual storeError writePageAt_Impl (PageHolder const & rPage, sal_uInt32 nOffset) = 0;
883cdf0e10cSrcweir
884cdf0e10cSrcweir virtual storeError peekAt_Impl (sal_uInt32 nOffset, void * pBuffer, sal_uInt32 nBytes) = 0;
885cdf0e10cSrcweir virtual storeError pokeAt_Impl (sal_uInt32 nOffset, void const * pBuffer, sal_uInt32 nBytes) = 0;
886cdf0e10cSrcweir
887cdf0e10cSrcweir virtual storeError getSize_Impl (sal_uInt32 & rnSize) = 0;
888cdf0e10cSrcweir virtual storeError setSize_Impl (sal_uInt32 nSize) = 0;
889cdf0e10cSrcweir };
890cdf0e10cSrcweir
891cdf0e10cSrcweir /*======================================================================*/
892cdf0e10cSrcweir
893cdf0e10cSrcweir template< class T > struct ResourceHolder
894cdf0e10cSrcweir {
895cdf0e10cSrcweir typedef typename T::destructor_type destructor_type;
896cdf0e10cSrcweir
897cdf0e10cSrcweir T m_value;
898cdf0e10cSrcweir
ResourceHolderResourceHolder899cdf0e10cSrcweir explicit ResourceHolder (T const & value = T()) : m_value (value) {}
~ResourceHolderResourceHolder900cdf0e10cSrcweir ~ResourceHolder() { reset(); }
901cdf0e10cSrcweir
getResourceHolder902cdf0e10cSrcweir T & get() { return m_value; }
getResourceHolder903cdf0e10cSrcweir T const & get() const { return m_value; }
904cdf0e10cSrcweir
setResourceHolder905cdf0e10cSrcweir void set (T const & value) { m_value = value; }
resetResourceHolder906cdf0e10cSrcweir void reset (T const & value = T())
907cdf0e10cSrcweir {
908cdf0e10cSrcweir T tmp (m_value);
909cdf0e10cSrcweir if (tmp != value)
910cdf0e10cSrcweir destructor_type()(tmp);
911cdf0e10cSrcweir set (value);
912cdf0e10cSrcweir }
releaseResourceHolder913cdf0e10cSrcweir T release()
914cdf0e10cSrcweir {
915cdf0e10cSrcweir T tmp (m_value);
916cdf0e10cSrcweir set (T());
917cdf0e10cSrcweir return tmp;
918cdf0e10cSrcweir }
919cdf0e10cSrcweir
ResourceHolderResourceHolder920cdf0e10cSrcweir ResourceHolder (ResourceHolder & rhs)
921cdf0e10cSrcweir {
922cdf0e10cSrcweir set (rhs.release());
923cdf0e10cSrcweir }
operator =ResourceHolder924cdf0e10cSrcweir ResourceHolder & operator= (ResourceHolder & rhs)
925cdf0e10cSrcweir {
926cdf0e10cSrcweir reset (rhs.release());
927cdf0e10cSrcweir return *this;
928cdf0e10cSrcweir }
929cdf0e10cSrcweir };
930cdf0e10cSrcweir
931cdf0e10cSrcweir struct FileHandle
932cdf0e10cSrcweir {
933cdf0e10cSrcweir oslFileHandle m_handle;
934cdf0e10cSrcweir
FileHandleFileHandle935cdf0e10cSrcweir FileHandle() : m_handle(0) {}
936cdf0e10cSrcweir
operator oslFileHandleFileHandle937cdf0e10cSrcweir operator oslFileHandle() { return m_handle; }
938cdf0e10cSrcweir
operator !=FileHandle939cdf0e10cSrcweir bool operator != (FileHandle const & rhs)
940cdf0e10cSrcweir {
941cdf0e10cSrcweir return (m_handle != rhs.m_handle);
942cdf0e10cSrcweir }
943cdf0e10cSrcweir
initializeFileHandle944cdf0e10cSrcweir oslFileError initialize (rtl_uString * pFilename, sal_uInt32 nFlags)
945cdf0e10cSrcweir {
946cdf0e10cSrcweir // Verify arguments.
947cdf0e10cSrcweir if (!pFilename || !nFlags)
948cdf0e10cSrcweir return osl_File_E_INVAL;
949cdf0e10cSrcweir
950cdf0e10cSrcweir // Convert into FileUrl.
951cdf0e10cSrcweir rtl::OUString aFileUrl;
952cdf0e10cSrcweir if (osl_getFileURLFromSystemPath (pFilename, &(aFileUrl.pData)) != osl_File_E_None)
953cdf0e10cSrcweir {
954cdf0e10cSrcweir // Not system path. Maybe a file url, already.
955cdf0e10cSrcweir rtl_uString_assign (&(aFileUrl.pData), pFilename);
956cdf0e10cSrcweir }
957cdf0e10cSrcweir
958cdf0e10cSrcweir // Acquire handle.
959cdf0e10cSrcweir return osl_openFile (aFileUrl.pData, &m_handle, nFlags);
960cdf0e10cSrcweir }
961cdf0e10cSrcweir
962cdf0e10cSrcweir struct CloseFile
963cdf0e10cSrcweir {
operator ()FileHandle::CloseFile964cdf0e10cSrcweir void operator()(FileHandle & rFile) const
965cdf0e10cSrcweir {
966cdf0e10cSrcweir if (rFile.m_handle != 0)
967cdf0e10cSrcweir {
968cdf0e10cSrcweir // Release handle.
969cdf0e10cSrcweir (void) osl_closeFile (rFile.m_handle);
970cdf0e10cSrcweir rFile.m_handle = 0;
971cdf0e10cSrcweir }
972cdf0e10cSrcweir }
973cdf0e10cSrcweir };
974cdf0e10cSrcweir typedef CloseFile destructor_type;
975cdf0e10cSrcweir };
976cdf0e10cSrcweir
977cdf0e10cSrcweir struct FileMapping
978cdf0e10cSrcweir {
979cdf0e10cSrcweir void * m_pAddr;
980cdf0e10cSrcweir sal_uInt64 m_uSize;
981cdf0e10cSrcweir
FileMappingFileMapping982cdf0e10cSrcweir FileMapping() : m_pAddr(0), m_uSize(0) {}
983cdf0e10cSrcweir
operator !=FileMapping984cdf0e10cSrcweir bool operator != (FileMapping const & rhs) const
985cdf0e10cSrcweir {
986cdf0e10cSrcweir return ((m_pAddr != rhs.m_pAddr) || (m_uSize != rhs.m_uSize));
987cdf0e10cSrcweir }
988cdf0e10cSrcweir
initializeFileMapping989cdf0e10cSrcweir oslFileError initialize (oslFileHandle hFile)
990cdf0e10cSrcweir {
991cdf0e10cSrcweir // Determine mapping size.
992cdf0e10cSrcweir oslFileError result = osl_getFileSize (hFile, &m_uSize);
993cdf0e10cSrcweir if (result != osl_File_E_None)
994cdf0e10cSrcweir return result;
995cdf0e10cSrcweir if (m_uSize > SAL_MAX_UINT32)
996cdf0e10cSrcweir return osl_File_E_OVERFLOW;
997cdf0e10cSrcweir
998cdf0e10cSrcweir // Acquire mapping.
999cdf0e10cSrcweir return osl_mapFile (hFile, &m_pAddr, m_uSize, 0, 0);
1000cdf0e10cSrcweir }
1001cdf0e10cSrcweir
1002cdf0e10cSrcweir struct UnmapFile
1003cdf0e10cSrcweir {
operator ()FileMapping::UnmapFile1004cdf0e10cSrcweir void operator ()(FileMapping & rMapping) const
1005cdf0e10cSrcweir {
1006cdf0e10cSrcweir if ((rMapping.m_pAddr != 0) && (rMapping.m_uSize != 0))
1007cdf0e10cSrcweir {
1008cdf0e10cSrcweir // Release mapping.
1009cdf0e10cSrcweir (void) osl_unmapFile (rMapping.m_pAddr, rMapping.m_uSize);
1010cdf0e10cSrcweir rMapping.m_pAddr = 0, rMapping.m_uSize = 0;
1011cdf0e10cSrcweir }
1012cdf0e10cSrcweir }
1013cdf0e10cSrcweir };
1014cdf0e10cSrcweir typedef UnmapFile destructor_type;
1015cdf0e10cSrcweir };
1016cdf0e10cSrcweir
1017cdf0e10cSrcweir /*======================================================================*/
1018cdf0e10cSrcweir
1019cdf0e10cSrcweir class FilePageAccess : public IPageAccess
1020cdf0e10cSrcweir {
1021cdf0e10cSrcweir oslFileHandle m_hFile;
1022cdf0e10cSrcweir
1023cdf0e10cSrcweir public:
1024cdf0e10cSrcweir static storeError ERROR_FROM_NATIVE (oslFileError eErrno);
1025cdf0e10cSrcweir static sal_uInt32 MODE_TO_NATIVE (storeAccessMode eMode);
1026cdf0e10cSrcweir
1027cdf0e10cSrcweir public:
FilePageAccess(oslFileHandle hFile=0)1028cdf0e10cSrcweir explicit FilePageAccess (oslFileHandle hFile = 0) : m_hFile (hFile) {}
1029cdf0e10cSrcweir virtual storeError initialize (storeAccessMode eAccessMode, sal_uInt16 nPageSize);
1030cdf0e10cSrcweir
1031cdf0e10cSrcweir private:
1032cdf0e10cSrcweir virtual storeError readPageAt_Impl (PageHolder & rPage, sal_uInt32 nOffset);
1033cdf0e10cSrcweir virtual storeError writePageAt_Impl (PageHolder const & rPage, sal_uInt32 nOffset);
1034cdf0e10cSrcweir
1035cdf0e10cSrcweir /* see @ OFileLockBytes */
1036cdf0e10cSrcweir virtual storeError peekAt_Impl (sal_uInt32 nOffset, void * pBuffer, sal_uInt32 nBytes);
1037cdf0e10cSrcweir virtual storeError pokeAt_Impl (sal_uInt32 nOffset, void const * pBuffer, sal_uInt32 nBytes);
1038cdf0e10cSrcweir
1039cdf0e10cSrcweir virtual storeError getSize_Impl (sal_uInt32 & rnSize);
1040cdf0e10cSrcweir virtual storeError setSize_Impl (sal_uInt32 nSize);
1041cdf0e10cSrcweir
1042cdf0e10cSrcweir protected:
1043cdf0e10cSrcweir virtual ~FilePageAccess();
1044cdf0e10cSrcweir
1045cdf0e10cSrcweir private:
1046cdf0e10cSrcweir /** Not implemented.
1047cdf0e10cSrcweir */
1048cdf0e10cSrcweir FilePageAccess (FilePageAccess const &);
1049cdf0e10cSrcweir FilePageAccess & operator= (FilePageAccess const &);
1050cdf0e10cSrcweir };
1051cdf0e10cSrcweir
initialize(storeAccessMode eAccessMode,sal_uInt16 nPageSize)1052cdf0e10cSrcweir storeError FilePageAccess::initialize (storeAccessMode eAccessMode, sal_uInt16 nPageSize)
1053cdf0e10cSrcweir {
1054cdf0e10cSrcweir (void) eAccessMode; // UNUSED
1055cdf0e10cSrcweir (void) nPageSize; // UNUSED
1056cdf0e10cSrcweir return store_E_Unknown; // NYI
1057cdf0e10cSrcweir }
~FilePageAccess()1058cdf0e10cSrcweir FilePageAccess::~FilePageAccess()
1059cdf0e10cSrcweir {
1060cdf0e10cSrcweir if (m_hFile != 0)
1061cdf0e10cSrcweir (void) osl_closeFile (m_hFile);
1062cdf0e10cSrcweir }
readPageAt_Impl(PageHolder & rPage,sal_uInt32 nOffset)1063cdf0e10cSrcweir storeError FilePageAccess::readPageAt_Impl (PageHolder & rPage, sal_uInt32 nOffset)
1064cdf0e10cSrcweir {
1065cdf0e10cSrcweir PageHolder page (0/*allocate()*/); /* @@@ construct w/ deallocator argument @@@ */
1066cdf0e10cSrcweir if (!page.get())
1067cdf0e10cSrcweir return store_E_OutOfMemory;
1068cdf0e10cSrcweir
1069cdf0e10cSrcweir swap<PageHolder>(page, rPage);
1070cdf0e10cSrcweir return peekAt (nOffset, rPage.get(), 0/*size*/);
1071cdf0e10cSrcweir }
writePageAt_Impl(PageHolder const & rPage,sal_uInt32 nOffset)1072cdf0e10cSrcweir storeError FilePageAccess::writePageAt_Impl (PageHolder const & rPage, sal_uInt32 nOffset)
1073cdf0e10cSrcweir {
1074cdf0e10cSrcweir return pokeAt (nOffset, rPage.get(), 0/*size*/);
1075cdf0e10cSrcweir }
peekAt_Impl(sal_uInt32 nOffset,void * pBuffer,sal_uInt32 nBytes)1076cdf0e10cSrcweir storeError FilePageAccess::peekAt_Impl (sal_uInt32 nOffset, void * pBuffer, sal_uInt32 nBytes)
1077cdf0e10cSrcweir {
1078cdf0e10cSrcweir sal_uInt64 nDone = 0;
1079cdf0e10cSrcweir oslFileError result = osl_readFileAt (m_hFile, nOffset, pBuffer, nBytes, &nDone);
1080cdf0e10cSrcweir if (result != osl_File_E_None)
1081cdf0e10cSrcweir return ERROR_FROM_NATIVE(result);
1082cdf0e10cSrcweir if (nDone != nBytes)
1083cdf0e10cSrcweir return (nDone != 0) ? store_E_CantRead : store_E_NotExists;
1084cdf0e10cSrcweir return store_E_None;
1085cdf0e10cSrcweir }
pokeAt_Impl(sal_uInt32 nOffset,void const * pBuffer,sal_uInt32 nBytes)1086cdf0e10cSrcweir storeError FilePageAccess::pokeAt_Impl (sal_uInt32 nOffset, void const * pBuffer, sal_uInt32 nBytes)
1087cdf0e10cSrcweir {
1088cdf0e10cSrcweir sal_uInt64 nDone = 0;
1089cdf0e10cSrcweir oslFileError result = osl_writeFileAt (m_hFile, nOffset, pBuffer, nBytes, &nDone);
1090cdf0e10cSrcweir if (result != osl_File_E_None)
1091cdf0e10cSrcweir return ERROR_FROM_NATIVE(result);
1092cdf0e10cSrcweir if (nDone != nBytes)
1093cdf0e10cSrcweir return store_E_CantWrite;
1094cdf0e10cSrcweir return store_E_None;
1095cdf0e10cSrcweir }
getSize_Impl(sal_uInt32 & rnSize)1096cdf0e10cSrcweir storeError FilePageAccess::getSize_Impl (sal_uInt32 & rnSize)
1097cdf0e10cSrcweir {
1098cdf0e10cSrcweir sal_uInt64 uSize = 0;
1099cdf0e10cSrcweir oslFileError result = osl_getFileSize (m_hFile, &uSize);
1100cdf0e10cSrcweir if (result != osl_File_E_None)
1101cdf0e10cSrcweir return ERROR_FROM_NATIVE(result);
1102cdf0e10cSrcweir if (uSize > SAL_MAX_UINT32)
1103cdf0e10cSrcweir return store_E_CantSeek;
1104cdf0e10cSrcweir
1105cdf0e10cSrcweir rnSize = sal::static_int_cast<sal_uInt32>(uSize);
1106cdf0e10cSrcweir return store_E_None;
1107cdf0e10cSrcweir }
setSize_Impl(sal_uInt32 nSize)1108cdf0e10cSrcweir storeError FilePageAccess::setSize_Impl (sal_uInt32 nSize)
1109cdf0e10cSrcweir {
1110cdf0e10cSrcweir oslFileError result = osl_setFileSize (m_hFile, nSize);
1111cdf0e10cSrcweir if (result != osl_File_E_None)
1112cdf0e10cSrcweir return ERROR_FROM_NATIVE(result);
1113cdf0e10cSrcweir return store_E_None;
1114cdf0e10cSrcweir }
ERROR_FROM_NATIVE(oslFileError eErrno)1115cdf0e10cSrcweir storeError FilePageAccess::ERROR_FROM_NATIVE (oslFileError eErrno)
1116cdf0e10cSrcweir {
1117cdf0e10cSrcweir switch (eErrno)
1118cdf0e10cSrcweir {
1119cdf0e10cSrcweir case osl_File_E_None:
1120cdf0e10cSrcweir return store_E_None;
1121cdf0e10cSrcweir
1122cdf0e10cSrcweir case osl_File_E_NOENT:
1123cdf0e10cSrcweir return store_E_NotExists;
1124cdf0e10cSrcweir
1125cdf0e10cSrcweir case osl_File_E_ACCES:
1126cdf0e10cSrcweir case osl_File_E_PERM:
1127cdf0e10cSrcweir return store_E_AccessViolation;
1128cdf0e10cSrcweir
1129cdf0e10cSrcweir case osl_File_E_AGAIN:
1130cdf0e10cSrcweir case osl_File_E_DEADLK:
1131cdf0e10cSrcweir return store_E_LockingViolation;
1132cdf0e10cSrcweir
1133cdf0e10cSrcweir case osl_File_E_BADF:
1134cdf0e10cSrcweir return store_E_InvalidHandle;
1135cdf0e10cSrcweir
1136cdf0e10cSrcweir case osl_File_E_INVAL:
1137cdf0e10cSrcweir return store_E_InvalidParameter;
1138cdf0e10cSrcweir
1139cdf0e10cSrcweir case osl_File_E_NOSPC:
1140cdf0e10cSrcweir return store_E_OutOfSpace;
1141cdf0e10cSrcweir
1142cdf0e10cSrcweir case osl_File_E_OVERFLOW:
1143cdf0e10cSrcweir return store_E_CantSeek;
1144cdf0e10cSrcweir
1145cdf0e10cSrcweir default:
1146cdf0e10cSrcweir return store_E_Unknown;
1147cdf0e10cSrcweir }
1148cdf0e10cSrcweir }
MODE_TO_NATIVE(storeAccessMode eAccessMode)1149cdf0e10cSrcweir sal_uInt32 FilePageAccess::MODE_TO_NATIVE(storeAccessMode eAccessMode)
1150cdf0e10cSrcweir {
1151cdf0e10cSrcweir sal_uInt32 nMode = 0;
1152cdf0e10cSrcweir switch (eAccessMode)
1153cdf0e10cSrcweir {
1154cdf0e10cSrcweir case store_AccessCreate:
1155cdf0e10cSrcweir case store_AccessReadCreate:
1156cdf0e10cSrcweir nMode |= osl_File_OpenFlag_Create;
1157cdf0e10cSrcweir // fall through
1158cdf0e10cSrcweir case store_AccessReadWrite:
1159cdf0e10cSrcweir nMode |= osl_File_OpenFlag_Write;
1160cdf0e10cSrcweir // fall through
1161cdf0e10cSrcweir case store_AccessReadOnly:
1162cdf0e10cSrcweir nMode |= osl_File_OpenFlag_Read;
1163cdf0e10cSrcweir break;
1164cdf0e10cSrcweir default:
1165cdf0e10cSrcweir OSL_PRECOND(0, "store::FilePageAccess: unknown storeAccessMode");
1166cdf0e10cSrcweir }
1167cdf0e10cSrcweir return nMode;
1168cdf0e10cSrcweir }
1169cdf0e10cSrcweir
1170cdf0e10cSrcweir /*===*/
1171cdf0e10cSrcweir
1172cdf0e10cSrcweir class MemoryPageAccess : public IPageAccess
1173cdf0e10cSrcweir {
1174cdf0e10cSrcweir /** Representation.
1175cdf0e10cSrcweir */
1176cdf0e10cSrcweir sal_uInt8 * m_pData;
1177cdf0e10cSrcweir sal_uInt32 m_nSize;
1178cdf0e10cSrcweir
1179cdf0e10cSrcweir /** Callback function to release Representation.
1180cdf0e10cSrcweir */
1181cdf0e10cSrcweir typedef void (*destructor_type)(sal_uInt8 * pData, sal_uInt32 nSize);
1182cdf0e10cSrcweir destructor_type m_destructor;
1183cdf0e10cSrcweir
1184cdf0e10cSrcweir /** Default destructor callback.
1185cdf0e10cSrcweir */
1186cdf0e10cSrcweir static void freeMemory (sal_uInt8 * pData, sal_uInt32 nSize);
1187cdf0e10cSrcweir
1188cdf0e10cSrcweir public:
MemoryPageAccess()1189cdf0e10cSrcweir MemoryPageAccess()
1190cdf0e10cSrcweir : m_pData (0), m_nSize (0), m_destructor (MemoryPageAccess::freeMemory)
1191cdf0e10cSrcweir {}
MemoryPageAccess(sal_uInt8 * pData,sal_uInt32 nSize,destructor_type destructor=MemoryPageAccess::freeMemory)1192cdf0e10cSrcweir MemoryPageAccess (sal_uInt8 * pData, sal_uInt32 nSize, destructor_type destructor = MemoryPageAccess::freeMemory)
1193cdf0e10cSrcweir : m_pData (pData), m_nSize (nSize), m_destructor (destructor)
1194cdf0e10cSrcweir {}
1195cdf0e10cSrcweir
1196cdf0e10cSrcweir virtual storeError initialize (storeAccessMode eAccessMode, sal_uInt16 nPageSize);
1197cdf0e10cSrcweir
1198cdf0e10cSrcweir private:
1199cdf0e10cSrcweir /** Page (size aligned) access.
1200cdf0e10cSrcweir */
1201cdf0e10cSrcweir virtual storeError readPageAt_Impl (PageHolder & rPage, sal_uInt32 nOffset);
1202cdf0e10cSrcweir virtual storeError writePageAt_Impl (PageHolder const & rPage, sal_uInt32 nOffset);
1203cdf0e10cSrcweir
1204cdf0e10cSrcweir /** Low level access.
1205cdf0e10cSrcweir */
1206cdf0e10cSrcweir virtual storeError peekAt_Impl (sal_uInt32 nOffset, void * pBuffer, sal_uInt32 nBytes);
1207cdf0e10cSrcweir virtual storeError pokeAt_Impl (sal_uInt32 nOffset, void const * pBuffer, sal_uInt32 nBytes);
1208cdf0e10cSrcweir
1209cdf0e10cSrcweir virtual storeError getSize_Impl (sal_uInt32 & rnSize);
1210cdf0e10cSrcweir virtual storeError setSize_Impl (sal_uInt32 nSize);
1211cdf0e10cSrcweir
1212cdf0e10cSrcweir protected:
1213cdf0e10cSrcweir virtual ~MemoryPageAccess();
1214cdf0e10cSrcweir
1215cdf0e10cSrcweir private:
1216cdf0e10cSrcweir /** Not implemented.
1217cdf0e10cSrcweir */
1218cdf0e10cSrcweir MemoryPageAccess (MemoryPageAccess const &);
1219cdf0e10cSrcweir MemoryPageAccess & operator= (MemoryPageAccess const &);
1220cdf0e10cSrcweir };
1221cdf0e10cSrcweir
initialize(storeAccessMode eAccessMode,sal_uInt16 nPageSize)1222cdf0e10cSrcweir storeError MemoryPageAccess::initialize (storeAccessMode eAccessMode, sal_uInt16 nPageSize)
1223cdf0e10cSrcweir {
1224cdf0e10cSrcweir (void) eAccessMode; // UNUSED
1225cdf0e10cSrcweir (void) nPageSize; // UNUSED
1226cdf0e10cSrcweir return store_E_Unknown; // NYI
1227cdf0e10cSrcweir }
~MemoryPageAccess()1228cdf0e10cSrcweir MemoryPageAccess::~MemoryPageAccess()
1229cdf0e10cSrcweir {
1230cdf0e10cSrcweir if (m_destructor != 0)
1231cdf0e10cSrcweir {
1232cdf0e10cSrcweir // release resource.
1233cdf0e10cSrcweir (*m_destructor)(m_pData, m_nSize);
1234cdf0e10cSrcweir }
1235cdf0e10cSrcweir }
readPageAt_Impl(PageHolder & rPage,sal_uInt32 nOffset)1236cdf0e10cSrcweir storeError MemoryPageAccess::readPageAt_Impl (PageHolder & rPage, sal_uInt32 nOffset)
1237cdf0e10cSrcweir {
1238cdf0e10cSrcweir /* OSL_PRECOND(nOffset % size == 0, "Unaligned page read."); */
1239cdf0e10cSrcweir PageHolder page (reinterpret_cast< PageData* >(m_pData + nOffset));
1240cdf0e10cSrcweir swap<PageHolder>(page, rPage);
1241cdf0e10cSrcweir return store_E_None;
1242cdf0e10cSrcweir }
writePageAt_Impl(PageHolder const & rPage,sal_uInt32 nOffset)1243cdf0e10cSrcweir storeError MemoryPageAccess::writePageAt_Impl (PageHolder const & rPage, sal_uInt32 nOffset)
1244cdf0e10cSrcweir {
1245cdf0e10cSrcweir PageData const * pagedata = rPage.get();
1246cdf0e10cSrcweir if (!(pagedata != 0))
1247cdf0e10cSrcweir return store_E_InvalidParameter;
1248cdf0e10cSrcweir
1249cdf0e10cSrcweir #if 0 /* NYI */
1250cdf0e10cSrcweir sal_uInt16 const bytes = pagedata->size(); // Descr.m_nSize;
1251cdf0e10cSrcweir OSL_ASSERT(bytes >= PageData::thePageSize);
1252cdf0e10cSrcweir
1253cdf0e10cSrcweir offset = rPage.location(); // Descr.m_nAddr;
1254cdf0e10cSrcweir OSL_ASSERT(nOffset == offset);
1255cdf0e10cSrcweir
1256cdf0e10cSrcweir OSL_PRECOND(offset % bytes == 0, "Unaligned page write.");
1257cdf0e10cSrcweir #endif /* NYI */
1258cdf0e10cSrcweir return pokeAt (nOffset, pagedata, pagedata->size());
1259cdf0e10cSrcweir }
peekAt_Impl(sal_uInt32 nOffset,void * pBuffer,sal_uInt32 nBytes)1260cdf0e10cSrcweir storeError MemoryPageAccess::peekAt_Impl (sal_uInt32 nOffset, void * pBuffer, sal_uInt32 nBytes)
1261cdf0e10cSrcweir {
1262cdf0e10cSrcweir // [SECURITY:ValInput]
1263cdf0e10cSrcweir sal_uInt8 * dst_lo = static_cast<sal_uInt8*>(pBuffer);
1264cdf0e10cSrcweir if (!(dst_lo != 0))
1265cdf0e10cSrcweir return store_E_InvalidParameter;
1266cdf0e10cSrcweir
1267cdf0e10cSrcweir sal_uInt8 * dst_hi = dst_lo + nBytes;
1268cdf0e10cSrcweir if (!(dst_lo <= dst_hi))
1269cdf0e10cSrcweir return store_E_InvalidParameter;
1270cdf0e10cSrcweir
1271cdf0e10cSrcweir // ...
1272cdf0e10cSrcweir sal_uInt8 const * src_lo = m_pData + nOffset;
1273cdf0e10cSrcweir if (!(src_lo <= m_pData + m_nSize))
1274cdf0e10cSrcweir return store_E_CantSeek;
1275cdf0e10cSrcweir
1276cdf0e10cSrcweir sal_uInt8 const * src_hi = src_lo + nBytes;
1277cdf0e10cSrcweir if (!(src_hi <= m_pData + m_nSize))
1278cdf0e10cSrcweir return store_E_CantRead;
1279cdf0e10cSrcweir
1280cdf0e10cSrcweir // copy.
1281cdf0e10cSrcweir memcpy (pBuffer, src_lo, (src_hi - src_lo));
1282cdf0e10cSrcweir return store_E_None;
1283cdf0e10cSrcweir }
pokeAt_Impl(sal_uInt32 nOffset,void const * pBuffer,sal_uInt32 nBytes)1284cdf0e10cSrcweir storeError MemoryPageAccess::pokeAt_Impl (sal_uInt32 nOffset, void const * pBuffer, sal_uInt32 nBytes)
1285cdf0e10cSrcweir {
1286cdf0e10cSrcweir // [SECURITY:ValInput]
1287cdf0e10cSrcweir sal_uInt8 const * src_lo = static_cast<sal_uInt8 const*>(pBuffer);
1288cdf0e10cSrcweir if (!(src_lo != 0))
1289cdf0e10cSrcweir return store_E_InvalidParameter;
1290cdf0e10cSrcweir
1291cdf0e10cSrcweir sal_uInt8 const * src_hi = src_lo + nBytes;
1292cdf0e10cSrcweir if (!(src_lo <= src_hi))
1293cdf0e10cSrcweir return store_E_InvalidParameter;
1294cdf0e10cSrcweir
1295cdf0e10cSrcweir sal_uInt64 const uSize = nOffset + nBytes;
1296cdf0e10cSrcweir if (uSize > SAL_MAX_UINT32)
1297cdf0e10cSrcweir return store_E_CantSeek;
1298cdf0e10cSrcweir
1299cdf0e10cSrcweir // ...
1300cdf0e10cSrcweir if (uSize > m_nSize)
1301cdf0e10cSrcweir {
1302cdf0e10cSrcweir // increase size.
1303cdf0e10cSrcweir storeError eErrCode = setSize (sal::static_int_cast<sal_uInt32>(uSize));
1304cdf0e10cSrcweir if (eErrCode != store_E_None)
1305cdf0e10cSrcweir return eErrCode;
1306cdf0e10cSrcweir }
1307cdf0e10cSrcweir
1308cdf0e10cSrcweir sal_uInt8 * dst_lo = m_pData + nOffset;
1309cdf0e10cSrcweir if (!(dst_lo <= m_pData + m_nSize))
1310cdf0e10cSrcweir return store_E_CantSeek;
1311cdf0e10cSrcweir
1312cdf0e10cSrcweir sal_uInt8 * dst_hi = dst_lo + nBytes;
1313cdf0e10cSrcweir if (!(dst_hi <= m_pData + m_nSize))
1314cdf0e10cSrcweir return store_E_CantWrite;
1315cdf0e10cSrcweir
1316cdf0e10cSrcweir // copy.
1317cdf0e10cSrcweir memcpy (dst_lo, src_lo, (src_hi - src_lo));
1318cdf0e10cSrcweir return store_E_None;
1319cdf0e10cSrcweir }
getSize_Impl(sal_uInt32 & rnSize)1320cdf0e10cSrcweir storeError MemoryPageAccess::getSize_Impl (sal_uInt32 & rnSize)
1321cdf0e10cSrcweir {
1322cdf0e10cSrcweir rnSize = m_nSize;
1323cdf0e10cSrcweir return store_E_None;
1324cdf0e10cSrcweir }
setSize_Impl(sal_uInt32 nSize)1325cdf0e10cSrcweir storeError MemoryPageAccess::setSize_Impl (sal_uInt32 nSize)
1326cdf0e10cSrcweir {
1327cdf0e10cSrcweir if (nSize != m_nSize)
1328cdf0e10cSrcweir {
1329cdf0e10cSrcweir sal_uInt8 * pData = static_cast<sal_uInt8*>(rtl_reallocateMemory (m_pData, nSize));
1330cdf0e10cSrcweir if (pData != 0)
1331cdf0e10cSrcweir {
1332cdf0e10cSrcweir if (nSize > m_nSize)
1333cdf0e10cSrcweir memset (pData + m_nSize, 0, sal::static_int_cast< size_t >(nSize - m_nSize));
1334cdf0e10cSrcweir }
1335cdf0e10cSrcweir else
1336cdf0e10cSrcweir {
1337cdf0e10cSrcweir if (nSize != 0)
1338cdf0e10cSrcweir return store_E_OutOfMemory;
1339cdf0e10cSrcweir }
1340cdf0e10cSrcweir m_pData = pData, m_nSize = nSize;
1341cdf0e10cSrcweir }
1342cdf0e10cSrcweir return store_E_None;
1343cdf0e10cSrcweir }
freeMemory(sal_uInt8 * pData,sal_uInt32)1344cdf0e10cSrcweir void MemoryPageAccess::freeMemory (sal_uInt8 * pData, sal_uInt32 /*nSize*/)
1345cdf0e10cSrcweir {
1346cdf0e10cSrcweir rtl_freeMemory (pData);
1347cdf0e10cSrcweir }
1348cdf0e10cSrcweir
1349cdf0e10cSrcweir /*===*/
1350cdf0e10cSrcweir
1351cdf0e10cSrcweir class MappedPageAccess : public MemoryPageAccess
1352cdf0e10cSrcweir {
1353cdf0e10cSrcweir /** @see MemoryPageAccess::destructor_type callback function.
1354cdf0e10cSrcweir */
1355cdf0e10cSrcweir static void unmapFile (sal_uInt8 * pData, sal_uInt32 nSize);
1356cdf0e10cSrcweir
1357cdf0e10cSrcweir public:
1358cdf0e10cSrcweir MappedPageAccess (sal_uInt8 * pData, sal_uInt32 nSize);
1359cdf0e10cSrcweir
1360cdf0e10cSrcweir virtual storeError initialize (storeAccessMode eAccessMode, sal_uInt16 nPageSize);
1361cdf0e10cSrcweir
1362cdf0e10cSrcweir virtual storeError writePageAt (PageHolder const & rPage, sal_uInt32 nOffset);
1363cdf0e10cSrcweir
1364cdf0e10cSrcweir private:
1365cdf0e10cSrcweir virtual storeError pokeAt_Impl (sal_uInt32 nOffset, void const * pBuffer, sal_uInt32 nBytes);
1366cdf0e10cSrcweir virtual storeError setSize_Impl (sal_uInt32 nSize);
1367cdf0e10cSrcweir
1368cdf0e10cSrcweir protected:
~MappedPageAccess()1369cdf0e10cSrcweir virtual ~MappedPageAccess() {}
1370cdf0e10cSrcweir };
1371cdf0e10cSrcweir
MappedPageAccess(sal_uInt8 * pData,sal_uInt32 nSize)1372cdf0e10cSrcweir MappedPageAccess::MappedPageAccess (sal_uInt8 * pData, sal_uInt32 nSize)
1373cdf0e10cSrcweir : MemoryPageAccess (pData, nSize, MappedPageAccess::unmapFile)
1374cdf0e10cSrcweir {
1375cdf0e10cSrcweir }
initialize(storeAccessMode eAccessMode,sal_uInt16 nPageSize)1376cdf0e10cSrcweir storeError MappedPageAccess::initialize (storeAccessMode eAccessMode, sal_uInt16 nPageSize)
1377cdf0e10cSrcweir {
1378cdf0e10cSrcweir OSL_PRECOND(eAccessMode == store_AccessReadOnly, "store::MappedPageAccess: invalid AccessMode");
1379cdf0e10cSrcweir return MemoryPageAccess::initialize (eAccessMode, nPageSize);
1380cdf0e10cSrcweir }
writePageAt(PageHolder const &,sal_uInt32)1381cdf0e10cSrcweir storeError MappedPageAccess::writePageAt (PageHolder const & /*rPage*/, sal_uInt32 /*nOffset*/)
1382cdf0e10cSrcweir {
1383cdf0e10cSrcweir return store_E_AccessViolation;
1384cdf0e10cSrcweir }
pokeAt_Impl(sal_uInt32,void const *,sal_uInt32)1385cdf0e10cSrcweir storeError MappedPageAccess::pokeAt_Impl (sal_uInt32 /*nOffset*/, void const * /*pBuffer*/, sal_uInt32 /*nBytes*/)
1386cdf0e10cSrcweir {
1387cdf0e10cSrcweir return store_E_AccessViolation;
1388cdf0e10cSrcweir }
setSize_Impl(sal_uInt32)1389cdf0e10cSrcweir storeError MappedPageAccess::setSize_Impl (sal_uInt32 /*nSize*/)
1390cdf0e10cSrcweir {
1391cdf0e10cSrcweir return store_E_AccessViolation;
1392cdf0e10cSrcweir }
unmapFile(sal_uInt8 * pData,sal_uInt32 nSize)1393cdf0e10cSrcweir void MappedPageAccess::unmapFile (sal_uInt8 * pData, sal_uInt32 nSize)
1394cdf0e10cSrcweir {
1395cdf0e10cSrcweir (void) osl_unmapFile (pData, nSize);
1396cdf0e10cSrcweir }
1397cdf0e10cSrcweir
1398cdf0e10cSrcweir #if 0 /* NYI */
1399cdf0e10cSrcweir storeError MemoryPageAccess_createInstance (
1400cdf0e10cSrcweir rtl::Reference< IPageAccess > & rxPageAccess,
1401cdf0e10cSrcweir storeAccessMode eAccessMode,
1402cdf0e10cSrcweir sal_uInt16 nPageSize
1403cdf0e10cSrcweir )
1404cdf0e10cSrcweir {
1405cdf0e10cSrcweir rxPageAccess = new MemoryPageAccess();
1406cdf0e10cSrcweir if (!rxPageAccess.is())
1407cdf0e10cSrcweir return store_E_OutOfMemory;
1408cdf0e10cSrcweir
1409cdf0e10cSrcweir return rxPageAccess->initialize (eAccessMode, nPageSize);
1410cdf0e10cSrcweir }
1411cdf0e10cSrcweir
1412cdf0e10cSrcweir storeError FilePageAccess_createInstance (
1413cdf0e10cSrcweir rtl::Reference< IPageAccess > & rxPageAccess,
1414cdf0e10cSrcweir rtl_uString * pFilename,
1415cdf0e10cSrcweir storeAccessMode eAccessMode,
1416cdf0e10cSrcweir sal_uInt16 nPageSize
1417cdf0e10cSrcweir )
1418cdf0e10cSrcweir {
1419cdf0e10cSrcweir // Acquire file handle.
1420cdf0e10cSrcweir ResourceHolder<FileHandle> xFile;
1421cdf0e10cSrcweir result = xFile.get().initialize (pFilename, MODE_TO_NATIVE(eAccessMode));
1422cdf0e10cSrcweir if (result != osl_File_E_None)
1423cdf0e10cSrcweir return ERROR_FROM_NATIVE(result);
1424cdf0e10cSrcweir
1425cdf0e10cSrcweir if (eAccessMode == store_AccessReadOnly)
1426cdf0e10cSrcweir {
1427cdf0e10cSrcweir ResourceHolder<FileMapping> xMapping;
1428cdf0e10cSrcweir result = xMapping.get().initialize (xFile.get());
1429cdf0e10cSrcweir if (result == osl_File_E_None)
1430cdf0e10cSrcweir {
1431cdf0e10cSrcweir const sal_uInt32 nSize = sal::static_int_cast<sal_uInt32>(xMapping.get().m_uSize);
1432cdf0e10cSrcweir rxPageAccess = new MappedPageAccess (xMapping.get().m_pAddr, nSize);
1433cdf0e10cSrcweir if (!rxPageAccess.is())
1434cdf0e10cSrcweir return store_E_OutOfMemory;
1435cdf0e10cSrcweir (void) xMapping.release();
1436cdf0e10cSrcweir }
1437cdf0e10cSrcweir }
1438cdf0e10cSrcweir if (!rxPageAccess.is())
1439cdf0e10cSrcweir {
1440cdf0e10cSrcweir rxPageAccess = new FilePageAccess (xFile.get());
1441cdf0e10cSrcweir if (!rxPageAccess.is())
1442cdf0e10cSrcweir return store_E_OutOfMemory;
1443cdf0e10cSrcweir (void) xFile.release();
1444cdf0e10cSrcweir }
1445cdf0e10cSrcweir return rxPageAccess->initialize (eAccessMode, nPageSize);
1446cdf0e10cSrcweir }
1447cdf0e10cSrcweir #endif /* NYI */
1448cdf0e10cSrcweir
1449cdf0e10cSrcweir /*========================================================================
1450cdf0e10cSrcweir *
1451cdf0e10cSrcweir * test...
1452cdf0e10cSrcweir *
1453cdf0e10cSrcweir *======================================================================*/
1454cdf0e10cSrcweir #if 0 /* NYI */
1455cdf0e10cSrcweir
1456cdf0e10cSrcweir struct IDataBlock
1457cdf0e10cSrcweir {
1458cdf0e10cSrcweir virtual sal_uInt16 singleCount() const = 0;
1459cdf0e10cSrcweir virtual sal_uInt32 singleLink (sal_uInt16 nIndex) const = 0;
1460cdf0e10cSrcweir virtual void singleLink (sal_uInt16 nIndex, sal_uInt32 nAddr) = 0;
1461cdf0e10cSrcweir
1462cdf0e10cSrcweir virtual storeError get() = 0;
1463cdf0e10cSrcweir virtual storeError put() = 0;
1464cdf0e10cSrcweir virtual storeError truncate() = 0;
1465cdf0e10cSrcweir };
1466cdf0e10cSrcweir
1467cdf0e10cSrcweir struct InodePageData : public PageData
1468cdf0e10cSrcweir {
1469cdf0e10cSrcweir virtual INameBlock & getNameBlock() = 0;
1470cdf0e10cSrcweir virtual IDataBlock & getDataBlock() = 0;
1471cdf0e10cSrcweir };
1472cdf0e10cSrcweir
1473cdf0e10cSrcweir template< class page_data_type >
1474cdf0e10cSrcweir page_data_type * query (PageData *, page_data_type *);
1475cdf0e10cSrcweir
1476cdf0e10cSrcweir template<> InodePageDataV2*
1477cdf0e10cSrcweir query (PageData & rData, InodePageDataV2 *)
1478cdf0e10cSrcweir {
1479cdf0e10cSrcweir if (rData.isKindOf(InodePageDataV2::m_nTypeId))
1480cdf0e10cSrcweir return static_cast<InodePageDataV2*>(&rData);
1481cdf0e10cSrcweir return 0;
1482cdf0e10cSrcweir }
1483cdf0e10cSrcweir
1484cdf0e10cSrcweir class InodePageObject : public PageObject
1485cdf0e10cSrcweir {
1486cdf0e10cSrcweir public:
1487cdf0e10cSrcweir static InodePageObject createInstance (PageData & rData)
1488cdf0e10cSrcweir {
1489cdf0e10cSrcweir if (query(&rData, static_cast<InodePageDataV2*>(0)))
1490cdf0e10cSrcweir return InodePageObjectV2 (static_cast<InodePageDataV2&>(rData));
1491cdf0e10cSrcweir else if (query(&rData, static_cast<InodePageDataV1*>(0)))
1492cdf0e10cSrcweir return InodePageObjectV1 (static_cast<InodePageDataV1&>(rData));
1493cdf0e10cSrcweir }
1494cdf0e10cSrcweir };
1495cdf0e10cSrcweir
1496cdf0e10cSrcweir #endif /* NYI */
1497cdf0e10cSrcweir
1498cdf0e10cSrcweir /*========================================================================
1499cdf0e10cSrcweir *
1500cdf0e10cSrcweir * main.
1501cdf0e10cSrcweir *
1502cdf0e10cSrcweir *======================================================================*/
1503cdf0e10cSrcweir
1504cdf0e10cSrcweir #include <stdio.h>
1505cdf0e10cSrcweir
1506cdf0e10cSrcweir #if 0 /* EXP */
1507cdf0e10cSrcweir class Interface
1508cdf0e10cSrcweir {
1509cdf0e10cSrcweir public:
1510cdf0e10cSrcweir virtual void deallocate(void *) /* = 0 */;
1511cdf0e10cSrcweir };
1512cdf0e10cSrcweir
1513cdf0e10cSrcweir class Implementation : public Interface
1514cdf0e10cSrcweir {
1515cdf0e10cSrcweir SharedCount m_count;
1516cdf0e10cSrcweir
1517cdf0e10cSrcweir public:
1518cdf0e10cSrcweir Implementation() : Interface() { printf("Ctor(%p)\n", this); }
1519cdf0e10cSrcweir ~Implementation() { printf("Dtor(%p)\n", this); }
1520cdf0e10cSrcweir
1521cdf0e10cSrcweir Implementation (Implementation const & rhs) : Interface(), m_count (rhs.m_count) { printf("CopyCtor(%p)\n", this); }
1522cdf0e10cSrcweir
1523cdf0e10cSrcweir virtual void deallocate(void *) {}
1524cdf0e10cSrcweir };
1525cdf0e10cSrcweir
1526cdf0e10cSrcweir Interface Interface_createInstance()
1527cdf0e10cSrcweir {
1528cdf0e10cSrcweir Implementation aInst;
1529cdf0e10cSrcweir return aInst;
1530cdf0e10cSrcweir }
1531cdf0e10cSrcweir #endif /* EXP */
1532cdf0e10cSrcweir
main(int argc,char ** argv)1533cdf0e10cSrcweir int SAL_CALL main (int argc, char ** argv)
1534cdf0e10cSrcweir {
1535cdf0e10cSrcweir OSL_PRECOND(argc >= 1, "t_page: error: insufficient number of arguments.");
1536cdf0e10cSrcweir if (argc < 1)
1537cdf0e10cSrcweir return 0;
1538cdf0e10cSrcweir
1539cdf0e10cSrcweir {
1540cdf0e10cSrcweir void *a = (void*)1, *b = (void*)2;
1541cdf0e10cSrcweir swap<void*>(a, b);
1542cdf0e10cSrcweir }
1543cdf0e10cSrcweir {
1544cdf0e10cSrcweir PageObject a;
1545cdf0e10cSrcweir PageObject b (a);
1546cdf0e10cSrcweir PageObject c;
1547cdf0e10cSrcweir
1548cdf0e10cSrcweir c = b;
1549cdf0e10cSrcweir a = a;
1550cdf0e10cSrcweir
1551cdf0e10cSrcweir }
1552cdf0e10cSrcweir {
1553cdf0e10cSrcweir TestBIOS aBIOS;
1554cdf0e10cSrcweir TestClient aClient;
1555cdf0e10cSrcweir aClient.dwim (aBIOS);
1556cdf0e10cSrcweir }
1557cdf0e10cSrcweir #if 0 /* EXP */
1558cdf0e10cSrcweir {
1559cdf0e10cSrcweir Interface aIfc1 (Interface_createInstance());
1560cdf0e10cSrcweir Interface aIfc2 (aIfc1);
1561cdf0e10cSrcweir }
1562cdf0e10cSrcweir #endif /* EXP */
1563cdf0e10cSrcweir
1564cdf0e10cSrcweir if (argc > 1)
1565cdf0e10cSrcweir {
1566cdf0e10cSrcweir rtl_uString * pFilename = 0;
1567cdf0e10cSrcweir rtl_uString_newFromAscii (&pFilename, argv[1]);
1568cdf0e10cSrcweir storeAccessMode eAccessMode = store_AccessReadOnly;
1569cdf0e10cSrcweir
1570cdf0e10cSrcweir // Acquire file handle.
1571cdf0e10cSrcweir ResourceHolder<FileHandle> h1;
1572cdf0e10cSrcweir oslFileError result = h1.get().initialize (pFilename, FilePageAccess::MODE_TO_NATIVE(eAccessMode));
1573cdf0e10cSrcweir if (result == osl_File_E_None)
1574cdf0e10cSrcweir {
1575cdf0e10cSrcweir ResourceHolder<FileHandle> h2 (h1);
1576cdf0e10cSrcweir h1 = h2;
1577cdf0e10cSrcweir
1578cdf0e10cSrcweir if (eAccessMode == store_AccessReadOnly)
1579cdf0e10cSrcweir {
1580cdf0e10cSrcweir ResourceHolder<FileMapping> m1;
1581cdf0e10cSrcweir result = m1.get().initialize (h1.get());
1582cdf0e10cSrcweir
1583cdf0e10cSrcweir const sal_uInt32 nSize = sal::static_int_cast<sal_uInt32>(m1.get().m_uSize);
1584cdf0e10cSrcweir (void) nSize; // UNUSED
1585cdf0e10cSrcweir
1586cdf0e10cSrcweir ResourceHolder<FileMapping> m2 (m1);
1587cdf0e10cSrcweir m1 = m2;
1588cdf0e10cSrcweir
1589cdf0e10cSrcweir result = osl_File_E_None;
1590cdf0e10cSrcweir }
1591cdf0e10cSrcweir }
1592cdf0e10cSrcweir }
1593cdf0e10cSrcweir
1594cdf0e10cSrcweir return 0;
1595cdf0e10cSrcweir }
1596