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