page_storage.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 libraries 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. /*
  24. * $XConsortium: page_storage.h /main/7 1996/07/18 14:55:30 drk $
  25. *
  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
  30. * OR DISCLOSURE.
  31. *
  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
  36. * INTERNATIONAL, LTD.
  37. *
  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.
  43. *
  44. * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
  45. * 1315 Dell Avenue
  46. * Campbell, CA 95008
  47. *
  48. */
  49. #ifndef _page_storage_h
  50. #define _page_storage_h 1
  51. #define NUM_PAGES 10
  52. #include "utility/pm_random.h"
  53. #include "dstr/heap.h"
  54. #include "dstr/void_ptr_array.h"
  55. #include "dynhash/imp_die.h"
  56. #include "storage/unixf_storage.h"
  57. #include "storage/heap_comp_funcs.h"
  58. #include "storage/page_cache.h"
  59. #include "storage/spointer.h"
  60. enum direction { positive, negative };
  61. class page;
  62. class str_index_record_t : public root
  63. {
  64. public:
  65. int str_offset;
  66. mmdb_pos_t loc;
  67. str_index_record_t(int offset, mmdb_pos_t lc = 0);
  68. virtual ~str_index_record_t() {};
  69. };
  70. void delete_str_index_record(const void* str_index_record_ptr);
  71. typedef str_index_record_t* str_index_record_tPtr;
  72. ////////////////////////////////////////////
  73. ////////////////////////////////////////////
  74. class store_trans
  75. {
  76. protected:
  77. enum trans_t { ENABLED, DISABLED };
  78. char* path;
  79. char* name;
  80. trans_t status;
  81. unixf_storage* log_store;
  82. imp_die* log_index;
  83. int max_pages;
  84. int page_sz;
  85. public:
  86. store_trans(char* path, char*name, int page_sz);
  87. ~store_trans();
  88. void init(rep_policy*);
  89. void quit();
  90. void set_max_pages(int max_pgs) {
  91. max_pages = max_pgs;
  92. };
  93. friend class page_storage;
  94. };
  95. /******************************************************/
  96. // cached page storage. Implemented on Unix file class.
  97. /******************************************************/
  98. #ifdef C_API
  99. #define f_global_pcache (*f_global_pcache_ptr)
  100. #endif
  101. class page_storage : public abs_storage
  102. {
  103. protected:
  104. store_trans trans_info;
  105. int page_sz ; // page size
  106. static int dv_sz ;
  107. static int abs_off ;
  108. #ifndef C_API
  109. static page_cache_global_part f_global_pcache;
  110. #else
  111. static page_cache_global_part* f_global_pcache_ptr;
  112. #endif
  113. page_cache_local_part f_local_pcache;
  114. int total_pages;
  115. // byte order
  116. int v_server_order;
  117. int v_db_order;
  118. buffer* v_buf; // aux. buf.
  119. int pagings ;
  120. int total_page_access;
  121. protected:
  122. Boolean seek_loc_negative(mmdb_pos_t& loc, int smd);
  123. Boolean seek_loc_positive(mmdb_pos_t& loc, int smd);
  124. public:
  125. page_storage(char* path, char* name,
  126. unixf_storage* store,
  127. int page_sz = PAGSIZ,
  128. int num_cached_pages = NUM_PAGES,
  129. mmdb_byte_order_t db_order_when_create_store = mmdb_big_endian
  130. );
  131. virtual ~page_storage();
  132. void remove(); // remove all pages in the store
  133. void sync();
  134. void sync(int pagenum);
  135. void sync(page*);
  136. void begin_trans();
  137. void commit_trans();
  138. void roll_back();
  139. void save_to_log(page* page_ptr);
  140. // get server and db order
  141. int server_order() { return v_server_order; } ;
  142. int db_order() { return v_db_order; };
  143. // i/o functions
  144. int readString (mmdb_pos_t loc, char* base, int len, int str_offset = 0);
  145. int get_str_ptr(mmdb_pos_t loc, char*&, int& len) ;
  146. int updateString(mmdb_pos_t loc, const char* base, int len, int string_ofst = 0, Boolean flush = false);
  147. int deleteString (mmdb_pos_t loc, Boolean flush = false);
  148. int insertString(mmdb_pos_t& loc, const char* base, int len, Boolean flush = false);
  149. int allocString (mmdb_pos_t& loc, int len, char*&, int mode = 0);
  150. int appendString(mmdb_pos_t loc, const char*, int len, Boolean flush_opt = false);
  151. int set_page_dirty(mmdb_pos_t loc);
  152. // iteration functions
  153. typedef enum access { READ, WRITE } access_t;
  154. int first() const; // first page's index in the store
  155. page* operator()(int page_num, enum access intent) ; //get the page
  156. void next(int&) const; // next page's index.
  157. // format the store to contain extra empty 'pages' pages
  158. int add_page_frames(int pages);
  159. // get locs of the pieces that a long string is broken into
  160. // The array should be deleted after use.
  161. int get_str_locs(mmdb_pos_t str_loc, str_index_record_tPtr*& locs, int& vector_leng);
  162. // seek loc to (loc +/- 1) position
  163. Boolean seek_loc(mmdb_pos_t& loc, const direction = positive, int = spointer_t::FIRST_RECD );
  164. mmdb_pos_t first_loc(); // return first loc in the store
  165. mmdb_pos_t last_loc(); // return last loc in the store
  166. // store status query functions
  167. int page_size() { return page_sz; };
  168. //
  169. void set_page_size(int pgsz) { page_sz = pgsz; };
  170. // how many pages in total in the store
  171. int pages() const { return total_pages; };
  172. // paging counting function
  173. void reset_paging_count();
  174. int paging_count() const;
  175. Boolean io_mode(int mode) ;
  176. // return an aux. buf.
  177. buffer& aux_buf();
  178. // printing functions
  179. virtual io_status asciiOut(ostream&) ;
  180. friend void close_file(const void*);
  181. friend void remove_from_global_cache(const void*);
  182. friend class storage_mgr_t;
  183. friend class handler;
  184. friend class page_cache_local_part;
  185. friend class page_cache_global_part;
  186. #ifdef C_API
  187. friend void initialize_MMDB();
  188. friend void quit_MMDB();
  189. #endif
  190. };
  191. typedef page_storage* page_storagePtr;
  192. #endif