Sirikata
pinto/src/PintoManagerLocationServiceCache.hpp
Go to the documentation of this file.
00001 /*  Sirikata
00002  *  PintoManagerLocationServiceCache.hpp
00003  *
00004  *  Copyright (c) 2010, Ewen Cheslack-Postava
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 libprox 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_PINTO_PINTO_MANAGER_LOCATION_SERVICE_CACHE_HPP_
00034 #define _SIRIKATA_PINTO_PINTO_MANAGER_LOCATION_SERVICE_CACHE_HPP_
00035 
00036 #include <prox/base/LocationServiceCache.hpp>
00037 #include "ProxSimulationTraits.hpp"
00038 #include <boost/thread.hpp>
00039 #include <sirikata/core/util/AggregateBoundingInfo.hpp>
00040 
00041 namespace Sirikata {
00042 
00043 /* Implementation of LocationServiceCache which tracks data reported by space
00044  * servers to Pinto master server.
00045  */
00046 class PintoManagerLocationServiceCache : public Prox::LocationServiceCache<ServerProxSimulationTraits> {
00047 public:
00048     PintoManagerLocationServiceCache();
00049     virtual ~PintoManagerLocationServiceCache();
00050 
00051     // Leaf inputs -- real space servers
00052     void addSpaceServer(ServerID sid, const TimedMotionVector3f& loc, const BoundingSphere3f& region, float32 maxSize);
00053     void updateSpaceServerLocation(ServerID sid, const TimedMotionVector3f& loc);
00054     void updateSpaceServerRegion(ServerID sid, const BoundingSphere3f& region);
00055     void updateSpaceServerMaxSize(ServerID sid, float32 ms);
00056     void removeSpaceServer(ServerID sid);
00057     // Aggregates -- generated for aggregates
00058     void addAggregate(ServerID sid);
00059     void updateAggregateLocation(ServerID sid, const TimedMotionVector3f& loc);
00060     void updateAggregateBounds(ServerID sid, const AggregateBoundingInfo& bnds);
00061     void removeAggregate(ServerID sid);
00062 
00063     virtual void addPlaceholderImposter(
00064         const ObjectID& uuid,
00065         const Vector3f& center_offset,
00066         const float32 center_bounds_radius,
00067         const float32 max_size,
00068         const String& zernike,
00069         const String& mesh
00070     );
00071 
00072     virtual Iterator startTracking(const ObjectID& id);
00073     virtual void stopTracking(const Iterator& id);
00074     virtual bool startRefcountTracking(const ObjectID& id);
00075     virtual void stopRefcountTracking(const ObjectID& id);
00076 
00077     bool tracking(const ObjectID& id);
00078 
00079     virtual TimedMotionVector3f location(const Iterator& id);
00080     virtual Vector3 centerOffset(const Iterator& id);
00081     virtual float32 centerBoundsRadius(const Iterator& id);
00082     virtual float32 maxSize(const Iterator& id);
00083     virtual bool isLocal(const Iterator& id);
00084     Prox::ZernikeDescriptor& zernikeDescriptor(const Iterator& id);
00085     String mesh(const Iterator& id);
00086     bool aggregate(const Iterator& id);
00087 
00088     virtual const ObjectID& iteratorID(const Iterator& id);
00089 
00090     virtual void addUpdateListener(LocationUpdateListenerType* listener);
00091     virtual void removeUpdateListener(LocationUpdateListenerType* listener);
00092 
00093 private:
00094     struct SpaceServerData {
00095         TimedMotionVector3f location;
00096         BoundingSphere3f region;
00097         float32 maxSize;
00098 
00099         bool aggregate;
00100 
00101         int16 tracking; // Refcount for multiple users -- query
00102                         // handlers and generating results
00103         bool removable;
00104     };
00105 
00106     typedef std::tr1::unordered_map<ServerID, SpaceServerData> ServerMap;
00107     typedef std::tr1::unordered_set<LocationUpdateListenerType*> ListenerSet;
00108 
00109     ServerMap mServers;
00110     ListenerSet mListeners;
00111 
00112     typedef boost::recursive_mutex Mutex;
00113     typedef boost::lock_guard<Mutex> Lock;
00114     Mutex mMutex;
00115 };
00116 
00117 } // namespace Sirikata
00118 
00119 #endif //_SIRIKATA_PINTO_PINTO_MANAGER_LOCATION_SERVICE_CACHE_HPP_