2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2014-12-01 10:47:38 +00:00
|
|
|
Copyright (c) 2014 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
template <typename TRequest>
|
2014-11-14 23:23:35 +00:00
|
|
|
mtpRequestId MTProtoSession::send(const TRequest &request, RPCResponseHandler callbacks, uint64 msCanWait, bool needsLayer, bool toMainDC, mtpRequestId after) {
|
2014-05-30 08:53:19 +00:00
|
|
|
mtpRequestId requestId = 0;
|
|
|
|
try {
|
2014-11-14 23:23:35 +00:00
|
|
|
uint32 requestSize = request.innerLength() >> 2;
|
|
|
|
mtpRequest reqSerialized(mtpRequestData::prepare(requestSize));
|
2014-05-30 08:53:19 +00:00
|
|
|
request.write(*reqSerialized);
|
|
|
|
|
|
|
|
DEBUG_LOG(("MTP Info: adding request to toSendMap, msCanWait %1").arg(msCanWait));
|
|
|
|
|
2014-11-12 20:30:26 +00:00
|
|
|
reqSerialized->msDate = getms(true); // > 0 - can send without container
|
2014-11-14 23:23:35 +00:00
|
|
|
reqSerialized->needsLayer = needsLayer;
|
2014-11-05 17:43:32 +00:00
|
|
|
if (after) reqSerialized->after = _mtp_internal::getRequest(after);
|
|
|
|
requestId = _mtp_internal::storeRequest(reqSerialized, callbacks);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
sendPrepared(reqSerialized, msCanWait);
|
|
|
|
} catch (Exception &e) {
|
|
|
|
requestId = 0;
|
|
|
|
_mtp_internal::rpcErrorOccured(requestId, callbacks, rpcClientError("NO_REQUEST_ID", QString("send() failed to queue request, exception: %1").arg(e.what())));
|
|
|
|
}
|
|
|
|
if (requestId) _mtp_internal::registerRequest(requestId, toMainDC ? -getDC() : getDC());
|
|
|
|
return requestId;
|
|
|
|
}
|