Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/corelibs/vos/metaobject.cc

Go to the documentation of this file.
00001 /*
00002     This file is part of the Virtual Object System of
00003     the Interreality project (http://interreality.org).
00004 
00005     Copyright (C) 2001-2003 Peter Amstutz
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library 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 GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 
00021     Peter Amstutz <tetron@interreality.org>
00022 */
00023 
00024 #include "metaobject.hh"
00025 #include "log.hh"
00026 #include "message.hh"
00027 
00028 using namespace VOS;
00029 
00030 /** @file
00031    Implements MetaObject.
00032  */
00033 
00034 MetaObject::MetaObject(MetaObject* superobj)
00035     : superobject(superobj)
00036 {
00037     if(superobject != 0) superobject->addObjectExtension(this);
00038 }
00039 
00040 MetaObject::~MetaObject()
00041 {
00042     if(typehandlers.size() > 0) {
00043         for(int i = (int)typehandlers.size() - 1; i >=0; i--) {
00044             typehandlers.erase(typehandlers.begin()+i);
00045             delete typehandlers[i];
00046         }
00047     }
00048 }
00049 
00050 void MetaObject::addObjectExtension(MetaObject* moe)
00051 {
00052     moe->superobject=this;
00053     typehandlers.push_back(moe);
00054 }
00055 
00056 MetaObject* MetaObject::getSuperObject()
00057 {
00058     return superobject;
00059 }
00060 
00061 MetaObject* MetaObject::getTopObject()
00062 {
00063     if(superobject) return superobject->getTopObject();
00064     else return this;
00065 }
00066 
00067 const deque<MetaObject*>& MetaObject::getTypeHandlers()
00068 {
00069     return typehandlers;
00070 }
00071 
00072 void MetaObject::initializeSecurity(Vobject& requester)
00073 {
00074 }
00075 
00076 const string& MetaObject::getName()
00077 {
00078     return superobject->getName();
00079 }
00080 
00081 Site& MetaObject::getSite()
00082 {
00083     return superobject->getSite();
00084 }
00085 
00086 const URL& MetaObject::getURL()
00087 {
00088     return superobject->getURL();
00089 }
00090 
00091 bool MetaObject::isLocal()
00092 {
00093     return superobject->isLocal();
00094 }
00095 
00096 bool MetaObject::isRemote()
00097 {
00098     return superobject->isRemote();
00099 }
00100 
00101 const set<string>& MetaObject::getTypes() throw (AccessControlError, RemoteError)
00102 {
00103     return superobject->getTypes();
00104 }
00105 
00106 const set<Vobject::ParentChildRelation*, Vobject::ParentChildRelation::Cmp>& MetaObject::getParents()
00107     throw (AccessControlError, RemoteError)
00108 {
00109     return superobject->getParents();
00110 }
00111 
00112 const deque<Vobject::ParentChildRelation*>& MetaObject::getChildren()
00113         throw (AccessControlError, RemoteError)
00114 {
00115     return superobject->getChildren();
00116 }
00117 
00118 void MetaObject::sendMessage(Message* m)
00119 {
00120     LOG("sendMessage", 4, "metaobject saw " << m->getNonce());
00121     touchedNonces.insert(m->getNonce());
00122     if(superobject != 0 && !superobject->touchedNonces.count(m->getNonce())) {
00123         superobject->sendMessage(m);
00124     }
00125     for(deque<MetaObject*>::iterator i=typehandlers.begin();
00126         i != typehandlers.end();
00127         i++) {
00128         if(!(*i)->touchedNonces.count(m->getNonce())) {
00129             LOG("sendMessage", 4, getURL().getString() << " sending to type handler " << (*i)->getType());
00130             (*i)->sendMessage(m);
00131         }
00132     }
00133     touchedNonces.erase(m->getNonce());
00134 }
00135 
00136 void MetaObject::sendMessage(MessageBlock* m)
00137 {
00138     superobject->sendMessage(m);
00139 }
00140 
00141 Message* MetaObject::receiveMessage() throw (MessageQueueEmptyError)
00142 {
00143     // pass reference through
00144     return superobject->receiveMessage();
00145 }
00146 
00147 bool MetaObject::hasMessageAvailable()
00148 {
00149     return superobject->hasMessageAvailable();
00150 }
00151 
00152 void MetaObject::sendUpdateMessage(Message* m)
00153 {
00154     LOG("sendUpdateMessage", 4, getName() << " metaobject saw " << m->getNonce() << " (there are "
00155         << (unsigned int)typehandlers.size() << " handlers)");
00156     touchedNonces.insert(m->getNonce());
00157     if(superobject != 0 && !superobject->touchedNonces.count(m->getNonce())) {
00158         superobject->sendUpdateMessage(m);
00159     }
00160     for(deque<MetaObject*>::iterator i=typehandlers.begin();
00161         i != typehandlers.end();
00162         i++) {
00163         if(!(*i)->touchedNonces.count(m->getNonce())) {
00164             (*i)->sendUpdateMessage(m);
00165         }
00166     }
00167     touchedNonces.erase(m->getNonce());
00168 }
00169 
00170 Message* MetaObject::receiveUpdateMessage() throw (MessageQueueEmptyError)
00171 {
00172     // pass reference through
00173     return superobject->receiveUpdateMessage();
00174 }
00175 
00176 bool MetaObject::hasUpdateMessageAvailable()
00177 {
00178     return superobject->hasUpdateMessageAvailable();
00179 }
00180 
00181 Vobject& MetaObject::findObject(const string& path)  throw (NoSuchSiteError, NoSuchObjectError,
00182                                                            URL::BadURLError, AccessControlError, RemoteError)
00183 {
00184     return superobject->findObject(path);
00185 }
00186 
00187 Vobject::ParentChildRelation& MetaObject::findChild(const string& path)
00188     throw (NoSuchObjectError, AccessControlError, RemoteError)
00189 {
00190     return superobject->findChild(path);
00191 }
00192 
00193 Vobject::ParentChildRelation& MetaObject::findParent(Vobject& parent)
00194     throw (NoSuchObjectError, AccessControlError, RemoteError)
00195 {
00196     return superobject->findParent(parent);
00197 }
00198 
00199 void MetaObject::setChild(int position, const string& contextual_name, Vobject* child)
00200     throw (AccessControlError, RemoteError)
00201 {
00202     return superobject->setChild(position, contextual_name, child);
00203 }
00204 
00205 void MetaObject::insertChild(int position, const string& contextual_name, Vobject* child)
00206     throw (AccessControlError, RemoteError)
00207 {
00208     return superobject->insertChild(position, contextual_name, child);
00209 }
00210 
00211 void MetaObject::removeChild(int position)
00212     throw (AccessControlError, RemoteError)
00213 {
00214     return superobject->removeChild(position);
00215 }
00216 
00217 const string MetaObject::getType()
00218 {
00219     return string("metaobject");
00220 }
00221 
00222 void MetaObject::addTypeListener(TypeChangeListener* tl, bool refresh)
00223 {
00224     superobject->addTypeListener(tl, refresh);
00225 }
00226 
00227 void MetaObject::addParentListener(ParentChangeListener* pl, bool refresh)
00228 {
00229     superobject->addParentListener(pl, refresh);
00230 }
00231 
00232 void MetaObject::addChildListener(ChildChangeListener* cl, bool refresh)
00233 {
00234     superobject->addChildListener(cl, refresh);
00235 }
00236 
00237 void MetaObject::removeTypeListener(TypeChangeListener* tl)
00238 {
00239     superobject->removeTypeListener(tl);
00240 }
00241 
00242 void MetaObject::removeParentListener(ParentChangeListener* pl)
00243 {
00244     superobject->removeParentListener(pl);
00245 }
00246 
00247 void MetaObject::removeChildListener(ChildChangeListener* cl)
00248 {
00249     superobject->removeChildListener(cl);
00250 }
00251 
00252 void MetaObject::addType(const string& s)
00253 {
00254     superobject->addType(s);
00255 }
00256 
00257 void MetaObject::acquire() {
00258     superobject->acquire();
00259 }
00260 
00261 void MetaObject::release() {
00262     superobject->release();
00263 }
00264 
00265 int MetaObject::getCount() {
00266     return superobject->getCount();
00267 }
00268 
00269 void MetaObject::doExcise()
00270 {
00271     RefCounted::excise();
00272 }
00273 
00274 void MetaObject::excise()
00275 {
00276     if(superobject) {
00277         superobject->excise();
00278     } else {
00279         RefCounted::excise();
00280 
00281         if(typehandlers.size() > 0) {
00282             for(int i = (int)typehandlers.size() - 1; i >=0; i--) {
00283                 typehandlers[i]->doExcise();
00284             }
00285         }
00286     }
00287 }
00288 
00289 void MetaObject::saveState(MessageBlock& output, set<string>& types, bool portable)
00290 {
00291     superobject->saveState(output, types, portable);
00292 }
00293 
00294 void MetaObject::doSaveState(MessageBlock& output, set<string>& types, bool portable)
00295 {
00296     LOG("metaobject", 4, "doSaveState called for " << getURL().getString() << " getType says " << getType());
00297 
00298     for(deque<MetaObject*>::iterator i=typehandlers.begin();
00299         i != typehandlers.end();
00300         i++)
00301     {
00302         (*i)->doSaveState(output, types, portable);
00303     }
00304 }
00305 
00306 void MetaObject::initialize() {
00307     for(deque<MetaObject*>::const_iterator i = typehandlers.begin();
00308         i != typehandlers.end(); i++)
00309     {
00310         (*i)->initialize();
00311     }
00312 }
00313 
00314 void MetaObject::addFlag(const string& flag)
00315 {
00316     superobject->addFlag(flag);
00317 }
00318 
00319 void MetaObject::removeFlag(const string& flag)
00320 {
00321     superobject->removeFlag(flag);
00322 }
00323 
00324 bool MetaObject::checkFlag(const string& flag)
00325 {
00326     return superobject->checkFlag(flag);
00327 }
00328 

Generated on Tue Aug 12 03:55:40 2003 for Interreality Project - VOS by doxygen 1.3.2