Ejemplo n.º 1
0
TTErr WebSocketAnswerManager::ReceiveDiscoverAnswer(TTSymbol from, TTAddress address, const TTValue& value, TTErr error)
{
    TTValue             v;
	TTString            key;
    WebSocketAnswerPtr  anAnswer;
    TTErr               err;
    
    key = from.string();
    key += address.string();
    
	err = mDiscoverAnswers->lookup(TTSymbol(key), v);
    
    if (!err) {
        anAnswer = WebSocketAnswerPtr((TTPtr)v[0]);
        
		if (anAnswer->getState() != TIMEOUT_EXCEEDED) {
			anAnswer->setAnswer(value, error);
			return kTTErrNone;
		}
	}
	else
		cout << "WebSocketAnswerManager::ReceiveDiscoverAnswer can't find a request at " << key << endl;
	
	return kTTErrGeneric;
}
Ejemplo n.º 2
0
void WebSocketAnswerManager::AddDiscoverAnswer(TTSymbol from, TTAddress address, int timeOutInMs)
{
	TTString key = from.string();
    key += address.string();
    
    WebSocketAnswerPtr anAnswer = new WebSocketAnswer();
    anAnswer->setTimeOut(timeOutInMs);
    
    mDiscoverAnswers->append(TTSymbol(key), (TTPtr)anAnswer);
}
Ejemplo n.º 3
0
int WebSocketAnswerManager::CheckDiscoverAnswer(TTSymbol from, TTAddress address, TTValue& value)
{
	int                 state;
    TTValue             v;
	TTString            key;
    WebSocketAnswerPtr  anAnswer;
    TTErr               err;
    
    key = from.string();
    key += address.string();
	
	// Looking for a WebSocketDiscoverAnswer object at the given address
	err = mDiscoverAnswers->lookup(TTSymbol(key), v);
    
    if (!err) {
        anAnswer = WebSocketAnswerPtr((TTPtr)v[0]);
        
        // wait
        anAnswer->wait();
        
		state = anAnswer->getState();
		
		// if an answer is received
		if(state != NO_ANSWER)
		{
			// get the answer
			anAnswer->getAnswer(value);
			mDiscoverAnswers->remove(TTSymbol(key));
            delete anAnswer;
		}
		
		return state;
	} 
	else
		return REQUEST_NOT_SENT;
}