From 0c7c7c76a96a82ec728a2d5c091941c4057ffb25 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Tue, 7 Dec 2010 11:24:28 -0800 Subject: MTP: Improve MtpProperty logging support Change-Id: I46800b99763edcc5e994d912941f9f5e9b1c94d2 Signed-off-by: Mike Lockwood --- media/mtp/MtpDevice.cpp | 45 ++++++++++++++++++++--- media/mtp/MtpDevice.h | 1 + media/mtp/MtpProperty.cpp | 91 +++++++++++++++++++++++++++++++++++++++++++++-- media/mtp/MtpProperty.h | 1 + 4 files changed, 130 insertions(+), 8 deletions(-) (limited to 'media/mtp') diff --git a/media/mtp/MtpDevice.cpp b/media/mtp/MtpDevice.cpp index a4d29a7..8d682ce 100644 --- a/media/mtp/MtpDevice.cpp +++ b/media/mtp/MtpDevice.cpp @@ -63,17 +63,13 @@ void MtpDevice::initialize() { openSession(); mDeviceInfo = getDeviceInfo(); if (mDeviceInfo) { - mDeviceInfo->print(); - if (mDeviceInfo->mDeviceProperties) { int count = mDeviceInfo->mDeviceProperties->size(); for (int i = 0; i < count; i++) { MtpDeviceProperty propCode = (*mDeviceInfo->mDeviceProperties)[i]; MtpProperty* property = getDevicePropDesc(propCode); - if (property) { - property->print(); + if (property) mDeviceProperties.push(property); - } } } } @@ -87,6 +83,45 @@ void MtpDevice::close() { } } +void MtpDevice::print() { + if (mDeviceInfo) { + mDeviceInfo->print(); + + if (mDeviceInfo->mDeviceProperties) { + LOGI("***** DEVICE PROPERTIES *****\n"); + int count = mDeviceInfo->mDeviceProperties->size(); + for (int i = 0; i < count; i++) { + MtpDeviceProperty propCode = (*mDeviceInfo->mDeviceProperties)[i]; + MtpProperty* property = getDevicePropDesc(propCode); + if (property) { + property->print(); + } + } + } + } + + if (mDeviceInfo->mPlaybackFormats) { + LOGI("***** OBJECT PROPERTIES *****\n"); + int count = mDeviceInfo->mPlaybackFormats->size(); + for (int i = 0; i < count; i++) { + MtpObjectFormat format = (*mDeviceInfo->mPlaybackFormats)[i]; + LOGI("*** FORMAT: %s\n", MtpDebug::getFormatCodeName(format)); + MtpObjectPropertyList* props = getObjectPropsSupported(format); + if (props) { + for (int j = 0; j < props->size(); j++) { + MtpObjectProperty prop = (*props)[j]; + MtpProperty* property = getObjectPropDesc(prop); + if (property) + property->print(); + else + LOGE("could not fetch property: %s", + MtpDebug::getObjectPropCodeName(prop)); + } + } + } + } +} + const char* MtpDevice::getDeviceName() { if (mDevice) return usb_device_get_name(mDevice); diff --git a/media/mtp/MtpDevice.h b/media/mtp/MtpDevice.h index 6eba8c8..c7ba7db 100644 --- a/media/mtp/MtpDevice.h +++ b/media/mtp/MtpDevice.h @@ -67,6 +67,7 @@ public: void initialize(); void close(); + void print(); const char* getDeviceName(); bool openSession(); diff --git a/media/mtp/MtpProperty.cpp b/media/mtp/MtpProperty.cpp index 4356a6f..3b38720 100644 --- a/media/mtp/MtpProperty.cpp +++ b/media/mtp/MtpProperty.cpp @@ -17,6 +17,7 @@ #define LOG_TAG "MtpProperty" #include "MtpDataPacket.h" +#include "MtpDebug.h" #include "MtpProperty.h" #include "MtpStringBuffer.h" #include "MtpUtils.h" @@ -317,9 +318,93 @@ void MtpProperty::setFormDateTime() { } void MtpProperty::print() { - LOGV("MtpProperty %04X\n", mCode); - LOGV(" type %04X\n", mType); - LOGV(" writeable %s\n", (mWriteable ? "true" : "false")); + MtpString buffer; + bool deviceProp = isDeviceProperty(); + if (deviceProp) + LOGI(" %s (%04X)", MtpDebug::getDevicePropCodeName(mCode), mCode); + else + LOGI(" %s (%04X)", MtpDebug::getObjectPropCodeName(mCode), mCode); + LOGI(" type %04X", mType); + LOGI(" writeable %s", (mWriteable ? "true" : "false")); + buffer = " default value: "; + print(mDefaultValue, buffer); + LOGI("%s", (const char *)buffer); + if (deviceProp) { + buffer = " current value: "; + print(mCurrentValue, buffer); + LOGI("%s", (const char *)buffer); + } + switch (mFormFlag) { + case kFormNone: + break; + case kFormRange: + buffer = " Range ("; + print(mMinimumValue, buffer); + buffer += ", "; + print(mMaximumValue, buffer); + buffer += ", "; + print(mStepSize, buffer); + LOGI("%s", (const char *)buffer); + break; + case kFormEnum: + buffer = " Enum { "; + for (int i = 0; i < mEnumLength; i++) { + print(mEnumValues[i], buffer); + buffer += " "; + } + buffer += "}"; + LOGI("%s", (const char *)buffer); + break; + case kFormDateTime: + LOGI(" DateTime\n"); + break; + default: + LOGI(" form %d\n", mFormFlag); + break; + } +} + +void MtpProperty::print(MtpPropertyValue& value, MtpString& buffer) { + switch (mType) { + case MTP_TYPE_INT8: + buffer.appendFormat("%d", value.u.i8); + break; + case MTP_TYPE_UINT8: + buffer.appendFormat("%d", value.u.u8); + break; + case MTP_TYPE_INT16: + buffer.appendFormat("%d", value.u.i16); + break; + case MTP_TYPE_UINT16: + buffer.appendFormat("%d", value.u.u16); + break; + case MTP_TYPE_INT32: + buffer.appendFormat("%d", value.u.i32); + break; + case MTP_TYPE_UINT32: + buffer.appendFormat("%d", value.u.u32); + break; + case MTP_TYPE_INT64: + buffer.appendFormat("%lld", value.u.i64); + break; + case MTP_TYPE_UINT64: + buffer.appendFormat("%lld", value.u.u64); + break; + case MTP_TYPE_INT128: + buffer.appendFormat("%08X%08X%08X%08X", value.u.i128[0], value.u.i128[1], + value.u.i128[2], value.u.i128[3]); + break; + case MTP_TYPE_UINT128: + buffer.appendFormat("%08X%08X%08X%08X", value.u.u128[0], value.u.u128[1], + value.u.u128[2], value.u.u128[3]); + break; + case MTP_TYPE_STR: + buffer.appendFormat("%s", value.str); + break; + default: + LOGE("unsupported type for MtpProperty::print\n"); + break; + } } void MtpProperty::readValue(MtpDataPacket& packet, MtpPropertyValue& value) { diff --git a/media/mtp/MtpProperty.h b/media/mtp/MtpProperty.h index f783a87..06ca56e 100644 --- a/media/mtp/MtpProperty.h +++ b/media/mtp/MtpProperty.h @@ -94,6 +94,7 @@ public: void setFormDateTime(); void print(); + void print(MtpPropertyValue& value, MtpString& buffer); inline bool isDeviceProperty() const { return ( ((mCode & 0xF000) == 0x5000) -- cgit v1.1