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: pref.cc /main/4 1996/06/11 17:30:27 cde-hal $
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
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.
53 #include "oliasdb/pref.h"
57 pref_smart_ptr::pref_smart_ptr(pref_base* uptr,
59 pbase(uptr), pref_set_hd_ptr(uptr -> pref_set_hd),
60 v_name_hd(0), v_cnfg_hd(0)
63 abs_storage *pref_store = pref_set_hd_ptr -> its_store();
65 oid_list_handler* pref_list = (*pref_set_hd_ptr) ->
66 get_locs(managers::query_mgr -> form_pstring_handler(name),
71 if ( pref_list == 0 ) {
73 MESSAGE(cerr, "NEW RECORD");
75 pbase -> trans().begin();
78 new tuple_handler(oid_t(USER_CONFIG_CODE, 0), pref_store);
80 v_name_hd = new pstring_handler(name, strlen(name), pref_store);
81 v_cnfg_hd = new pstring_handler("", 0, pref_store);
83 (*w) -> pinned_insert(BASE_COMPONENT_INDEX, v_name_hd -> its_oid());
84 (*w) -> pinned_insert(BASE_COMPONENT_INDEX+1, v_cnfg_hd -> its_oid());
89 smart_ptr::_init(w->its_oid(), pref_store);
91 (*pref_set_hd_ptr) -> insert_object( *w );
93 pbase -> trans().end();
96 catch (mmdbException&, e)
98 smart_ptr::_init(ground, 0); // mark the pref obsolete
99 pbase -> trans().rollback();
106 MESSAGE(cerr, "OLD RECORD");
108 if ( (*pref_list) -> count() == 0 ) {
109 throw(stringException("zero prefs in the list"));
112 smart_ptr::_init((*pref_list) -> operator()(1), pref_store);
114 v_name_hd = (pstring_handler*)
115 get_handler(BASE_COMPONENT_INDEX, STRING_CODE);
116 v_cnfg_hd = (pstring_handler*)
117 get_handler(BASE_COMPONENT_INDEX+1, STRING_CODE);;
122 pref_smart_ptr::~pref_smart_ptr()
128 Boolean pref_smart_ptr::update_value(const pstring& new_uc)
130 return update_value(((pstring&)new_uc).get(), ((pstring&)new_uc).size());
133 Boolean pref_smart_ptr::update_value(const char* new_pref,
137 pbase -> trans().begin();
139 (*v_cnfg_hd) -> update(new_pref, new_pref_sz);
141 pbase -> trans().end();
144 catch (mmdbException&, e)
146 pbase -> trans().rollback();
155 Boolean pref_smart_ptr::remove_from_db()
158 pbase -> trans().begin();
160 (*pref_set_hd_ptr) -> remove_component(its_oid());
162 pbase -> trans().end();
165 catch (mmdbException&, e)
167 pbase -> trans().rollback();
176 char* pref_smart_ptr::name()
178 return (*v_name_hd) -> get();
181 pstring* pref_smart_ptr::pref_value()
183 return v_cnfg_hd -> operator->();