interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

/home/tetron/hack/vos/libs/vos/vos/vobjectextension.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 
00024 #ifndef _VOBJECTEXTENSION_HH_
00025 #define _VOBJECTEXTENSION_HH_
00026 
00027 
00028 #include <boost/thread/recursive_mutex.hpp>
00029 
00030 #include <vos/vutil/refcount.hh>
00031 #include <vos/vutil/url.hh>
00032 #include <vos/vutil/log.hh>
00033 #include <vos/vos/vobject.hh>
00034 #include <vos/vutil/readwritemutex.hh>
00035 #include <vos/vos/listener.hh>
00036 #include <vos/vos/parentchildrel.hh>
00037 #include <vos/vos/iterator.hh>
00038 #include <vos/vos/acl.hh>
00039 
00040 #include <deque>
00041 #include <stdexcept>
00042 
00043 
00044 namespace VOS
00045 {
00046     class Site;
00047     class Message;
00048     class MessageBlock;
00049     class TypeChangeListener;
00050     class ParentChangeListener;
00051     class ChildChangeListener;
00052     class ParentChildRelation;
00053     class VobjectState;
00054     class VobjectBase;
00055     class AccessControlState;
00056 
00057     class PCRIterator;
00058     typedef PCRIterator ChildListIterator;
00059     typedef PCRIterator ParentSetIterator;
00060     class StringIterator;
00061     typedef StringIterator TypeSetIterator;
00062 
00063 /** @class VobjectExtension vobjectextension.hh vos/vos/vobjectextension.hh
00064     @ingroup libvos
00065     Virtual Object System extension interface
00066 
00067     Allows you to hook into various methods on a Vobject to extend
00068     their functionality.  You want to subclass this and override the
00069     methods you are interested in.  The pre_ methods are called prior
00070     to running the default behavior of the method.  The post_ methods
00071     are run after the default behavior of the method has executed.  If
00072     you return false or a non-null value (depending on the particular
00073     method) from a pre_ method this will prevent the default behavior
00074     from being run, meaning it will return after running all the pre_
00075     extensions; this also means it will also skip running any post_
00076     methods.
00077 */
00078 class VOS_API VobjectExtension : public Dispatchable
00079 {
00080 public:
00081     virtual ~VobjectExtension() { };
00082 
00083     virtual void extensionAttachedTo(VobjectBase* vb) { };
00084 
00085     /** Destry this extension.  By default will do "delete this" but
00086         can be overridden if that's not what you want (such as if the
00087         extension is shared among several Vobjects.)
00088     */
00089     virtual void destroy() { delete this; }
00090 
00091     virtual TypeSetIterator* pre_getTypes(VobjectState& state,
00092                                           boost::recursive_mutex::scoped_lock& state_lock,
00093                                           Vobject* requester) { return 0; };
00094     virtual ParentSetIterator* pre_getParents(VobjectState& state,
00095                                               boost::recursive_mutex::scoped_lock& state_lock,
00096                                               Vobject* requester)  { return 0; };
00097     virtual ChildListIterator* pre_getChildren(VobjectState& state,
00098                                                boost::recursive_mutex::scoped_lock& state_lock,
00099                                                Vobject* requester, int start, int end)  { return 0; };
00100 
00101     virtual int pre_numChildren(VobjectState& state,
00102                                 boost::recursive_mutex::scoped_lock& state_lock,
00103                                                Vobject* requester)  { return -1; };
00104 
00105     virtual VUtil::vRef<ParentChildRelation> pre_findObject(VobjectState& state,
00106                                                      boost::recursive_mutex::scoped_lock& state_lock,
00107                                 Vobject* requester, const std::string& path)
00108         { return VUtil::vRef<ParentChildRelation>(); };
00109 
00110     virtual VUtil::vRef<ParentChildRelation> pre_findChild(VobjectState& state,
00111                                                     boost::recursive_mutex::scoped_lock& state_lock,
00112                                Vobject* requester, const std::string& path)
00113         { return VUtil::vRef<ParentChildRelation>(); };
00114 
00115     virtual VUtil::vRef<ParentChildRelation> pre_findChild(VobjectState& state,
00116                                                     boost::recursive_mutex::scoped_lock& state_lock,
00117                                Vobject* requester, int pos)
00118         { return VUtil::vRef<ParentChildRelation>(); };
00119 
00120     virtual VUtil::vRef<ParentChildRelation> pre_findParent(VobjectState& state,
00121                                                      boost::recursive_mutex::scoped_lock& state_lock,
00122                                                      Vobject* requester, Vobject& parent)
00123         { return VUtil::vRef<ParentChildRelation>(); };
00124 
00125     virtual bool pre_addType(VobjectState& state, boost::recursive_mutex::scoped_lock& state_lock,
00126                              Vobject* requester, const std::string& s)  { return true; };
00127     virtual void post_addType(VobjectState& state,
00128                               boost::recursive_mutex::scoped_lock& state_lock,
00129                               Vobject* requester, const std::string& s)  { };
00130 
00131     virtual bool pre_removeType(VobjectState& state,
00132                                 boost::recursive_mutex::scoped_lock& state_lock,
00133                              Vobject* requester, const std::string& s)  { return true; };
00134     virtual void post_removeType(VobjectState& state,
00135                                  boost::recursive_mutex::scoped_lock& state_lock,
00136                               Vobject* requester, const std::string& s)  { };
00137 
00138     virtual bool pre_insertChild(VobjectState& state,
00139                                  boost::recursive_mutex::scoped_lock& state_lock,
00140                                  Vobject* requester,
00141                                  int position, const std::string& contextual_name,
00142                                  Vobject* child)  { return true;  };
00143     virtual void post_insertChild(VobjectState& state,
00144                                   boost::recursive_mutex::scoped_lock& state_lock,
00145                                   Vobject* requester,
00146                                   int position, const std::string& contextual_name,
00147                                   Vobject* child) { };
00148 
00149     virtual bool pre_setChild(VobjectState& state,
00150                               boost::recursive_mutex::scoped_lock& state_lock,
00151                               Vobject* requester,
00152                               int position, const std::string& contextual_name,
00153                               Vobject* child) { return true; };
00154     virtual void post_setChild(VobjectState& state,
00155                                boost::recursive_mutex::scoped_lock& state_lock,
00156                                Vobject* requester,
00157                                int position, const std::string& contextual_name, Vobject* child,
00158                                const std::string& oldcontextual_name, Vobject* oldchild) { };
00159 
00160     virtual bool pre_removeChild(VobjectState& state,
00161                                  boost::recursive_mutex::scoped_lock& state_lock,
00162                                  Vobject* requester,
00163                                  ParentChildRelation* pcr, bool strict) { return true; };
00164     virtual void post_removeChild(VobjectState& state,
00165                                   boost::recursive_mutex::scoped_lock& state_lock,
00166                                   Vobject* requester,
00167                                   ParentChildRelation* pcr, bool strict) { };
00168 
00169     virtual bool pre_addTypeListener(VobjectState& state,
00170                                      boost::recursive_mutex::scoped_lock& state_lock,
00171                                      Vobject* requester, TypeChangeListener* t, bool refresh) { return true; };
00172     virtual void post_addTypeListener(VobjectState& state,
00173                                       boost::recursive_mutex::scoped_lock& state_lock,
00174                                       Vobject* requester, TypeChangeListener* t, bool refresh) { };
00175 
00176     virtual bool pre_removeTypeListener(VobjectState& state,
00177                                         boost::recursive_mutex::scoped_lock& state_lock,
00178                                         Vobject* requester, TypeChangeListener* t) { return true; };
00179     virtual void post_removeTypeListener(VobjectState& state,
00180                                          boost::recursive_mutex::scoped_lock& state_lock,
00181                                          Vobject* requester, TypeChangeListener* t) { };
00182 
00183     virtual bool pre_addChildListener(VobjectState& state,
00184                                       boost::recursive_mutex::scoped_lock& state_lock,
00185                                       Vobject* requester, ChildChangeListener* t, bool refresh) { return true; };
00186     virtual void post_addChildListener(VobjectState& state,
00187                                        boost::recursive_mutex::scoped_lock& state_lock,
00188                                        Vobject* requester, ChildChangeListener* t, bool refresh) { };
00189 
00190     virtual bool pre_removeChildListener(VobjectState& state,
00191                                          boost::recursive_mutex::scoped_lock& state_lock,
00192                                          Vobject* requester, ChildChangeListener* t) { return true; };
00193     virtual void post_removeChildListener(VobjectState& state,
00194                                           boost::recursive_mutex::scoped_lock& state_lock,
00195                                           Vobject* requester, ChildChangeListener* t) { };
00196 
00197     virtual bool pre_addParentListener(VobjectState& state,
00198                                        boost::recursive_mutex::scoped_lock& state_lock,
00199                                        Vobject* requester, ParentChangeListener* t, bool refresh) { return true; };
00200     virtual void post_addParentListener(VobjectState& state,
00201                                         boost::recursive_mutex::scoped_lock& state_lock,
00202                                         Vobject* requester, ParentChangeListener* t, bool refresh) { };
00203 
00204     virtual bool pre_removeParentListener(VobjectState& state,
00205                                           boost::recursive_mutex::scoped_lock& state_lock,
00206                                           Vobject* requester, ParentChangeListener* t) { return true; };
00207     virtual void post_removeParentListener(VobjectState& state,
00208                                            boost::recursive_mutex::scoped_lock& state_lock,
00209                                            Vobject* requester, ParentChangeListener* t) { };
00210 
00211     virtual StringIterator* pre_getPolicy(AccessControlState* acs, Vobject* requester,
00212                                           const std::string& domain, Identity* id)
00213         { return 0; }
00214     virtual StringIterator* pre_getAvailablePolicies(AccessControlState* acs,
00215                                                      Vobject* requester,
00216                                                      const std::string& domain)
00217         { return 0; }
00218 
00219     virtual bool pre_addToACL(AccessControlState* acs, Vobject* requester,
00220                               const std::string& ACLname, Vobject* id) { return true; }
00221     virtual void post_addToACL(AccessControlState* acs, Vobject* requester,
00222                                const std::string& ACLname, Vobject* id,
00223                                const std::string& oldACLname) { }
00224 
00225     virtual bool pre_removeFromACL(AccessControlState* acs, Vobject* requester,
00226                                    const std::string& ACLname, Vobject* id)
00227         { return true; }
00228     virtual void post_removeFromACL(AccessControlState* acs, Vobject* requester,
00229                                     const std::string& ACLname, Vobject* id) { }
00230 
00231     virtual bool pre_deleteACL(AccessControlState* acs, Vobject* requester,
00232                                const std::string& policies) { return true; }
00233     virtual void post_deleteACL(AccessControlState* acs, Vobject* requester,
00234                                 const std::string& policies,
00235                                 AccessControlList* oldacl) { }
00236 
00237     virtual std::string pre_getDefaultPolicy(AccessControlState* acs, Vobject* requester,
00238                                              const std::string& domain) { return ""; }
00239 
00240     virtual bool pre_setDefaultPolicy(AccessControlState* acs, Vobject* requester,
00241                                       const std::string& policy) { return true; }
00242     virtual void post_setDefaultPolicy(AccessControlState* acs, Vobject* requester,
00243                                        const std::string& policy,
00244                                        const std::string& oldpolicy) { }
00245     virtual ACLIterator* pre_getAllACLs(AccessControlState* acs, Vobject* requester)
00246         { return 0; }
00247 };
00248 
00249 
00250 }
00251 
00252 #endif