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 <drm/DrmMetadata.h>
18
19 using namespace android;
20
getCount(void) const21 int DrmMetadata::getCount(void) const {
22 return mMetadataMap.size();
23 }
24
put(const String8 * key,const char * value)25 status_t DrmMetadata::put(const String8* key,
26 const char* value) {
27 if((value != NULL) && (key != NULL)) {
28 int length = strlen(value);
29 char* charValue = new char[length + 1];
30
31 memcpy(charValue, value, length);
32 charValue[length] = '\0';
33 mMetadataMap.add(*key, charValue);
34 }
35 return NO_ERROR;
36 }
37
get(const String8 & key) const38 String8 DrmMetadata::get(const String8& key) const {
39 if (NULL != getValue(&key)) {
40 return String8(getValue(&key));
41 }
42 else {
43 return String8("");
44 }
45 }
46
getValue(const String8 * key) const47 const char* DrmMetadata::getValue(const String8* key) const {
48 if(key != NULL) {
49 if (NAME_NOT_FOUND != mMetadataMap.indexOfKey(*key)) {
50 return mMetadataMap.valueFor(*key);
51 }
52 else {
53 return NULL;
54 }
55 } else {
56 return NULL;
57 }
58 }
59
getAsByteArray(const String8 * key) const60 const char* DrmMetadata::getAsByteArray(const String8* key) const {
61 return getValue(key);
62 }
63
hasNext()64 bool DrmMetadata::KeyIterator::hasNext() {
65 return mIndex < mDrmMetadata->mMetadataMap.size();
66 }
67
next()68 const String8& DrmMetadata::KeyIterator::next() {
69 const String8& key = mDrmMetadata->mMetadataMap.keyAt(mIndex);
70 mIndex++;
71 return key;
72 }
73
keyIterator()74 DrmMetadata::KeyIterator DrmMetadata::keyIterator() {
75 return KeyIterator(this);
76 }
77
KeyIterator(const DrmMetadata::KeyIterator & keyIterator)78 DrmMetadata::KeyIterator::KeyIterator(const DrmMetadata::KeyIterator& keyIterator) :
79 mDrmMetadata(keyIterator.mDrmMetadata),
80 mIndex(keyIterator.mIndex) {
81 ALOGV("DrmMetadata::KeyIterator::KeyIterator");
82 }
83
operator =(const DrmMetadata::KeyIterator & keyIterator)84 DrmMetadata::KeyIterator& DrmMetadata::KeyIterator::operator=(const DrmMetadata::KeyIterator& keyIterator) {
85 ALOGV("DrmMetadata::KeyIterator::operator=");
86 mDrmMetadata = keyIterator.mDrmMetadata;
87 mIndex = keyIterator.mIndex;
88 return *this;
89 }
90
91
iterator()92 DrmMetadata::Iterator DrmMetadata::iterator() {
93 return Iterator(this);
94 }
95
Iterator(const DrmMetadata::Iterator & iterator)96 DrmMetadata::Iterator::Iterator(const DrmMetadata::Iterator& iterator) :
97 mDrmMetadata(iterator.mDrmMetadata),
98 mIndex(iterator.mIndex) {
99 ALOGV("DrmMetadata::Iterator::Iterator");
100 }
101
operator =(const DrmMetadata::Iterator & iterator)102 DrmMetadata::Iterator& DrmMetadata::Iterator::operator=(const DrmMetadata::Iterator& iterator) {
103 ALOGV("DrmMetadata::Iterator::operator=");
104 mDrmMetadata = iterator.mDrmMetadata;
105 mIndex = iterator.mIndex;
106 return *this;
107 }
108
hasNext()109 bool DrmMetadata::Iterator::hasNext() {
110 return mIndex < mDrmMetadata->mMetadataMap.size();
111 }
112
next()113 String8 DrmMetadata::Iterator::next() {
114 String8 value = String8(mDrmMetadata->mMetadataMap.editValueAt(mIndex));
115 mIndex++;
116 return value;
117 }
118