blob: 3dee435e749b3d10892cff0fb713ddf67d43df90 [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 {
Takeshi Aimidc549d62010-09-20 23:40:41 +090046 for (unsigned int i = 0; i < mMimeTypeVector.size(); i++) {
aimitakeshid074e302010-07-29 10:12:27 +090047 const String8 item = mMimeTypeVector.itemAt(i);
48
Glenn Kastenf8a18422011-03-14 11:32:29 -070049 if (!strcasecmp(item.string(), mimeType.string())) {
aimitakeshid074e302010-07-29 10:12:27 +090050 return true;
51 }
52 }
53 return false;
54}
55
56bool DrmSupportInfo::isSupportedFileSuffix(const String8& fileType) const {
Takeshi Aimidc549d62010-09-20 23:40:41 +090057 for (unsigned int i = 0; i < mFileSuffixVector.size(); i++) {
aimitakeshid074e302010-07-29 10:12:27 +090058 const String8 item = mFileSuffixVector.itemAt(i);
59
Glenn Kastenf8a18422011-03-14 11:32:29 -070060 if (!strcasecmp(item.string(), fileType.string())) {
aimitakeshid074e302010-07-29 10:12:27 +090061 return true;
62 }
63 }
64 return false;
65}
66
67DrmSupportInfo& DrmSupportInfo::operator=(const DrmSupportInfo& drmSupportInfo) {
68 mMimeTypeVector = drmSupportInfo.mMimeTypeVector;
69 mFileSuffixVector = drmSupportInfo.mFileSuffixVector;
70 mDescription = drmSupportInfo.mDescription;
71 return *this;
72}
73
74int DrmSupportInfo::getMimeTypeCount(void) const {
75 return mMimeTypeVector.size();
76}
77
78int DrmSupportInfo::getFileSuffixCount(void) const {
79 return mFileSuffixVector.size();
80}
81
82status_t DrmSupportInfo::addMimeType(const String8& mimeType) {
83 mMimeTypeVector.push(mimeType);
84 return DRM_NO_ERROR;
85}
86
87status_t DrmSupportInfo::addFileSuffix(const String8& fileSuffix) {
88 mFileSuffixVector.push(fileSuffix);
89 return DRM_NO_ERROR;
90}
91
92status_t DrmSupportInfo::setDescription(const String8& description) {
93 mDescription = description;
94 return DRM_NO_ERROR;
95}
96
97String8 DrmSupportInfo::getDescription() const {
98 return mDescription;
99}
100
101DrmSupportInfo::FileSuffixIterator DrmSupportInfo::getFileSuffixIterator() {
102 return FileSuffixIterator(this);
103}
104
105DrmSupportInfo::MimeTypeIterator DrmSupportInfo::getMimeTypeIterator() {
106 return MimeTypeIterator(this);
107}
108
109DrmSupportInfo::FileSuffixIterator::FileSuffixIterator(
110 const DrmSupportInfo::FileSuffixIterator& iterator) :
111 mDrmSupportInfo(iterator.mDrmSupportInfo),
112 mIndex(iterator.mIndex) {
113
114}
115
116DrmSupportInfo::FileSuffixIterator& DrmSupportInfo::FileSuffixIterator::operator=(
117 const DrmSupportInfo::FileSuffixIterator& iterator) {
118 mDrmSupportInfo = iterator.mDrmSupportInfo;
119 mIndex = iterator.mIndex;
120 return *this;
121}
122
123bool DrmSupportInfo::FileSuffixIterator::hasNext() {
124 return mIndex < mDrmSupportInfo->mFileSuffixVector.size();
125}
126
127String8& DrmSupportInfo::FileSuffixIterator::next() {
128 String8& value = mDrmSupportInfo->mFileSuffixVector.editItemAt(mIndex);
129 mIndex++;
130 return value;
131}
132
133DrmSupportInfo::MimeTypeIterator::MimeTypeIterator(
134 const DrmSupportInfo::MimeTypeIterator& iterator) :
135 mDrmSupportInfo(iterator.mDrmSupportInfo),
136 mIndex(iterator.mIndex) {
137
138}
139
140DrmSupportInfo::MimeTypeIterator& DrmSupportInfo::MimeTypeIterator::operator=(
141 const DrmSupportInfo::MimeTypeIterator& iterator) {
142 mDrmSupportInfo = iterator.mDrmSupportInfo;
143 mIndex = iterator.mIndex;
144 return *this;
145}
146
147bool DrmSupportInfo::MimeTypeIterator::hasNext() {
148 return mIndex < mDrmSupportInfo->mMimeTypeVector.size();
149}
150
151String8& DrmSupportInfo::MimeTypeIterator::next() {
152 String8& value = mDrmSupportInfo->mMimeTypeVector.editItemAt(mIndex);
153 mIndex++;
154 return value;
155}