root.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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: root.h /main/6 1996/07/18 14:46:10 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 _root_h
  50. #define _root_h 1
  51. #include "utility/funcs.h"
  52. #include "utility/buffer.h"
  53. #include "storage/rep_cell.h"
  54. #include "storage/page.h"
  55. #include "object/oid_t.h"
  56. #include "object/c_codes.h"
  57. #include "object/new_delete.h"
  58. //#include "Exceptions.hh"
  59. class abs_storage;
  60. /************************************/
  61. // constants used to name status bits
  62. /************************************/
  63. enum obj_mode_t { HEALTH,
  64. SWAP_ALLOWED,
  65. PERSISTENT,
  66. UPDATE,
  67. OLD_OBJECT,
  68. CDR
  69. };
  70. /************************************/
  71. // structure recording various status
  72. // of an object
  73. /************************************/
  74. struct status_t
  75. {
  76. unsigned reserved: 10; //
  77. unsigned swap: 1; // swapped out allowed? (true, or false)
  78. unsigned cdr: 1; // compacted disk rep? (true, or false)
  79. unsigned ok: 1; // in good shape ? (true, or false)
  80. unsigned persistent: 1; // persistent ? (true, or false)
  81. unsigned update: 1; // updated ? (true, or false)
  82. unsigned old_object :1; // old object? (true, or false)
  83. unsigned ref_count: 16; // reference count [0, 2^16 - 1];
  84. };
  85. /************************************/
  86. // structure recording io information
  87. /************************************/
  88. class persistent_info
  89. {
  90. public:
  91. persistent_info(abs_storage* s = 0, c_code_t = 0,
  92. mmdb_pos_t = 0, Boolean =0, Boolean = 0);
  93. ~persistent_info() {};
  94. Boolean cdr;
  95. abs_storage* storage;
  96. c_code_t class_code;
  97. mmdb_pos_t position;
  98. Boolean persistent; // true -> on persisent store
  99. // false -> on memory
  100. Boolean old_object; // true -> object has been created on store
  101. };
  102. extern persistent_info transient_info;
  103. /*************************************/
  104. // The root class
  105. /*************************************/
  106. #define THIS 0 // const to name this object
  107. #define BASE_COMPONENT_INDEX 1 // const to name the 1st component
  108. class root : public Destructable, public rep_cell
  109. {
  110. protected:
  111. /***************************/
  112. // instance-wise data
  113. /***************************/
  114. oid_t f_oid;
  115. status_t status;
  116. abs_storage* storage_ptr;
  117. virtual void init_persistent_info(persistent_info* = &transient_info);
  118. void set_c_code(c_code_t); // set class code
  119. /***************************/
  120. // static data and function
  121. /***************************/
  122. static void* heap_alloc( size_t sz );
  123. public:
  124. root(c_code_t c_id = ROOT_CODE);
  125. root(const oid_t& );
  126. root(const root&);
  127. virtual ~root() ;
  128. #ifdef C_API
  129. NEW_AND_DELETE_SIGNATURES(root);
  130. #endif
  131. MMDB_SIGNATURES(root);
  132. // status set and get functions
  133. virtual void set_mode(obj_mode_t, Boolean);
  134. Boolean get_mode(obj_mode_t) const;
  135. // reference count set and get functions
  136. void reset_ref_count();
  137. void set_ref_count(int delta);
  138. int get_ref_count();
  139. abs_storage* get_store() { return storage_ptr; };
  140. // status inquiry functions
  141. virtual Boolean OK() const ; // in good shape ?
  142. virtual ostream& memory_layout(root*, ostream& = cerr);
  143. /*
  144. // value comparison functions
  145. virtual Boolean value_EQ(root&, Boolean safe = true) const ;
  146. virtual Boolean value_LS(root&, Boolean safe = true) const ;
  147. */
  148. // export functions
  149. const oid_t& my_oid() const ; // get oid
  150. // ascii In and Out functions
  151. virtual io_status asciiOut(ostream&) ; // output (ASCII)
  152. virtual io_status asciiIn(istream&) ; // init from istream (ASCII)
  153. friend ostream& operator<<(ostream&, const root&) ;
  154. // compacted disk representation In and Out functions
  155. virtual int cdr_sizeof();
  156. virtual io_status cdrOut(buffer&);
  157. virtual io_status cdrIn(buffer&);
  158. virtual void commit() {}; // for commit all components
  159. friend class template_mgr_t;
  160. friend class service_mgr_t;
  161. friend class oid;
  162. #ifdef C_API
  163. friend void initialize_MMDB();
  164. friend void quit_MMDB();
  165. #endif
  166. };
  167. typedef root* rootPtr;
  168. #endif