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 |
{
|
|
197 |
return iObserver.Clean( aPlugin, aContent, aIndex );
|
|
198 |
}
|
|
199 |
|
|
200 |
MAiContentObserver& CAiContentObserverOptimizer::Observer() const
|
|
201 |
{
|
|
202 |
return iObserver;
|
|
203 |
}
|
|
204 |
|
|
205 |
TInt CAiContentObserverOptimizer::AddToBlackList( TInt aContentId, TInt aIndex )
|
|
206 |
{
|
|
207 |
TInt err = KErrNone;
|
|
208 |
if ( !IsInBlackList( aContentId, aIndex ) )
|
|
209 |
{
|
|
210 |
TAiPublishBlackList entry;
|
|
211 |
entry.iContentId = aContentId;
|
|
212 |
entry.iIndex = aIndex;
|
|
213 |
err = iBlackList.Append( entry );
|
|
214 |
}
|
|
215 |
return err;
|
|
216 |
}
|
|
217 |
|
|
218 |
TBool CAiContentObserverOptimizer::IsInBlackList( TInt aContentId, TInt aIndex ) const
|
|
219 |
{
|
|
220 |
for (TInt i = 0; i < iBlackList.Count(); ++i )
|
|
221 |
{
|
|
222 |
if ( iBlackList[i].iContentId == aContentId &&
|
|
223 |
iBlackList[i].iIndex == aIndex )
|
|
224 |
{
|
|
225 |
return ETrue;
|
|
226 |
}
|
|
227 |
}
|
|
228 |
return EFalse;
|
|
229 |
}
|
|
230 |
|
|
231 |
void CAiContentObserverOptimizer::ClearBlackList()
|
|
232 |
{
|
|
233 |
iBlackList.Reset();
|
|
234 |
}
|
|
235 |
|
|
236 |
CAiContentObserverOptimizer::CAiContentObserverOptimizer(MAiContentObserver& aObserver):
|
|
237 |
iObserver( aObserver )
|
|
238 |
{
|
|
239 |
}
|
|
240 |
|
|
241 |
// end of file
|