summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--media/mtp/MtpDatabase.h15
-rw-r--r--media/mtp/MtpServer.cpp34
-rw-r--r--media/mtp/MtpServer.h1
3 files changed, 36 insertions, 14 deletions
diff --git a/media/mtp/MtpDatabase.h b/media/mtp/MtpDatabase.h
index 1566a11..7feb3dc 100644
--- a/media/mtp/MtpDatabase.h
+++ b/media/mtp/MtpDatabase.h
@@ -27,16 +27,25 @@ class MtpDatabase {
public:
virtual ~MtpDatabase() {}
- virtual MtpObjectHandle addFile(const char* path,
+ // called from SendObjectInfo to reserve a database entry for the incoming file
+ virtual MtpObjectHandle beginSendObject(const char* path,
MtpObjectFormat format,
MtpObjectHandle parent,
MtpStorageID storage,
uint64_t size,
time_t modified) = 0;
+ // called to report success or failure of the SendObject file transfer
+ // success should signal a notification of the new object's creation,
+ // failure should remove the database entry created in beginSendObject
+ virtual void endSendObject(const char* path,
+ MtpObjectHandle handle,
+ MtpObjectFormat format,
+ bool succeeded) = 0;
+
virtual MtpObjectHandleList* getObjectList(MtpStorageID storageID,
- MtpObjectFormat format,
- MtpObjectHandle parent) = 0;
+ MtpObjectFormat format,
+ MtpObjectHandle parent) = 0;
virtual MtpResponseCode getObjectProperty(MtpObjectHandle handle,
MtpObjectProperty property,
diff --git a/media/mtp/MtpServer.cpp b/media/mtp/MtpServer.cpp
index 5a16a03..e8f09fa 100644
--- a/media/mtp/MtpServer.cpp
+++ b/media/mtp/MtpServer.cpp
@@ -123,6 +123,7 @@ MtpServer::MtpServer(int fd, MtpDatabase* database,
mSessionID(0),
mSessionOpen(false),
mSendObjectHandle(kInvalidObjectHandle),
+ mSendObjectFormat(0),
mSendObjectFileSize(0)
{
initObjectProperties();
@@ -519,8 +520,8 @@ MtpResponseCode MtpServer::doSendObjectInfo() {
path += (const char *)name;
mDatabase->beginTransaction();
- MtpObjectHandle handle = mDatabase->addFile((const char*)path, format, parent, storageID,
- mSendObjectFileSize, modifiedTime);
+ MtpObjectHandle handle = mDatabase->beginSendObject((const char*)path,
+ format, parent, storageID, mSendObjectFileSize, modifiedTime);
if (handle == kInvalidObjectHandle) {
mDatabase->rollbackTransaction();
return MTP_RESPONSE_GENERAL_ERROR;
@@ -538,6 +539,7 @@ MtpResponseCode MtpServer::doSendObjectInfo() {
mSendObjectFilePath = path;
// save the handle for the SendObject call, which should follow
mSendObjectHandle = handle;
+ mSendObjectFormat = format;
}
mResponse.setParameter(1, storageID);
@@ -548,13 +550,18 @@ MtpResponseCode MtpServer::doSendObjectInfo() {
}
MtpResponseCode MtpServer::doSendObject() {
+ MtpResponseCode result = MTP_RESPONSE_OK;
+ mode_t mask;
+ int ret;
+
if (mSendObjectHandle == kInvalidObjectHandle) {
LOGE("Expected SendObjectInfo before SendObject");
- return MTP_RESPONSE_NO_VALID_OBJECT_INFO;
+ result = MTP_RESPONSE_NO_VALID_OBJECT_INFO;
+ goto done;
}
// read the header
- int ret = mData.readDataHeader(mFD);
+ ret = mData.readDataHeader(mFD);
// FIXME - check for errors here.
// reset so we don't attempt to send this back
@@ -563,11 +570,12 @@ MtpResponseCode MtpServer::doSendObject() {
mtp_file_range mfr;
mfr.fd = open(mSendObjectFilePath, O_RDWR | O_CREAT | O_TRUNC);
if (mfr.fd < 0) {
- return MTP_RESPONSE_GENERAL_ERROR;
+ result = MTP_RESPONSE_GENERAL_ERROR;
+ goto done;
}
fchown(mfr.fd, getuid(), mFileGroup);
// set permissions
- mode_t mask = umask(0);
+ mask = umask(0);
fchmod(mfr.fd, mFilePermission);
umask(mask);
@@ -578,18 +586,22 @@ MtpResponseCode MtpServer::doSendObject() {
ret = ioctl(mFD, MTP_RECEIVE_FILE, (unsigned long)&mfr);
close(mfr.fd);
- // FIXME - we need to delete mSendObjectHandle from the database if this fails.
LOGV("MTP_RECEIVE_FILE returned %d", ret);
- mSendObjectHandle = kInvalidObjectHandle;
if (ret < 0) {
unlink(mSendObjectFilePath);
if (errno == ECANCELED)
- return MTP_RESPONSE_TRANSACTION_CANCELLED;
+ result = MTP_RESPONSE_TRANSACTION_CANCELLED;
else
- return MTP_RESPONSE_GENERAL_ERROR;
+ result = MTP_RESPONSE_GENERAL_ERROR;
}
- return MTP_RESPONSE_OK;
+
+done:
+ mDatabase->endSendObject(mSendObjectFilePath, mSendObjectHandle, mSendObjectFormat,
+ result == MTP_RESPONSE_OK);
+ mSendObjectHandle = kInvalidObjectHandle;
+ mSendObjectFormat = 0;
+ return result;
}
MtpResponseCode MtpServer::doDeleteObject() {
diff --git a/media/mtp/MtpServer.h b/media/mtp/MtpServer.h
index afba846..37b1cbe 100644
--- a/media/mtp/MtpServer.h
+++ b/media/mtp/MtpServer.h
@@ -60,6 +60,7 @@ private:
// handle for new object, set by SendObjectInfo and used by SendObject
MtpObjectHandle mSendObjectHandle;
+ MtpObjectFormat mSendObjectFormat;
MtpString mSendObjectFilePath;
size_t mSendObjectFileSize;