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

vos/metaobjects/misc/avatar.cc

Go to the documentation of this file.
00001 /* $Id: avatar.cc,v 1.26 2003/07/23 00:17:26 reed Exp $ */
00002 
00003 
00004 
00005 /* This file was generated by otd2cpp.pl, a script for ADR by Reed Hedges <reed@zerohour.net>.
00006    Search for TODO for stuff that needs editing. You will want to especially fill in constructors,
00007    destructors, message handlers, non-property subobjects...
00008 
00009    I can make no garuntee that this code will work, or even that it even is safe to run.
00010    Use it at your own risk.
00011 */
00012 
00013 
00014 #include <stdexcept>
00015 #include <vos/corelibs/vos/vos.hh>
00016 #include <vos/metaobjects/property/property.hh>
00017 #include "avatar.hh"
00018 #include "hypercard.hh"
00019 
00020 using namespace std;
00021 
00022 /* initialize static class variables */
00023 const unsigned short Avatar::AVAILABLE = 0;
00024 const unsigned short Avatar::AWAY = 1;
00025 const unsigned short Avatar::EXTENDEDAWAY = 2;
00026 const unsigned short Avatar::BUSY = 3;
00027 
00028 /* Constructors */
00029 
00030 Avatar::Avatar(MetaObject* s) : MetaObject(s) {
00031     defaultAccessControl = &NoPropertyAccessControl::static_;
00032 }
00033 
00034 LocalAvatar::LocalAvatar(MetaObject* s) : Avatar(s), MetaObject(s) {
00035 
00036 }
00037 
00038 
00039 
00040 RemoteAvatar::RemoteAvatar(MetaObject* s) : Avatar(s), MetaObject(s) {
00041 
00042 }
00043 
00044 
00045 
00046 /* Return type string ("avatar") */
00047 
00048 const string Avatar::getType() {
00049     return string("misc:avatar");
00050 }
00051 
00052 /* Register extenders with libvos MetaFactory */
00053 void Avatar::registerExtenders() {
00054     static bool done = false;
00055     if(! done) {
00056         LocalSite::addLocalObjectExtension(typeid(LocalAvatar).name(), &LocalAvatar::new_LocalAvatar);
00057         LocalSite::addLocalObjectExtension(typeid(Avatar).name(), &LocalAvatar::new_LocalAvatar);
00058         LocalSite::addLocalObjectExtension("misc:avatar", &LocalAvatar::new_LocalAvatar);
00059         RemoteSite::addRemoteObjectExtension(typeid(RemoteAvatar).name(), &RemoteAvatar::new_RemoteAvatar);
00060         RemoteSite::addRemoteObjectExtension(typeid(Avatar).name(), &RemoteAvatar::new_RemoteAvatar);
00061         RemoteSite::addRemoteObjectExtension("misc:avatar", &RemoteAvatar::new_RemoteAvatar);
00062         done = true;
00063     }
00064 }
00065 
00066 
00067 /* Get and set Subproperties and other Subobjects */
00068 
00069 string Avatar::getNick() {
00070     string s;
00071     try {
00072         vRef<Property> p = meta_cast<Property*>(&findObject("misc:nick"));
00073         if(&p)
00074             p->read(s);
00075         else
00076             throw bad_cast();
00077     } catch(NoSuchObjectError) {
00078         s = getName();
00079     }
00080     return s;
00081 }
00082 
00083 void Avatar::setNick(const string& value, PropertyAccessControl* pac) {
00084     if(pac == 0)
00085         pac = defaultAccessControl;
00086     Property::setProperty(*this, "misc:nick", value, "text/plain", pac);
00087 }
00088 
00089 Property* Avatar::getNickObj() {
00090     return meta_cast<Property*>(&findObject("misc:nick"));
00091 }
00092 
00093 void Avatar::setNickObj(Property* obj) {
00094     try {
00095         vRef<ParentChildRelation> pcr = findChild("misc:nick");
00096         setChild(pcr->position, "misc:nick", obj);
00097     } catch (NoSuchObjectError) {
00098         insertChild(-1, "misc:nick", obj);
00099     }
00100 }
00101 
00102 void Avatar::addNickListener(PropertyListener* listener) {
00103     vRef<Property> p = meta_cast<Property*>(&findObject("misc:nick"));
00104     if(!&p)
00105         throw bad_cast();
00106     p->addPropertyListener(listener);
00107 }
00108 
00109 void Avatar::removeNickListener(PropertyListener* listener) {
00110     vRef<Property> p = meta_cast<Property*>(&findObject("misc:nick"));
00111     if(!&p)
00112         throw bad_cast();
00113     p->removePropertyListener(listener);
00114 }
00115 
00116 string Avatar::getFullname() {
00117     try {
00118         string s;
00119         vRef<Property> p = meta_cast<Property*>(&findObject("misc:fullname"));
00120         if(&p)
00121             p->read(s);
00122         else
00123             throw bad_cast();
00124         return s;
00125     } catch (NoSuchObjectError) {
00126         return "";
00127     }
00128 }
00129 
00130 string Avatar::getFullnameDatatype() {
00131     try {
00132         string s;
00133         vRef<Property> p = meta_cast<Property*>(&findObject("misc:fullname"));
00134         if(&p)
00135             s = p->getDataType();
00136         else
00137             throw bad_cast();
00138         return s;
00139     } catch(NoSuchObjectError) {
00140         return "text/plain"; // datatype of ""
00141     }
00142 }
00143 
00144 void Avatar::setFullname(const string& value, const string& datatype, PropertyAccessControl* pac) {
00145     if(pac == 0)
00146         pac = defaultAccessControl;
00147     Property::setProperty(*this, "misc:fullname", value, datatype, pac);
00148 }
00149 
00150 Property* Avatar::getFullnameObj() {
00151     return meta_cast<Property*>(&findObject("misc:fullname"));
00152 }
00153 
00154 void Avatar::setFullnameObj(Property* obj) {
00155     try {
00156         vRef<ParentChildRelation> pcr = findChild("misc:fullname");
00157         setChild(pcr->position, "misc:fullname", obj);
00158     } catch (NoSuchObjectError) {
00159         insertChild(-1, "misc:fullname", obj);
00160     }
00161 }
00162 
00163 void Avatar::setSelectedObj(Vobject* obj) {
00164     if(obj == 0) {
00165         LOG("avatar", 1, "setSelectedObj: removing selected-object.");
00166         try {
00167             vRef<ParentChildRelation> pcr = findChild("misc:selected-object");
00168             removeChild(pcr->position);
00169         } catch(...) {
00170         }
00171         return;
00172     }
00173 
00174     try {
00175         LOG("avatar", 1, "setSelectedObj: finding selected-object hypercard");
00176         vRef<Hypercard> hc = meta_cast<Hypercard*>(&findObject("misc:selected-object"));
00177         if(!&hc) {
00178             LOG("avatar", 1, "setSelectedObj: selected-object is not a hypercard!"); 
00179             throw bad_cast();
00180         }
00181         LOG("avatar", 1, "setSelectedObj: setting link");
00182         hc->setLink(obj);
00183     } catch (NoSuchObjectError) {
00184         LOG("avatar", 1, "setSelectedObj: selected-object hypercard not found; creating...");
00185         vRef<Hypercard> hc = meta_cast<Hypercard*>(
00186                 Site::getDefaultPeer()->createMetaObject("avatar-selected-object-hypercard", &NoAccessControl::static_, typeid(Hypercard).name(), 0)
00187         );
00188         hc->setLink(obj);
00189         hc->setTitle("selected object");
00190         insertChild(-1, "misc:selected-object", &hc);
00191     }
00192 }
00193 
00194 void Avatar::setSelectedHypercard(Hypercard* hc) {
00195     try {
00196         vRef<ParentChildRelation> rel = findChild("misc:selected-object");
00197         setChild(rel->position, "misc:selected-object", hc);
00198     } catch(NoSuchObjectError) {
00199         insertChild(-1, "misc:selected-object", hc);
00200     }
00201 }
00202 
00203 
00204 Hypercard* Avatar::getSelectedHypercard() {
00205     vRef<Vobject> obj = &findObject("misc:selected-object");
00206     if(!&obj)
00207         throw NoSuchObjectError("Avatar has no misc:selected-object");
00208     Hypercard* hc = meta_cast<Hypercard*>(&obj);
00209     if(!hc)
00210         throw bad_cast();
00211     return hc;
00212 }
00213 
00214 Vobject* Avatar::getSelectedObj() {
00215     return &(getSelectedHypercard()->getLink());
00216 }
00217 
00218 string Avatar::getInfo() {
00219     try {
00220         string s;
00221         vRef<Property> p = meta_cast<Property*>(&findObject("misc:info"));
00222         if(&p)
00223             p->read(s);
00224         else
00225             throw bad_cast();
00226         return s;
00227     } catch(NoSuchObjectError) {
00228         return "";
00229     }
00230 }
00231 
00232 string Avatar::getInfoDatatype() {
00233     try {
00234         string s;
00235         vRef<Property> p = meta_cast<Property*>(&findObject("misc:info"));
00236         if(&p)
00237             s = p->getDataType();
00238         else
00239             throw bad_cast();
00240         return s;
00241     } catch(NoSuchObjectError) {
00242         return "text/plain";
00243     }
00244 }
00245 
00246 void Avatar::setInfo(const string& value, const string& datatype, PropertyAccessControl* pac) {
00247     if(pac == 0)
00248         pac = defaultAccessControl;
00249     Property::setProperty(*this, "misc:info", value, datatype, pac);
00250 }
00251 
00252 void Avatar::setUserId(const string& userid, PropertyAccessControl* pac) {
00253     if(!pac)
00254         pac = defaultAccessControl;
00255     Property::setProperty(*this, "misc:user-id", userid, "text/plain", pac);
00256 }
00257 
00258 string Avatar::getUserId() {
00259     vRef<Property> p = meta_cast<Property*>(&findObject("misc:user-id"));
00260     string s;
00261     if(&p)
00262         p->read(s);
00263     else
00264         throw bad_cast();
00265     return s;
00266 }
00267 
00268     
00269 
00270 
00271 
00272 Property* Avatar::getInfoObj() {
00273     return meta_cast<Property*>(&findObject("misc:info"));
00274 }
00275 
00276 void Avatar::setInfoObj(Property* obj) {
00277     try {
00278         vRef<ParentChildRelation> pcr = findChild("misc:info");
00279         setChild(pcr->position, "misc:info", obj);
00280     } catch (NoSuchObjectError) {
00281         insertChild(-1, "misc:info", obj);
00282     }
00283 }
00284 
00285 void Avatar::addInfoListener(PropertyListener* listener) {
00286     vRef<Property> p = meta_cast<Property*>(&findObject("misc:info"));
00287     if(!&p)
00288         throw bad_cast();
00289     p->addPropertyListener(listener);
00290 }
00291 
00292 void Avatar::removeInfoListener(PropertyListener* listener) {
00293     vRef<Property> p = meta_cast<Property*>(&findObject("misc:info"));
00294     if(!&p) throw bad_cast();
00295     p->removePropertyListener(listener);
00296 }
00297 
00298 
00299 unsigned short Avatar::getPresence() {
00300     try {
00301         string s;
00302         vRef<Property> p = meta_cast<Property*>(&findObject("misc:presence_code"));
00303         if(!&p) throw bad_cast();
00304         p->read(s);
00305         if(s == "chat")
00306             return AVAILABLE;
00307         else if(s == "away")
00308             return AWAY;
00309         else if(s == "xa")
00310             return EXTENDEDAWAY;
00311         else if(s == "dnd")
00312             return BUSY;
00313         else
00314             return AVAILABLE;
00315     } catch(NoSuchObjectError) {
00316         return AVAILABLE;
00317     }
00318 }
00319 
00320 
00321 void Avatar::setPresence(unsigned short code, PropertyAccessControl* pac) {
00322     if(pac == 0)
00323         pac = defaultAccessControl;
00324     string c;
00325     switch(code) {
00326         case AVAILABLE:
00327             c = "chat";
00328             break;
00329         case AWAY:
00330             c = "away";
00331             break;
00332         case EXTENDEDAWAY:
00333             c = "xa";
00334             break;
00335         case BUSY:
00336             c = "dnd";
00337             break;
00338         default:
00339             c = "chat";
00340     }
00341     Property::setProperty(*this, "misc:presence_code", c, "text/plain", pac);
00342 }
00343 
00344 Property* Avatar::getPresenceObj() {
00345     return meta_cast<Property*>(&findObject("misc:presence_code"));
00346 }
00347 
00348 void Avatar::setPresenceObj(Property* obj) {
00349     try {
00350         vRef<ParentChildRelation> pcr = findChild("misc:presence_code");
00351         setChild(pcr->position, "misc:presence_code", obj);
00352     } catch (NoSuchObjectError) {
00353         insertChild(-1, "misc:presence_code", obj);
00354     }
00355 }
00356 
00357 void Avatar::addPresenceListener(PropertyListener* listener) {
00358     vRef<Property> p = meta_cast<Property*>(&findObject("misc:presence_code"));
00359     if(!&p) throw bad_cast();
00360     p->addPropertyListener(listener);
00361 }
00362 
00363 void Avatar::removePresenceListener(PropertyListener* listener) {
00364     vRef<Property> p = meta_cast<Property*>(&findObject("misc:presence_code"));
00365     if(!&p) throw bad_cast();
00366     p->removePropertyListener(listener);
00367 }
00368 
00369 string Avatar::getPresenceDescription() {
00370     try {
00371         string s;
00372         vRef<Property> p = meta_cast<Property*>(&findObject("misc:presence_description"));
00373         if(!&p) throw bad_cast();
00374         p->read(s);
00375         return s;
00376     } catch(NoSuchObjectError) {
00377         return "";
00378     }
00379 }
00380 
00381 string Avatar::getPresenceDescriptionDatatype() {
00382     try {
00383         vRef<Property> p =
00384 meta_cast<Property*>(&findObject("misc:presence_description"));
00385         if(!&p) throw bad_cast();
00386         return p->getDataType();
00387     } catch(NoSuchObjectError) {
00388         return "text/plain";
00389     }
00390 }
00391 
00392 void Avatar::setPresenceDescription(const string& value, const string& datatype,
00393 PropertyAccessControl* pac) {
00394     if(pac == 0)
00395         pac = defaultAccessControl;
00396     Property::setProperty(*this, "misc:presence_description", value, datatype, defaultAccessControl);
00397 }
00398 
00399 
00400 Property* Avatar::getPresenceDescriptionObj() {
00401     return meta_cast<Property*>(&findObject("misc:presence_description"));
00402 }
00403 
00404 void Avatar::setPresenceDescriptionObj(Property* obj) {
00405     try {
00406         vRef<ParentChildRelation> pcr = findChild("misc:presence_description");
00407         setChild(pcr->position, "misc:presence_description", obj);
00408     } catch (NoSuchObjectError) {
00409         insertChild(-1, "misc:presence_description", obj);
00410     }
00411 }
00412 
00413 /* Process local object messages */
00414 void LocalAvatar::sendMessage(Message* m) {
00415 
00416 
00417     /* Let superclass have message */
00418     Avatar::sendMessage(m);
00419 }
00420 
00421 
00422 
00423 
00424 
00425 /* Process remote update messages */
00426 void RemoteAvatar::sendUpdateMessage(Message* m) {
00427 
00428 
00429     /* branch to update message handlers specific to RemoteAvatar */
00430 
00431     /* let superclass have message... */
00432     Avatar::sendUpdateMessage(m);
00433 }
00434 
00435 
00436 
00437 MetaObject* LocalAvatar::new_LocalAvatar(MetaObject* s, const string& type) {
00438     return new LocalAvatar(s);
00439 }
00440 
00441 MetaObject* RemoteAvatar::new_RemoteAvatar(MetaObject* s, const string& type) {
00442     return new RemoteAvatar(s);
00443 }
00444 
00445 
00446 void Avatar::initialize() {
00447     setPropertyAccessControl(&NoPropertyAccessControl::static_);
00448 }
00449 
00450 void Avatar::setPropertyAccessControl(PropertyAccessControl* pac) {
00451     assert(pac);
00452     defaultAccessControl = pac;
00453 }
00454 
00455 PropertyAccessControl* Avatar::getPropertyAccessControl(){
00456     return defaultAccessControl;
00457 }

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