2
0

root.C 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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.cc /main/5 1996/07/18 14:45:50 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. #include "object/root.h"
  50. #include "api/transaction.h"
  51. persistent_info::persistent_info(abs_storage* s, c_code_t c,
  52. mmdb_pos_t p, Boolean per, Boolean d)
  53. {
  54. cdr = false;
  55. storage = s;
  56. class_code = c;
  57. position = p;
  58. persistent = per;
  59. old_object = d;
  60. }
  61. persistent_info transient_info;
  62. root::root(c_code_t c_id) : f_oid(c_id, 0)
  63. {
  64. init_persistent_info();
  65. }
  66. root::root(const oid_t& x ) : f_oid(x)
  67. {
  68. init_persistent_info();
  69. }
  70. root::root(const root& x) : f_oid(x.f_oid), status(x.status)
  71. {
  72. init_persistent_info();
  73. }
  74. void root::init_persistent_info(persistent_info* pinfo)
  75. {
  76. /*
  77. MESSAGE(cerr, "STATUS before set");
  78. debug(cerr, int(get_mode(PERSISTENT)));
  79. debug(cerr, int(get_mode(BASE_DATA_INITED)));
  80. debug(cerr, int(storage_ptr));
  81. */
  82. status.ok = TOBIT(true);
  83. status.ref_count = 0;
  84. storage_ptr = pinfo -> storage;
  85. set_mode(CDR, pinfo -> cdr);
  86. set_mode(PERSISTENT, pinfo -> persistent);
  87. set_mode(SWAP_ALLOWED, true);
  88. switch ( pinfo -> persistent ) {
  89. case true: // disk object case
  90. f_oid.v_i_code = pinfo -> position;
  91. set_mode(OLD_OBJECT, pinfo -> old_object);
  92. break;
  93. case false: // vm object case
  94. f_oid.v_i_code = 0;
  95. set_mode(OLD_OBJECT, false);
  96. break;
  97. }
  98. }
  99. root::~root()
  100. {
  101. }
  102. void root::set_c_code(c_code_t x)
  103. {
  104. f_oid.v_c_code = x;
  105. }
  106. void root::set_mode(obj_mode_t mode, Boolean v)
  107. {
  108. switch ( mode ) {
  109. case HEALTH:
  110. status.ok = TOBIT(v);
  111. break;
  112. case PERSISTENT:
  113. status.persistent = TOBIT(v);
  114. break;
  115. case UPDATE:
  116. if ( v == true && g_transac && storage_ptr ) {
  117. g_transac -> book(f_oid, storage_ptr);
  118. }
  119. status.update= TOBIT(v);
  120. break;
  121. case OLD_OBJECT:
  122. status.old_object= TOBIT(v);
  123. break;
  124. case CDR:
  125. status.cdr= TOBIT(v);
  126. break;
  127. case SWAP_ALLOWED:
  128. status.swap = TOBIT(v);
  129. break;
  130. }
  131. }
  132. Boolean root::get_mode(obj_mode_t mode) const
  133. {
  134. Boolean ok = false;
  135. switch ( mode ) {
  136. case HEALTH:
  137. ok = TOBOOLEAN(status.ok);
  138. break;
  139. case PERSISTENT:
  140. ok = TOBOOLEAN(status.persistent);
  141. break;
  142. case UPDATE:
  143. ok = TOBOOLEAN(status.update);
  144. break;
  145. case OLD_OBJECT:
  146. ok = TOBOOLEAN(status.old_object);
  147. break;
  148. case CDR:
  149. ok = TOBOOLEAN(status.cdr);
  150. break;
  151. case SWAP_ALLOWED:
  152. ok = TOBOOLEAN(status.swap);
  153. break;
  154. }
  155. return ok;
  156. }
  157. void root::reset_ref_count()
  158. {
  159. status.ref_count = 0;
  160. }
  161. void root::set_ref_count(int delta)
  162. {
  163. status.ref_count += delta;
  164. }
  165. int root::get_ref_count()
  166. {
  167. return status.ref_count;
  168. }
  169. Boolean root::OK() const
  170. {
  171. return get_mode(HEALTH);
  172. }
  173. const oid_t& root::my_oid() const
  174. {
  175. return f_oid;
  176. }
  177. io_status root::asciiOut(ostream& out)
  178. {
  179. return f_oid.asciiOut(out);
  180. }
  181. ostream& operator<<(ostream& out, const root& rt)
  182. {
  183. (*(root*)&rt).asciiOut(out);
  184. return out;
  185. }
  186. io_status root::asciiIn(istream& in)
  187. {
  188. return f_oid.asciiIn(in);
  189. }
  190. ostream& root::memory_layout(root* rt, ostream& out)
  191. {
  192. MESSAGE(cerr, "In memory_layout");
  193. debug(cerr, long(rt));
  194. debug(cerr, (int)sizeof(*rt));
  195. long* p = (long*)rt;
  196. int ptrs = sizeof(*rt)/sizeof(long);
  197. for ( int i=0; i<ptrs; i++ )
  198. out << long(p[i]) << " ";
  199. out << "\n";
  200. return out;
  201. }
  202. void* root::heap_alloc( size_t sz )
  203. {
  204. return (void*) new char[sz];
  205. }
  206. int root::cdr_sizeof()
  207. {
  208. return sizeof(char);
  209. }
  210. io_status root::cdrOut(buffer& buf)
  211. {
  212. unsigned int status_rep = 0;
  213. lsb_putbits(status_rep, 3, 1, status.cdr);
  214. lsb_putbits(status_rep, 2, 1, status.ok);
  215. lsb_putbits(status_rep, 1, 1, status.persistent);
  216. lsb_putbits(status_rep, 0, 1, status.update);
  217. buf.put((char)status_rep);
  218. return done;
  219. }
  220. io_status root::cdrIn(buffer& buf)
  221. {
  222. char char_status_rep = 0;
  223. buf.get(char_status_rep);
  224. unsigned int status_rep = char_status_rep;
  225. status.cdr = lsb_getbits((unsigned)status_rep, 3, 1);
  226. status.ok = lsb_getbits((unsigned)status_rep, 2, 1);
  227. status.persistent = lsb_getbits((unsigned)status_rep, 1, 1);
  228. status.update = lsb_getbits((unsigned)status_rep, 0, 1);
  229. return done;
  230. }
  231. MMDB_BODIES(root)
  232. #ifdef C_API
  233. NEW_AND_DELETE_BODIES_SIMPLE(root)
  234. #endif