Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / mark.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: mark.cc /main/6 1996/07/18 14:47:10 drk $
25  *
26  * Copyright (c) 1992 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
52 #include "oliasdb/mark.h"
53
54 umark::umark() : tuple(2, USER_MARK_CODE) 
55 {
56 }
57
58
59 MMDB_BODIES(umark)
60
61 mark_smart_ptr::
62 mark_smart_ptr(mark_base* uptr, const char* node_locator) :
63         mbase(uptr), 
64         v_loct_hd(0), v_mark_hd(0)
65 {
66 #ifdef INTERCEPT_MARK_CALLS
67 MESSAGE(cerr, "mark_smart_ptr::cstr (1)");
68 debug(cerr, uptr -> get_base_name());
69 debug(cerr, node_locator);
70 #endif
71
72    mark_set_hd_ptr = uptr->mark_set_hd;
73
74    try {
75       mbase -> trans().begin();
76    
77       abs_storage* marks_store = mark_set_hd_ptr -> its_store();
78
79    /////////////////////
80    // init tuple part
81    /////////////////////
82
83       tuple_handler* x = (tuple_handler*)
84         (new handler(USER_MARK_CODE, marks_store));
85
86    
87       v_loct_hd = 
88          new pstring_handler(node_locator, strlen(node_locator), marks_store);
89
90 //(v_loct_hd->operator->())->asciiOut(cerr);
91    
92       v_mark_hd = 
93          new pstring_handler("", 0, marks_store);
94 /*
95 debug(cerr, v_loct_hd -> its_oid());
96 debug(cerr, *v_loct_hd);
97 debug(cerr, int(v_loct_hd));
98 debug(cerr, v_mark_hd -> its_oid());
99 debug(cerr, *v_mark_hd);
100 debug(cerr, int(v_mark_hd));
101 */  
102
103       (*x) -> pinned_insert(BASE_COMPONENT_INDEX, v_loct_hd -> its_oid());
104       (*x) -> pinned_insert(BASE_COMPONENT_INDEX+1, v_mark_hd -> its_oid());
105       
106       x -> commit();
107    /////////////////////
108    // init smart_ptr
109    /////////////////////
110
111       smart_ptr::_init(x->its_oid(), marks_store);
112    
113    ////////////////////////
114    // insert into mark set
115    ////////////////////////
116       v_loct_hd -> commit(); // commit it so that the locator
117                              // can be seen inside insert_object(). 
118       (*mark_set_hd_ptr) -> insert_object( *x );
119
120       mark_set_hd_ptr -> commit();
121    
122    //debug(cerr, x -> its_oid());
123
124      delete x;
125    
126      mbase -> trans().end();
127    }
128
129    catch (beginTransException&, e)
130       {
131          smart_ptr::_init(ground, 0); // mark the mark obsolete
132          rethrow;
133       }
134    catch (commitTransException&, e)
135       {
136          smart_ptr::_init(ground, 0); // mark the mark obsolete
137          rethrow;
138       }
139    catch (mmdbException&, e)
140       {
141          smart_ptr::_init(ground, 0); // mark the mark obsolete
142          mbase -> trans().rollback();
143          rethrow;
144       }
145    end_try;
146 }
147
148 mark_smart_ptr::
149 mark_smart_ptr(mark_base* uptr, const oid_t& mark_id) :
150    smart_ptr(uptr->mark_set_hd->its_store(), mark_id), 
151    mbase(uptr), mark_set_hd_ptr(uptr -> mark_set_hd)
152 {
153 #ifdef INTERCEPT_MARK_CALLS
154 MESSAGE(cerr, "mark_smart_ptr::cstr (2)");
155 debug(cerr, uptr -> get_base_name());
156 debug(cerr, mark_id);
157 #endif
158
159    try 
160    {
161       v_loct_hd = (pstring_handler*)
162                get_handler(BASE_COMPONENT_INDEX, STRING_CODE);
163       v_mark_hd = (pstring_handler*)
164                get_handler(BASE_COMPONENT_INDEX+1, STRING_CODE);
165    }
166
167    catch (mmdbException&, e)
168       {
169          smart_ptr::_init(ground, 0); // mark the mark obsolete
170          rethrow;
171       }
172    end_try;
173
174 }
175
176 mark_smart_ptr::~mark_smart_ptr()
177 {
178    delete v_loct_hd;
179    delete v_mark_hd;
180 }
181
182 void mark_smart_ptr::update_usermark(const pstring& new_mark)
183 {
184    update_usermark(((pstring&)new_mark).get(), ((pstring&)new_mark).size());
185 }
186
187 void mark_smart_ptr::update_usermark(const char* new_mark_str,
188                               int new_mark_str_sz)
189 {
190    try {
191       mbase -> trans().begin();
192
193       (*v_mark_hd) -> update(new_mark_str, new_mark_str_sz);
194       v_mark_hd -> commit(); 
195
196       mbase -> trans().end();
197    }
198
199    catch (beginTransException&, e)
200       {
201          rethrow;
202       }
203    catch (commitTransException&, e)
204       {
205          rethrow;
206       }
207    catch (mmdbException&, e)
208       {
209          mbase -> trans().rollback();
210          rethrow;
211       }
212    end_try;
213 }
214
215 void mark_smart_ptr::remove_from_db()
216 {
217    try {
218       mbase -> trans().begin();
219
220       (*mark_set_hd_ptr) -> remove_component(its_oid()); 
221       mark_set_hd_ptr -> commit(); 
222
223       mbase -> trans().end();
224    }
225
226    catch (beginTransException&, e)
227       {
228          rethrow;
229       }
230    catch (commitTransException&, e)
231       {
232          rethrow;
233       }
234    catch (mmdbException&, e)
235       {
236          mbase -> trans().rollback();
237          rethrow;
238       }
239    end_try;
240 }
241
242 const char* mark_smart_ptr::node_locator()
243 {
244    return (*v_loct_hd) -> get();
245 }
246
247 pstring* mark_smart_ptr::mark_value()
248 {
249 /*
250 pstring *z  = v_mark_hd -> operator->();
251 debug(cerr, z -> size());
252 */
253
254    return v_mark_hd -> operator->();
255 }
256
257 ostream& operator <<(ostream& out, mark_smart_ptr& umark)
258 {
259    const char* x = umark.node_locator();
260    if ( x )
261       out << "node_locator: " <<  x << "\n";
262
263    out << "mark_value: ";
264
265    umark.mark_value() -> asciiOut(out);
266
267 //   out << "\n";
268
269    return out;
270 }