00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- 00002 this file is part of rcssserver3D 00003 Fri May 9 2003 00004 Copyright (C) 2002,2003 Koblenz University 00005 Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group 00006 $Id: zeitgeist.cpp,v 1.8 2004/05/05 14:09:46 fruit Exp $ 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; version 2 of the License. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 */ 00021 #include "zeitgeist.h" 00022 #include <iostream> 00023 #include <sstream> 00024 00025 using namespace std; 00026 using namespace zeitgeist; 00027 00028 Zeitgeist::Zeitgeist(string dotName) 00029 { 00030 ConstructCore(); 00031 RunInitScript(dotName); 00032 } 00033 00034 Zeitgeist::Zeitgeist(string dotName, string relPathPrefix) 00035 { 00036 ConstructCore(); 00037 00038 if (mCore->GetScriptServer() == 0) 00039 { 00040 return; 00041 } 00042 00043 mCore->GetScriptServer()->SetInitRelPathPrefix(relPathPrefix); 00044 RunInitScript(dotName); 00045 } 00046 00047 Zeitgeist::~Zeitgeist() 00048 { 00049 // this Zeitgeist object owns the only shared_ptr to the 00050 // core. Class objects only own weak_ptrs to the core. Destructing 00051 // the core implicitly after this destructor finishes, invalidates 00052 // our shared_ptr prior to the call to Core::~Core() and all 00053 // instances are left without a valid core reference on shutdown 00054 // (calls to OnUnlink). Therefore we destruct the core and the hierarchy explicitly 00055 // with the mCore reference intact. 00056 00057 mCore->Desctruct(); 00058 } 00059 00060 void Zeitgeist::ConstructCore() 00061 { 00062 mCore = boost::shared_ptr<Core>(new Core()); 00063 mCore->Construct(mCore); 00064 } 00065 00066 void Zeitgeist::RunInitScript(string dotName) 00067 { 00068 if (mCore->GetScriptServer() == 0) 00069 { 00070 return; 00071 } 00072 00073 // setup the dot directory in the script server 00074 mCore->GetScriptServer()->SetDotName(dotName); 00075 00076 // run the zeitgeist init script 00077 mCore->GetScriptServer()->RunInitScript 00078 ( 00079 "zeitgeist.rb", 00080 "lib/zeitgeist", 00081 ScriptServer::IS_COMMON 00082 ); 00083 } 00084 00085 00086 boost::shared_ptr<CoreContext> Zeitgeist::CreateContext() 00087 { 00088 return mCore->CreateContext(); 00089 } 00090 00091 boost::shared_ptr<Core>& Zeitgeist::GetCore() 00092 { 00093 return mCore; 00094 }