00001 // Dump.cpp,v 4.20 2005/10/28 16:14:52 ossama Exp 00002 00003 #include "ace/Dump.h" 00004 #include "ace/Guard_T.h" 00005 #include "ace/Thread_Mutex.h" 00006 #include "ace/Object_Manager.h" 00007 #include "ace/Log_Msg.h" 00008 00009 ACE_RCSID(ace, Dump, "Dump.cpp,v 4.20 2005/10/28 16:14:52 ossama Exp") 00010 00011 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00012 00013 // Implementations (very simple for now...) 00014 00015 ACE_Dumpable::~ACE_Dumpable (void) 00016 { 00017 ACE_TRACE ("ACE_Dumpable::~ACE_Dumpable"); 00018 } 00019 00020 ACE_Dumpable::ACE_Dumpable (const void *this_ptr) 00021 : this_ (this_ptr) 00022 { 00023 ACE_TRACE ("ACE_Dumpable::ACE_Dumpable"); 00024 } 00025 00026 ACE_Dumpable_Ptr::ACE_Dumpable_Ptr (const ACE_Dumpable *dumper) 00027 : dumper_ (dumper) 00028 { 00029 ACE_TRACE ("ACE_Dumpable_Ptr::ACE_Dumpable_Ptr"); 00030 } 00031 00032 const ACE_Dumpable * 00033 ACE_Dumpable_Ptr::operator->() const 00034 { 00035 ACE_TRACE ("ACE_Dumpable_Ptr::operator->"); 00036 return this->dumper_; 00037 } 00038 00039 void 00040 ACE_Dumpable_Ptr::operator= (const ACE_Dumpable *dumper) const 00041 { 00042 ACE_TRACE ("ACE_Dumpable_Ptr::operator="); 00043 if (this->dumper_ != dumper) 00044 { 00045 delete const_cast <ACE_Dumpable *> (this->dumper_); 00046 (const_cast<ACE_Dumpable_Ptr *> (this))->dumper_ = dumper; 00047 } 00048 } 00049 00050 ACE_ODB::ACE_ODB (void) 00051 // Let the Tuple default constructor initialize object_table_ 00052 : current_size_ (0) 00053 { 00054 ACE_TRACE ("ACE_ODB::ACE_ODB"); 00055 } 00056 00057 ACE_ODB * 00058 ACE_ODB::instance (void) 00059 { 00060 ACE_TRACE ("ACE_ODB::instance"); 00061 00062 if (ACE_ODB::instance_ == 0) 00063 { 00064 ACE_MT (ACE_Thread_Mutex *lock = 00065 ACE_Managed_Object<ACE_Thread_Mutex>::get_preallocated_object 00066 (ACE_Object_Manager::ACE_DUMP_LOCK); 00067 ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, *lock, 0)); 00068 00069 if (ACE_ODB::instance_ == 0) 00070 ACE_NEW_RETURN (ACE_ODB::instance_, 00071 ACE_ODB, 00072 0); 00073 } 00074 00075 return ACE_ODB::instance_; 00076 } 00077 00078 void 00079 ACE_ODB::dump_objects (void) 00080 { 00081 ACE_TRACE ("ACE_ODB::dump_objects"); 00082 for (int i = 0; i < this->current_size_; i++) 00083 { 00084 if (this->object_table_[i].this_ != 0) 00085 // Dump the state of the object. 00086 this->object_table_[i].dumper_->dump (); 00087 } 00088 } 00089 00090 // This method registers a new <dumper>. It detects 00091 // duplicates and simply overwrites them. 00092 00093 void 00094 ACE_ODB::register_object (const ACE_Dumpable *dumper) 00095 { 00096 ACE_TRACE ("ACE_ODB::register_object"); 00097 int i; 00098 int slot = 0; 00099 00100 for (i = 0; i < this->current_size_; i++) 00101 { 00102 if (this->object_table_[i].this_ == 0) 00103 slot = i; 00104 else if (this->object_table_[i].this_ == dumper->this_) 00105 { 00106 slot = i; 00107 break; 00108 } 00109 } 00110 00111 if (i == this->current_size_) 00112 { 00113 slot = this->current_size_++; 00114 ACE_ASSERT (this->current_size_ < ACE_ODB::MAX_TABLE_SIZE); 00115 } 00116 this->object_table_[slot].this_ = dumper->this_; 00117 this->object_table_[slot].dumper_ = dumper; 00118 } 00119 00120 void 00121 ACE_ODB::remove_object (const void *this_ptr) 00122 { 00123 ACE_TRACE ("ACE_ODB::remove_object"); 00124 int i; 00125 00126 for (i = 0; i < this->current_size_; i++) 00127 { 00128 if (this->object_table_[i].this_ == this_ptr) 00129 break; 00130 } 00131 00132 if (i < this->current_size_) 00133 { 00134 this->object_table_[i].this_ = 0; 00135 this->object_table_[i].dumper_ = 0; 00136 } 00137 } 00138 00139 ACE_ODB *ACE_ODB::instance_ = 0; 00140 00141 ACE_END_VERSIONED_NAMESPACE_DECL