Sirikata
|
00001 /* Sirikata 00002 * Proximity.hpp 00003 * 00004 * Copyright (c) 2009, 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 Sirikata 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_SPACE_PROXIMITY_HPP_ 00034 #define _SIRIKATA_SPACE_PROXIMITY_HPP_ 00035 00036 #include <sirikata/space/Platform.hpp> 00037 #include <sirikata/core/util/UUID.hpp> 00038 #include <sirikata/core/util/SolidAngle.hpp> 00039 00040 #include <sirikata/core/service/PollingService.hpp> 00041 00042 #include <sirikata/space/LocationService.hpp> 00043 #include <sirikata/space/CoordinateSegmentation.hpp> 00044 #include <sirikata/space/MigrationDataClient.hpp> 00045 #include <sirikata/space/SpaceNetwork.hpp> 00046 #include <sirikata/space/ObjectHostSession.hpp> 00047 00048 #include <sirikata/core/util/Factory.hpp> 00049 #include <sirikata/pintoloc/BaseProxCommandable.hpp> 00050 00051 namespace Sirikata { 00052 00053 class ProximityInputEvent; 00054 class ProximityOutputEvent; 00055 class AggregateManager; 00056 00057 class SIRIKATA_SPACE_EXPORT Proximity : 00058 public PollingService, 00059 MigrationDataClient, 00060 CoordinateSegmentation::Listener, 00061 SpaceNetworkConnectionListener, 00062 public ObjectSessionListener, 00063 public ObjectHostSessionListener, 00064 protected LocationServiceListener, 00065 protected MessageRecipient, 00066 public Pinto::BaseProxCommandable 00067 { 00068 public: 00069 Proximity(SpaceContext* ctx, LocationService* locservice, CoordinateSegmentation* cseg, SpaceNetwork* net, AggregateManager* aggmgr, const Duration& poll_freq); 00070 virtual ~Proximity(); 00071 00072 // ** These interfaces are required 00073 00074 // Service Interface overrides 00075 virtual void start(); 00076 virtual void stop(); 00077 00078 // Objects 00079 virtual void addQuery(UUID obj, SolidAngle sa, uint32 max_results) = 0; 00080 virtual void addQuery(UUID obj, const String& params) = 0; 00081 virtual void removeQuery(UUID obj) = 0; 00082 00083 // PollingService Interface 00084 virtual void poll(); 00085 00086 // MigrationDataClient Interface 00087 virtual std::string migrationClientTag() = 0; 00088 virtual std::string generateMigrationData(const UUID& obj, ServerID source_server, ServerID dest_server) = 0; 00089 virtual void receiveMigrationData(const UUID& obj, ServerID source_server, ServerID dest_server, const std::string& data) = 0; 00090 00091 // ** These interfaces are stubbed out because you don't necessarily need to 00092 // ** override them. Some subsets, however, are required, i.e. at least 00093 // ** either ObjectSessionListener or ObjectHostSessionListener 00094 00095 // CoordinateSegmentation::Listener Interface 00096 virtual void updatedSegmentation(CoordinateSegmentation* cseg, const std::vector<SegmentationInfo>& new_seg) { } 00097 00098 // SpaceNetworkConnectionListener Interface 00099 virtual void onSpaceNetworkConnected(ServerID sid) { } 00100 virtual void onSpaceNetworkDisconnected(ServerID sid) { } 00101 00102 // ObjectSessionListener Interface 00103 virtual void newSession(ObjectSession* session) { } 00104 virtual void sessionClosed(ObjectSession* session) { } 00105 00106 // ObjectHostSessionListener Interface 00107 virtual void onObjectHostSession(const OHDP::NodeID& id, ObjectHostSessionPtr oh_sess) { } 00108 virtual void onObjectHostSessionEnded(const OHDP::NodeID& id) { } 00109 00110 // LocationServiceListener Interface 00111 // Implement as necessary, some updates may be ignored 00112 00113 // MessageRecipient Interface 00114 virtual void receiveMessage(Message* msg) { } 00115 00116 protected: 00117 00118 // MAIN Thread 00119 00120 // Update stats server 00121 void reportStats(); 00122 00123 virtual int32 objectQueries() const { return 0; } 00124 virtual int32 objectHostQueries() const { return 0; } 00125 virtual int32 serverQueries() const { return 0; } 00126 00127 // Fields 00128 // Thread safe: 00129 00130 SpaceContext* mContext; 00131 Network::IOStrand* mProxStrand; 00132 00133 // NOTE: MAIN Thread access only unless you know the methods are 00134 // thread-safe 00135 00136 LocationService* mLocService; 00137 CoordinateSegmentation* mCSeg; 00138 00139 AggregateManager* mAggregateManager; 00140 00141 // Stats 00142 Poller mStatsPoller; 00143 const String mTimeSeriesObjectQueryCountName; 00144 const String mTimeSeriesObjectHostQueryCountName; 00145 const String mTimeSeriesServerQueryCountName; 00146 00147 }; //class Proximity 00148 00149 00150 class SIRIKATA_SPACE_EXPORT ProximityFactory 00151 : public AutoSingleton<ProximityFactory>, 00152 public Factory6<Proximity*, SpaceContext*, LocationService*, CoordinateSegmentation*, SpaceNetwork*, AggregateManager*, const String&> 00153 { 00154 public: 00155 static ProximityFactory& getSingleton(); 00156 static void destroy(); 00157 }; // class ProximityFactory 00158 00159 00160 } // namespace Sirikata 00161 00162 #endif //_SIRIKATA_SPACE_PROXIMITY_HPP_