blob: 4a4d798ca43f7420f0a1e18aa234c2e43e365af2 [file] [log] [blame]
aimitakeshid074e302010-07-29 10:12:27 +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/DrmConstraints.h>
18
19using namespace android;
20
21const String8 DrmConstraints::MAX_REPEAT_COUNT("max_repeat_count");
22const String8 DrmConstraints::REMAINING_REPEAT_COUNT("remaining_repeat_count");
23const String8 DrmConstraints::LICENSE_START_TIME("license_start_time");
24const String8 DrmConstraints::LICENSE_EXPIRY_TIME("license_expiry_time");
25const String8 DrmConstraints::LICENSE_AVAILABLE_TIME("license_available_time");
26const String8 DrmConstraints::EXTENDED_METADATA("extended_metadata");
27
28int DrmConstraints::getCount(void) const {
29 return mConstraintMap.size();
30}
31
32status_t DrmConstraints::put(const String8* key, const char* value) {
33 int length = strlen(value);
34 char* charValue = new char[length + 1];
35 if (NULL != charValue) {
36 strncpy(charValue, value, length);
37 charValue[length] = '\0';
38 mConstraintMap.add(*key, charValue);
39 }
40 return DRM_NO_ERROR;
41}
42
43String8 DrmConstraints::get(const String8& key) const {
44 if (NULL != getValue(&key)) {
45 return String8(getValue(&key));
46 }
47 return String8("");
48}
49
50const char* DrmConstraints::getValue(const String8* key) const {
51 if (NAME_NOT_FOUND != mConstraintMap.indexOfKey(*key)) {
52 return mConstraintMap.valueFor(*key);
53 }
54 return NULL;
55}
56
57const char* DrmConstraints::getAsByteArray(const String8* key) const {
58 return getValue(key);
59}
60
61bool DrmConstraints::KeyIterator::hasNext() {
62 return mIndex < mDrmConstraints->mConstraintMap.size();
63}
64
65const String8& DrmConstraints::KeyIterator::next() {
66 const String8& key = mDrmConstraints->mConstraintMap.keyAt(mIndex);
67 mIndex++;
68 return key;
69}
70
71DrmConstraints::KeyIterator DrmConstraints::keyIterator() {
72 return KeyIterator(this);
73}
74
75DrmConstraints::KeyIterator::KeyIterator(const DrmConstraints::KeyIterator& keyIterator)
76 : mDrmConstraints(keyIterator.mDrmConstraints),
77 mIndex(keyIterator.mIndex) {
aimitakeshid074e302010-07-29 10:12:27 +090078}
79
80DrmConstraints::KeyIterator& DrmConstraints::KeyIterator::operator=(
81 const DrmConstraints::KeyIterator& keyIterator) {
aimitakeshid074e302010-07-29 10:12:27 +090082 mDrmConstraints = keyIterator.mDrmConstraints;
83 mIndex = keyIterator.mIndex;
84 return *this;
85}
86
87
88DrmConstraints::Iterator DrmConstraints::iterator() {
89 return Iterator(this);
90}
91
92DrmConstraints::Iterator::Iterator(const DrmConstraints::Iterator& iterator) :
93 mDrmConstraints(iterator.mDrmConstraints),
94 mIndex(iterator.mIndex) {
aimitakeshid074e302010-07-29 10:12:27 +090095}
96
97DrmConstraints::Iterator& DrmConstraints::Iterator::operator=(
98 const DrmConstraints::Iterator& iterator) {
aimitakeshid074e302010-07-29 10:12:27 +090099 mDrmConstraints = iterator.mDrmConstraints;
100 mIndex = iterator.mIndex;
101 return *this;
102}
103
104bool DrmConstraints::Iterator::hasNext() {
105 return mIndex < mDrmConstraints->mConstraintMap.size();
106}
107
108String8 DrmConstraints::Iterator::next() {
109 String8 value = String8(mDrmConstraints->mConstraintMap.editValueAt(mIndex));
110 mIndex++;
111 return value;
112}
113