blob: 5400bdd45cb849ec57ec401344dca5482937df5c [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/DrmSupportInfo.h>
Carl Shapiro39ad8262011-03-22 11:51:57 -070018#include <strings.h>
aimitakeshid074e302010-07-29 10:12:27 +090019
20using namespace android;
21
22DrmSupportInfo::DrmSupportInfo() {
23
24}
25
26DrmSupportInfo::DrmSupportInfo(const DrmSupportInfo& drmSupportInfo):
27 mMimeTypeVector(drmSupportInfo.mMimeTypeVector),
28 mFileSuffixVector(drmSupportInfo.mFileSuffixVector),
29 mDescription(drmSupportInfo.mDescription) {
30
31}
32
33bool DrmSupportInfo::operator<(const DrmSupportInfo& drmSupportInfo) const {
34 // Do we need to check mMimeTypeVector & mFileSuffixVector ?
35 // Note Vector doesn't overrides "<" operator
36 return mDescription < drmSupportInfo.mDescription;
37}
38
39bool DrmSupportInfo::operator==(const DrmSupportInfo& drmSupportInfo) const {
40 // Do we need to check mMimeTypeVector & mFileSuffixVector ?
41 // Note Vector doesn't overrides "==" operator
42 return (mDescription == drmSupportInfo.mDescription);
43}
44
45bool DrmSupportInfo::isSupportedMimeType(const String8& mimeType) const {
Gloria Wangb7e7bdf2011-06-22 14:55:16 -070046 if (String8("") == mimeType) {
47 return false;
48 }
49
Takeshi Aimidc549d62010-09-20 23:40:41 +090050 for (unsigned int i = 0; i < mMimeTypeVector.size(); i++) {
aimitakeshid074e302010-07-29 10:12:27 +090051 const String8 item = mMimeTypeVector.itemAt(i);
52
Glenn Kastenf8a18422011-03-14 11:32:29 -070053 if (!strcasecmp(item.string(), mimeType.string())) {
aimitakeshid074e302010-07-29 10:12:27 +090054 return true;
55 }
56 }
57 return false;
58}
59
60bool DrmSupportInfo::isSupportedFileSuffix(const String8& fileType) const {
Takeshi Aimidc549d62010-09-20 23:40:41 +090061 for (unsigned int i = 0; i < mFileSuffixVector.size(); i++) {
aimitakeshid074e302010-07-29 10:12:27 +090062 const String8 item = mFileSuffixVector.itemAt(i);
63
Glenn Kastenf8a18422011-03-14 11:32:29 -070064 if (!strcasecmp(item.string(), fileType.string())) {
aimitakeshid074e302010-07-29 10:12:27 +090065 return true;
66 }
67 }
68 return false;
69}
70
71DrmSupportInfo& DrmSupportInfo::operator=(const DrmSupportInfo& drmSupportInfo) {
72 mMimeTypeVector = drmSupportInfo.mMimeTypeVector;
73 mFileSuffixVector = drmSupportInfo.mFileSuffixVector;
74 mDescription = drmSupportInfo.mDescription;
75 return *this;
76}
77
78int DrmSupportInfo::getMimeTypeCount(void) const {
79 return mMimeTypeVector.size();
80}
81
82int DrmSupportInfo::getFileSuffixCount(void) const {
83 return mFileSuffixVector.size();
84}
85
86status_t DrmSupportInfo::addMimeType(const String8& mimeType) {
87 mMimeTypeVector.push(mimeType);
88 return DRM_NO_ERROR;
89}
90
91status_t DrmSupportInfo::addFileSuffix(const String8& fileSuffix) {
92 mFileSuffixVector.push(fileSuffix);
93 return DRM_NO_ERROR;
94}
95
96status_t DrmSupportInfo::setDescription(const String8& description) {
97 mDescription = description;
98 return DRM_NO_ERROR;
99}
100
101String8 DrmSupportInfo::getDescription() const {
102 return mDescription;
103}
104
105DrmSupportInfo::FileSuffixIterator DrmSupportInfo::getFileSuffixIterator() {
106 return FileSuffixIterator(this);
107}
108
109DrmSupportInfo::MimeTypeIterator DrmSupportInfo::getMimeTypeIterator() {
110 return MimeTypeIterator(this);
111}
112
113DrmSupportInfo::FileSuffixIterator::FileSuffixIterator(
114 const DrmSupportInfo::FileSuffixIterator& iterator) :
115 mDrmSupportInfo(iterator.mDrmSupportInfo),
116 mIndex(iterator.mIndex) {
117
118}
119
120DrmSupportInfo::FileSuffixIterator& DrmSupportInfo::FileSuffixIterator::operator=(
121 const DrmSupportInfo::FileSuffixIterator& iterator) {
122 mDrmSupportInfo = iterator.mDrmSupportInfo;
123 mIndex = iterator.mIndex;
124 return *this;
125}
126
127bool DrmSupportInfo::FileSuffixIterator::hasNext() {
128 return mIndex < mDrmSupportInfo->mFileSuffixVector.size();
129}
130
131String8& DrmSupportInfo::FileSuffixIterator::next() {
132 String8& value = mDrmSupportInfo->mFileSuffixVector.editItemAt(mIndex);
133 mIndex++;
134 return value;
135}
136
137DrmSupportInfo::MimeTypeIterator::MimeTypeIterator(
138 const DrmSupportInfo::MimeTypeIterator& iterator) :
139 mDrmSupportInfo(iterator.mDrmSupportInfo),
140 mIndex(iterator.mIndex) {
141
142}
143
144DrmSupportInfo::MimeTypeIterator& DrmSupportInfo::MimeTypeIterator::operator=(
145 const DrmSupportInfo::MimeTypeIterator& iterator) {
146 mDrmSupportInfo = iterator.mDrmSupportInfo;
147 mIndex = iterator.mIndex;
148 return *this;
149}
150
151bool DrmSupportInfo::MimeTypeIterator::hasNext() {
152 return mIndex < mDrmSupportInfo->mMimeTypeVector.size();
153}
154
155String8& DrmSupportInfo::MimeTypeIterator::next() {
156 String8& value = mDrmSupportInfo->mMimeTypeVector.editItemAt(mIndex);
157 mIndex++;
158 return value;
159}