Sirikata
|
00001 /* Sirikata Object Host -- Proxy Creation and Destruction manager 00002 * ProxyManager.hpp 00003 * 00004 * Copyright (c) 2009, Daniel Reiter Horn 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are 00009 * met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in 00014 * the documentation and/or other materials provided with the 00015 * distribution. 00016 * * Neither the name of Sirikata nor the names of its contributors may 00017 * be used to endorse or promote products derived from this software 00018 * without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00021 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00022 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00023 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00024 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 */ 00032 00033 #ifndef _SIRIKATA_PROXY_MANAGER_HPP_ 00034 #define _SIRIKATA_PROXY_MANAGER_HPP_ 00035 00036 #include <sirikata/core/util/ListenerProvider.hpp> 00037 00038 #include <sirikata/proxyobject/Defs.hpp> 00039 #include "ProxyCreationListener.hpp" 00040 #include <sirikata/core/util/PresenceProperties.hpp> 00041 00042 #include <sirikata/core/util/SerializationCheck.hpp> 00043 00044 namespace Sirikata { 00045 00047 class SIRIKATA_PROXYOBJECT_EXPORT ProxyManager 00048 : public SelfWeakPtr<ProxyManager>, 00049 public Provider<ProxyCreationListener*>, 00050 public Noncopyable, 00051 SerializationCheck 00052 { 00053 public: 00054 typedef std::vector<SpaceObjectReference> ObjectReferenceList; 00055 00056 static ProxyManagerPtr construct(VWObjectPtr parent, const SpaceObjectReference& _id); 00057 virtual ~ProxyManager(); 00058 00059 const SpaceObjectReference& id() const { return mID; } 00060 00061 VWObjectPtr parent() const { return mParent; } 00062 00064 virtual void initialize(); 00066 virtual void destroy(); 00067 00069 virtual ProxyObjectPtr createObject( 00070 const SpaceObjectReference& id, 00071 const TimedMotionVector3f& tmv, const TimedMotionQuaternion& tmq, const AggregateBoundingInfo& bs, 00072 const Transfer::URI& meshuri, const String& phy, bool isAggregate, uint64 seqNo 00073 ); 00074 00076 virtual void destroyObject(const ProxyObjectPtr &newObj); 00077 00079 int32 size(); 00083 int32 activeSize(); 00084 00086 virtual ProxyObjectPtr getProxyObject(const SpaceObjectReference &id) const; 00087 00088 virtual void getAllObjectReferences(std::vector<SpaceObjectReference>& allObjReferences) const; 00089 00093 void resetAllProxies(); 00094 00095 private: 00096 friend class ProxyObject; 00097 00098 ProxyManager(VWObjectPtr parent, const SpaceObjectReference& _id); 00099 00100 // These track the *entire* lifetime of ProxyObjects. This allows 00101 // clients of ProxyManager to hold onto ProxyObjects beyond when 00102 // they are valid. This ProxyManager keeps track of weak copies of 00103 // those ProxyObjects and reuses them. This guarantees that there 00104 // is only one ProxyObject for any given identifier from this 00105 // ProxyManager at any time, and that it is guaranteed to receive 00106 // updates (so that, if the object is removed and the re-added to 00107 // the result set, clients holding references from the first 00108 // addition will continue to receive updates). 00109 void proxyDeleted(const ObjectReference& id); 00110 00111 // Parent HostedObject 00112 VWObjectPtr mParent; 00113 // Presence identifier that runs this ProxyManager 00114 SpaceObjectReference mID; 00115 00116 struct ProxyData { 00117 ProxyData(ProxyObjectPtr p) 00118 : ptr(p), wptr(p) 00119 {} 00120 00121 ProxyObjectPtr ptr; 00122 ProxyObjectWPtr wptr; 00123 }; 00124 typedef std::tr1::unordered_map<ObjectReference, ProxyData, ObjectReference::Hasher> ProxyMap; 00125 ProxyMap mProxyMap; 00126 00127 // We explicitly track when we add/remove active proxies because computing 00128 // this when you have a large number of aggregates is expensive (requires 00129 // scanning through all entries). 00130 uint32 mActiveCount; 00131 }; 00132 00133 typedef std::tr1::shared_ptr<ProxyManager> ProxyManagerPtr; 00134 typedef std::tr1::weak_ptr<ProxyManager> ProxyManagerWPtr; 00135 00136 } 00137 00138 #endif //_SIRIKATA_PROXY_MANAGER_HPP_