bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -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 | * Copyright (C) 2014 TeamWin - bigbiff and Dees_Troy mtp database conversion to C++ |
| 17 | */ |
| 18 | |
| 19 | #include "MtpDebug.h" |
| 20 | #include "MtpDataPacket.h" |
| 21 | #include "MtpDeviceInfo.h" |
| 22 | #include "MtpStringBuffer.h" |
| 23 | |
| 24 | MtpDeviceInfo::MtpDeviceInfo() |
| 25 | : mStandardVersion(0), |
| 26 | mVendorExtensionID(0), |
| 27 | mVendorExtensionVersion(0), |
| 28 | mVendorExtensionDesc(NULL), |
| 29 | mFunctionalCode(0), |
| 30 | mOperations(NULL), |
| 31 | mEvents(NULL), |
| 32 | mDeviceProperties(NULL), |
| 33 | mCaptureFormats(NULL), |
| 34 | mPlaybackFormats(NULL), |
| 35 | mManufacturer(NULL), |
| 36 | mModel(NULL), |
| 37 | mVersion(NULL), |
| 38 | mSerial(NULL) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | MtpDeviceInfo::~MtpDeviceInfo() { |
| 43 | if (mVendorExtensionDesc) |
| 44 | free(mVendorExtensionDesc); |
| 45 | delete mOperations; |
| 46 | delete mEvents; |
| 47 | delete mDeviceProperties; |
| 48 | delete mCaptureFormats; |
| 49 | delete mPlaybackFormats; |
| 50 | if (mManufacturer) |
| 51 | free(mManufacturer); |
| 52 | if (mModel) |
| 53 | free(mModel); |
| 54 | if (mVersion) |
| 55 | free(mVersion); |
| 56 | if (mSerial) |
| 57 | free(mSerial); |
| 58 | } |
| 59 | |
| 60 | void MtpDeviceInfo::read(MtpDataPacket& packet) { |
| 61 | MtpStringBuffer string; |
| 62 | |
| 63 | // read the device info |
| 64 | mStandardVersion = packet.getUInt16(); |
| 65 | mVendorExtensionID = packet.getUInt32(); |
| 66 | mVendorExtensionVersion = packet.getUInt16(); |
| 67 | |
| 68 | packet.getString(string); |
| 69 | mVendorExtensionDesc = strdup((const char *)string); |
| 70 | |
| 71 | mFunctionalCode = packet.getUInt16(); |
| 72 | mOperations = packet.getAUInt16(); |
| 73 | mEvents = packet.getAUInt16(); |
| 74 | mDeviceProperties = packet.getAUInt16(); |
| 75 | mCaptureFormats = packet.getAUInt16(); |
| 76 | mPlaybackFormats = packet.getAUInt16(); |
| 77 | |
| 78 | packet.getString(string); |
| 79 | mManufacturer = strdup((const char *)string); |
| 80 | packet.getString(string); |
| 81 | mModel = strdup((const char *)string); |
| 82 | packet.getString(string); |
| 83 | mVersion = strdup((const char *)string); |
| 84 | packet.getString(string); |
| 85 | mSerial = strdup((const char *)string); |
| 86 | } |
| 87 | |
| 88 | void MtpDeviceInfo::print() { |
| 89 | MTPI("Device Info:\n\tmStandardVersion: %d\n\tmVendorExtensionID: %d\n\tmVendorExtensionVersiony: %d\n", |
| 90 | mStandardVersion, mVendorExtensionID, mVendorExtensionVersion); |
| 91 | MTPI("\tmVendorExtensionDesc: %s\n\tmFunctionalCode: %d\n\tmManufacturer: %s\n\tmModel: %s\n\tmVersion: %s\n\tmSerial: %s\n", |
| 92 | mVendorExtensionDesc, mFunctionalCode, mManufacturer, mModel, mVersion, mSerial); |
| 93 | } |
| 94 | |