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