Sirikata
pinto/src/ManualPintoManager.hpp
Go to the documentation of this file.
00001 // Copyright (c) 2012 Sirikata Authors. All rights reserved.
00002 // Use of this source code is governed by a BSD-style license that can
00003 // be found in the LICENSE file.
00004 
00005 #ifndef _SIRIKATA_MANUAL_PINTO_MANAGER_HPP_
00006 #define _SIRIKATA_MANUAL_PINTO_MANAGER_HPP_
00007 
00008 #include "PintoManagerBase.hpp"
00009 
00010 #include <prox/manual/QueryHandler.hpp>
00011 #include <prox/base/QueryEventListener.hpp>
00012 #include <prox/base/LocationUpdateListener.hpp>
00013 
00014 #include "PintoManagerLocationServiceCache.hpp"
00015 
00016 #include <sirikata/core/prox/Defs.hpp>
00017 
00018 namespace Sirikata {
00019 
00025 class ManualPintoManager
00026     : public PintoManagerBase,
00027       public Prox::QueryEventListener<ServerProxSimulationTraits, Prox::ManualQuery<ServerProxSimulationTraits> >
00028 {
00029 public:
00030     ManualPintoManager(PintoContext* ctx);
00031     virtual ~ManualPintoManager();
00032 
00033 private:
00034     typedef Prox::ManualQueryHandler<ServerProxSimulationTraits> ProxQueryHandler;
00035     typedef Prox::ManualQuery<ServerProxSimulationTraits> Query;
00036     typedef Prox::QueryEvent<ServerProxSimulationTraits> QueryEvent;
00037 
00038     // PintoManagerBase overrides
00039     virtual void onConnected(Sirikata::Network::Stream* newStream);
00040     virtual void onInitialMessage(Sirikata::Network::Stream* stream);
00041     virtual void onRegionUpdate(Sirikata::Network::Stream* stream, BoundingSphere3f bounds);
00042     virtual void onMaxSizeUpdate(Sirikata::Network::Stream* stream, float32 ms);
00043     virtual void onQueryUpdate(Sirikata::Network::Stream* stream, const String& update);
00044     virtual void onDisconnected(Sirikata::Network::Stream* stream);
00045 
00046 
00047     // QueryEventListener Interface
00048     virtual void queryHasEvents(Query* query);
00049 
00050     // AggregateListener Overrides
00051     virtual void aggregateBoundsUpdated(ProxAggregator* handler, const ServerID& objid, const Vector3f& bnds_center, const float32 bnds_center_radius, const float32 max_obj_size);
00052 
00053     // Send a location update to subscribers of the given node
00054     void sendLocUpdate(ServerID about);
00055 
00056 
00057     // Command handlers
00058     virtual void commandProperties(const Command::Command& cmd, Command::Commander* cmdr, Command::CommandID cmdid);
00059     virtual void commandListHandlers(const Command::Command& cmd, Command::Commander* cmdr, Command::CommandID cmdid);
00060     virtual void commandForceRebuild(const Command::Command& cmd, Command::Commander* cmdr, Command::CommandID cmdid);
00061     virtual void commandListNodes(const Command::Command& cmd, Command::Commander* cmdr, Command::CommandID cmdid);
00062     virtual void commandListQueriers(const Command::Command& cmd, Command::Commander* cmdr, Command::CommandID cmdid);
00063     virtual void commandStats(const Command::Command& cmd, Command::Commander* cmdr, Command::CommandID cmdid);
00064 
00065 
00066     // Tick the QueryHandler. We don't actually care about time since Servers
00067     // won't be in motion. Should only be called when the server data or query
00068     // data is updated.
00069     void tick();
00070 
00071     typedef std::tr1::unordered_set<ServerID> ServerSet;
00072     struct ClientData {
00073         ClientData()
00074          : query(NULL),
00075            seqno(0)
00076         {}
00077 
00078         Query* query;
00079         uint64 seqno;
00080         // Track copy of query results so we can clean up subscriptions
00081         ServerSet results;
00082     };
00083     typedef std::tr1::unordered_map<Sirikata::Network::Stream*, ClientData> ClientDataMap;
00084     ClientDataMap mClients;
00085     // Reverse index for queryHasEvents callbacks
00086     typedef std::tr1::unordered_map<Query*, Sirikata::Network::Stream*> ClientsByQuery;
00087     ClientsByQuery mClientsByQuery;
00088     // Index of subscribers generated by queries
00089     typedef std::tr1::unordered_set<Sirikata::Network::Stream*> ClientStreamSet;
00090     typedef std::tr1::unordered_map<ServerID, ClientStreamSet> ServerSubscriberMap;
00091     ServerSubscriberMap mServerSubscribers;
00092     // Single list of prox index IDs since we only have 1 querier -> all results
00093     // will use the same set of indices.
00094     typedef std::tr1::unordered_set<ProxIndexID> ProxIndexIDSet;
00095     ProxIndexIDSet mProxIndices;
00096 
00097     ProxQueryHandler* mQueryHandler;
00098     Time mLastTime;
00099     Duration mDt;
00100 }; // class ManualPintoManager
00101 
00102 } // namespace Sirikata
00103 
00104 #endif //_SIRIKATA_MANUAL_PINTO_MANAGER_HPP_