DrmSupportInfo.cpp revision 27ed8ad2db653f6ac07dcf8bcc05e2409c8bb024
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/DrmSupportInfo.h>
18
19using namespace android;
20
21DrmSupportInfo::DrmSupportInfo() {
22
23}
24
25DrmSupportInfo::DrmSupportInfo(const DrmSupportInfo& drmSupportInfo):
26    mMimeTypeVector(drmSupportInfo.mMimeTypeVector),
27    mFileSuffixVector(drmSupportInfo.mFileSuffixVector),
28    mDescription(drmSupportInfo.mDescription) {
29
30}
31
32bool DrmSupportInfo::operator<(const DrmSupportInfo& drmSupportInfo) const {
33    // Do we need to check mMimeTypeVector & mFileSuffixVector ?
34    // Note Vector doesn't overrides "<" operator
35    return mDescription < drmSupportInfo.mDescription;
36}
37
38bool DrmSupportInfo::operator==(const DrmSupportInfo& drmSupportInfo) const {
39    // Do we need to check mMimeTypeVector & mFileSuffixVector ?
40    // Note Vector doesn't overrides "==" operator
41    return (mDescription == drmSupportInfo.mDescription);
42}
43
44bool DrmSupportInfo::isSupportedMimeType(const String8& mimeType) const {
45    for (int i = 0; i < mMimeTypeVector.size(); i++) {
46        const String8 item = mMimeTypeVector.itemAt(i);
47
48        if (String8("") != mimeType && item.find(mimeType) != -1) {
49            return true;
50        }
51    }
52    return false;
53}
54
55bool DrmSupportInfo::isSupportedFileSuffix(const String8& fileType) const {
56    for (int i = 0; i < mFileSuffixVector.size(); i++) {
57        const String8 item = mFileSuffixVector.itemAt(i);
58
59        if (String8("") != fileType && item.find(fileType) != -1) {
60            return true;
61        }
62    }
63    return false;
64}
65
66DrmSupportInfo& DrmSupportInfo::operator=(const DrmSupportInfo& drmSupportInfo) {
67    mMimeTypeVector = drmSupportInfo.mMimeTypeVector;
68    mFileSuffixVector = drmSupportInfo.mFileSuffixVector;
69    mDescription = drmSupportInfo.mDescription;
70    return *this;
71}
72
73int DrmSupportInfo::getMimeTypeCount(void) const {
74    return mMimeTypeVector.size();
75}
76
77int DrmSupportInfo::getFileSuffixCount(void) const {
78    return mFileSuffixVector.size();
79}
80
81status_t DrmSupportInfo::addMimeType(const String8& mimeType) {
82    mMimeTypeVector.push(mimeType);
83    return DRM_NO_ERROR;
84}
85
86status_t DrmSupportInfo::addFileSuffix(const String8& fileSuffix) {
87    mFileSuffixVector.push(fileSuffix);
88    return DRM_NO_ERROR;
89}
90
91status_t DrmSupportInfo::setDescription(const String8& description) {
92    mDescription = description;
93    return DRM_NO_ERROR;
94}
95
96String8 DrmSupportInfo::getDescription() const {
97    return mDescription;
98}
99
100DrmSupportInfo::FileSuffixIterator DrmSupportInfo::getFileSuffixIterator() {
101    return FileSuffixIterator(this);
102}
103
104DrmSupportInfo::MimeTypeIterator DrmSupportInfo::getMimeTypeIterator() {
105    return MimeTypeIterator(this);
106}
107
108DrmSupportInfo::FileSuffixIterator::FileSuffixIterator(
109    const DrmSupportInfo::FileSuffixIterator& iterator) :
110    mDrmSupportInfo(iterator.mDrmSupportInfo),
111    mIndex(iterator.mIndex) {
112
113}
114
115DrmSupportInfo::FileSuffixIterator& DrmSupportInfo::FileSuffixIterator::operator=(
116    const DrmSupportInfo::FileSuffixIterator& iterator) {
117    mDrmSupportInfo = iterator.mDrmSupportInfo;
118    mIndex = iterator.mIndex;
119    return *this;
120}
121
122bool DrmSupportInfo::FileSuffixIterator::hasNext() {
123    return mIndex < mDrmSupportInfo->mFileSuffixVector.size();
124}
125
126String8& DrmSupportInfo::FileSuffixIterator::next() {
127    String8& value = mDrmSupportInfo->mFileSuffixVector.editItemAt(mIndex);
128    mIndex++;
129    return value;
130}
131
132DrmSupportInfo::MimeTypeIterator::MimeTypeIterator(
133    const DrmSupportInfo::MimeTypeIterator& iterator) :
134    mDrmSupportInfo(iterator.mDrmSupportInfo),
135    mIndex(iterator.mIndex) {
136
137}
138
139DrmSupportInfo::MimeTypeIterator& DrmSupportInfo::MimeTypeIterator::operator=(
140    const DrmSupportInfo::MimeTypeIterator& iterator) {
141    mDrmSupportInfo = iterator.mDrmSupportInfo;
142    mIndex = iterator.mIndex;
143    return *this;
144}
145
146bool DrmSupportInfo::MimeTypeIterator::hasNext() {
147    return mIndex < mDrmSupportInfo->mMimeTypeVector.size();
148}
149
150String8& DrmSupportInfo::MimeTypeIterator::next() {
151    String8& value = mDrmSupportInfo->mMimeTypeVector.editItemAt(mIndex);
152    mIndex++;
153    return value;
154}
155
156