DrmInfoEvent.cpp revision 5ff7836da0220b3097f36c8a5e82111816ebca62
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 <utils/String8.h> 18#include <drm/DrmInfoEvent.h> 19#include <stdlib.h> 20 21using namespace android; 22 23DrmInfoEvent::DrmInfoEvent(int uniqueId, int infoType, const String8 message) 24 : mUniqueId(uniqueId), 25 mInfoType(infoType), 26 mMessage(message), 27 mDrmBuffer() { 28 29} 30 31DrmInfoEvent::DrmInfoEvent(int uniqueId, int infoType, const String8 message, 32 const DrmBuffer& drmBuffer) 33 : mUniqueId(uniqueId), mInfoType(infoType), mMessage(message), mDrmBuffer() { 34 setData(drmBuffer); 35} 36 37DrmInfoEvent::~DrmInfoEvent() { 38 delete [] mDrmBuffer.data; 39} 40 41 42int DrmInfoEvent::getUniqueId() const { 43 return mUniqueId; 44} 45 46int DrmInfoEvent::getType() const { 47 return mInfoType; 48} 49 50const String8 DrmInfoEvent::getMessage() const { 51 return mMessage; 52} 53 54int DrmInfoEvent::getCount() const { 55 return mAttributes.size(); 56} 57 58status_t DrmInfoEvent::put(const String8& key, String8& value) { 59 mAttributes.add(key, value); 60 return DRM_NO_ERROR; 61} 62 63const String8 DrmInfoEvent::get(const String8& key) const { 64 if (mAttributes.indexOfKey(key) != NAME_NOT_FOUND) { 65 return mAttributes.valueFor(key); 66 } 67 return String8(""); 68} 69 70const DrmBuffer& DrmInfoEvent::getData() const { 71 return mDrmBuffer; 72} 73 74void DrmInfoEvent::setData(const DrmBuffer& drmBuffer) { 75 delete [] mDrmBuffer.data; 76 mDrmBuffer.data = new char[drmBuffer.length];; 77 mDrmBuffer.length = drmBuffer.length; 78 memcpy(mDrmBuffer.data, drmBuffer.data, drmBuffer.length); 79} 80 81DrmInfoEvent::KeyIterator DrmInfoEvent::keyIterator() const { 82 return KeyIterator(this); 83} 84 85DrmInfoEvent::Iterator DrmInfoEvent::iterator() const { 86 return Iterator(this); 87} 88 89// KeyIterator implementation 90DrmInfoEvent::KeyIterator::KeyIterator(const DrmInfoEvent::KeyIterator& keyIterator) 91 : mDrmInfoEvent(keyIterator.mDrmInfoEvent), mIndex(keyIterator.mIndex) { 92} 93 94bool DrmInfoEvent::KeyIterator::hasNext() { 95 return (mIndex < mDrmInfoEvent->mAttributes.size()); 96} 97 98const String8& DrmInfoEvent::KeyIterator::next() { 99 const String8& key = mDrmInfoEvent->mAttributes.keyAt(mIndex); 100 mIndex++; 101 return key; 102} 103 104DrmInfoEvent::KeyIterator& DrmInfoEvent::KeyIterator::operator=( 105 const DrmInfoEvent::KeyIterator& keyIterator) { 106 mDrmInfoEvent = keyIterator.mDrmInfoEvent; 107 mIndex = keyIterator.mIndex; 108 return *this; 109} 110 111// Iterator implementation 112DrmInfoEvent::Iterator::Iterator(const DrmInfoEvent::Iterator& iterator) 113 : mDrmInfoEvent(iterator.mDrmInfoEvent), mIndex(iterator.mIndex) { 114} 115 116DrmInfoEvent::Iterator& DrmInfoEvent::Iterator::operator=(const DrmInfoEvent::Iterator& iterator) { 117 mDrmInfoEvent = iterator.mDrmInfoEvent; 118 mIndex = iterator.mIndex; 119 return *this; 120} 121 122bool DrmInfoEvent::Iterator::hasNext() { 123 return mIndex < mDrmInfoEvent->mAttributes.size(); 124} 125 126const String8& DrmInfoEvent::Iterator::next() { 127 const String8& value = mDrmInfoEvent->mAttributes.editValueAt(mIndex); 128 mIndex++; 129 return value; 130} 131