MtpObjectInfo.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #define LOG_TAG "MtpObjectInfo"
  17. #include "MtpDebug.h"
  18. #include "MtpDataPacket.h"
  19. #include "MtpObjectInfo.h"
  20. #include "MtpStringBuffer.h"
  21. #include "MtpUtils.h"
  22. namespace android {
  23. MtpObjectInfo::MtpObjectInfo(MtpObjectHandle handle)
  24. : mHandle(handle),
  25. mStorageID(0),
  26. mFormat(0),
  27. mProtectionStatus(0),
  28. mCompressedSize(0),
  29. mThumbFormat(0),
  30. mThumbCompressedSize(0),
  31. mThumbPixWidth(0),
  32. mThumbPixHeight(0),
  33. mImagePixWidth(0),
  34. mImagePixHeight(0),
  35. mImagePixDepth(0),
  36. mParent(0),
  37. mAssociationType(0),
  38. mAssociationDesc(0),
  39. mSequenceNumber(0),
  40. mName(NULL),
  41. mDateCreated(0),
  42. mDateModified(0),
  43. mKeywords(NULL)
  44. {
  45. }
  46. MtpObjectInfo::~MtpObjectInfo() {
  47. if (mName)
  48. free(mName);
  49. if (mKeywords)
  50. free(mKeywords);
  51. }
  52. bool MtpObjectInfo::read(MtpDataPacket& packet) {
  53. MtpStringBuffer string;
  54. time_t time;
  55. if (!packet.getUInt32(mStorageID)) return false;
  56. if (!packet.getUInt16(mFormat)) return false;
  57. if (!packet.getUInt16(mProtectionStatus)) return false;
  58. if (!packet.getUInt32(mCompressedSize)) return false;
  59. if (!packet.getUInt16(mThumbFormat)) return false;
  60. if (!packet.getUInt32(mThumbCompressedSize)) return false;
  61. if (!packet.getUInt32(mThumbPixWidth)) return false;
  62. if (!packet.getUInt32(mThumbPixHeight)) return false;
  63. if (!packet.getUInt32(mImagePixWidth)) return false;
  64. if (!packet.getUInt32(mImagePixHeight)) return false;
  65. if (!packet.getUInt32(mImagePixDepth)) return false;
  66. if (!packet.getUInt32(mParent)) return false;
  67. if (!packet.getUInt16(mAssociationType)) return false;
  68. if (!packet.getUInt32(mAssociationDesc)) return false;
  69. if (!packet.getUInt32(mSequenceNumber)) return false;
  70. if (!packet.getString(string)) return false;
  71. mName = strdup((const char *)string);
  72. if (!mName) return false;
  73. if (!packet.getString(string)) return false;
  74. if (parseDateTime((const char*)string, time))
  75. mDateCreated = time;
  76. if (!packet.getString(string)) return false;
  77. if (parseDateTime((const char*)string, time))
  78. mDateModified = time;
  79. if (!packet.getString(string)) return false;
  80. mKeywords = strdup((const char *)string);
  81. if (!mKeywords) return false;
  82. return true;
  83. }
  84. void MtpObjectInfo::print() {
  85. ALOGD("MtpObject Info %08X: %s\n", mHandle, mName);
  86. ALOGD(" mStorageID: %08X mFormat: %04X mProtectionStatus: %d\n",
  87. mStorageID, mFormat, mProtectionStatus);
  88. ALOGD(" mCompressedSize: %d mThumbFormat: %04X mThumbCompressedSize: %d\n",
  89. mCompressedSize, mFormat, mThumbCompressedSize);
  90. ALOGD(" mThumbPixWidth: %d mThumbPixHeight: %d\n", mThumbPixWidth, mThumbPixHeight);
  91. ALOGD(" mImagePixWidth: %d mImagePixHeight: %d mImagePixDepth: %d\n",
  92. mImagePixWidth, mImagePixHeight, mImagePixDepth);
  93. ALOGD(" mParent: %08X mAssociationType: %04X mAssociationDesc: %04X\n",
  94. mParent, mAssociationType, mAssociationDesc);
  95. ALOGD(" mSequenceNumber: %d mDateCreated: %ld mDateModified: %ld mKeywords: %s\n",
  96. mSequenceNumber, mDateCreated, mDateModified, mKeywords);
  97. }
  98. } // namespace android