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

Commit 66a9abef authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Add getObjectPropValue function to MtpDevice.

In the MTP spec, the object size is stored in MtpObjectInfo as unsigned
32-bit integer and fetched by the getObjectInfo operation. For the
objects that are more than 4GB, the object size is provided as one of
extra properties, which are fetched by different operation.

The CL adds to getObjectPropValue method to MtpDevice class so that
client code can obtain 4GB+ object size from object property.

BUG=27805369

Change-Id: I0b91facd07cdc19866cb29f7df08bb1698bcf60b
parent 6fbc20c9
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -611,7 +611,7 @@ MtpProperty* MtpDevice::getObjectPropDesc(MtpObjectProperty code, MtpObjectForma
        return NULL;
    if (!readData())
        return NULL;
    MtpResponseCode ret = readResponse();
    const MtpResponseCode ret = readResponse();
    if (ret == MTP_RESPONSE_OK) {
        MtpProperty* property = new MtpProperty;
        if (property->read(mData))
@@ -622,6 +622,25 @@ MtpProperty* MtpDevice::getObjectPropDesc(MtpObjectProperty code, MtpObjectForma
    return NULL;
}

bool MtpDevice::getObjectPropValue(MtpObjectHandle handle, MtpProperty* property) {
    if (property == nullptr)
        return false;

    Mutex::Autolock autoLock(mMutex);

    mRequest.reset();
    mRequest.setParameter(1, handle);
    mRequest.setParameter(2, property->getPropertyCode());
    if (!sendRequest(MTP_OPERATION_GET_OBJECT_PROP_VALUE))
        return false;
    if (!readData())
        return false;
    if (readResponse() != MTP_RESPONSE_OK)
        return false;
    property->setCurrentValue(mData);
    return true;
}

bool MtpDevice::readObject(MtpObjectHandle handle,
                           ReadObjectCallback callback,
                           uint32_t expectedLength,
+3 −0
Original line number Diff line number Diff line
@@ -107,6 +107,9 @@ public:
    MtpProperty*            getDevicePropDesc(MtpDeviceProperty code);
    MtpProperty*            getObjectPropDesc(MtpObjectProperty code, MtpObjectFormat format);

    // Reads value of |property| for |handle|. Returns true on success.
    bool                    getObjectPropValue(MtpObjectHandle handle, MtpProperty* property);

    bool                    readObject(MtpObjectHandle handle, ReadObjectCallback callback,
                                    uint32_t objectSize, void* clientData);
    bool                    readObject(MtpObjectHandle handle, const char* destPath, int group,
+6 −0
Original line number Diff line number Diff line
@@ -236,6 +236,12 @@ void MtpProperty::setCurrentValue(const uint16_t* string) {
        mCurrentValue.str = NULL;
}

void MtpProperty::setCurrentValue(MtpDataPacket& packet) {
    free(mCurrentValue.str);
    mCurrentValue.str = NULL;
    readValue(packet, mCurrentValue);
}

void MtpProperty::setFormRange(int min, int max, int step) {
    mFormFlag = kFormRange;
    switch (mType) {
+4 −1
Original line number Diff line number Diff line
@@ -81,13 +81,16 @@ public:
                                     int defaultValue = 0);
    virtual             ~MtpProperty();

    inline MtpPropertyCode getPropertyCode() const { return mCode; }
    MtpPropertyCode getPropertyCode() const { return mCode; }
    MtpDataType getDataType() const { return mType; }

    bool                read(MtpDataPacket& packet);
    void                write(MtpDataPacket& packet);

    void                setDefaultValue(const uint16_t* string);
    void                setCurrentValue(const uint16_t* string);
    void                setCurrentValue(MtpDataPacket& packet);
    const MtpPropertyValue& getCurrentValue() { return mCurrentValue; }

    void                setFormRange(int min, int max, int step);
    void                setFormEnum(const int* values, int count);