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

vos/metaobjects/policy/hostedavatar.cc

Go to the documentation of this file.
00001 /* $Id: hostedavatar.cc,v 1.4 2003/07/23 00:17:30 reed Exp $ */
00002 
00003 
00004 /** @file hostedAvatar.cc Define HostedAvatar, a MetaObject for "policy:hostedAvatar" object types. */
00005 
00006 /* This file was generated by otd2cpp.pl, a script for VOS by Reed Hedges
00007  * <reed@zerohour.net> and Peter Amstutz <tetron@interreality.org>.  Search for
00008  * TODO for stuff that needs editing. You will want to especially fill in
00009  * constructors, destructors, message handlers, non-property subobjects...
00010  *
00011  * The authors of otd2cpp.pl make no guarantee that this code will work, or even
00012  * that it even is safe to run.  Use it at your own risk.
00013  */
00014 
00015 
00016 
00017 
00018 #include <vos/corelibs/vos/vos.hh>
00019 #include <vos/metaobjects/property/property.hh>
00020 #include "hostedavatar.hh"
00021 
00022 NoHostedAvatarAccessControl NoHostedAvatarAccessControl::static_;
00023 
00024 /* Constructor */
00025 HostedAvatar::HostedAvatar(MetaObject* s) : MetaObject(s)
00026 {
00027     accessControl = &NoPropertyAccessControl::static_;
00028 }
00029 
00030 /* Destructor */
00031 HostedAvatar::~HostedAvatar() {
00032 }
00033 
00034 /* Get/Set default AC */
00035 void HostedAvatar::setPropertyAccessControl(PropertyAccessControl* ac) {
00036     accessControl = ac;
00037 }
00038 
00039 PropertyAccessControl* HostedAvatar::getPropertyAccessControl() {
00040     return accessControl;
00041 }
00042 
00043 LocalHostedAvatar::LocalHostedAvatar(MetaObject* s) : HostedAvatar(s), MetaObject(s), hostedavatarAC(0)
00044 {
00045     addMessageHandler<LocalHostedAvatar>("policy:request-avatar", this, &LocalHostedAvatar::handleRequestAvatar);
00046     accessControl = &NoPropertyAccessControl::static_;
00047 }
00048 
00049 LocalHostedAvatar::~LocalHostedAvatar() {
00050 }
00051 
00052 /* Initialize required subobjects: */
00053 
00054 void LocalHostedAvatar::initialize(PropertyAccessControl* ac) {
00055     accessControl = ac;
00056     initialize();
00057 }
00058 
00059 void LocalHostedAvatar::initialize() {
00060 
00061     vRef<LocalSite> localsite = Site::getDefaultPeer();
00062 }
00063 
00064 RemoteHostedAvatar::RemoteHostedAvatar(MetaObject* s) : HostedAvatar(s), MetaObject(s)
00065 {
00066     addUpdateHandler<RemoteHostedAvatar>("policy:request-avatar-reply", this, &RemoteHostedAvatar::handleRequestAvatarReply);
00067 
00068 }
00069 
00070 RemoteHostedAvatar::~RemoteHostedAvatar() {
00071 }
00072 
00073 /* Return type string ("policy:hostedAvatar") */
00074 
00075 const string HostedAvatar::getType() {
00076     return string("policy:hosted-avatar");
00077 }
00078 
00079 /* Register extenders with libvos MetaFactory */
00080 void HostedAvatar::registerExtenders() {
00081     static bool done = false;
00082     if(! done) {
00083     LocalSite::addLocalObjectExtension(typeid(LocalHostedAvatar).name(), &LocalHostedAvatar::new_LocalHostedAvatar);
00084     LocalSite::addLocalObjectExtension(typeid(HostedAvatar).name(), &LocalHostedAvatar::new_LocalHostedAvatar);
00085     LocalSite::addLocalObjectExtension("policy:hosted-avatar", &LocalHostedAvatar::new_LocalHostedAvatar);
00086     RemoteSite::addRemoteObjectExtension(typeid(RemoteHostedAvatar).name(), &RemoteHostedAvatar::new_RemoteHostedAvatar);
00087     RemoteSite::addRemoteObjectExtension(typeid(HostedAvatar).name(), &RemoteHostedAvatar::new_RemoteHostedAvatar);
00088     RemoteSite::addRemoteObjectExtension("policy:hosted-avatar", &RemoteHostedAvatar::new_RemoteHostedAvatar);
00089     done = true;
00090     }
00091 }
00092 
00093 /* Get and set Subproperties and other Subobjects */
00094 
00095 string HostedAvatar::getHostedAvatarIsRequired() {
00096     string s;
00097     vRef<Vobject> v = findObject("policy:hosted-avatar-is-required");
00098  meta_cast<Property&>(*v).read(s);
00099     return s;
00100 }
00101 
00102 string HostedAvatar::getHostedAvatarIsRequiredDatatype() {
00103     string s;
00104     vRef<Vobject> v = findObject("policy:hosted-avatar-is-required");
00105     s = meta_cast<Property&>(*v).getDataType();
00106     return s;
00107 }
00108 
00109 void HostedAvatar::setHostedAvatarIsRequired(const string& value, const string& datatype, PropertyAccessControl* ac) {
00110     if(ac == NULL)
00111         ac = accessControl;
00112     Property::setProperty(*this, "policy:hosted-avatar-is-required", value, datatype, ac);
00113 }
00114 
00115 Vobject* HostedAvatar::getHostedAvatarIsRequiredObject() {
00116     return &findObject("policy:hosted-avatar-is-required");
00117 }
00118 
00119 void HostedAvatar::setHostedAvatarIsRequiredObject(Vobject* newobj) {
00120     try {
00121         vRef<ParentChildRelation> pcr = findChild("policy:hosted-avatar-is-required");
00122         setChild(pcr->position, "policy:hosted-avatar-is-required", newobj);
00123     } catch (NoSuchObjectError) {
00124         insertChild(-1, "policy:hosted-avatar-is-required", newobj);
00125     }
00126 }
00127 
00128 /* Local Actuators: */
00129 
00130 /* Do request-avatar. */
00131 
00132 Vobject& LocalHostedAvatar::doRequestAvatar(Vobject* myavatar) {
00133     throw AccessControlError("Not implemented");
00134 }
00135 
00136 /* Message Handlers:  */
00137 
00138     /* Handle message request-avatar */
00139 
00140 void LocalHostedAvatar::handleRequestAvatar(Message* m) {
00141     /* Fields in this message are:
00142        myavatar (A vobject supplied by the requester.  This may indicate a requested form for the avatar (how it looks) and where to relay certain types of messages (such as chat messages for Talkative vobjects).) Optional. Default is:
00143     */
00144 
00145     /* Replies are:
00146        request-avatar-reply () Fields: path (If the operation was successful, this field contains a rooted path to the avatar that is assigned tothis site.);  error (Only returned if no avatar was created (for access control or other reasons).);
00147     */
00148 
00149     /* TODO: one way to handle the message is to call the actuator (doRequestAvatar).  To reply to the message, if there is more than one possible reply, you probably want to choose only one... (but it's up to you of course...) */
00150 
00151 
00152     try {
00153         vRef<Message> reply = new Message();
00154         LocalVobject::initReply(this, &reply, m, "policy:request-avatar-reply");
00155         vRef<Vobject> from = Vobject::findObjectFromRoot(m->getFrom());
00156         vRef<Vobject> suppliedavatar;
00157 
00158         try {
00159             suppliedavatar = Vobject::findObjectFromRoot(m->getField("myavatar").value);
00160         } catch(Message::NoSuchFieldError){
00161         } catch(NoSuchObjectError){
00162         }
00163 
00164         try {
00165             if(hostedavatarAC) {
00166                 if(hostedavatarAC->checkRequestAvatarPermission(*from, &suppliedavatar)) {
00167                     vRef<Vobject> v = doRequestAvatar(&suppliedavatar);
00168                     reply->insertField(-1, "path", v->getURL().getString());
00169                 }
00170             } else {
00171                 LOG("hostedavatar", 1, "Warning: HostedAvatar vobject " << getURL().getString() << " does not have an access control!  Failing by default");
00172                 throw AccessControlError("This vobject is not initialized properly");
00173             }
00174         } catch(AccessControlError e) {
00175             reply->insertField(-1, "error", e.what());
00176         }
00177 
00178         from->sendMessage(&reply);
00179     } catch(Message::NoSuchFieldError e) {
00180         /* A field wasn't found */
00181     }
00182 
00183 }
00184 
00185 /* Remote Actuators: */
00186 
00187 /* Do request-avatar. */
00188 
00189 Vobject& RemoteHostedAvatar::doRequestAvatar(Vobject* myavatar) {
00190 
00191     /* Create a new message and send it to the local object, and wait for reply.
00192      * If your message expects no reply, remove the line that calls "waitFor". */
00193 
00194     vRef<Message> m = new Message();
00195     vRef<LocalSite> ls = RemoteVobject::initFields(this, &m, "policy:request-avatar", true);
00196     if(myavatar) {
00197         m->insertField(-1, "myavatar", myavatar->getURL().getString());
00198     }
00199 
00200     sendMessage(&m);
00201     vRef<RemoteSite> site = dynamic_cast<RemoteSite&>(getSite());
00202     vRef<Message> n = ls->waitFor(m->getNonce(), &site);
00203     try {
00204         string path = n->getField("path").value;
00205         Vobject& v = Vobject::findObjectFromRoot(path);
00206         return v; // pass reference up
00207     } catch(Message::NoSuchFieldError e) {
00208         try {
00209             throw AccessControlError(n->getField("error").value);
00210         } catch(Message::NoSuchFieldError) {
00211             throw RemoteError("Didn't get back an expected field");
00212         }
00213     } catch(NoSuchObjectError e) {
00214         throw RemoteError("The object in path field did not exist.");
00215     } catch(NoSuchSiteError e) {
00216         throw RemoteError("The object in path field did not exist.");
00217     } catch(URL::BadURLError e) {
00218         throw RemoteError("The object path field was maelformed.");
00219     } catch(...) {
00220         throw RemoteError("Something bad just happened.");
00221     }
00222 }
00223 
00224 /* Generators for factory */
00225 
00226 
00227 MetaObject* LocalHostedAvatar::new_LocalHostedAvatar(MetaObject *s, const string& type) {
00228     LocalHostedAvatar* o = new LocalHostedAvatar(s);
00229     return o;
00230 }
00231 
00232 MetaObject* RemoteHostedAvatar::new_RemoteHostedAvatar(MetaObject *s, const string& type) {
00233     return new RemoteHostedAvatar(s);
00234 }
00235 
00236 /* Handle request-avatar-reply. */
00237 
00238 void RemoteHostedAvatar::handleRequestAvatarReply(Message* m) { }

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