Ejemplo n.º 1
0
	void execCallback(mtpRequestId requestId, const mtpPrime *from, const mtpPrime *end) {
		RPCResponseHandler h;
		{
			QMutexLocker locker(&parserMapLock);
			ParserMap::iterator i = parserMap.find(requestId);
			if (i != parserMap.cend()) {
				h = i.value();
				parserMap.erase(i);

				DEBUG_LOG(("RPC Info: found parser for request %1, trying to parse response..").arg(requestId));
			}
		}
		if (h.onDone || h.onFail) {
			try {
				if (from >= end) throw mtpErrorInsufficient();

				if (*from == mtpc_rpc_error) {
					RPCError err(MTPRpcError(from, end));
					DEBUG_LOG(("RPC Info: error received, code %1, type %2, description: %3").arg(err.code()).arg(err.type()).arg(err.description()));
					if (!rpcErrorOccured(requestId, h, err)) {
						QMutexLocker locker(&parserMapLock);
						parserMap.insert(requestId, h);
						return;
					}
				} else {
					if (h.onDone) (*h.onDone)(requestId, from, end);
				}
			} catch (Exception &e) {
				if (!rpcErrorOccured(requestId, h, rpcClientError("RESPONSE_PARSE_FAILED", QString("exception text: ") + e.what()))) {
					QMutexLocker locker(&parserMapLock);
					parserMap.insert(requestId, h);
					return;
				}
			}
		} else {
			DEBUG_LOG(("RPC Info: parser not found for %1").arg(requestId));
		}
		unregisterRequest(requestId);
	}
Ejemplo n.º 2
0
    bool waitRequest( const uint32_t requestID_, Request::Result& result,
                      const uint32_t timeout )
        {
            result.rUint128.low = 0;
            result.rUint128.high = 0;
            Request* request = 0;
            {
                ScopedFastWrite mutex( lock );
                RequestHashCIter i = requests.find( requestID_ );
                if( i == requests.end( ))
                    return false;

                request = i->second;
            }

            const bool requestServed = request->lock.set( timeout );
            if( requestServed )
                result = request->result;

            unregisterRequest( requestID_ );
            return requestServed;
        }