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_LIBSPACE_MASTER_PINTO_SERVER_QUERIER_BASE_HPP_ 00006 #define _SIRIKATA_LIBSPACE_MASTER_PINTO_SERVER_QUERIER_BASE_HPP_ 00007 00008 #include <sirikata/space/PintoServerQuerier.hpp> 00009 #include <sirikata/core/network/IOStrand.hpp> 00010 #include <sirikata/core/network/Stream.hpp> 00011 #include <sirikata/space/SpaceContext.hpp> 00012 00013 #define OPT_MASTER_PINTO_PROTOCOL "protocol" 00014 #define OPT_MASTER_PINTO_PROTOCOL_OPTIONS "protocol-options" 00015 #define OPT_MASTER_PINTO_HOST "host" 00016 #define OPT_MASTER_PINTO_PORT "port" 00017 00018 namespace Sirikata { 00019 00020 namespace Protocol { 00021 namespace MasterPinto { 00022 class PintoResponse; 00023 } 00024 } 00025 00026 00035 class MasterPintoServerQuerierBase : public PintoServerQuerier { 00036 public: 00037 MasterPintoServerQuerierBase(SpaceContext* ctx, const String& params); 00038 virtual ~MasterPintoServerQuerierBase(); 00039 00040 // Service Interface 00041 virtual void start(); 00042 virtual void stop(); 00043 00044 // PintoServerQuerier Interface 00045 virtual void updateRegion(const BoundingBox3f& region); 00046 virtual void updateLargestObject(float max_radius); 00047 virtual void updateQuery(const String& update) = 0; 00048 00049 protected: 00050 00051 // Connection events for implementations 00052 // onConnected - invoked when connection to pinto server is made, allowing 00053 // you to, e.g., initialize queries 00054 virtual void onConnected() {} 00055 // onDisconnected - invoked when connection to pinto server is lost, 00056 // allowing you to, e.g., clean up data. 00057 virtual void onDisconnected() {} 00058 00059 // Data events for implementations - a message has been received. The data 00060 // should be processed by the implementation 00061 virtual void onPintoData(const String& data) = 0; 00062 00063 // Helpers 00064 enum QueueUpdateType { 00065 QueueUpdate, 00066 DoNotQueueUpdate 00067 }; 00068 // Send a query update, or, if not connected yet, possibly queue it to be 00069 // sent later 00070 void sendQueryUpdate(const String& data, QueueUpdateType queue = QueueUpdate); 00071 00072 private: 00073 // Connection management 00074 void connect(); 00075 bool connected() { return mConnected; } 00076 00077 // Handlers for mServerStream 00078 void handleServerConnection(Network::Stream::ConnectionStatus status, const std::string &reason); 00079 void handleServerReceived(Network::Chunk& data, const Network::Stream::PauseReceiveCallback& pause); 00080 void handleServerReadySend(); 00081 00082 // If connected and any properties are marked as dirty, tries to 00083 // send an update to the server 00084 void tryServerUpdate(); 00085 00086 protected: 00087 SpaceContext* mContext; 00088 00089 Network::IOStrand* mIOStrand; 00090 00091 Network::Stream* mServerStream; 00092 00093 private: 00094 String mHost; 00095 String mPort; 00096 00097 bool mConnecting; 00098 bool mConnected; 00099 bool mGaveID; 00100 00101 BoundingBox3f mRegion; 00102 bool mRegionDirty; 00103 float32 mMaxRadius; 00104 bool mMaxRadiusDirty; 00105 00106 std::vector<String> mQueuedQueryUpdates; 00107 }; // MasterPintoServerQuerierBase 00108 00109 } // namespace Sirikata 00110 00111 #endif //_SIRIKATA_LIBSPACE_MASTER_PINTO_SERVER_QUERIER_BASE_HPP_