Sirikata
|
#include <EmersonHttpManager.hpp>
Public Types | |
typedef uint32 | EmersonHttpToken |
typedef std::tr1::shared_ptr < Transfer::HttpManager::HttpResponse > | HttpRespPtr |
Public Member Functions | |
EmersonHttpManager (JSCtx *ctx) | |
~EmersonHttpManager () | |
void | deregisterContext (JSContextStruct *toDeregister) |
EmersonHttpToken | makeRequest (Sirikata::Network::Address addr, Transfer::HttpManager::HTTP_METHOD method, std::string req, v8::Persistent< v8::Function > cb, JSContextStruct *jscont) |
Each request sent out is associated with a unique EmersonHttpToken taken from currentToken (currentToken is incremented as a result of this call). | |
Private Types | |
typedef std::map < EmersonHttpToken, EmersonHttpToken > | TokenMap |
typedef TokenMap::iterator | TokenMapIter |
typedef std::pair < JSContextStruct *, v8::Persistent < v8::Function > > | ContextCBPair |
typedef std::map < EmersonHttpToken, ContextCBPair > | TokenCBMap |
typedef TokenCBMap::iterator | TokenCBMapIter |
typedef std::map < JSContextStruct *, TokenMap > | ContextTokenMap |
typedef ContextTokenMap::iterator | ContextTokenMapIter |
Private Member Functions | |
void | receiveHttpResponse (EmersonHttpToken respToken, HttpRespPtr hrp, Transfer::HttpManager::ERR_TYPE error, const boost::system::error_code &boost_error) |
Whenever we issue an http request, we wrap this function as the httpcallback. | |
void | postReceiveResp (EmersonHttpToken respToken, HttpRespPtr hrp, Transfer::HttpManager::ERR_TYPE error, const boost::system::error_code &boost_error) |
void | debugPrintTokenMap () |
void | debugPrintContextMap () |
Private Attributes | |
EmersonHttpToken | currentToken |
ContextTokenMap | ctxTokeMap |
For each context, ctxTokeMap tracks all the outstanding http tokens for this existing context. | |
TokenCBMap | tokeCBMap |
For each token, can re-access its context struct and callback function from tokeCBMap. | |
EmersonHttpPtr | managerLiveness |
JSCtx * | mContext |
typedef std::pair<JSContextStruct* , v8::Persistent<v8::Function> > Sirikata::JS::EmersonHttpManager::ContextCBPair [private] |
typedef std::map<JSContextStruct*, TokenMap> Sirikata::JS::EmersonHttpManager::ContextTokenMap [private] |
typedef ContextTokenMap::iterator Sirikata::JS::EmersonHttpManager::ContextTokenMapIter [private] |
typedef uint32 Sirikata::JS::EmersonHttpManager::EmersonHttpToken |
typedef std::tr1::shared_ptr<Transfer::HttpManager::HttpResponse> Sirikata::JS::EmersonHttpManager::HttpRespPtr |
typedef std::map<EmersonHttpToken, ContextCBPair> Sirikata::JS::EmersonHttpManager::TokenCBMap [private] |
typedef TokenCBMap::iterator Sirikata::JS::EmersonHttpManager::TokenCBMapIter [private] |
typedef std::map<EmersonHttpToken, EmersonHttpToken> Sirikata::JS::EmersonHttpManager::TokenMap [private] |
typedef TokenMap::iterator Sirikata::JS::EmersonHttpManager::TokenMapIter [private] |
Sirikata::JS::EmersonHttpManager::EmersonHttpManager | ( | JSCtx * | ctx | ) |
References managerLiveness.
Sirikata::JS::EmersonHttpManager::~EmersonHttpManager | ( | ) |
void Sirikata::JS::EmersonHttpManager::debugPrintContextMap | ( | ) | [private] |
References ctxTokeMap, and tokeCBMap.
void Sirikata::JS::EmersonHttpManager::debugPrintTokenMap | ( | ) | [private] |
References tokeCBMap.
void Sirikata::JS::EmersonHttpManager::deregisterContext | ( | JSContextStruct * | toDeregister | ) |
References ctxTokeMap, Sirikata::Logging::detailed, Sirikata::Logging::error, JSLOG, and tokeCBMap.
EmersonHttpManager::EmersonHttpToken Sirikata::JS::EmersonHttpManager::makeRequest | ( | Sirikata::Network::Address | addr, |
Transfer::HttpManager::HTTP_METHOD | method, | ||
std::string | req, | ||
v8::Persistent< v8::Function > | cb, | ||
JSContextStruct * | jscont | ||
) |
Each request sent out is associated with a unique EmersonHttpToken taken from currentToken (currentToken is incremented as a result of this call).
If never sent a request from this from this context (ie, ctxTokeMap[jscont] is undefined), creates a new element in ctxTokeMap indexed by jscont.
Appends token associated with request to entry in ctxTokeMap[jscont]. Also, creates a new entry in tokeCBMap that associates this request's token with jscont and cb.
Returns the token associated with the request: in the future, may allow a user him/herself, to cancel an http request.
References ctxTokeMap, currentToken, Sirikata::SelfWeakPtr< EmersonHttpManager >::getSharedPtr(), Sirikata::Transfer::HttpManager::getSingleton(), Sirikata::Transfer::HttpManager::makeRequest(), managerLiveness, receiveHttpResponse(), and tokeCBMap.
void Sirikata::JS::EmersonHttpManager::postReceiveResp | ( | EmersonHttpToken | respToken, |
HttpRespPtr | hrp, | ||
Transfer::HttpManager::ERR_TYPE | error, | ||
const boost::system::error_code & | boost_error | ||
) | [private] |
References Sirikata::Transfer::HttpManager::BOOST_ERROR, ctxTokeMap, Sirikata::Logging::detailed, Sirikata::JS::JSSuspendable::getIsSuspended(), Sirikata::JS::JSContextStruct::httpFail(), Sirikata::JS::JSContextStruct::httpSuccess(), Sirikata::Logging::info, JSLOG, managerLiveness, Sirikata::Transfer::HttpManager::REQUEST_PARSING_FAILED, Sirikata::Transfer::HttpManager::RESPONSE_PARSING_FAILED, and tokeCBMap.
Referenced by receiveHttpResponse().
void Sirikata::JS::EmersonHttpManager::receiveHttpResponse | ( | EmersonHttpToken | respToken, |
HttpRespPtr | hrp, | ||
Transfer::HttpManager::ERR_TYPE | error, | ||
const boost::system::error_code & | boost_error | ||
) | [private] |
Whenever we issue an http request, we wrap this function as the httpcallback.
We map what emerson callback and context is associated with this http request with respToken, which can be used as an index to tokeCBMap. If get an error, pass error to callback. If JSContext is null (it had been cleared between the time we sent the query and received its response), do not evaluate callback. If jscontext is suspended, do not evaluate callback and dispose of v8 callback.
In all cases, remove entry from tokeCBMap and remove entry from value of ctxTokeMap.
References Sirikata::JS::JSCtx::initialized(), JSLOG, mContext, Sirikata::JS::JSCtx::objStrand, postReceiveResp(), Sirikata::JS::JSCtx::stopped(), and Sirikata::Logging::warn.
Referenced by makeRequest().
For each context, ctxTokeMap tracks all the outstanding http tokens for this existing context.
For its token map values, each token map key is identical to its index. Use a map so that lookup is fast.
Referenced by debugPrintContextMap(), deregisterContext(), makeRequest(), and postReceiveResp().
Referenced by makeRequest().
Referenced by EmersonHttpManager(), makeRequest(), and postReceiveResp().
JSCtx* Sirikata::JS::EmersonHttpManager::mContext [private] |
Referenced by receiveHttpResponse().
For each token, can re-access its context struct and callback function from tokeCBMap.
Referenced by debugPrintContextMap(), debugPrintTokenMap(), deregisterContext(), makeRequest(), and postReceiveResp().