1/*
2 * Copyright (C) 2007 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#include <rights/RoManager.h>
18#include <rights/Asset.h>
19
20using namespace ustl;
21
22RoManager* RoManager::msInstance = NULL;
23
24/** see RoManager.h */
25RoManager* RoManager::Instance()
26{
27    if (NULL == msInstance)
28    {
29        msInstance = new RoManager();
30    }
31
32    return msInstance;
33}
34
35/** see RoManager.h */
36RoManager::RoManager()
37{
38//load the ro list from local system.
39}
40
41/** see RoManager.h */
42RoManager::~RoManager()
43{
44    msInstance = NULL;
45
46    for (vector<Ro*>::iterator it = mRoList.begin();
47         it != mRoList.end(); it++)
48    {
49        delete (*it);
50    }
51
52    mRoList.clear();
53}
54
55/** see RoManager.h */
56Ro::ERRCODE RoManager::installRo(istringstream *roStream)
57{
58    Ro *ro = new Ro();
59
60    Ro::ERRCODE ret = ro->parse(roStream);
61
62    if (Ro::RO_OK == ret)
63    {
64        ro->save();
65
66        mRoList.push_back(ro);
67    }
68
69    return ret;
70}
71
72/** see RoManager.h */
73Ro* RoManager::getRoByContentID(const string& contentID)
74{
75    for (vector<Ro*>::iterator it = mRoList.begin();
76         it != mRoList.end(); it++)
77    {
78        for (vector<Asset*>::iterator ita = (*it)->mAssetList.begin();
79             ita != (*it)->mAssetList.end(); ita++)
80        {
81            if (contentID.compare((*ita)->getContentID()) == 0)
82            {
83                return *it;
84            }
85        }
86    }
87
88    return NULL;
89}
90
91/** see RoManager.h */
92Ro* RoManager::getRo(const string& roID)
93{
94    for (vector<Ro*>::iterator it = mRoList.begin();
95         it != mRoList.end(); it++)
96    {
97        if (roID.compare((*it)->getRoID()) == 0)
98        {
99            return (*it);
100        }
101    }
102
103    return NULL;
104}
105
106/** see RoManager.h */
107vector<Ro*> RoManager::getAllRo()
108{
109    return mRoList;
110}
111
112/** see RoManager.h */
113bool RoManager::deleteRo(const string& roID)
114{
115    return true;
116}
117
118/** see RoManager.h */
119bool RoManager::checkRoInCache(const string& roID)
120{
121    return true;
122}
123
124/** see RoManager.h */
125const string& RoManager::getDevicePrivateKey() const
126{
127    string pk;
128    return pk;
129}
130