Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 37433651 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

PTP host: Implement getObjectHandles and getObjectInfo commands



Change-Id: I3ff6e52237f400b4e50c534a1f964c80789bfe98
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent a2f2a34d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -58,11 +58,13 @@ LOCAL_SRC_FILES:= \
                  MtpDataPacket.cpp                     \
                  MtpDebug.cpp                          \
                  MtpDeviceInfo.cpp                     \
                  MtpObjectInfo.cpp                     \
                  MtpPacket.cpp                         \
                  MtpRequestPacket.cpp                  \
                  MtpResponsePacket.cpp                 \
                  MtpStorageInfo.cpp                    \
                  MtpStringBuffer.cpp                   \
                  MtpUtils.cpp                          \
                  ../../libs/utils/VectorImpl.cpp       \
                  ../../libs/utils/SharedBuffer.cpp     \

+36 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "MtpClient.h"
#include "MtpDebug.h"
#include "MtpDeviceInfo.h"
#include "MtpObjectInfo.h"
#include "MtpStorageInfo.h"
#include "MtpStringBuffer.h"

@@ -46,7 +47,6 @@ MtpClient::MtpClient(struct usb_endpoint *ep_in, struct usb_endpoint *ep_out,
MtpClient::~MtpClient() {
}


bool MtpClient::openSession() {
printf("openSession\n");
    mSessionID = 0;
@@ -118,6 +118,41 @@ printf("getStorageInfo returned %04X\n", ret);
    return NULL;
}

MtpObjectHandleList* MtpClient::getObjectHandles(MtpStorageID storageID,
            MtpObjectFormat format, MtpObjectHandle parent) {
    mRequest.reset();
    mRequest.setParameter(1, storageID);
    mRequest.setParameter(2, format);
    mRequest.setParameter(3, parent);
    if (!sendRequest(MTP_OPERATION_GET_OBJECT_HANDLES))
        return NULL;
    if (!readData())
        return NULL;
    MtpResponseCode ret = readResponse();
printf("getObjectHandles returned %04X\n", ret);
    if (ret == MTP_RESPONSE_OK) {
        return mData.getAUInt32();
    }
    return NULL;
}

MtpObjectInfo* MtpClient::getObjectInfo(MtpObjectHandle handle) {
    mRequest.reset();
    mRequest.setParameter(1, handle);
    if (!sendRequest(MTP_OPERATION_GET_OBJECT_INFO))
        return NULL;
    if (!readData())
        return NULL;
    MtpResponseCode ret = readResponse();
printf("getObjectInfo returned %04X\n", ret);
    if (ret == MTP_RESPONSE_OK) {
        MtpObjectInfo* info = new MtpObjectInfo(handle);
        info->read(mData);
        return info;
    }
    return NULL;
}

bool MtpClient::sendRequest(MtpOperationCode operation) {
    printf("sendRequest: %s\n", MtpDebug::getOperationCodeName(operation));
    mRequest.setOperationCode(operation);
+22 −19
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
namespace android {

class MtpDeviceInfo;
class MtpObjectInfo;
class MtpStorageInfo;

class MtpClient {
@@ -53,6 +54,8 @@ public:
    MtpDeviceInfo*          getDeviceInfo();
    MtpStorageIDList*       getStorageIDs();
    MtpStorageInfo*         getStorageInfo(MtpStorageID storageID);
    MtpObjectHandleList*    getObjectHandles(MtpStorageID storageID, MtpObjectFormat format, MtpObjectHandle parent);
    MtpObjectInfo*          getObjectInfo(MtpObjectHandle handle);

private:
    bool                    sendRequest(MtpOperationCode operation);
+96 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdlib.h>

#include "MtpDataPacket.h"
#include "MtpObjectInfo.h"
#include "MtpStringBuffer.h"
#include "MtpUtils.h"

namespace android {

MtpObjectInfo::MtpObjectInfo(MtpObjectHandle handle)
    :   mHandle(handle),
        mStorageID(0),
        mFormat(0),
        mProtectionStatus(0),
        mCompressedSize(0),
        mThumbFormat(0),
        mThumbCompressedSize(0),
        mThumbPixWidth(0),
        mThumbPixHeight(0),
        mImagePixWidth(0),
        mImagePixHeight(0),
        mImagePixDepth(0),
        mParent(0),
        mAssociationType(0),
        mAssociationDesc(0),
        mSequenceNumber(0),
        mName(NULL),
        mDateCreated(0),
        mDateModified(0),
        mKeywords(NULL)
{
}

MtpObjectInfo::~MtpObjectInfo() {
    if (mName)
        free(mName);
    if (mKeywords)
        free(mKeywords);
}

void MtpObjectInfo::read(MtpDataPacket& packet) {
    MtpStringBuffer string;
    time_t time;

    mStorageID = packet.getUInt32();
    mFormat = packet.getUInt16();
    mProtectionStatus = packet.getUInt16();
    mCompressedSize = packet.getUInt32();
    mThumbFormat = packet.getUInt16();
    mCompressedSize = packet.getUInt32();
    mThumbPixWidth = packet.getUInt32();
    mThumbPixHeight = packet.getUInt32();
    mImagePixWidth = packet.getUInt32();
    mImagePixHeight = packet.getUInt32();
    mImagePixDepth = packet.getUInt32();
    mParent = packet.getUInt32();
    mAssociationType = packet.getUInt16();
    mAssociationDesc = packet.getUInt32();
    mSequenceNumber = packet.getUInt32();

    packet.getString(string);
    mName = strdup((const char *)string);

    packet.getString(string);
    if (parseDateTime((const char*)string, time))
        mDateCreated = time;

    packet.getString(string);
    if (parseDateTime((const char*)string, time))
        mDateModified = time;

    packet.getString(string);
    mKeywords = strdup((const char *)string);
}

void MtpObjectInfo::print() {
    printf("MtpObject Info %08X: %s\n", mHandle, mName);
}

}  // namespace android
+60 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _MTP_OBJECT_INFO_H
#define _MTP_OBJECT_INFO_H

#include "MtpTypes.h"

namespace android {

class MtpDataPacket;

class MtpObjectInfo {
public:
    MtpObjectHandle     mHandle;
    MtpStorageID        mStorageID;
    MtpObjectFormat     mFormat;
    uint16_t            mProtectionStatus;
    uint32_t            mCompressedSize;
    MtpObjectFormat     mThumbFormat;
    uint32_t            mThumbCompressedSize;
    uint32_t            mThumbPixWidth;
    uint32_t            mThumbPixHeight;
    uint32_t            mImagePixWidth;
    uint32_t            mImagePixHeight;
    uint32_t            mImagePixDepth;
    MtpObjectHandle     mParent;
    uint16_t            mAssociationType;
    uint32_t            mAssociationDesc;
    uint32_t            mSequenceNumber;
    char*               mName;
    time_t              mDateCreated;
    time_t              mDateModified;
    char*               mKeywords;

public:
                        MtpObjectInfo(MtpObjectHandle handle);
    virtual             ~MtpObjectInfo();

    void                read(MtpDataPacket& packet);

    void                print();
};

}; // namespace android

#endif // _MTP_OBJECT_INFO_H
Loading