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