00001 /* 00002 This file is part of the Virtual Object System of 00003 the Interreality project (http://interreality.org). 00004 00005 Copyright (C) 2001-2003 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 _LOCALVOBJECT_HH_ 00024 #define _LOCALVOBJECT_HH_ 00025 00026 /** @file 00027 Defines LocalVobject 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 MessageBlock; 00037 class LocalSite; 00038 class RemoteSite; 00039 class VobjectAccessControl; 00040 class URL; 00041 class VobjectEvent; 00042 00043 00044 /** @class LocalVobject localvobject.hh vos/corelibs/vos/localvobject.hh 00045 * 00046 * This class contains the code to respond to messages from remote 00047 objects inquiring about the Vobject's state. 00048 */ 00049 class VOS_API LocalVobject : public virtual VobjectImplementation 00050 { 00051 private: 00052 //map<string, Message*> waitForNonces; 00053 deque<VobjectAccessControl*> accesscontrols; 00054 00055 void findObjectHandler(Message* m); 00056 void getTypesHandler(Message* m); 00057 void getParentsHandler(Message* m); 00058 void addChildHandler(Message* m); 00059 void removeChildHandler(Message* m); 00060 void startListeningHandler(Message* m); 00061 void stopListeningHandler(Message* m); 00062 void typeAddHandler(Message* m); 00063 public: 00064 LocalVobject(const string& name, LocalSite* s, VobjectAccessControl* accesscontrol); 00065 virtual void sendMessage(Message* m); 00066 virtual void sendMessage(MessageBlock* m); 00067 virtual void setURL(const URL& u) { url = u; } 00068 00069 /** Block until a message bearing a specific nonce is received, 00070 and return that message. 00071 @param nonce the nonce string to wait for 00072 @param timeout maximum time to wait, in seconds, before failing (will throw a TimeoutError) 00073 @param from the remote site the message is expected from. 00074 @throw TimeoutError 00075 @returns the message which matched this nonce. NOTE YOU MUST CALL release() WHEN DONE OR USE A pREF() BLOCK 00076 */ 00077 Message* waitFor(const string& nonce, RemoteSite* from, double timeout = VOS_DEFAULT_TIMEOUT); 00078 00079 /** Insert a new policy into the access policy list. The access 00080 policy list is traversed from beginning to end, calling each 00081 access control policy in order until either a policy returns 00082 false (deny) or the end of the list is reached. If access is 00083 denied, list traversal immediately stops and the requested 00084 action is denied. If the end of the list is reached without a 00085 denial, the requested action is permitted. 00086 00087 @param pos The position to be inserted into. As with most 00088 other parts of VOS, a positive value counts from the beginning 00089 and a negative value counts from the end. In particular, a 00090 position of 0 will insert at the head of the list, making it 00091 the the first policy to be consulted. A position of -1 will 00092 insert at the end of the list, making it the last policy to be 00093 consulted. 00094 00095 @param ac the access control policy 00096 */ 00097 virtual void insertAccessControl(int pos, VobjectAccessControl* ac); 00098 00099 /** Add a named policy. 00100 @see VobjectAccessControl::getPolicy 00101 */ 00102 virtual void insertAccessControl(int pos, const string& policyname); 00103 00104 /** Remove the access policy at the specified position. 00105 @param pos the position of the policy in the policy list 00106 @see insertAccessControl */ 00107 virtual void removeAccessControl(int pos); 00108 00109 /** Remove all instances of the specified access policy from the policy list. 00110 @param m the access control policy to remove 00111 @see insertAccessControl */ 00112 virtual void removeAccessControl(VobjectAccessControl* m); 00113 00114 /** Remove all policies matching this name. */ 00115 virtual void removeAccessControl(const string& policyname); 00116 00117 /** @return the current access control policy list. 00118 @see insertAccessControl */ 00119 virtual const deque<VobjectAccessControl*>& getAccessControls(); 00120 00121 /** Traverse the access policy list and determine whether to allow this event 00122 @param e the event to permit 00123 @return true if the event is permitted, false to deny this event 00124 */ 00125 virtual bool validateAccess(VobjectEvent& e, string& message); 00126 00127 /** Convenience function which initializes various message fields when 00128 replying to a message. 00129 @param v the 'from' object 00130 @param reply the message whose fields will be filled in 00131 @param m the message we're replying to, to set the 'to' field 00132 @param method the method to use 00133 @note Here is what this method actually does: 00134 @code 00135 reply->setType("update"); 00136 reply->setMethod(method); 00137 reply->setTo(m->getFrom()); 00138 reply->setFrom(v->getURL().getString()); 00139 reply->setNonce(m->getNonce()); 00140 @endcode 00141 See also RemoteVobject::initReply() 00142 */ 00143 static void initReply(Vobject* v, Message* reply, Message* m, const string& method); 00144 00145 virtual void addType(const string& s); 00146 00147 virtual void setChild(int position, const string& contextual_name, Vobject* child) 00148 throw (AccessControlError, RemoteError); 00149 00150 virtual void insertChild(int position, const string& contextual_name, Vobject* child) 00151 throw (AccessControlError, RemoteError); 00152 00153 virtual void removeChild(int position) 00154 throw (AccessControlError, RemoteError); 00155 00156 }; 00157 } 00158 00159 #endif