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 17#define LOG_TAG "MtpDeviceInfo" 18 19#include "MtpDebug.h" 20#include "MtpDataPacket.h" 21#include "MtpDeviceInfo.h" 22#include "MtpStringBuffer.h" 23 24namespace android { 25 26MtpDeviceInfo::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 44MtpDeviceInfo::~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 62void 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 90void MtpDeviceInfo::print() { 91 ALOGV("Device Info:\n\tmStandardVersion: %d\n\tmVendorExtensionID: %d\n\tmVendorExtensionVersiony: %d\n", 92 mStandardVersion, mVendorExtensionID, mVendorExtensionVersion); 93 ALOGV("\tmVendorExtensionDesc: %s\n\tmFunctionalCode: %d\n\tmManufacturer: %s\n\tmModel: %s\n\tmVersion: %s\n\tmSerial: %s\n", 94 mVendorExtensionDesc, mFunctionalCode, mManufacturer, mModel, mVersion, mSerial); 95} 96 97} // namespace android 98