blob: 2315aa94dc62a567794f90614c34a6b8f15af8fc [file] [log] [blame]
aimitakeshi27ed8ad2010-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
aimitakeshi27ed8ad2010-07-29 10:12:27 +090017#include <utils/String8.h>
18#include <drm/DrmInfoEvent.h>
Takeshi Aimi5ff78362012-07-11 17:09:21 +090019#include <stdlib.h>
aimitakeshi27ed8ad2010-07-29 10:12:27 +090020
21using namespace android;
22
Gloria Wang79cbc132011-03-17 15:02:34 -070023DrmInfoEvent::DrmInfoEvent(int uniqueId, int infoType, const String8 message)
aimitakeshi27ed8ad2010-07-29 10:12:27 +090024 : mUniqueId(uniqueId),
25 mInfoType(infoType),
Takeshi Aimi5ff78362012-07-11 17:09:21 +090026 mMessage(message),
27 mDrmBuffer() {
aimitakeshi27ed8ad2010-07-29 10:12:27 +090028
29}
30
Takeshi Aimi5ff78362012-07-11 17:09:21 +090031DrmInfoEvent::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
aimitakeshi27ed8ad2010-07-29 10:12:27 +090042int DrmInfoEvent::getUniqueId() const {
43 return mUniqueId;
44}
45
46int DrmInfoEvent::getType() const {
47 return mInfoType;
48}
49
Gloria Wang79cbc132011-03-17 15:02:34 -070050const String8 DrmInfoEvent::getMessage() const {
aimitakeshi27ed8ad2010-07-29 10:12:27 +090051 return mMessage;
52}
53
Takeshi Aimi5ff78362012-07-11 17:09:21 +090054int 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}