handler.C 4.7 KB

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