/home/tetron/hack/vos/libs/vos/vos/vobjectevent.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-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 <http://www.interreality.org> 00022 */ 00023 #ifndef _VOBJECTEVENT_HH_ 00024 #define _VOBJECTEVENT_HH_ 00025 00026 /** @file 00027 Defines ChildChangeListener, ParentChangeListener, and TypeChangeListener. 00028 */ 00029 00030 #include <vos/vos/vosdefs.hh> 00031 #include <vos/vutil/refcount.hh> 00032 #include <vos/vos/vobject.hh> 00033 00034 #include <string> 00035 00036 namespace VOS 00037 { 00038 class Vobject; 00039 class ChildChangeListener; 00040 class ParentChangeListener; 00041 class TypeChangeListener; 00042 00043 /** @class VobjectEvent vobjectevent.hh vos/vos/vobjectevent.hh 00044 @ingroup libvos 00045 00046 This class describes an event changing the state of a Vobject. 00047 This event has either been requested to happen or has already 00048 happened, depending respectively on whether it is supplied as part 00049 of an access control callback or a listener notification callback. 00050 @note A VobjectEvent is a reference counted object. This means 00051 that you may keep a reference to an event which has been passed to 00052 you if you increment its count with acquire() and/or use vRef<>. 00053 */ 00054 class VOS_API VobjectEvent : public VUtil::RefCounted 00055 { 00056 public: 00057 typedef enum {TypeInsert, TypeRemove, ParentInsert, ParentRemove, 00058 ChildInsert, ChildReplace, ChildRemove, 00059 ReadChild, ReadParent, ReadType, 00060 ChildrenListen, ParentListen, TypeListen, 00061 ReadACL, AddToACL, RemoveFromACL, DeleteACL, SetDefaultPolicy} EventType; 00062 private: 00063 EventType event; 00064 Vobject* initiator; 00065 Vobject* from; 00066 int position; 00067 std::string newstring; // used for both contextual name and new type events 00068 Vobject* newchild; 00069 Vobject* oldchild; 00070 public: 00071 /** Construct a ReadChild, ReadParent, ChildInserted, 00072 ChildRemoved, ParentInserted or ParentRemoved event. 00073 00074 @param et The type of event that occured 00075 @param init The object which caused this event to occur 00076 @param fromobj The parent object involved 00077 @param pos The position of the child object in question 00078 @param contextname The contextual name of the child object in question 00079 @param childobj The child object involved 00080 */ 00081 VobjectEvent(EventType et, Vobject* init, 00082 Vobject& fromobj, int pos, const std::string& contextname, 00083 Vobject& childobj); 00084 00085 /** Construct a ChildReplaced event. 00086 @param et The type of event that occured 00087 @param init The object which caused this event to occur 00088 @param fromobj The parent object 00089 @param pos The position of the child object in question 00090 @param contextname The contextual name of the child object in question 00091 @param newobj The new child at this position 00092 @param oldobj The old child at this position 00093 */ 00094 VobjectEvent(EventType et, Vobject* init, 00095 Vobject& fromobj, int pos, const std::string& contextname, 00096 Vobject& newobj, Vobject& oldobj); 00097 00098 /** Construct a ReadType, TypeInserted, TypeRemoved or RemoveACL event. 00099 @param et The type of event that occured 00100 @param init The object which caused this event to occur 00101 @param fromobj The parent object of this child change event 00102 @param str The newly added type string for Type events, or the ACL for RemoveACL event 00103 */ 00104 VobjectEvent(EventType et, Vobject* init, 00105 Vobject& fromobj, const std::string& str); 00106 00107 /** Construct a ChildrenListen, ParentListen TypeListen or ReadACL event 00108 @param et The type of event that occured 00109 @param requester The object which wants to start listening or do the read 00110 @param fromobj The object that will be listened to or read from 00111 */ 00112 VobjectEvent(EventType et, Vobject* requester, 00113 Vobject& fromobj); 00114 00115 /** Construct an AddToACL or RemoveFromACL event 00116 @param et The type of event that occured 00117 @param requester The object which wants to make the change 00118 @param fromobj the object on which the security is changing 00119 @param acl the access control list to change 00120 @param aclmember The identity or group that will be added or removed from the ACL 00121 */ 00122 VobjectEvent(EventType et, Vobject* requester, 00123 Vobject& fromobj, const std::string& acl, 00124 Vobject& aclmember); 00125 00126 virtual ~VobjectEvent(); 00127 00128 /** @return What type of event this is. */ 00129 EventType getEvent() { return event; } 00130 00131 /** @return The object which requested or initiated this event. 00132 May be null. For access control checks, this is the object 00133 which is requesting access. 00134 */ 00135 VUtil::vRef<Vobject> getInitiator() { return VUtil::vRef<Vobject>(initiator, true); } 00136 00137 /** @return The parent Vobject being changed. Always a vaild 00138 object. */ 00139 VUtil::vRef<Vobject> getParent() { return VUtil::vRef<Vobject>(from, true); } 00140 00141 /** @return The Vobject which is changing state. Always a valid 00142 object. 00143 */ 00144 VUtil::vRef<Vobject> getAffectedObject() { return VUtil::vRef<Vobject>(from, true); } 00145 00146 /** @return The child Vobject which was affected on a ParentInsert 00147 or ParentRemove event, or the requested object to read on a 00148 ReadChild event. Will be NULL for TypeInsert, TypeRemove and 00149 all Listen events. */ 00150 VUtil::vRef<Vobject> getChild() { return VUtil::vRef<Vobject>(newchild, true); } 00151 00152 /** @return The identity or group to be added or removed on a 00153 AddToACL or RemoveFromACL event. */ 00154 VUtil::vRef<Vobject> getACLMember() { return VUtil::vRef<Vobject>(newchild, true); } 00155 00156 /** @return The child Vobject which was newly added on a 00157 ChildInsert or ChildReplace event. Will be NULL for 00158 ChildRemove, TypeInsert, TypeRemove and all Read and Listen 00159 events. */ 00160 VUtil::vRef<Vobject> getNewChild() { return VUtil::vRef<Vobject>(newchild, true); } 00161 00162 /** @return The previous Vobject occupying this position. Only 00163 valid for ChildRemove and ChildReplace events, NULL otherwise. 00164 */ 00165 VUtil::vRef<Vobject> getOldChild() { return VUtil::vRef<Vobject>(oldchild, true); } 00166 00167 /** @return The absolute position of the child Vobject in parent, or -1 if this is a 00168 TypeInserted or TypeRemoved event.*/ 00169 int getPosition() { return position; } 00170 00171 /** @return The contextual name of the child Vobject. */ 00172 const std::string& getContextualName() { return newstring; } 00173 00174 /** @return The added or removed type for type change events. */ 00175 const std::string& getNewType() { return newstring; } 00176 /** @return The added or removed type for type change events. */ 00177 const std::string& getType() { return newstring; } 00178 /** @return The added or removed type for type change events. */ 00179 const std::string& getOldType() { return newstring; } 00180 00181 /** @return The access control list being changed.. */ 00182 const std::string& getAffectedACL() { return newstring; } 00183 00184 void deliverTo(ChildChangeListener* ccl); 00185 00186 void deliverTo(TypeChangeListener* ccl); 00187 00188 void deliverTo(ParentChangeListener* ccl); 00189 }; 00190 00191 } 00192 00193 #endif