Sirikata
|
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_BASE_HPP_ 00006 #define _SIRIKATA_PINTO_MANAGER_BASE_HPP_ 00007 00008 #include "PintoContext.hpp" 00009 #include <sirikata/core/service/Service.hpp> 00010 #include <sirikata/core/network/StreamListener.hpp> 00011 #include <sirikata/core/network/Stream.hpp> 00012 00013 #include "ProxSimulationTraits.hpp" 00014 00015 #include <prox/base/QueryEventListener.hpp> 00016 #include <prox/base/AggregateListener.hpp> 00017 00018 #include "PintoManagerLocationServiceCache.hpp" 00019 00020 #include <sirikata/pintoloc/BaseProxCommandable.hpp> 00021 00022 namespace Sirikata { 00023 00029 class PintoManagerBase 00030 : public Service, 00031 public Prox::AggregateListener<ServerProxSimulationTraits>, 00032 Pinto::BaseProxCommandable 00033 { 00034 public: 00035 typedef Prox::Aggregator<ServerProxSimulationTraits> ProxAggregator; 00036 00037 PintoManagerBase(PintoContext* ctx); 00038 virtual ~PintoManagerBase(); 00039 00040 virtual void start(); 00041 virtual void stop(); 00042 00043 private: 00044 void newStreamCallback(Sirikata::Network::Stream* newStream, Sirikata::Network::Stream::SetCallbacks& setCallbacks); 00045 00046 void handleClientConnection(Sirikata::Network::Stream* stream, Network::Stream::ConnectionStatus status, const std::string &reason); 00047 void handleClientReceived(Sirikata::Network::Stream* stream, Network::Chunk& data, const Network::Stream::PauseReceiveCallback& pause) ; 00048 void handleClientReadySend(Sirikata::Network::Stream* stream); 00049 00050 protected: 00051 // Events that implementations might care about 00052 virtual void onConnected(Sirikata::Network::Stream* newStream); 00053 virtual void onInitialMessage(Sirikata::Network::Stream* stream); 00054 virtual void onRegionUpdate(Sirikata::Network::Stream* stream, BoundingSphere3f bounds); 00055 virtual void onMaxSizeUpdate(Sirikata::Network::Stream* stream, float32 ms); 00056 virtual void onQueryUpdate(Sirikata::Network::Stream* stream, const String& update); 00057 virtual void onDisconnected(Sirikata::Network::Stream* stream); 00058 00059 00060 // AggregateListener Interface 00061 virtual void aggregateCreated(ProxAggregator* handler, const ServerID& objid); 00062 virtual void aggregateChildAdded(ProxAggregator* handler, const ServerID& objid, const ServerID& child, const Vector3f& bnds_center, const float32 bnds_center_radius, const float32 max_obj_size); 00063 virtual void aggregateChildRemoved(ProxAggregator* handler, const ServerID& objid, const ServerID& child, const Vector3f& bnds_center, const float32 bnds_center_radius, const float32 max_obj_size); 00064 virtual void aggregateBoundsUpdated(ProxAggregator* handler, const ServerID& objid, const Vector3f& bnds_center, const float32 bnds_center_radius, const float32 max_obj_size); 00065 virtual void aggregateDestroyed(ProxAggregator* handler, const ServerID& objid); 00066 virtual void aggregateObserved(ProxAggregator* handler, const ServerID& objid, uint32 nobservers, uint32 nchildren); 00067 00068 00069 // Utility for implementations so they don't have to track ServerIDs 00070 ServerID streamServerID(Sirikata::Network::Stream*) const; 00071 00072 00073 PintoContext* mContext; 00074 Network::IOStrand* mStrand; 00075 Network::StreamListener* mListener; 00076 00077 PintoManagerLocationServiceCache* mLocCache; 00078 00079 private: 00080 typedef std::tr1::unordered_map<Sirikata::Network::Stream*, ServerID> StreamServerIDMap; 00081 StreamServerIDMap mStreamServers; 00082 }; // class PintoManagerBase 00083 00084 } // namespace Sirikata 00085 00086 #endif //_SIRIKATA_PINTO_MANAGER_BASE_HPP_