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_REQUEST_H__
     18 #define __DRM_INFO_REQUEST_H__
     19 
     20 #include "drm_framework_common.h"
     21 
     22 namespace android {
     23 
     24 /**
     25  * This is an utility class used to pass required parameters to get
     26  * the necessary information to communicate with online DRM server
     27  *
     28  * An instance of this class is passed to
     29  * DrmManagerClient::acquireDrmInfo(const DrmInfoRequest*) to get the
     30  * instance of DrmInfo.
     31  *
     32  */
     33 class DrmInfoRequest {
     34 public:
     35     // Changes in following constants should be in sync with DrmInfoRequest.java
     36     static const int TYPE_REGISTRATION_INFO = 1;
     37     static const int TYPE_UNREGISTRATION_INFO = 2;
     38     static const int TYPE_RIGHTS_ACQUISITION_INFO = 3;
     39     static const int TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO = 4;
     40 
     41     /**
     42      * Key to pass the unique id for the account or the user
     43      */
     44     static const String8 ACCOUNT_ID;
     45     /**
     46      * Key to pass the subscription id
     47      */
     48     static const String8 SUBSCRIPTION_ID;
     49 
     50 public:
     51     /**
     52      * Constructor for DrmInfoRequest
     53      *
     54      * @param[in] infoType Type of information
     55      * @param[in] mimeType MIME type
     56      */
     57     DrmInfoRequest(int infoType, const String8& mimeType);
     58 
     59     /**
     60      * Destructor for DrmInfoRequest
     61      */
     62     virtual ~DrmInfoRequest() {}
     63 
     64 public:
     65     /**
     66      * Iterator for key
     67      */
     68     class KeyIterator {
     69         friend class DrmInfoRequest;
     70 
     71     private:
     72         KeyIterator(const DrmInfoRequest* drmInfoRequest)
     73             : mDrmInfoRequest(const_cast <DrmInfoRequest*> (drmInfoRequest)), mIndex(0) {}
     74 
     75     public:
     76         KeyIterator(const KeyIterator& keyIterator);
     77         KeyIterator& operator=(const KeyIterator& keyIterator);
     78         virtual ~KeyIterator() {}
     79 
     80     public:
     81         bool hasNext();
     82         const String8& next();
     83 
     84     private:
     85         DrmInfoRequest* mDrmInfoRequest;
     86         unsigned int mIndex;
     87     };
     88 
     89     /**
     90      * Iterator
     91      */
     92     class Iterator {
     93         friend class DrmInfoRequest;
     94 
     95     private:
     96         Iterator(const DrmInfoRequest* drmInfoRequest)
     97             : mDrmInfoRequest(const_cast <DrmInfoRequest*> (drmInfoRequest)), mIndex(0) {}
     98 
     99     public:
    100         Iterator(const Iterator& iterator);
    101         Iterator& operator=(const Iterator& iterator);
    102         virtual ~Iterator() {}
    103 
    104     public:
    105         bool hasNext();
    106         String8& next();
    107 
    108     private:
    109         DrmInfoRequest* mDrmInfoRequest;
    110         unsigned int mIndex;
    111     };
    112 
    113 public:
    114     /**
    115      * Returns information type associated with this instance
    116      *
    117      * @return Information type
    118      */
    119     int getInfoType(void) const;
    120 
    121     /**
    122      * Returns MIME type associated with this instance
    123      *
    124      * @return MIME type
    125      */
    126     String8 getMimeType(void) const;
    127 
    128     /**
    129      * Returns the number of entries in DrmRequestInfoMap
    130      *
    131      * @return Number of entries
    132      */
    133     int getCount(void) const;
    134 
    135     /**
    136      * Adds optional information as <key, value> pair to this instance
    137      *
    138      * @param[in] key Key to add
    139      * @param[in] value Value to add
    140      * @return Returns the error code
    141      */
    142     status_t put(const String8& key, const String8& value);
    143 
    144     /**
    145      * Retrieves the value of given key
    146      *
    147      * @param key Key whose value to be retrieved
    148      * @return The value
    149      */
    150     String8 get(const String8& key) const;
    151 
    152     /**
    153      * Returns KeyIterator object to walk through the keys associated with this instance
    154      *
    155      * @return KeyIterator object
    156      */
    157     KeyIterator keyIterator() const;
    158 
    159     /**
    160      * Returns Iterator object to walk through the values associated with this instance
    161      *
    162      * @return Iterator object
    163      */
    164     Iterator iterator() const;
    165 
    166 private:
    167     int mInfoType;
    168     String8 mMimeType;
    169 
    170     typedef KeyedVector<String8, String8> DrmRequestInfoMap;
    171     DrmRequestInfoMap mRequestInformationMap;
    172 };
    173 
    174 };
    175 
    176 #endif /* __DRM_INFO_REQUEST_H__ */
    177 
    178