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_HTTP_SERVERID_MAP_HPP_ 00006 #define _SIRIKATA_HTTP_SERVERID_MAP_HPP_ 00007 00008 #include <sirikata/core/network/ServerIDMap.hpp> 00009 #include <sirikata/core/transfer/HttpManager.hpp> 00010 00011 namespace Sirikata { 00012 00018 class HttpServerIDMap : public ServerIDMap { 00019 const String mInternalHost; 00020 const String mInternalService; 00021 const String mInternalPath; 00022 00023 const String mExternalHost; 00024 const String mExternalService; 00025 const String mExternalPath; 00026 00027 const uint32 mRetries; 00028 00029 struct RequestInfo { 00030 RequestInfo( 00031 const ServerID& _sid, Address4LookupCallback _cb, 00032 const String& _host, 00033 const String& _service, 00034 const String& _path) 00035 : sid(_sid), cb(_cb), host(_host), service(_service), path(_path) 00036 {} 00037 00038 const ServerID sid; 00039 const Address4LookupCallback cb; 00040 const String host; 00041 const String service; 00042 const String path; 00043 }; 00044 00045 void startLookup( 00046 const RequestInfo& ri, 00047 const uint32 retry 00048 ); 00049 void finishLookup( 00050 const RequestInfo& ri, 00051 const uint32 retry, 00052 Transfer::HttpManager::HttpResponsePtr response, 00053 Transfer::HttpManager::ERR_TYPE error, 00054 const boost::system::error_code &boost_error); 00055 // Returns true if retrying. If returns false, caller should report error. 00056 bool retryOrFail( 00057 const RequestInfo& ri, 00058 const uint32 retry 00059 ); 00060 public: 00061 HttpServerIDMap( 00062 Context* ctx, 00063 const String& internal_host, const String& internal_service, const String& internal_path, 00064 const String& external_host, const String& external_service, const String& external_path, 00065 uint32 retries 00066 ); 00067 virtual ~HttpServerIDMap() {} 00068 00069 virtual void lookupInternal(const ServerID& sid, Address4LookupCallback cb); 00070 virtual void lookupExternal(const ServerID& sid, Address4LookupCallback cb); 00071 virtual void lookupRandomExternal(Address4LookupCallback cb); 00072 }; 00073 00074 } // namespace Sirikata 00075 00076 #endif //_SIRIKATA_HTTP_SERVERID_MAP_HPP_