2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
24 * $XConsortium: page_storage.h /main/7 1996/07/18 14:55:30 drk $
26 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27 * All rights reserved. Unpublished -- rights reserved under
28 * the Copyright Laws of the United States. USE OF A COPYRIGHT
29 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
32 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
34 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
38 * RESTRICTED RIGHTS LEGEND
39 * Use, duplication, or disclosure by the Government is subject
40 * to the restrictions as set forth in subparagraph (c)(l)(ii)
41 * of the Rights in Technical Data and Computer Software clause
42 * at DFARS 252.227-7013.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
51 #ifndef _page_storage_h
52 #define _page_storage_h 1
56 #include "utility/pm_random.h"
57 #include "dstr/heap.h"
58 #include "dstr/void_ptr_array.h"
59 #include "dynhash/imp_die.h"
60 #include "storage/unixf_storage.h"
61 #include "storage/heap_comp_funcs.h"
62 #include "storage/page_cache.h"
63 #include "storage/spointer.h"
65 enum direction { positive, negative };
69 class str_index_record_t : public root
76 str_index_record_t(int offset, mmdb_pos_t lc = 0);
77 virtual ~str_index_record_t() {};
80 void delete_str_index_record(const void* str_index_record_ptr);
82 typedef str_index_record_t* str_index_record_tPtr;
84 ////////////////////////////////////////////
85 ////////////////////////////////////////////
90 enum trans_t { ENABLED, DISABLED };
95 unixf_storage* log_store;
102 store_trans(char* path, char*name, int page_sz);
105 void init(rep_policy*);
108 void set_max_pages(int max_pgs) {
112 friend class page_storage;
115 /******************************************************/
116 // cached page storage. Implemented on Unix file class.
117 /******************************************************/
120 #define f_global_pcache (*f_global_pcache_ptr)
124 class page_storage : public abs_storage
128 buffer* v_buf; // aux. buf.
130 int page_sz ; // page size
136 static page_cache_global_part f_global_pcache;
138 static page_cache_global_part* f_global_pcache_ptr;
141 page_cache_local_part f_local_pcache;
146 int total_page_access;
148 store_trans trans_info;
156 Boolean seek_loc_negative(mmdb_pos_t& loc, int smd);
157 Boolean seek_loc_positive(mmdb_pos_t& loc, int smd);
160 page_storage(char* path, char* name,
161 unixf_storage* store,
162 int page_sz = PAGSIZ,
163 int num_cached_pages = NUM_PAGES,
164 mmdb_byte_order_t db_order_when_create_store = mmdb_big_endian
166 virtual ~page_storage();
168 void remove(); // remove all pages in the store
171 void sync(int pagenum);
177 void save_to_log(page* page_ptr);
179 // get server and db order
180 int server_order() { return v_server_order; } ;
181 int db_order() { return v_db_order; };
185 int readString (mmdb_pos_t loc, char* base, int len, int str_offset = 0);
186 int get_str_ptr(mmdb_pos_t loc, char*&, int& len) ;
188 int updateString(mmdb_pos_t loc, const char* base, int len, int string_ofst = 0, Boolean flush = false);
189 int deleteString (mmdb_pos_t loc, Boolean flush = false);
190 int insertString(mmdb_pos_t& loc, const char* base, int len, Boolean flush = false);
191 int allocString (mmdb_pos_t& loc, int len, char*&, int mode = 0);
192 int appendString(mmdb_pos_t loc, const char*, int len, Boolean flush_opt = false);
194 int set_page_dirty(mmdb_pos_t loc);
196 // iteration functions
197 typedef enum access { READ, WRITE } access_t;
198 int first() const; // first page's index in the store
199 page* operator()(int page_num, enum access intent) ; //get the page
200 void next(int&) const; // next page's index.
203 // format the store to contain extra empty 'pages' pages
204 int add_page_frames(int pages);
207 // get locs of the pieces that a long string is broken into
208 // The array should be deleted after use.
209 int get_str_locs(mmdb_pos_t str_loc, str_index_record_tPtr*& locs, int& vector_leng);
211 // seek loc to (loc +/- 1) position
212 Boolean seek_loc(mmdb_pos_t& loc, const direction = positive, int = spointer_t::FIRST_RECD );
213 mmdb_pos_t first_loc(); // return first loc in the store
214 mmdb_pos_t last_loc(); // return last loc in the store
216 // store status query functions
217 int page_size() { return page_sz; };
220 void set_page_size(int pgsz) { page_sz = pgsz; };
222 // how many pages in total in the store
223 int pages() const { return total_pages; };
225 // paging counting function
226 void reset_paging_count();
227 int paging_count() const;
229 Boolean io_mode(int mode) ;
231 // return an aux. buf.
234 // printing functions
235 virtual io_status asciiOut(ostream&) ;
237 friend void close_file(const void*);
238 friend void remove_from_global_cache(const void*);
240 friend class storage_mgr_t;
241 friend class handler;
242 friend class page_cache_local_part;
243 friend class page_cache_global_part;
246 friend void initialize_MMDB();
247 friend void quit_MMDB();
251 typedef page_storage* page_storagePtr;