Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / object / handler.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: handler.cc /main/5 1996/07/18 14:41:25 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/handler.h"
52 #include "mgrs/managers.h"
53
54 //memory_pool handler::handler_space_pool;
55 extern memory_pool g_memory_pool;
56
57 handler::handler() : 
58 store(0), obj_id(ground), obj_ptr(0)
59 {
60 }
61
62 handler::handler(const oid_t& id, abs_storage* s) : 
63 store(s), obj_id(id), obj_ptr(0)
64 {
65 }
66
67 handler::handler(c_code_t cod, abs_storage* s) : 
68 store(s), obj_id(cod, 0), obj_ptr(0)
69 {
70    if ( s ) 
71       operator->(); // to init the object from the store
72 }
73
74 handler::handler(rootPtr ptr, abs_storage* s) : 
75 store(s), obj_id(ptr -> my_oid()), obj_ptr(ptr)
76 {
77 }
78
79 void handler::set(rootPtr ptr, abs_storage* s)
80 {
81    store = (abs_storage*)s;
82
83    if ( ptr )
84       obj_id.become(ptr -> my_oid());
85
86    obj_ptr = ptr;
87 }
88
89 handler::~handler()
90 {
91    if ( store ) {
92       managers::template_mgr -> quit_obj(store, obj_ptr);
93    } else
94       delete obj_ptr;
95
96 //   commit();
97 //   delete obj_ptr;
98 }
99
100 void handler::destroy()
101 {
102    if ( store )
103       managers::template_mgr -> destroy_obj(store, obj_ptr);
104    else
105       delete obj_ptr;
106 }
107
108 void handler::sync()
109 {
110    if ( store ) store -> sync();
111 }
112
113 void handler::commit()
114 {
115    if ( store ) {
116       if ( obj_ptr )
117          obj_ptr -> commit(); // save all its handler components
118       managers::template_mgr -> commit_obj(store, obj_ptr);
119    }
120 }
121
122 root* handler::operator ->()
123 {
124    if ( store ) {
125
126       if ( obj_ptr == 0 ) {
127
128 /*
129            (obj_ptr && obj_id.eq(obj_ptr -> my_oid()) == false )
130 MESSAGE(cerr, "handler::operator ->()");
131 debug(cerr, (void*)obj_ptr);
132 debug(cerr, obj_id);
133         if ( obj_ptr -> get_mode(SWAP_ALLOWED) == true )
134            //r_obj_cache.promote_object(store, obj_ptr);
135 */
136
137          //obj_ptr = r_obj_cache.init_object(store, obj_id);
138
139          if ( obj_id.icode() ) {
140            managers::template_mgr -> init_obj(store, obj_id.icode(), obj_ptr);
141          } else {
142            managers::template_mgr -> create_obj(store, obj_id.ccode(), obj_ptr);
143          }
144
145
146 ///////////////////////////////////////////////////////////////////
147 // update the handler side object id. Its class code may not
148 // be initialized as class code of a oid_t is not saved on the disk.
149 // We do not expect this check will degrade the performance as
150 // this init_object block is only called once for the operator->().
151 // Subsequent calls will bypass it as obj_ptr is not 0.
152 ///////////////////////////////////////////////////////////////////
153          obj_id.become(obj_ptr -> my_oid());
154
155       } 
156    }
157
158    if ( store && obj_ptr == 0 ) {
159        debug(cerr, long(store));
160        debug(cerr, its_oid());
161        throw(stringException("null obj ptr"));
162    };
163
164    return obj_ptr;
165 }
166
167
168 handler::operator root&()
169 {
170    return *(this -> operator->());
171 }
172
173 void* handler::operator new( size_t x )
174 {
175    //return (void*)g_memory_pool.alloc(x);
176
177    return ::operator new(x);
178 }
179
180 void handler::operator delete( void* ptr )
181 {
182    //g_memory_pool.free((char*)ptr);
183
184    ::operator delete(ptr);
185 }