aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [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 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 17 | #include <utils/String8.h> |
| 18 | #include <drm/DrmInfoEvent.h> |
Takeshi Aimi | 5ff7836 | 2012-07-11 17:09:21 +0900 | [diff] [blame] | 19 | #include <stdlib.h> |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 20 | |
| 21 | using namespace android; |
| 22 | |
Gloria Wang | 79cbc13 | 2011-03-17 15:02:34 -0700 | [diff] [blame] | 23 | DrmInfoEvent::DrmInfoEvent(int uniqueId, int infoType, const String8 message) |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 24 | : mUniqueId(uniqueId), |
| 25 | mInfoType(infoType), |
Takeshi Aimi | 5ff7836 | 2012-07-11 17:09:21 +0900 | [diff] [blame] | 26 | mMessage(message), |
| 27 | mDrmBuffer() { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 28 | |
| 29 | } |
| 30 | |
Takeshi Aimi | 5ff7836 | 2012-07-11 17:09:21 +0900 | [diff] [blame] | 31 | DrmInfoEvent::DrmInfoEvent(int uniqueId, int infoType, const String8 message, |
| 32 | const DrmBuffer& drmBuffer) |
| 33 | : mUniqueId(uniqueId), mInfoType(infoType), mMessage(message), mDrmBuffer() { |
| 34 | setData(drmBuffer); |
| 35 | } |
| 36 | |
| 37 | DrmInfoEvent::~DrmInfoEvent() { |
| 38 | delete [] mDrmBuffer.data; |
| 39 | } |
| 40 | |
| 41 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 42 | int DrmInfoEvent::getUniqueId() const { |
| 43 | return mUniqueId; |
| 44 | } |
| 45 | |
| 46 | int DrmInfoEvent::getType() const { |
| 47 | return mInfoType; |
| 48 | } |
| 49 | |
Gloria Wang | 79cbc13 | 2011-03-17 15:02:34 -0700 | [diff] [blame] | 50 | const String8 DrmInfoEvent::getMessage() const { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 51 | return mMessage; |
| 52 | } |
| 53 | |
Takeshi Aimi | 5ff7836 | 2012-07-11 17:09:21 +0900 | [diff] [blame] | 54 | int DrmInfoEvent::getCount() const { |
| 55 | return mAttributes.size(); |
| 56 | } |
| 57 | |
| 58 | status_t DrmInfoEvent::put(const String8& key, String8& value) { |
| 59 | mAttributes.add(key, value); |
| 60 | return DRM_NO_ERROR; |
| 61 | } |
| 62 | |
| 63 | const String8 DrmInfoEvent::get(const String8& key) const { |
| 64 | if (mAttributes.indexOfKey(key) != NAME_NOT_FOUND) { |
| 65 | return mAttributes.valueFor(key); |
| 66 | } |
| 67 | return String8(""); |
| 68 | } |
| 69 | |
| 70 | const DrmBuffer& DrmInfoEvent::getData() const { |
| 71 | return mDrmBuffer; |
| 72 | } |
| 73 | |
| 74 | void DrmInfoEvent::setData(const DrmBuffer& drmBuffer) { |
| 75 | delete [] mDrmBuffer.data; |
| 76 | mDrmBuffer.data = new char[drmBuffer.length];; |
| 77 | mDrmBuffer.length = drmBuffer.length; |
| 78 | memcpy(mDrmBuffer.data, drmBuffer.data, drmBuffer.length); |
| 79 | } |
| 80 | |
| 81 | DrmInfoEvent::KeyIterator DrmInfoEvent::keyIterator() const { |
| 82 | return KeyIterator(this); |
| 83 | } |
| 84 | |
| 85 | DrmInfoEvent::Iterator DrmInfoEvent::iterator() const { |
| 86 | return Iterator(this); |
| 87 | } |
| 88 | |
| 89 | // KeyIterator implementation |
| 90 | DrmInfoEvent::KeyIterator::KeyIterator(const DrmInfoEvent::KeyIterator& keyIterator) |
| 91 | : mDrmInfoEvent(keyIterator.mDrmInfoEvent), mIndex(keyIterator.mIndex) { |
| 92 | } |
| 93 | |
| 94 | bool DrmInfoEvent::KeyIterator::hasNext() { |
| 95 | return (mIndex < mDrmInfoEvent->mAttributes.size()); |
| 96 | } |
| 97 | |
| 98 | const String8& DrmInfoEvent::KeyIterator::next() { |
| 99 | const String8& key = mDrmInfoEvent->mAttributes.keyAt(mIndex); |
| 100 | mIndex++; |
| 101 | return key; |
| 102 | } |
| 103 | |
| 104 | DrmInfoEvent::KeyIterator& DrmInfoEvent::KeyIterator::operator=( |
| 105 | const DrmInfoEvent::KeyIterator& keyIterator) { |
| 106 | mDrmInfoEvent = keyIterator.mDrmInfoEvent; |
| 107 | mIndex = keyIterator.mIndex; |
| 108 | return *this; |
| 109 | } |
| 110 | |
| 111 | // Iterator implementation |
| 112 | DrmInfoEvent::Iterator::Iterator(const DrmInfoEvent::Iterator& iterator) |
| 113 | : mDrmInfoEvent(iterator.mDrmInfoEvent), mIndex(iterator.mIndex) { |
| 114 | } |
| 115 | |
| 116 | DrmInfoEvent::Iterator& DrmInfoEvent::Iterator::operator=(const DrmInfoEvent::Iterator& iterator) { |
| 117 | mDrmInfoEvent = iterator.mDrmInfoEvent; |
| 118 | mIndex = iterator.mIndex; |
| 119 | return *this; |
| 120 | } |
| 121 | |
| 122 | bool DrmInfoEvent::Iterator::hasNext() { |
| 123 | return mIndex < mDrmInfoEvent->mAttributes.size(); |
| 124 | } |
| 125 | |
| 126 | const String8& DrmInfoEvent::Iterator::next() { |
| 127 | const String8& value = mDrmInfoEvent->mAttributes.editValueAt(mIndex); |
| 128 | mIndex++; |
| 129 | return value; |
| 130 | } |