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: root.cc /main/5 1996/07/18 14:45:50 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 #include "object/root.h"
52 #include "api/transaction.h"
54 persistent_info::persistent_info(abs_storage* s, c_code_t c,
55 mmdb_pos_t p, Boolean per, Boolean d)
65 persistent_info transient_info;
67 root::root(c_code_t c_id) : f_oid(c_id, 0)
69 init_persistent_info();
72 root::root(const oid_t& x ) : f_oid(x)
74 init_persistent_info();
77 root::root(const root& x) : f_oid(x.f_oid), status(x.status)
79 init_persistent_info();
82 void root::init_persistent_info(persistent_info* pinfo)
85 MESSAGE(cerr, "STATUS before set");
86 debug(cerr, int(get_mode(PERSISTENT)));
87 debug(cerr, int(get_mode(BASE_DATA_INITED)));
88 debug(cerr, int(storage_ptr));
91 status.ok = TOBIT(true);
94 storage_ptr = pinfo -> storage;
95 set_mode(CDR, pinfo -> cdr);
96 set_mode(PERSISTENT, pinfo -> persistent);
97 set_mode(SWAP_ALLOWED, true);
99 switch ( pinfo -> persistent ) {
101 case true: // disk object case
102 f_oid.v_i_code = pinfo -> position;
103 set_mode(OLD_OBJECT, pinfo -> old_object);
107 case false: // vm object case
109 set_mode(OLD_OBJECT, false);
118 void root::set_c_code(c_code_t x)
123 void root::set_mode(obj_mode_t mode, Boolean v)
127 status.ok = TOBIT(v);
130 status.persistent = TOBIT(v);
134 if ( v == true && g_transac && storage_ptr ) {
135 g_transac -> book(f_oid, storage_ptr);
138 status.update= TOBIT(v);
141 status.old_object= TOBIT(v);
144 status.cdr= TOBIT(v);
147 status.swap = TOBIT(v);
152 Boolean root::get_mode(obj_mode_t mode) const
157 ok = TOBOOLEAN(status.ok);
160 ok = TOBOOLEAN(status.persistent);
163 ok = TOBOOLEAN(status.update);
166 ok = TOBOOLEAN(status.old_object);
169 ok = TOBOOLEAN(status.cdr);
172 ok = TOBOOLEAN(status.swap);
178 void root::reset_ref_count()
180 status.ref_count = 0;
183 void root::set_ref_count(int delta)
185 status.ref_count += delta;
188 int root::get_ref_count()
190 return status.ref_count;
193 Boolean root::OK() const
195 return get_mode(HEALTH);
198 const oid_t& root::my_oid() const
203 io_status root::asciiOut(ostream& out)
205 return f_oid.asciiOut(out);
208 ostream& operator<<(ostream& out, const root& rt)
210 (*(root*)&rt).asciiOut(out);
214 io_status root::asciiIn(istream& in)
216 return f_oid.asciiIn(in);
219 ostream& root::memory_layout(root* rt, ostream& out)
221 MESSAGE(cerr, "In memory_layout");
222 debug(cerr, long(rt));
223 debug(cerr, (int)sizeof(*rt));
226 int ptrs = sizeof(*rt)/sizeof(long);
228 for ( int i=0; i<ptrs; i++ )
229 out << long(p[i]) << " ";
236 void* root::heap_alloc( size_t sz )
238 return (void*) new char[sz];
242 int root::cdr_sizeof()
248 io_status root::cdrOut(buffer& buf)
250 unsigned int status_rep = 0;
252 lsb_putbits(status_rep, 3, 1, status.cdr);
253 lsb_putbits(status_rep, 2, 1, status.ok);
254 lsb_putbits(status_rep, 1, 1, status.persistent);
255 lsb_putbits(status_rep, 0, 1, status.update);
257 buf.put((char)status_rep);
262 io_status root::cdrIn(buffer& buf)
264 char char_status_rep = 0;
265 buf.get(char_status_rep);
267 unsigned int status_rep = char_status_rep;
269 status.cdr = lsb_getbits((unsigned)status_rep, 3, 1);
270 status.ok = lsb_getbits((unsigned)status_rep, 2, 1);
271 status.persistent = lsb_getbits((unsigned)status_rep, 1, 1);
272 status.update = lsb_getbits((unsigned)status_rep, 0, 1);
280 NEW_AND_DELETE_BODIES_SIMPLE(root)