Sirikata
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
Sirikata::JS::EmersonHttpManager Class Reference

#include <EmersonHttpManager.hpp>

Inheritance diagram for Sirikata::JS::EmersonHttpManager:
Collaboration diagram for Sirikata::JS::EmersonHttpManager:

List of all members.

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
JSCtxmContext

Member Typedef Documentation

typedef std::pair<JSContextStruct* , v8::Persistent<v8::Function> > Sirikata::JS::EmersonHttpManager::ContextCBPair [private]
typedef ContextTokenMap::iterator Sirikata::JS::EmersonHttpManager::ContextTokenMapIter [private]
typedef TokenCBMap::iterator Sirikata::JS::EmersonHttpManager::TokenCBMapIter [private]
typedef TokenMap::iterator Sirikata::JS::EmersonHttpManager::TokenMapIter [private]

Constructor & Destructor Documentation

Sirikata::JS::EmersonHttpManager::EmersonHttpManager ( JSCtx ctx)

References managerLiveness.

Sirikata::JS::EmersonHttpManager::~EmersonHttpManager ( )

Member Function Documentation

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)
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]
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().


Member Data Documentation

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 receiveHttpResponse().

For each token, can re-access its context struct and callback function from tokeCBMap.

Referenced by debugPrintContextMap(), debugPrintTokenMap(), deregisterContext(), makeRequest(), and postReceiveResp().


The documentation for this class was generated from the following files: