Skip to content

Commit

Permalink
pass transactionId to session getDeviceInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
whoozle committed Jan 9, 2025
1 parent 82e3c29 commit b40ce21
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion mtp/ptp/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
33 changes: 18 additions & 15 deletions mtp/ptp/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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<msg::DeviceInfo>(info);
}
Expand Down
2 changes: 1 addition & 1 deletion mtp/ptp/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename ... Args>
Expand Down

0 comments on commit b40ce21

Please sign in to comment.