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/gateway.cc

Go to the documentation of this file.
00001 /* $Id: gateway.cc,v 1.4 2003/07/23 00:17:27 reed Exp $ */
00002 
00003 
00004 /** @file gateway.cc Define Gateway, a MetaObject for "misc:gateway" 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 "gateway.hh"
00021 
00022 /* Constructor */
00023 Gateway::Gateway(MetaObject* s) : MetaObject(s)
00024 {
00025     accessControl = &NoPropertyAccessControl::static_;
00026 }
00027 
00028 /* Destructor */
00029 Gateway::~Gateway() {
00030 }
00031 
00032 /* Get/Set default AC */
00033 void Gateway::setPropertyAccessControl(PropertyAccessControl* ac) {
00034     accessControl = ac;
00035 }
00036 
00037 PropertyAccessControl* Gateway::getPropertyAccessControl() {
00038     return accessControl;
00039 }
00040 
00041 LocalGateway::LocalGateway(MetaObject* s) : Gateway(s), MetaObject(s)
00042 {
00043     addMessageHandler<LocalGateway>("request-forward", this, &LocalGateway::handleRequestForward);
00044     accessControl = &NoPropertyAccessControl::static_;
00045 }
00046 
00047 LocalGateway::~LocalGateway() {
00048 }
00049 
00050 /* Initialize required subobjects: */
00051 
00052 void LocalGateway::initialize(PropertyAccessControl* ac) {
00053     accessControl = ac;
00054     initialize();
00055 }
00056 
00057 void LocalGateway::initialize() {
00058 
00059     vRef<LocalSite> localsite = Site::getDefaultPeer();
00060 }
00061 
00062 RemoteGateway::RemoteGateway(MetaObject* s) : Gateway(s), MetaObject(s)
00063 {
00064     //addUpdateHandler<RemoteGateway>("request-forward-reply", this, &RemoteGateway::handleRequestForwardReply);
00065 }
00066 
00067 RemoteGateway::~RemoteGateway() {
00068 }
00069 
00070 /* Return type string ("misc:gateway") */
00071 
00072 const string Gateway::getType() {
00073     return string("misc:gateway");
00074 }
00075 
00076 /* Register extenders with libvos MetaFactory */
00077 void Gateway::registerExtenders() {
00078     static bool done = false;
00079     if(! done) {
00080     LocalSite::addLocalObjectExtension(typeid(LocalGateway).name(), &LocalGateway::new_LocalGateway);
00081     LocalSite::addLocalObjectExtension(typeid(Gateway).name(), &LocalGateway::new_LocalGateway);
00082     LocalSite::addLocalObjectExtension("misc:gateway", &LocalGateway::new_LocalGateway);
00083     RemoteSite::addRemoteObjectExtension(typeid(RemoteGateway).name(), &RemoteGateway::new_RemoteGateway);
00084     RemoteSite::addRemoteObjectExtension(typeid(Gateway).name(), &RemoteGateway::new_RemoteGateway);
00085     RemoteSite::addRemoteObjectExtension("misc:gateway", &RemoteGateway::new_RemoteGateway);
00086     done = true;
00087     }
00088 }
00089 
00090 /* Get and set Subproperties and other Subobjects */
00091 
00092 /* Local Actuators: */
00093 
00094 /* Do request-forward. */
00095 
00096 void LocalGateway::requestForward(LocalSocketSite* ls) {
00097     /* TODO: do stuff! */
00098 }
00099 
00100 /* Message Handlers:  */
00101 
00102 /* Handle message request-forward */
00103 void LocalGateway::handleRequestForward(Message* m) {
00104     /* Fields in this message are:
00105     */
00106 
00107     /* Replies are: request-forward-reply () Fields: sitename (The
00108         gateway has established a forward to theclient's actual site
00109         using this site name, which the clientshould now use as its
00110         primary site name.); error ( If this field is present, the
00111         operation failed.);
00112     */
00113 
00114     /* TODO: one way to handle the message is to call the actuator
00115      * (requestForward).  To reply to the message, if there is more
00116      * than one possible reply, you probably want to choose only
00117      * one... (but it's up to you of course...) */
00118 
00119 
00120     try {
00121         vRef<Message> reply = new Message();
00122         LocalVobject::initReply(this, &reply, m, "request-forward-reply");
00123         vRef<Vobject> from = Vobject::findObjectFromRoot(m->getFrom());
00124 
00125         /* TODO add fields to reply (reply->insertField(-1, "field", "value"); */
00126 
00127         from->sendMessage(&reply);
00128     } catch(Message::NoSuchFieldError e) {
00129         /* A field wasn't found */
00130     }
00131 }
00132 
00133 /* Remote Actuators: */
00134 
00135 /* Do request-forward. */
00136 
00137 void RemoteGateway::requestForward(LocalSocketSite* ls) {
00138 
00139     /* Create a new message and send it to the local object, and wait for reply.
00140      * If your message expects no reply, remove the line that calls "waitFor". */
00141 
00142     vRef<Message> m = new Message();
00143     vRef<LocalSite> oursite = RemoteVobject::initFields(this, &m, "request-forward", true);
00144     sendMessage(&m);
00145     vRef<RemoteSite> site = dynamic_cast<RemoteSite&>(getSite());
00146     vRef<Message> n = ls->waitFor(m->getNonce(), &site);
00147 
00148     try {
00149         URL u(ls->getURL());
00150         u.setHostAndPort(n->getField("sitename").value);
00151         ls->addHostAlias(u.getHostAndPort());
00152         ls->setPrimaryHostname(u.getHostAndPort());
00153     } catch(Message::NoSuchFieldError) {
00154         try {
00155             LOG("gateway", 1, "Could not get a forward: " << n->getField("error").value);
00156         } catch(Message::NoSuchFieldError) {
00157         }
00158     }
00159 }
00160 
00161 /* Generators for factory */
00162 
00163 MetaObject* LocalGateway::new_LocalGateway(MetaObject *s, const string& type) {
00164     LocalGateway* o = new LocalGateway(s);
00165     return o;
00166 }
00167 
00168 MetaObject* RemoteGateway::new_RemoteGateway(MetaObject *s, const string& type) {
00169     return new RemoteGateway(s);
00170 }
00171 
00172 /* Handle request-forward-reply. */
00173 
00174 void RemoteGateway::handleRequestForwardReply(Message* m) { }

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