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/DrmInfo.h>
18
19 using namespace android;
20
DrmInfo(int infoType,const DrmBuffer & drmBuffer,const String8 & mimeType)21 DrmInfo::DrmInfo(int infoType, const DrmBuffer& drmBuffer, const String8& mimeType) :
22 mInfoType(infoType),
23 mData(drmBuffer),
24 mMimeType(mimeType) {
25
26 }
27
getInfoType(void) const28 int DrmInfo::getInfoType(void) const {
29 return mInfoType;
30 }
31
getMimeType(void) const32 String8 DrmInfo::getMimeType(void) const {
33 return mMimeType;
34 }
35
getData(void) const36 const DrmBuffer& DrmInfo::getData(void) const {
37 return mData;
38 }
39
getCount(void) const40 int DrmInfo::getCount(void) const {
41 return mAttributes.size();
42 }
43
put(const String8 & key,const String8 & value)44 status_t DrmInfo::put(const String8& key, const String8& value) {
45 mAttributes.add(key, value);
46 return DRM_NO_ERROR;
47 }
48
get(const String8 & key) const49 String8 DrmInfo::get(const String8& key) const {
50 if (NAME_NOT_FOUND != mAttributes.indexOfKey(key)) {
51 return mAttributes.valueFor(key);
52 }
53 return String8("");
54 }
55
indexOfKey(const String8 & key) const56 int DrmInfo::indexOfKey(const String8& key) const {
57 return mAttributes.indexOfKey(key);
58 }
59
keyIterator() const60 DrmInfo::KeyIterator DrmInfo::keyIterator() const {
61 return KeyIterator(this);
62 }
63
iterator() const64 DrmInfo::Iterator DrmInfo::iterator() const {
65 return Iterator(this);
66 }
67
68 // KeyIterator implementation
KeyIterator(const DrmInfo::KeyIterator & keyIterator)69 DrmInfo::KeyIterator::KeyIterator(const DrmInfo::KeyIterator& keyIterator) :
70 mDrmInfo(keyIterator.mDrmInfo), mIndex(keyIterator.mIndex) {
71
72 }
73
hasNext()74 bool DrmInfo::KeyIterator::hasNext() {
75 return (mIndex < mDrmInfo->mAttributes.size());
76 }
77
next()78 const String8& DrmInfo::KeyIterator::next() {
79 const String8& key = mDrmInfo->mAttributes.keyAt(mIndex);
80 mIndex++;
81 return key;
82 }
83
operator =(const DrmInfo::KeyIterator & keyIterator)84 DrmInfo::KeyIterator& DrmInfo::KeyIterator::operator=(const DrmInfo::KeyIterator& keyIterator) {
85 mDrmInfo = keyIterator.mDrmInfo;
86 mIndex = keyIterator.mIndex;
87 return *this;
88 }
89
90 // Iterator implementation
Iterator(const DrmInfo::Iterator & iterator)91 DrmInfo::Iterator::Iterator(const DrmInfo::Iterator& iterator)
92 : mDrmInfo(iterator.mDrmInfo), mIndex(iterator.mIndex) {
93
94 }
95
operator =(const DrmInfo::Iterator & iterator)96 DrmInfo::Iterator& DrmInfo::Iterator::operator=(const DrmInfo::Iterator& iterator) {
97 mDrmInfo = iterator.mDrmInfo;
98 mIndex = iterator.mIndex;
99 return *this;
100 }
101
hasNext()102 bool DrmInfo::Iterator::hasNext() {
103 return mIndex < mDrmInfo->mAttributes.size();
104 }
105
next()106 String8& DrmInfo::Iterator::next() {
107 String8& value = mDrmInfo->mAttributes.editValueAt(mIndex);
108 mIndex++;
109 return value;
110 }
111
112