|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "mcsdrmobservermanager.h" |
|
20 #include "mcsdrmobserver.h" |
|
21 #include "menusrvengutils.h" |
|
22 #include <apaid.h> |
|
23 #include <DRMEvent.h> |
|
24 |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // destructor |
|
28 // --------------------------------------------------------------------------- |
|
29 RMcsDrmObserverManager::~RMcsDrmObserverManager() |
|
30 { |
|
31 } |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // destructor |
|
35 // --------------------------------------------------------------------------- |
|
36 void RMcsDrmObserverManager::Close() |
|
37 { |
|
38 iObservers.ResetAndDestroy(); |
|
39 } |
|
40 |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // default constructor |
|
44 // --------------------------------------------------------------------------- |
|
45 RMcsDrmObserverManager::RMcsDrmObserverManager( CMenuSrvEngUtils& aUtils ): |
|
46 iUtils( aUtils ) |
|
47 { |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 // --------------------------------------------------------------------------- |
|
53 void RMcsDrmObserverManager::AddL( CMcsDrmObserver* aObserver ) |
|
54 { |
|
55 User::LeaveIfError( iObservers.Append( aObserver ) ); |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 // --------------------------------------------------------------------------- |
|
61 void RMcsDrmObserverManager::Remove( CMcsDrmObserver* aObserver ) |
|
62 { |
|
63 TInt ptrIndex( iObservers.Find( aObserver ) ); |
|
64 if ( KErrNotFound != ptrIndex ) |
|
65 { |
|
66 delete aObserver; |
|
67 iObservers.Remove( ptrIndex ); |
|
68 } |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 // --------------------------------------------------------------------------- |
|
74 void RMcsDrmObserverManager::RemoveMissingObservers( |
|
75 const RArray<TUid>& aDrmProtectedArray ) |
|
76 { |
|
77 TInt index = 0; |
|
78 while (index < iObservers.Count() ) |
|
79 { |
|
80 if ( aDrmProtectedArray.Find( iObservers[index]->Uid() ) == KErrNotFound ) |
|
81 { |
|
82 delete iObservers[index]; |
|
83 iObservers.Remove( index ); |
|
84 } |
|
85 else |
|
86 { |
|
87 index++; |
|
88 } |
|
89 } |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 // --------------------------------------------------------------------------- |
|
95 TInt RMcsDrmObserverManager::FindUid( TUid aUid ) |
|
96 { |
|
97 TInt ret( KErrNotFound ); |
|
98 for (TInt i = 0; i < iObservers.Count(); i++) |
|
99 { |
|
100 if (iObservers[i]->Uid() == aUid) |
|
101 { |
|
102 ret = i; |
|
103 break; |
|
104 } |
|
105 } |
|
106 return ret; |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 // --------------------------------------------------------------------------- |
|
112 void RMcsDrmObserverManager::CreateObserversL( |
|
113 const RArray<TUid>& aDrmArray, |
|
114 TDRMEventType aMask, |
|
115 MMcsDrmObserver& aObserver ) |
|
116 { |
|
117 for (TInt i = 0; i < aDrmArray.Count(); i++) |
|
118 { |
|
119 if (FindUid(aDrmArray[i]) == KErrNotFound) |
|
120 { |
|
121 TApaAppInfo info; |
|
122 iUtils.GetApaAppInfo(aDrmArray[i], info); |
|
123 |
|
124 CMcsDrmObserver* observer= NULL; |
|
125 if (CMenuSrvEngUtils::IsMiddlet(info) ) |
|
126 { |
|
127 TBuf<KMaxFileName> contentId; |
|
128 CMenuSrvEngUtils::GetJavaContentIdL(info.iUid, contentId); |
|
129 |
|
130 observer = CMcsDrmObserver::NewL(aObserver, contentId, |
|
131 aDrmArray[i], aMask); |
|
132 |
|
133 TInt err = iObservers.Append(observer); |
|
134 if( err != KErrNone) |
|
135 { |
|
136 delete observer; |
|
137 User::Leave( err ); |
|
138 } |
|
139 } |
|
140 } |
|
141 } |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 // --------------------------------------------------------------------------- |
|
147 void RMcsDrmObserverManager::CreateObserversL( |
|
148 const RArray<TUid>& aDrmProtectedArray, |
|
149 MMcsDrmObserver& aObserver ) |
|
150 { |
|
151 CreateObserversL(aDrmProtectedArray, KEventModify, |
|
152 aObserver); |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 // --------------------------------------------------------------------------- |
|
158 void RMcsDrmObserverManager::RefreshObserverL( |
|
159 const RArray<TUid>& aDrmProtectedArray, |
|
160 TUid aUid, |
|
161 MMcsDrmObserver& aObserver ) |
|
162 { |
|
163 TInt index = FindUid( aUid ); |
|
164 if ( index != KErrNotFound ) |
|
165 { |
|
166 delete iObservers[index]; |
|
167 iObservers.Remove( index ); |
|
168 CreateObserversL(aDrmProtectedArray, KEventModify, |
|
169 aObserver); |
|
170 } |
|
171 |
|
172 } |