Sirikata
pinto/src/PintoManager.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_PINTO_MANAGER_HPP_
00006 #define _SIRIKATA_PINTO_MANAGER_HPP_
00007 
00008 #include "PintoManagerBase.hpp"
00009 
00010 #include <prox/geom/QueryHandler.hpp>
00011 #include <prox/base/QueryEventListener.hpp>
00012 #include <prox/base/LocationUpdateListener.hpp>
00013 
00014 #include "PintoManagerLocationServiceCache.hpp"
00015 
00016 namespace Sirikata {
00017 
00023 class PintoManager
00024     : public PintoManagerBase,
00025       public Prox::QueryEventListener<ServerProxSimulationTraits, Prox::Query<ServerProxSimulationTraits> >
00026 {
00027 public:
00028     PintoManager(PintoContext* ctx);
00029     virtual ~PintoManager();
00030 
00031 private:
00032     typedef Prox::QueryHandler<ServerProxSimulationTraits> ProxQueryHandler;
00033     typedef Prox::Query<ServerProxSimulationTraits> Query;
00034     typedef Prox::QueryEvent<ServerProxSimulationTraits> QueryEvent;
00035 
00036     // PintoManagerBase overrides
00037     virtual void onConnected(Sirikata::Network::Stream* newStream);
00038     virtual void onInitialMessage(Sirikata::Network::Stream* stream);
00039     virtual void onRegionUpdate(Sirikata::Network::Stream* stream, BoundingSphere3f bounds);
00040     virtual void onMaxSizeUpdate(Sirikata::Network::Stream* stream, float32 ms);
00041     virtual void onQueryUpdate(Sirikata::Network::Stream* stream, const String& update);
00042     virtual void onDisconnected(Sirikata::Network::Stream* stream);
00043 
00044 
00045     // QueryEventListener Interface
00046     virtual void queryHasEvents(Query* query);
00047 
00048     // Command handlers
00049     virtual void commandProperties(const Command::Command& cmd, Command::Commander* cmdr, Command::CommandID cmdid);
00050     virtual void commandListHandlers(const Command::Command& cmd, Command::Commander* cmdr, Command::CommandID cmdid);
00051     virtual void commandForceRebuild(const Command::Command& cmd, Command::Commander* cmdr, Command::CommandID cmdid);
00052     virtual void commandListNodes(const Command::Command& cmd, Command::Commander* cmdr, Command::CommandID cmdid);
00053     virtual void commandListQueriers(const Command::Command& cmd, Command::Commander* cmdr, Command::CommandID cmdid);
00054     virtual void commandStats(const Command::Command& cmd, Command::Commander* cmdr, Command::CommandID cmdid);
00055 
00056 
00057     // Tick the QueryHandler. We don't actually care about time since Servers
00058     // won't be in motion. Should only be called when the server data or query
00059     // data is updated.
00060     void tick();
00061 
00062     struct ClientData {
00063         ClientData()
00064          : query(NULL)
00065         {}
00066 
00067         Query* query;
00068     };
00069     typedef std::tr1::unordered_map<Sirikata::Network::Stream*, ClientData> ClientDataMap;
00070     ClientDataMap mClients;
00071     // Reverse index for queryHasEvents callbacks
00072     typedef std::tr1::unordered_map<Query*, Sirikata::Network::Stream*> ClientsByQuery;
00073     ClientsByQuery mClientsByQuery;
00074 
00075     ProxQueryHandler* mQueryHandler;
00076     Time mLastTime;
00077     Duration mDt;
00078 };
00079 
00080 } // namespace Sirikata
00081 
00082 #endif //_SIRIKATA_PINTO_MANAGER_HPP_