blob: 2c7538af55765de683052258ea55f197604ac143 [file] [log] [blame]
Takeshi Aimidc9186562010-11-16 13:56:11 +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
17#ifndef __DRM_METADATA_H__
18#define __DRM_METADATA_H__
19
20#include "drm_framework_common.h"
21
22namespace android {
23
24/**
25 * This is an utility class which contains the constraints information.
26 *
27 * As a result of DrmManagerClient::getMetadata(const String8*)
28 * an instance of DrmMetadata would be returned.
29 */
30class DrmMetadata {
31public:
32 /**
33 * Iterator for key
34 */
35 class KeyIterator {
36 friend class DrmMetadata;
37 private:
38 KeyIterator(DrmMetadata* drmMetadata) : mDrmMetadata(drmMetadata), mIndex(0) {}
39
40 public:
41 KeyIterator(const KeyIterator& keyIterator);
42 KeyIterator& operator=(const KeyIterator& keyIterator);
43 virtual ~KeyIterator() {}
44
45 public:
46 bool hasNext();
47 const String8& next();
48
49 private:
50 DrmMetadata* mDrmMetadata;
51 unsigned int mIndex;
52 };
53
54 /**
55 * Iterator for constraints
56 */
57 class Iterator {
58 friend class DrmMetadata;
59 private:
60 Iterator(DrmMetadata* drmMetadata) : mDrmMetadata(drmMetadata), mIndex(0) {}
61
62 public:
63 Iterator(const Iterator& iterator);
64 Iterator& operator=(const Iterator& iterator);
65 virtual ~Iterator() {}
66
67 public:
68 bool hasNext();
69 String8 next();
70
71 private:
72 DrmMetadata* mDrmMetadata;
73 unsigned int mIndex;
74 };
75
76public:
77 DrmMetadata() {}
78 virtual ~DrmMetadata() {
79 DrmMetadata::KeyIterator keyIt = this->keyIterator();
80
81 while (keyIt.hasNext()) {
82 String8 key = keyIt.next();
83 const char* value = this->getAsByteArray(&key);
84 if (NULL != value) {
85 delete[] value;
86 value = NULL;
87 }
88 }
89 mMetadataMap.clear();
90 }
91
92public:
93 int getCount(void) const;
94 status_t put(const String8* key, const char* value);
95 String8 get(const String8& key) const;
96 const char* getAsByteArray(const String8* key) const;
97 KeyIterator keyIterator();
98 Iterator iterator();
99
100private:
101 const char* getValue(const String8* key) const;
102
103private:
104 typedef KeyedVector<String8, const char*> DrmMetadataMap;
105 DrmMetadataMap mMetadataMap;
106};
107
108};
109
110#endif /* __DRM_METADATA_H__ */
111