00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "remotemetaobject.hh"
00025 #include "remotesite.hh"
00026 #include "message.hh"
00027
00028 using namespace VOS;
00029
00030
00031
00032
00033
00034 RemoteMetaObject::RemoteMetaObject(const string& name, RemoteSite* remotesite)
00035 : VobjectImplementation(name, remotesite, false),
00036 RemoteVobject(name, remotesite),
00037 MetaObject(0)
00038 {
00039 }
00040
00041 RemoteMetaObject::~RemoteMetaObject() {
00042 LOG("remotemetaobject", 4, "deleting " << getURL().getString());
00043 }
00044
00045 const string& RemoteMetaObject::getName()
00046 {
00047 if(superobject != 0) return superobject->getName();
00048 else return RemoteVobject::getName();
00049 }
00050
00051 Site& RemoteMetaObject::getSite()
00052 {
00053 if(superobject != 0) return superobject->getSite();
00054 else return RemoteVobject::getSite();
00055 }
00056
00057 const URL& RemoteMetaObject::getURL()
00058 {
00059 if(superobject != 0) return superobject->getURL();
00060 else return RemoteVobject::getURL();
00061 }
00062
00063 bool RemoteMetaObject::isLocal()
00064 {
00065 if(superobject != 0) return superobject->isLocal();
00066 else return RemoteVobject::isLocal();
00067 }
00068
00069 bool RemoteMetaObject::isRemote()
00070 {
00071 if(superobject != 0) return superobject->isRemote();
00072 else return RemoteVobject::isRemote();
00073 }
00074
00075 const set<string>& RemoteMetaObject::getTypes() throw (AccessControlError, RemoteError)
00076 {
00077 if(superobject != 0) return superobject->getTypes();
00078 else return RemoteVobject::getTypes();
00079 }
00080
00081 void RemoteMetaObject::addType(const string& s)
00082 {
00083 if(superobject !=0) return superobject->addType(s);
00084 else return RemoteVobject::addType(s);
00085 }
00086
00087 const set<Vobject::ParentChildRelation*, Vobject::ParentChildRelation::Cmp>& RemoteMetaObject::getParents()
00088 throw (AccessControlError, RemoteError)
00089 {
00090 if(superobject != 0) return superobject->getParents();
00091 else return RemoteVobject::getParents();
00092 }
00093
00094 const deque<Vobject::ParentChildRelation*>& RemoteMetaObject::getChildren()
00095 throw (AccessControlError, RemoteError)
00096 {
00097 if(superobject != 0) return superobject->getChildren();
00098 else return RemoteVobject::getChildren();
00099 }
00100
00101 void RemoteMetaObject::sendMessage(Message* m)
00102 {
00103 MetaObject::sendMessage(m);
00104
00105 if(superobject == 0) {
00106 RemoteVobject::sendMessage(m);
00107 }
00108 }
00109
00110 void RemoteMetaObject::sendMessage(MessageBlock* m)
00111 {
00112 MetaObject::sendMessage(m);
00113
00114 if(superobject == 0) {
00115 RemoteVobject::sendMessage(m);
00116 }
00117 }
00118
00119 Message* RemoteMetaObject::receiveMessage() throw (MessageQueueEmptyError)
00120 {
00121 if(superobject != 0) return superobject->receiveMessage();
00122 else return RemoteVobject::receiveMessage();
00123 }
00124
00125 bool RemoteMetaObject::hasMessageAvailable()
00126 {
00127 if(superobject != 0) return superobject->hasMessageAvailable();
00128 else return RemoteVobject::hasMessageAvailable();
00129 }
00130
00131 void RemoteMetaObject::handleNewType(const string& t)
00132 {
00133 for(deque<MetaObject*>::const_iterator i = getTypeHandlers().begin();
00134 i != getTypeHandlers().end(); i++)
00135 {
00136 if((*i)->getType() == t) {
00137 return;
00138 }
00139 }
00140
00141 RemoteSite::extendMetaObject(this, t.c_str());
00142
00143
00144 bool hastype=false;
00145 for(deque<MetaObject*>::const_iterator i = getTypeHandlers().begin();
00146 i != getTypeHandlers().end(); i++)
00147 {
00148 if((*i)->getType() == t) {
00149 hastype=true;
00150 }
00151 }
00152
00153 string s = t;
00154
00155
00156
00157 for(unsigned int i = (unsigned int)s.size(); !hastype; ) {
00158 for(i--; i > 0 && s[i] != '.'; i--);
00159 if(i == 0) break;
00160
00161 s = s.substr(0, i);
00162
00163 RemoteSite::extendMetaObject(this, s.c_str());
00164
00165 hastype=false;
00166 for(deque<MetaObject*>::const_iterator i = getTypeHandlers().begin();
00167 i != getTypeHandlers().end(); i++) {
00168 if((*i)->getType() == s) {
00169 hastype=true;
00170 }
00171 }
00172 if(hastype) {
00173 VobjectImplementation::addType(this, s);
00174 }
00175 }
00176
00177 }
00178
00179 void RemoteMetaObject::sendUpdateMessage(Message* m)
00180 {
00181 LOG("refcount", 5, "before sending to MetaObject::sendUpdateMessage count on message " << m->getCount());
00182 MetaObject::sendUpdateMessage(m);
00183 LOG("refcount", 5, "after sending to MetaObject::sendUpdateMessage count on message " << m->getCount());
00184
00185 if(superobject == 0) {
00186 LOG("refcount", 5, "before sending to RemoteVobject::sendUpdateMessage count on message " << m->getCount());
00187 RemoteVobject::sendUpdateMessage(m);
00188 LOG("refcount", 5, "after sending to RemoteVobject::sendUpdateMessage count on message " << m->getCount());
00189
00190 if(m->getMethod() == "core:type-add-update") {
00191 for(int i=0; i < m->getNumFields(); ++i) {
00192 const Message::Field& t=m->getField(i);
00193 if(t.key == "type") {
00194 handleNewType(t.value);
00195 }
00196 }
00197 }
00198 }
00199 }
00200
00201 Message* RemoteMetaObject::receiveUpdateMessage() throw (MessageQueueEmptyError)
00202 {
00203 if(superobject != 0) return superobject->receiveUpdateMessage();
00204 else return RemoteVobject::receiveUpdateMessage();
00205 }
00206
00207 bool RemoteMetaObject::hasUpdateMessageAvailable()
00208 {
00209 if(superobject != 0) return superobject->hasUpdateMessageAvailable();
00210 else return RemoteVobject::hasUpdateMessageAvailable();
00211 }
00212
00213 Vobject& RemoteMetaObject::findObject(const string& path)
00214 throw (NoSuchSiteError, NoSuchObjectError, URL::BadURLError, AccessControlError, RemoteError)
00215 {
00216 if(superobject != 0) return superobject->findObject(path);
00217 else return RemoteVobject::findObject(path);
00218 }
00219
00220 Vobject::ParentChildRelation& RemoteMetaObject::findChild(const string& path)
00221 throw (NoSuchObjectError, AccessControlError, RemoteError)
00222 {
00223 if(superobject != 0) return superobject->findChild(path);
00224 else return RemoteVobject::findChild(path);
00225 }
00226
00227 Vobject::ParentChildRelation& RemoteMetaObject::findParent(Vobject& parent)
00228 throw (NoSuchObjectError, AccessControlError, RemoteError)
00229 {
00230 if(superobject != 0) return superobject->findParent(parent);
00231 else return RemoteVobject::findParent(parent);
00232 }
00233
00234 void RemoteMetaObject::setChild(int position, const string& contextual_name, Vobject* child)
00235 throw (AccessControlError, RemoteError)
00236 {
00237 if(superobject != 0) return superobject->setChild(position, contextual_name, child);
00238 else return RemoteVobject::setChild(position, contextual_name, child);
00239 }
00240
00241 void RemoteMetaObject::insertChild(int position, const string& contextual_name, Vobject* child)
00242 throw (AccessControlError, RemoteError)
00243 {
00244 if(superobject != 0) return superobject->insertChild(position, contextual_name, child);
00245 else return RemoteVobject::insertChild(position, contextual_name, child);
00246 }
00247
00248 void RemoteMetaObject::removeChild(int position)
00249 throw (AccessControlError, RemoteError)
00250 {
00251 if(superobject != 0) return superobject->removeChild(position);
00252 else return RemoteVobject::removeChild(position);
00253 }
00254
00255 void RemoteMetaObject::addTypeListener(TypeChangeListener* tl, bool refresh)
00256 {
00257 if(superobject != 0) superobject->addTypeListener(tl, refresh);
00258 else RemoteVobject::addTypeListener(tl, refresh);
00259 }
00260
00261 void RemoteMetaObject::addParentListener(ParentChangeListener* pl, bool refresh)
00262 {
00263 if(superobject != 0) superobject->addParentListener(pl, refresh);
00264 else RemoteVobject::addParentListener(pl, refresh);
00265 }
00266
00267 void RemoteMetaObject::addChildListener(ChildChangeListener* cl, bool refresh)
00268 {
00269 if(superobject != 0) superobject->addChildListener(cl, refresh);
00270 else RemoteVobject::addChildListener(cl, refresh);
00271 }
00272
00273 void RemoteMetaObject::removeTypeListener(TypeChangeListener* tl)
00274 {
00275 if(superobject != 0) superobject->removeTypeListener(tl);
00276 else RemoteVobject::removeTypeListener(tl);
00277 }
00278
00279 void RemoteMetaObject::removeParentListener(ParentChangeListener* pl)
00280 {
00281 if(superobject != 0) superobject->removeParentListener(pl);
00282 else RemoteVobject::removeParentListener(pl);
00283 }
00284
00285 void RemoteMetaObject::removeChildListener(ChildChangeListener* cl)
00286 {
00287 if(superobject != 0) superobject->removeChildListener(cl);
00288 else RemoteVobject::removeChildListener(cl);
00289 }
00290
00291 void RemoteMetaObject::excise()
00292 {
00293 MetaObject::excise();
00294 RemoteVobject::excise();
00295 }
00296
00297 void RemoteMetaObject::acquire() {
00298 if(superobject != 0) superobject->acquire();
00299 else RemoteVobject::acquire();
00300 }
00301
00302 void RemoteMetaObject::release() {
00303 if(superobject != 0) superobject->release();
00304 else RemoteVobject::release();
00305 }
00306
00307 int RemoteMetaObject::getCount() {
00308 if(superobject != 0) return superobject->getCount();
00309 else return RemoteVobject::getCount();
00310 }
00311
00312 void RemoteMetaObject::saveState(MessageBlock& output, set<string>& types, bool portable)
00313 {
00314 if(superobject !=0) return superobject->saveState(output, types, portable);
00315 else {
00316 RemoteVobject::saveState(output, types, portable);
00317 doSaveState(output, types, portable);
00318 }
00319 }
00320
00321 void RemoteMetaObject::addFlag(const string& flag)
00322 {
00323 if(superobject) superobject->addFlag(flag);
00324 else RemoteVobject::addFlag(flag);
00325 }
00326
00327 void RemoteMetaObject::removeFlag(const string& flag)
00328 {
00329 if(superobject) superobject->removeFlag(flag);
00330 else RemoteVobject::removeFlag(flag);
00331 }
00332
00333 bool RemoteMetaObject::checkFlag(const string& flag)
00334 {
00335 if(superobject) return superobject->checkFlag(flag);
00336 else return RemoteVobject::checkFlag(flag);
00337 }
00338