Mike Lockwood | 5bae7f6 | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 17 | #define LOG_TAG "MtpDeviceInfo" |
Mike Lockwood | 5bae7f6 | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 18 | |
Mike Lockwood | 3e6616d | 2010-06-29 18:11:52 -0400 | [diff] [blame] | 19 | #include "MtpDebug.h" |
Mike Lockwood | 5bae7f6 | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 20 | #include "MtpDataPacket.h" |
| 21 | #include "MtpDeviceInfo.h" |
| 22 | #include "MtpStringBuffer.h" |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | MtpDeviceInfo::MtpDeviceInfo() |
| 27 | : mStandardVersion(0), |
| 28 | mVendorExtensionID(0), |
| 29 | mVendorExtensionVersion(0), |
| 30 | mVendorExtensionDesc(NULL), |
| 31 | mFunctionalCode(0), |
| 32 | mOperations(NULL), |
| 33 | mEvents(NULL), |
| 34 | mDeviceProperties(NULL), |
| 35 | mCaptureFormats(NULL), |
| 36 | mPlaybackFormats(NULL), |
| 37 | mManufacturer(NULL), |
| 38 | mModel(NULL), |
| 39 | mVersion(NULL), |
| 40 | mSerial(NULL) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | MtpDeviceInfo::~MtpDeviceInfo() { |
| 45 | if (mVendorExtensionDesc) |
| 46 | free(mVendorExtensionDesc); |
| 47 | delete mOperations; |
| 48 | delete mEvents; |
| 49 | delete mDeviceProperties; |
| 50 | delete mCaptureFormats; |
| 51 | delete mPlaybackFormats; |
| 52 | if (mManufacturer) |
| 53 | free(mManufacturer); |
| 54 | if (mModel) |
| 55 | free(mModel); |
| 56 | if (mVersion) |
| 57 | free(mVersion); |
| 58 | if (mSerial) |
| 59 | free(mSerial); |
| 60 | } |
| 61 | |
| 62 | void MtpDeviceInfo::read(MtpDataPacket& packet) { |
| 63 | MtpStringBuffer string; |
| 64 | |
| 65 | // read the device info |
| 66 | mStandardVersion = packet.getUInt16(); |
| 67 | mVendorExtensionID = packet.getUInt32(); |
| 68 | mVendorExtensionVersion = packet.getUInt16(); |
| 69 | |
| 70 | packet.getString(string); |
| 71 | mVendorExtensionDesc = strdup((const char *)string); |
| 72 | |
| 73 | mFunctionalCode = packet.getUInt16(); |
| 74 | mOperations = packet.getAUInt16(); |
| 75 | mEvents = packet.getAUInt16(); |
| 76 | mDeviceProperties = packet.getAUInt16(); |
| 77 | mCaptureFormats = packet.getAUInt16(); |
| 78 | mPlaybackFormats = packet.getAUInt16(); |
| 79 | |
| 80 | packet.getString(string); |
| 81 | mManufacturer = strdup((const char *)string); |
| 82 | packet.getString(string); |
| 83 | mModel = strdup((const char *)string); |
| 84 | packet.getString(string); |
| 85 | mVersion = strdup((const char *)string); |
| 86 | packet.getString(string); |
| 87 | mSerial = strdup((const char *)string); |
| 88 | } |
| 89 | |
| 90 | void MtpDeviceInfo::print() { |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 91 | ALOGV("Device Info:\n\tmStandardVersion: %d\n\tmVendorExtensionID: %d\n\tmVendorExtensionVersiony: %d\n", |
Mike Lockwood | 5bae7f6 | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 92 | mStandardVersion, mVendorExtensionID, mVendorExtensionVersion); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 93 | ALOGV("\tmVendorExtensionDesc: %s\n\tmFunctionalCode: %d\n\tmManufacturer: %s\n\tmModel: %s\n\tmVersion: %s\n\tmSerial: %s\n", |
Mike Lockwood | 5bae7f6 | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 94 | mVendorExtensionDesc, mFunctionalCode, mManufacturer, mModel, mVersion, mSerial); |
| 95 | } |
| 96 | |
| 97 | } // namespace android |