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

Commit 15ac558b authored by Daichi Hirono's avatar Daichi Hirono Committed by Android (Google) Code Review
Browse files

Merge "Add getObjectPropValue function to MtpDevice." into nyc-dev

parents 63870faf 66a9abef
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);