author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 21:55:16 +0300 | |
branch | RCL_3 |
changeset 118 | 8baec10861af |
parent 114 | a5a39a295112 |
child 130 | 67f2ed48ad91 |
permissions | -rw-r--r-- |
114 | 1 |
/* |
2 |
* Copyright (c) 2006 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: Active Idle Content Observer optimizer |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include "aicontentobserveroptimizer.h" |
|
20 |
||
21 |
CAiContentObserverOptimizer* CAiContentObserverOptimizer::NewL(MAiContentObserver& aObserver) |
|
22 |
{ |
|
23 |
return new(ELeave) CAiContentObserverOptimizer( aObserver ); |
|
24 |
} |
|
25 |
||
26 |
CAiContentObserverOptimizer::~CAiContentObserverOptimizer() |
|
27 |
{ |
|
28 |
iBlackList.Close(); |
|
29 |
} |
|
30 |
||
31 |
TInt CAiContentObserverOptimizer::StartTransaction( TInt aTxId ) |
|
32 |
{ |
|
33 |
TInt err = KErrAlreadyExists; |
|
34 |
if ( iTransactionStarted ) |
|
35 |
{ |
|
36 |
return err; |
|
37 |
} |
|
38 |
iCommitNeeded = EFalse; |
|
39 |
||
40 |
err = iObserver.StartTransaction( aTxId ); |
|
41 |
if ( err == KErrNone ) |
|
42 |
{ |
|
43 |
iTransactionStarted = ETrue; |
|
44 |
} |
|
45 |
return err; |
|
46 |
} |
|
47 |
||
48 |
||
49 |
TInt CAiContentObserverOptimizer::Commit( TInt aTxId ) |
|
50 |
{ |
|
51 |
TInt err = KErrNotReady; |
|
52 |
if ( iTransactionStarted ) |
|
53 |
{ |
|
54 |
if ( iCommitNeeded ) |
|
55 |
{ |
|
56 |
iCommitNeeded = EFalse; |
|
57 |
err = iObserver.Commit( aTxId ); |
|
58 |
} |
|
59 |
else |
|
60 |
{ |
|
61 |
err = CancelTransaction( aTxId ); |
|
62 |
} |
|
63 |
} |
|
64 |
iTransactionStarted = EFalse; |
|
65 |
return err; |
|
66 |
} |
|
67 |
||
68 |
||
69 |
TInt CAiContentObserverOptimizer::CancelTransaction( TInt aTxId ) |
|
70 |
{ |
|
71 |
TInt err = KErrNotReady; |
|
72 |
if ( iTransactionStarted ) |
|
73 |
{ |
|
74 |
err = iObserver.CancelTransaction( aTxId ); |
|
75 |
} |
|
76 |
iTransactionStarted = EFalse; |
|
77 |
return err; |
|
78 |
} |
|
79 |
||
80 |
||
81 |
TBool CAiContentObserverOptimizer::CanPublish( CHsContentPublisher& aPlugin, |
|
82 |
TInt aContent, |
|
83 |
TInt aIndex ) |
|
84 |
{ |
|
85 |
return iObserver.CanPublish( aPlugin, aContent, aIndex ); |
|
86 |
} |
|
87 |
||
88 |
TInt CAiContentObserverOptimizer::Publish( CHsContentPublisher& aPlugin, |
|
89 |
TInt aContent, |
|
90 |
TInt aResource, |
|
91 |
TInt aIndex ) |
|
92 |
{ |
|
93 |
if ( IsInBlackList( aContent, aIndex ) ) |
|
94 |
{ |
|
95 |
return KErrNotFound; |
|
96 |
} |
|
97 |
TInt err = iObserver.Publish( aPlugin, aContent, aResource, aIndex ); |
|
98 |
// Publish went through OK, we need to commit the transaction |
|
99 |
if ( err == KErrNone && iTransactionStarted ) |
|
100 |
{ |
|
101 |
iCommitNeeded = ETrue; |
|
102 |
} |
|
103 |
// publish failed because the ui declaration doesn't |
|
104 |
// include this content => add to black list and |
|
105 |
// don't try to publish again |
|
106 |
else if ( err == KErrNotFound || err == KErrNotSupported ) |
|
107 |
{ |
|
108 |
AddToBlackList( aContent, aIndex ); |
|
109 |
} |
|
110 |
return err; |
|
111 |
} |
|
112 |
||
113 |
||
114 |
TInt CAiContentObserverOptimizer::Publish( CHsContentPublisher& aPlugin, |
|
115 |
TInt aContent, |
|
116 |
const TDesC16& aText, |
|
117 |
TInt aIndex ) |
|
118 |
{ |
|
119 |
if ( IsInBlackList( aContent, aIndex ) ) |
|
120 |
{ |
|
121 |
return KErrNotFound; |
|
122 |
} |
|
123 |
TInt err = iObserver.Publish( aPlugin, aContent, aText, aIndex ); |
|
124 |
// Publish went through OK, we need to commit the transaction |
|
125 |
if ( err == KErrNone && iTransactionStarted ) |
|
126 |
{ |
|
127 |
iCommitNeeded = ETrue; |
|
128 |
} |
|
129 |
// publish failed because the ui declaration doesn't |
|
130 |
// include this content => add to black list and |
|
131 |
// don't try to publish again |
|
132 |
else if ( err == KErrNotFound || err == KErrNotSupported ) |
|
133 |
{ |
|
134 |
AddToBlackList( aContent, aIndex ); |
|
135 |
} |
|
136 |
return err; |
|
137 |
} |
|
138 |
||
139 |
||
140 |
TInt CAiContentObserverOptimizer::Publish( CHsContentPublisher& aPlugin, |
|
141 |
TInt aContent, |
|
142 |
const TDesC8& aBuf, |
|
143 |
TInt aIndex ) |
|
144 |
{ |
|
145 |
if ( IsInBlackList( aContent, aIndex ) ) |
|
146 |
{ |
|
147 |
return KErrNotFound; |
|
148 |
} |
|
149 |
TInt err = iObserver.Publish( aPlugin, aContent, aBuf, aIndex ); |
|
150 |
// Publish went through OK, we need to commit the transaction |
|
151 |
if ( err == KErrNone && iTransactionStarted ) |
|
152 |
{ |
|
153 |
iCommitNeeded = ETrue; |
|
154 |
} |
|
155 |
// publish failed because the ui declaration doesn't |
|
156 |
// include this content => add to black list and |
|
157 |
// don't try to publish again |
|
158 |
else if ( err == KErrNotFound || err == KErrNotSupported ) |
|
159 |
{ |
|
160 |
AddToBlackList( aContent, aIndex ); |
|
161 |
} |
|
162 |
return err; |
|
163 |
||
164 |
} |
|
165 |
||
166 |
||
167 |
TInt CAiContentObserverOptimizer::Publish( CHsContentPublisher& aPlugin, |
|
168 |
TInt aContent, |
|
169 |
RFile& aFile, |
|
170 |
TInt aIndex ) |
|
171 |
{ |
|
172 |
if ( IsInBlackList( aContent, aIndex ) ) |
|
173 |
{ |
|
174 |
return KErrNotFound; |
|
175 |
} |
|
176 |
TInt err = iObserver.Publish( aPlugin, aContent, aFile, aIndex ); |
|
177 |
// Publish went through OK, we need to commit the transaction |
|
178 |
if ( err == KErrNone && iTransactionStarted ) |
|
179 |
{ |
|
180 |
iCommitNeeded = ETrue; |
|
181 |
} |
|
182 |
// publish failed because the ui declaration doesn't |
|
183 |
// include this content => add to black list and |
|
184 |
// don't try to publish again |
|
185 |
else if ( err == KErrNotFound || err == KErrNotSupported ) |
|
186 |
{ |
|
187 |
AddToBlackList( aContent, aIndex ); |
|
188 |
} |
|
189 |
return err; |
|
190 |
} |
|
191 |
||
192 |
||
193 |
TInt CAiContentObserverOptimizer::Clean( CHsContentPublisher& aPlugin, |
|
194 |
TInt aContent, |
|
195 |
TInt aIndex ) |
|
196 |
{ |
|
118
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
197 |
if ( IsInBlackList( aContent, aIndex ) ) |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
198 |
{ |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
199 |
return KErrNotFound; |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
200 |
} |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
201 |
TInt err = iObserver.Clean( aPlugin, aContent, aIndex ); |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
202 |
// Publish went through OK, we need to commit the transaction |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
203 |
if ( err == KErrNone && iTransactionStarted ) |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
204 |
{ |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
205 |
iCommitNeeded = ETrue; |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
206 |
} |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
207 |
// publish failed because the ui declaration doesn't |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
208 |
// include this content => add to black list and |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
209 |
// don't try to publish again |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
210 |
else if ( err == KErrNotFound || err == KErrNotSupported ) |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
211 |
{ |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
212 |
AddToBlackList( aContent, aIndex ); |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
213 |
} |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
114
diff
changeset
|
214 |
return err; |
114 | 215 |
} |
216 |
||
217 |
MAiContentObserver& CAiContentObserverOptimizer::Observer() const |
|
218 |
{ |
|
219 |
return iObserver; |
|
220 |
} |
|
221 |
||
222 |
TInt CAiContentObserverOptimizer::AddToBlackList( TInt aContentId, TInt aIndex ) |
|
223 |
{ |
|
224 |
TInt err = KErrNone; |
|
225 |
if ( !IsInBlackList( aContentId, aIndex ) ) |
|
226 |
{ |
|
227 |
TAiPublishBlackList entry; |
|
228 |
entry.iContentId = aContentId; |
|
229 |
entry.iIndex = aIndex; |
|
230 |
err = iBlackList.Append( entry ); |
|
231 |
} |
|
232 |
return err; |
|
233 |
} |
|
234 |
||
235 |
TBool CAiContentObserverOptimizer::IsInBlackList( TInt aContentId, TInt aIndex ) const |
|
236 |
{ |
|
237 |
for (TInt i = 0; i < iBlackList.Count(); ++i ) |
|
238 |
{ |
|
239 |
if ( iBlackList[i].iContentId == aContentId && |
|
240 |
iBlackList[i].iIndex == aIndex ) |
|
241 |
{ |
|
242 |
return ETrue; |
|
243 |
} |
|
244 |
} |
|
245 |
return EFalse; |
|
246 |
} |
|
247 |
||
248 |
void CAiContentObserverOptimizer::ClearBlackList() |
|
249 |
{ |
|
250 |
iBlackList.Reset(); |
|
251 |
} |
|
252 |
||
253 |
CAiContentObserverOptimizer::CAiContentObserverOptimizer(MAiContentObserver& aObserver): |
|
254 |
iObserver( aObserver ) |
|
255 |
{ |
|
256 |
} |
|
257 |
||
258 |
// end of file |