blob: 6cc5ec1409245b16810e8835925e676599138cb6 [file] [log] [blame]
Takeshi Aimidc9186562010-11-16 13:56:11 +09001/*
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
19using namespace android;
20
21int DrmMetadata::getCount(void) const {
22 return mMetadataMap.size();
23}
24
25status_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
38String8 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
47const 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
60const char* DrmMetadata::getAsByteArray(const String8* key) const {
61 return getValue(key);
62}
63
64bool DrmMetadata::KeyIterator::hasNext() {
65 return mIndex < mDrmMetadata->mMetadataMap.size();
66}
67
68const String8& DrmMetadata::KeyIterator::next() {
69 const String8& key = mDrmMetadata->mMetadataMap.keyAt(mIndex);
70 mIndex++;
71 return key;
72}
73
74DrmMetadata::KeyIterator DrmMetadata::keyIterator() {
75 return KeyIterator(this);
76}
77
78DrmMetadata::KeyIterator::KeyIterator(const DrmMetadata::KeyIterator& keyIterator) :
79 mDrmMetadata(keyIterator.mDrmMetadata),
80 mIndex(keyIterator.mIndex) {
81 LOGV("DrmMetadata::KeyIterator::KeyIterator");
82}
83
84DrmMetadata::KeyIterator& DrmMetadata::KeyIterator::operator=(const DrmMetadata::KeyIterator& keyIterator) {
85 LOGV("DrmMetadata::KeyIterator::operator=");
86 mDrmMetadata = keyIterator.mDrmMetadata;
87 mIndex = keyIterator.mIndex;
88 return *this;
89}
90
91
92DrmMetadata::Iterator DrmMetadata::iterator() {
93 return Iterator(this);
94}
95
96DrmMetadata::Iterator::Iterator(const DrmMetadata::Iterator& iterator) :
97 mDrmMetadata(iterator.mDrmMetadata),
98 mIndex(iterator.mIndex) {
99 LOGV("DrmMetadata::Iterator::Iterator");
100}
101
102DrmMetadata::Iterator& DrmMetadata::Iterator::operator=(const DrmMetadata::Iterator& iterator) {
103 LOGV("DrmMetadata::Iterator::operator=");
104 mDrmMetadata = iterator.mDrmMetadata;
105 mIndex = iterator.mIndex;
106 return *this;
107}
108
109bool DrmMetadata::Iterator::hasNext() {
110 return mIndex < mDrmMetadata->mMetadataMap.size();
111}
112
113String8 DrmMetadata::Iterator::next() {
114 String8 value = String8(mDrmMetadata->mMetadataMap.editValueAt(mIndex));
115 mIndex++;
116 return value;
117}