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 #ifndef __DRM_METADATA_H__ 18 #define __DRM_METADATA_H__ 19 20 #include "drm_framework_common.h" 21 22 namespace 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 */ 30 class DrmMetadata { 31 public: 32 /** 33 * Iterator for key 34 */ 35 class KeyIterator { 36 friend class DrmMetadata; 37 private: KeyIterator(DrmMetadata * drmMetadata)38 KeyIterator(DrmMetadata* drmMetadata) : mDrmMetadata(drmMetadata), mIndex(0) {} 39 40 public: 41 KeyIterator(const KeyIterator& keyIterator); 42 KeyIterator& operator=(const KeyIterator& 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: Iterator(DrmMetadata * drmMetadata)60 Iterator(DrmMetadata* drmMetadata) : mDrmMetadata(drmMetadata), mIndex(0) {} 61 62 public: 63 Iterator(const Iterator& iterator); 64 Iterator& operator=(const Iterator& 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 76 public: DrmMetadata()77 DrmMetadata() {} ~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 92 public: 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 100 private: 101 const char* getValue(const String8* key) const; 102 103 private: 104 typedef KeyedVector<String8, const char*> DrmMetadataMap; 105 DrmMetadataMap mMetadataMap; 106 }; 107 108 }; 109 110 #endif /* __DRM_METADATA_H__ */ 111 112