00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "object.h"
00023 #include "class.h"
00024 #include "core.h"
00025 #include "leaf.h"
00026 #include <iostream>
00027 #include <boost/version.hpp>
00028
00029 using namespace boost;
00030 using namespace std;
00031 using namespace zeitgeist;
00032
00033 Object::Object()
00034 {
00035 }
00036
00037 Object::~Object()
00038 {
00039 if (mClass.get())
00040 {
00041 mClass->DetachInstance(GetSelf());
00042 }
00043 }
00044
00045 bool Object::Construct(const boost::shared_ptr<Object>& self, const boost::shared_ptr<Class>& creator)
00046 {
00047 mSelf = self;
00048 mClass = creator;
00049
00050
00051 return ConstructInternal();
00052 }
00053
00054 boost::shared_ptr<Class> Object::GetClass() const
00055 {
00056 if (mClass.get() == 0)
00057 {
00058 const Leaf* leaf = dynamic_cast<const Leaf*>(this);
00059
00060 if (leaf != 0)
00061 {
00062 if (leaf->GetFullPath() != "ClassClass")
00063 {
00064 std::cerr << "(Object) ERROR: failed to get Class object "
00065 << "for '" << leaf->GetName()
00066 << "' installed at '"
00067 << leaf->GetFullPath() << "'\n";
00068 }
00069 } else {
00070 std::cerr << "(Object) ERROR: failed to get Class object for unknown\n";
00071 }
00072 }
00073 return mClass;
00074 }
00075
00076 boost::weak_ptr<Object>& Object::GetSelf()
00077 {
00078 return mSelf;
00079 }
00080
00081 const boost::weak_ptr<Object>& Object::GetSelf() const
00082 {
00083 return mSelf;
00084 }
00085
00086 boost::shared_ptr<Core> Object::GetCore() const
00087 {
00088 assert(mClass.get() != NULL);
00089 boost::shared_ptr<Core> core = mClass->GetCore();
00090
00091 if (core.get() == 0)
00092 {
00093 std::cout << "(Object) ERROR: failed to get zeitgeist core ";
00094 const Leaf* leaf = dynamic_cast<const Leaf*>(this);
00095
00096 if (leaf != 0)
00097 {
00098 std::cout << "for '" << leaf->GetName()
00099 << std::cout << "' installed at '"
00100 << leaf->GetFullPath()
00101 << "'";
00102 }
00103
00104 std::cout << std::endl;
00105 }
00106
00107 return mClass->GetCore();
00108 }
00109
00110 void Object::Dump() const
00111 {
00112 cout << "Object: " << (void*) this;
00113 if (shared_ptr<Object> self = mSelf.lock())
00114 {
00115 cout << " " << (void*) self.get();
00116 } else {
00117 cout << " " << "(expired)";
00118 }
00119 cout << " - use count = " << mSelf.use_count() << endl;
00120 }
00121
00122 void Object::Invoke(const std::string &functionName, const ParameterList& parameter)
00123 {
00124 Class::TCmdProc cmd = mClass->GetCmdProc(functionName);
00125 if (cmd != NULL)
00126 {
00127 if (shared_ptr<Object> self = GetSelf().lock())
00128 {
00129 GCValue out = cmd(self.get(), parameter);
00130 }
00131 }
00132 }
00133
00134 const boost::shared_ptr<FileServer>& Object::GetFile() const
00135 {
00136 return GetCore()->GetFileServer();
00137 }
00138
00139 const boost::shared_ptr<LogServer>& Object::GetLog() const
00140 {
00141 return GetCore()->GetLogServer();
00142 }
00143
00144 const boost::shared_ptr<ScriptServer>& Object::GetScript() const
00145 {
00146 return GetCore()->GetScriptServer();
00147 }
00148
00149 bool Object::ConstructInternal()
00150 {
00151 return true;
00152 }