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/DrmInfo.h>
     18 
     19 using namespace android;
     20 
     21 DrmInfo::DrmInfo(int infoType, const DrmBuffer& drmBuffer, const String8& mimeType) :
     22     mInfoType(infoType),
     23     mData(drmBuffer),
     24     mMimeType(mimeType) {
     25 
     26 }
     27 
     28 int DrmInfo::getInfoType(void) const {
     29     return mInfoType;
     30 }
     31 
     32 String8 DrmInfo::getMimeType(void) const {
     33     return mMimeType;
     34 }
     35 
     36 const DrmBuffer& DrmInfo::getData(void) const {
     37     return mData;
     38 }
     39 
     40 int DrmInfo::getCount(void) const {
     41     return mAttributes.size();
     42 }
     43 
     44 status_t DrmInfo::put(const String8& key, const String8& value) {
     45     mAttributes.add(key, value);
     46     return DRM_NO_ERROR;
     47 }
     48 
     49 String8 DrmInfo::get(const String8& key) const {
     50     if (NAME_NOT_FOUND != mAttributes.indexOfKey(key)) {
     51         return mAttributes.valueFor(key);
     52     }
     53     return String8("");
     54 }
     55 
     56 int DrmInfo::indexOfKey(const String8& key) const {
     57     return mAttributes.indexOfKey(key);
     58 }
     59 
     60 DrmInfo::KeyIterator DrmInfo::keyIterator() const {
     61     return KeyIterator(this);
     62 }
     63 
     64 DrmInfo::Iterator DrmInfo::iterator() const {
     65     return Iterator(this);
     66 }
     67 
     68 // KeyIterator implementation
     69 DrmInfo::KeyIterator::KeyIterator(const DrmInfo::KeyIterator& keyIterator) :
     70     mDrmInfo(keyIterator.mDrmInfo), mIndex(keyIterator.mIndex) {
     71 
     72 }
     73 
     74 bool DrmInfo::KeyIterator::hasNext() {
     75     return (mIndex < mDrmInfo->mAttributes.size());
     76 }
     77 
     78 const String8& DrmInfo::KeyIterator::next() {
     79     const String8& key = mDrmInfo->mAttributes.keyAt(mIndex);
     80     mIndex++;
     81     return key;
     82 }
     83 
     84 DrmInfo::KeyIterator& DrmInfo::KeyIterator::operator=(const DrmInfo::KeyIterator& keyIterator) {
     85     mDrmInfo = keyIterator.mDrmInfo;
     86     mIndex = keyIterator.mIndex;
     87     return *this;
     88 }
     89 
     90 // Iterator implementation
     91 DrmInfo::Iterator::Iterator(const DrmInfo::Iterator& iterator)
     92     : mDrmInfo(iterator.mDrmInfo), mIndex(iterator.mIndex) {
     93 
     94 }
     95 
     96 DrmInfo::Iterator& DrmInfo::Iterator::operator=(const DrmInfo::Iterator& iterator) {
     97     mDrmInfo = iterator.mDrmInfo;
     98     mIndex = iterator.mIndex;
     99     return *this;
    100 }
    101 
    102 bool DrmInfo::Iterator::hasNext() {
    103     return mIndex < mDrmInfo->mAttributes.size();
    104 }
    105 
    106 String8& DrmInfo::Iterator::next() {
    107     String8& value = mDrmInfo->mAttributes.editValueAt(mIndex);
    108     mIndex++;
    109     return value;
    110 }
    111 
    112