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/remotevobject.hh

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, 2002 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 #ifndef _REMOTEVOBJECT_HH_
00024 #define _REMOTEVOBJECT_HH_
00025 
00026 /** @file
00027     Defines RemoteVobject.
00028 */
00029 
00030 #include <vos/corelibs/vos/vosdefs.hh>
00031 #include <vos/corelibs/vos/vobject.hh>
00032 
00033 namespace VOS
00034 {
00035     class Message;
00036     class RemoteSite;
00037     class LocalSite;
00038 
00039 /** @class RemoteVobject remotevobject.hh vos/corelibs/vos/remotevobject.hh
00040  * This class allows you to access remotely Vobjects as if they were
00041     local.
00042  */
00043 class VOS_API RemoteVobject : public virtual VobjectImplementation
00044 {
00045 private:
00046     void addChildUpdateHandler(Message* m);
00047     void addParentUpdateHandler(Message* m);
00048     void removeChildUpdateHandler(Message* m);
00049     void removeParentUpdateHandler(Message* m);
00050     void typeUpdateHandler(Message* m);
00051     void addListenerReplyHandler(Message* m);
00052 
00053     bool resetChildren;
00054 protected:
00055     RemoteVobject(const string& name, RemoteSite* remotesite);
00056 public:
00057     virtual ~RemoteVobject();
00058 
00059     virtual void sendMessage(Message* m);
00060     virtual void sendMessage(MessageBlock* m);
00061     virtual void sendUpdateMessage(Message* m);
00062     virtual const ChildList& getChildren()
00063         throw (AccessControlError, RemoteError);
00064     virtual const ParentSet& getParents()
00065         throw (AccessControlError, RemoteError);
00066     virtual const TypeSet& getTypes()
00067         throw (AccessControlError, RemoteError);
00068 
00069     virtual Vobject& findObject(const string& path)
00070         throw (NoSuchSiteError, NoSuchObjectError, URL::BadURLError, AccessControlError, RemoteError);
00071 
00072     virtual Vobject::ParentChildRelation& findChild(const string& path)
00073         throw (NoSuchObjectError, AccessControlError, RemoteError);
00074     virtual void setChild(int position, const string& contextual_name, Vobject* child)
00075         throw (AccessControlError, RemoteError);
00076     virtual void  insertChild(int position, const string& contextual_name, Vobject* child)
00077         throw (AccessControlError, RemoteError);
00078     virtual void removeChild(int position)
00079         throw (AccessControlError, RemoteError);
00080     virtual void addType(const string& type);
00081 
00082     virtual void addTypeListener(TypeChangeListener* tl, bool notifyImmediately = true);
00083     virtual void addParentListener(ParentChangeListener* pl, bool notifyImmediately = true);
00084     virtual void addChildListener(ChildChangeListener* cl, bool notifyImmediately = true);
00085     virtual void removeTypeListener(TypeChangeListener* tl);
00086     virtual void removeParentListener(ParentChangeListener* pl);
00087     virtual void removeChildListener(ChildChangeListener* cl);
00088 
00089     virtual void acquire();
00090     virtual void release();
00091 
00092     /** Convenience function which initializes various message fields when
00093         sending out a message.
00094         @param v the remote object emitting this message
00095         @param m the message to be filled in
00096         @param method the method field
00097         @param withnonce whether to generate a nonce or not
00098         @returns The local site which this remote object's site is
00099         peered to.  This is useful because you often want to do something like
00100         @code
00101     vRef<Message> m = new Message();
00102         vRef<LocalSite> ls = initFields(this, &m, "my-method", true);
00103         // fill in some other fields here
00104     sendMessage(&m);
00105     vRef<Site> site = getSite();
00106         vRef<Message> thereply = ls->waitFor(m->getNonce(), dynamic_cast<RemoteSite*>(&site));
00107         // do stuff with 'thereply'
00108         @endcode
00109         NOTE YOU MUST CALL release() WHEN DONE OR USE A rREF() BLOCK (as shown above)
00110         @note Here is what this method actually does:
00111         @code
00112         m->setType("message");
00113         LocalSite& ls = dynamic_cast<RemoteSite*>(&(v->getSite()))->getLocalPeer();
00114         m->setFrom(ls.getURL().getString());
00115         m->setTo(v->getURL().getString());
00116         m->setMethod(method);
00117         if(withnonce) m->generateNonce();
00118         @endcode
00119         See also LocalVobject::initReply()
00120     */
00121     static LocalSite& initFields(Vobject* v, Message* m, const string& method, bool withnonce);
00122 };
00123 }
00124 
00125 #endif

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