From b40ce2168b8630540d84a1a0330e6b31b7bbf4ab Mon Sep 17 00:00:00 2001 From: Vladimir Menshakov Date: Thu, 9 Jan 2025 22:08:56 +0000 Subject: [PATCH] pass transactionId to session getDeviceInfo --- mtp/ptp/Device.cpp | 2 +- mtp/ptp/Session.cpp | 33 ++++++++++++++++++--------------- mtp/ptp/Session.h | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/mtp/ptp/Device.cpp b/mtp/ptp/Device.cpp index 7bf189f7..d855115c 100644 --- a/mtp/ptp/Device.cpp +++ b/mtp/ptp/Device.cpp @@ -208,7 +208,7 @@ namespace mtp } msg::DeviceInfo Device::GetInfo() - { return Session::GetDeviceInfo(_packeter); } + { return Session::GetDeviceInfo(_packeter, /*transactionId=*/0); } bool Device::Matches(const std::string & filter) { diff --git a/mtp/ptp/Session.cpp b/mtp/ptp/Session.cpp index 77dd6273..29c53307 100644 --- a/mtp/ptp/Session.cpp +++ b/mtp/ptp/Session.cpp @@ -42,12 +42,27 @@ namespace mtp throw InvalidResponseException(__func__, (RCODE)); \ } while(false) + class Session::Transaction + { + Session * _session; + public: + u32 Id; + + Transaction(Session *session): _session(session) + { session->SetCurrentTransaction(this); } + ~Transaction() + { _session->SetCurrentTransaction(0); } + }; + Session::Session(const PipePacketer & packeter, u32 sessionId): _packeter(packeter), _sessionId(sessionId), _nextTransactionId(1), _transaction(), _getObjectModificationTimeBuggy(false), _separateBulkWrites(false), _defaultTimeout(DefaultTimeout) { - _deviceInfo = GetDeviceInfo(_packeter, _defaultTimeout); + { + Transaction tr(this); + _deviceInfo = GetDeviceInfo(_packeter, tr.Id, _defaultTimeout); + } if (_deviceInfo.Manufacturer == "Microsoft") _separateBulkWrites = true; @@ -63,18 +78,6 @@ namespace mtp Session::~Session() { try { Close(); } catch(const std::exception &ex) { } } - class Session::Transaction - { - Session * _session; - public: - u32 Id; - - Transaction(Session *session): _session(session) - { session->SetCurrentTransaction(this); } - ~Transaction() - { _session->SetCurrentTransaction(0); } - }; - void Session::SetCurrentTransaction(Transaction *transaction) { scoped_mutex_lock l(_transactionMutex); @@ -157,10 +160,10 @@ namespace mtp return Get(transaction.Id, response); } - msg::DeviceInfo Session::GetDeviceInfo(PipePacketer& packeter, int timeout) + msg::DeviceInfo Session::GetDeviceInfo(PipePacketer& packeter, u32 transactionId, int timeout) { ByteArray response; - Send(packeter, OperationRequest(OperationCode::GetDeviceInfo, 0), timeout); + Send(packeter, OperationRequest(OperationCode::GetDeviceInfo, transactionId), timeout); auto info = Get(packeter, 0, response, timeout); return ParseResponse(info); } diff --git a/mtp/ptp/Session.h b/mtp/ptp/Session.h index 240ab408..5fb2c626 100644 --- a/mtp/ptp/Session.h +++ b/mtp/ptp/Session.h @@ -144,7 +144,7 @@ namespace mtp //windows specific void EnableSecureFileOperations(u32 cmac1[4]); - static msg::DeviceInfo GetDeviceInfo(PipePacketer& packeter, int timeout = 0); + static msg::DeviceInfo GetDeviceInfo(PipePacketer& packeter, u32 transactionId, int timeout = 0); private: template