Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / storage / page_cache.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: page_cache.h /main/3 1996/06/11 17:44:27 cde-hal $ */
24
25 #ifndef _page_cache_h
26 #define _page_cache_h 1
27
28 class page;
29 class page_storage;
30
31 #define MMDB_CACHED_PAGES 100
32 #define MIN_MMDB_CACHED_PAGES 10
33
34 #include "dstr/bset.h"
35
36 class page_cache_local_part
37 {
38
39 protected:
40    int f_num_cached_pages ;  // number of cached pages
41
42    heap f_free_space;        // a heap recording free
43                              // space on each page
44
45    bset f_page_pool_index;    // index to pages in the pool
46
47    int f_current_page_num;
48    page* f_current_page_ptr;
49
50 public:
51    page_cache_local_part(unsigned int exp_cached_page);
52    virtual ~page_cache_local_part();
53
54 // init the heap
55    Boolean init_heap(page_storage*);
56    Boolean quit_heap(page_storage*);
57
58 // does the cache hold page 'page_num'?
59    page* in_cache(page_storage* st, int page_num);
60
61 // get a non-empty page
62    fbytes_t* find_host_page(page_storage*, Boolean& new_page, int len = 0);
63    void adjust_heap(fbytes_t* v, Boolean new_page);
64
65    friend class page_cache_global_part ;
66 };
67
68 class lru;
69
70 class page_cache_global_part 
71 {
72
73 public:
74 //////////////////////////////////////////////////////////////////////
75 // The default value (0) triggers the constructor to 
76 // search for the value in the shell variable MMDB_CACHED_PAGES.
77 // If the varialble is undefind, the value set by const MMDB_CACHED_PAGES
78 // will be used.
79 //////////////////////////////////////////////////////////////////////
80    page_cache_global_part(unsigned int total_allowed_pages = 0);
81    virtual ~page_cache_global_part() ;
82
83    void remove_pages(page_storage* st);
84
85 // return a free page frame from cache
86    page* load_new_page(page_storage*, int page_num, Boolean byteOrder);
87
88    ostream& print_cached_pages(ostream&); // show cached pages.
89
90    friend class page_cache_local_part;
91    friend class page_storage;
92    friend void remove_from_global_cache(const void*);
93
94 protected:
95    unsigned int    f_total_allowed_pages;
96    lru             f_replace_policy;
97 };
98
99 #endif