Home | History | Annotate | Download | only in drm
      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_INFO_H__
     18 #define __DRM_INFO_H__
     19 
     20 #include "drm_framework_common.h"
     21 
     22 namespace android {
     23 
     24 /**
     25  * This is an utility class in which necessary information required to transact
     26  * between device and online DRM server is described. DRM Framework achieves
     27  * server registration, license acquisition and any other server related transaction
     28  * by passing an instance of this class to DrmManagerClient::processDrmInfo(const DrmInfo*).
     29  *
     30  * The Caller can retrieve the DrmInfo instance by using
     31  * DrmManagerClient::acquireDrmInfo(const DrmInfoRequest*) by passing DrmInfoRequest instance.
     32  *
     33  */
     34 class DrmInfo {
     35 public:
     36     /**
     37      * Constructor for DrmInfo
     38      *
     39      * @param[in] infoType Type of information
     40      * @param[in] drmBuffer Trigger data
     41      * @param[in] mimeType MIME type
     42      */
     43     DrmInfo(int infoType, const DrmBuffer& drmBuffer, const String8& mimeType);
     44 
     45     /**
     46      * Destructor for DrmInfo
     47      */
     48     virtual ~DrmInfo() {}
     49 
     50 public:
     51     /**
     52      * Iterator for key
     53      */
     54     class KeyIterator {
     55         friend class DrmInfo;
     56 
     57     private:
     58         KeyIterator(const DrmInfo* drmInfo)
     59             : mDrmInfo(const_cast <DrmInfo*> (drmInfo)), mIndex(0) {}
     60 
     61     public:
     62         KeyIterator(const KeyIterator& keyIterator);
     63         KeyIterator& operator=(const KeyIterator& keyIterator);
     64         virtual ~KeyIterator() {}
     65 
     66     public:
     67         bool hasNext();
     68         const String8& next();
     69 
     70     private:
     71         DrmInfo* mDrmInfo;
     72         unsigned int mIndex;
     73     };
     74 
     75     /**
     76      * Iterator
     77      */
     78     class Iterator {
     79         friend class DrmInfo;
     80 
     81     private:
     82         Iterator(const DrmInfo* drmInfo)
     83             : mDrmInfo(const_cast <DrmInfo*> (drmInfo)), mIndex(0) {}
     84 
     85     public:
     86         Iterator(const Iterator& iterator);
     87         Iterator& operator=(const Iterator& iterator);
     88         virtual ~Iterator() {}
     89 
     90     public:
     91         bool hasNext();
     92         String8& next();
     93 
     94     private:
     95         DrmInfo* mDrmInfo;
     96         unsigned int mIndex;
     97     };
     98 
     99 public:
    100     /**
    101      * Returns information type associated with this instance
    102      *
    103      * @return Information type
    104      */
    105     int getInfoType(void) const;
    106 
    107     /**
    108      * Returns MIME type associated with this instance
    109      *
    110      * @return MIME type
    111      */
    112     String8 getMimeType(void) const;
    113 
    114     /**
    115      * Returns the trigger data associated with this instance
    116      *
    117      * @return Trigger data
    118      */
    119     const DrmBuffer& getData(void) const;
    120 
    121     /**
    122      * Returns the number of attributes contained in this instance
    123      *
    124      * @return Number of attributes
    125      */
    126     int getCount(void) const;
    127 
    128     /**
    129      * Adds optional information as <key, value> pair to this instance
    130      *
    131      * @param[in] key Key to add
    132      * @param[in] value Value to add
    133      * @return Returns the error code
    134      */
    135     status_t put(const String8& key, const String8& value);
    136 
    137     /**
    138      * Retrieves the value of given key
    139      *
    140      * @param key Key whose value to be retrieved
    141      * @return The value
    142      */
    143     String8 get(const String8& key) const;
    144 
    145     /**
    146      * Returns KeyIterator object to walk through the keys associated with this instance
    147      *
    148      * @return KeyIterator object
    149      */
    150     KeyIterator keyIterator() const;
    151 
    152     /**
    153      * Returns Iterator object to walk through the values associated with this instance
    154      *
    155      * @return Iterator object
    156      */
    157     Iterator iterator() const;
    158 
    159     /**
    160      * Returns index of the given key
    161      *
    162      * @return index
    163      */
    164     int indexOfKey(const String8& key) const;
    165 
    166 protected:
    167     int mInfoType;
    168     DrmBuffer mData;
    169     String8 mMimeType;
    170     KeyedVector<String8, String8> mAttributes;
    171 };
    172 
    173 };
    174 
    175 #endif /* __DRM_INFO_H__ */
    176 
    177