mark.C 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 libraries 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. #include "oliasdb/mark.h"
  50. umark::umark() : mmdb_tuple(2, USER_MARK_CODE), mark_set_hd_ptr(NULL)
  51. {
  52. }
  53. MMDB_BODIES(umark)
  54. mark_smart_ptr::
  55. mark_smart_ptr(mark_base* uptr, const char* node_locator) :
  56. mbase(uptr),
  57. v_loct_hd(0), v_mark_hd(0)
  58. {
  59. #ifdef INTERCEPT_MARK_CALLS
  60. MESSAGE(cerr, "mark_smart_ptr::cstr (1)");
  61. debug(cerr, uptr -> get_base_name());
  62. debug(cerr, node_locator);
  63. #endif
  64. mark_set_hd_ptr = uptr->mark_set_hd;
  65. mtry {
  66. mbase -> trans().begin();
  67. abs_storage* marks_store = mark_set_hd_ptr -> its_store();
  68. /////////////////////
  69. // init tuple part
  70. /////////////////////
  71. mmdb_tuple_handler* x = (mmdb_tuple_handler*)
  72. (new handler(USER_MARK_CODE, marks_store));
  73. v_loct_hd =
  74. new pstring_handler(node_locator, strlen(node_locator), marks_store);
  75. //(v_loct_hd->operator->())->asciiOut(cerr);
  76. v_mark_hd =
  77. new pstring_handler("", 0, marks_store);
  78. /*
  79. debug(cerr, v_loct_hd -> its_oid());
  80. debug(cerr, *v_loct_hd);
  81. debug(cerr, int(v_loct_hd));
  82. debug(cerr, v_mark_hd -> its_oid());
  83. debug(cerr, *v_mark_hd);
  84. debug(cerr, int(v_mark_hd));
  85. */
  86. (*x) -> pinned_insert(BASE_COMPONENT_INDEX, v_loct_hd -> its_oid());
  87. (*x) -> pinned_insert(BASE_COMPONENT_INDEX+1, v_mark_hd -> its_oid());
  88. x -> commit();
  89. /////////////////////
  90. // init smart_ptr
  91. /////////////////////
  92. smart_ptr::_init(x->its_oid(), marks_store);
  93. ////////////////////////
  94. // insert into mark set
  95. ////////////////////////
  96. v_loct_hd -> commit(); // commit it so that the locator
  97. // can be seen inside insert_object().
  98. (*mark_set_hd_ptr) -> insert_object( *x );
  99. mark_set_hd_ptr -> commit();
  100. //debug(cerr, x -> its_oid());
  101. delete x;
  102. mbase -> trans().end();
  103. }
  104. mcatch (beginTransException&, e)
  105. {
  106. smart_ptr::_init(ground, 0); // mark the mark obsolete
  107. rethrow;
  108. }
  109. mcatch (commitTransException&, e)
  110. {
  111. smart_ptr::_init(ground, 0); // mark the mark obsolete
  112. rethrow;
  113. }
  114. mcatch (mmdbException&, e)
  115. {
  116. smart_ptr::_init(ground, 0); // mark the mark obsolete
  117. mbase -> trans().rollback();
  118. rethrow;
  119. }
  120. end_try;
  121. }
  122. mark_smart_ptr::
  123. mark_smart_ptr(mark_base* uptr, const oid_t& mark_id) :
  124. smart_ptr(uptr->mark_set_hd->its_store(), mark_id),
  125. mbase(uptr), mark_set_hd_ptr(uptr -> mark_set_hd)
  126. {
  127. #ifdef INTERCEPT_MARK_CALLS
  128. MESSAGE(cerr, "mark_smart_ptr::cstr (2)");
  129. debug(cerr, uptr -> get_base_name());
  130. debug(cerr, mark_id);
  131. #endif
  132. mtry
  133. {
  134. v_loct_hd = (pstring_handler*)
  135. get_handler(BASE_COMPONENT_INDEX, STRING_CODE);
  136. v_mark_hd = (pstring_handler*)
  137. get_handler(BASE_COMPONENT_INDEX+1, STRING_CODE);
  138. }
  139. mcatch (mmdbException&, e)
  140. {
  141. smart_ptr::_init(ground, 0); // mark the mark obsolete
  142. rethrow;
  143. }
  144. end_try;
  145. }
  146. mark_smart_ptr::~mark_smart_ptr()
  147. {
  148. delete v_loct_hd;
  149. delete v_mark_hd;
  150. }
  151. void mark_smart_ptr::update_usermark(const pstring& new_mark)
  152. {
  153. update_usermark(((pstring&)new_mark).get(), ((pstring&)new_mark).size());
  154. }
  155. void mark_smart_ptr::update_usermark(const char* new_mark_str,
  156. int new_mark_str_sz)
  157. {
  158. mtry {
  159. mbase -> trans().begin();
  160. (*v_mark_hd) -> update(new_mark_str, new_mark_str_sz);
  161. v_mark_hd -> commit();
  162. mbase -> trans().end();
  163. }
  164. mcatch (beginTransException&, e)
  165. {
  166. rethrow;
  167. }
  168. mcatch (commitTransException&, e)
  169. {
  170. rethrow;
  171. }
  172. mcatch (mmdbException&, e)
  173. {
  174. mbase -> trans().rollback();
  175. rethrow;
  176. }
  177. end_try;
  178. }
  179. void mark_smart_ptr::remove_from_db()
  180. {
  181. mtry {
  182. mbase -> trans().begin();
  183. (*mark_set_hd_ptr) -> remove_component(its_oid());
  184. mark_set_hd_ptr -> commit();
  185. mbase -> trans().end();
  186. }
  187. mcatch (beginTransException&, e)
  188. {
  189. rethrow;
  190. }
  191. mcatch (commitTransException&, e)
  192. {
  193. rethrow;
  194. }
  195. mcatch (mmdbException&, e)
  196. {
  197. mbase -> trans().rollback();
  198. rethrow;
  199. }
  200. end_try;
  201. }
  202. const char* mark_smart_ptr::node_locator()
  203. {
  204. return (*v_loct_hd) -> get();
  205. }
  206. pstring* mark_smart_ptr::mark_value()
  207. {
  208. /*
  209. pstring *z = v_mark_hd -> operator->();
  210. debug(cerr, z -> size());
  211. */
  212. return v_mark_hd -> operator->();
  213. }
  214. ostream& operator <<(ostream& out, mark_smart_ptr& umark)
  215. {
  216. const char* x = umark.node_locator();
  217. if ( x )
  218. out << "node_locator: " << x << "\n";
  219. out << "mark_value: ";
  220. umark.mark_value() -> asciiOut(out);
  221. // out << "\n";
  222. return out;
  223. }