|
1 /* |
|
2 * Copyright (c) 2005-2007 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 * Plug-in main class |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <LiwServiceHandler.h> |
|
20 #include <LiwVariant.h> |
|
21 #include <LiwGenericParam.h> |
|
22 #include "wrtdata.h" |
|
23 #include "wrtdataobserver.h" |
|
24 #include "wrtdatapluginconst.h" |
|
25 // --------------------------------------------------------------------------- |
|
26 // Constructor |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 CWrtDataObserver::CWrtDataObserver () |
|
30 { |
|
31 |
|
32 } |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // Destructor |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 CWrtDataObserver ::~CWrtDataObserver () |
|
39 { |
|
40 TRAP_IGNORE( ReleaseL()); |
|
41 iInterface = NULL; |
|
42 iData = NULL; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // Register for notifications |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 void CWrtDataObserver::RegisterL( CLiwDefaultMap* aFilter ) |
|
50 { |
|
51 CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL(); |
|
52 CleanupStack::PushL( inParamList ); |
|
53 CLiwGenericParamList* outParamList = CLiwGenericParamList::NewL(); |
|
54 CleanupStack::PushL( outParamList ); |
|
55 |
|
56 // Fill in input list for RequestNotification command |
|
57 inParamList->AppendL(TLiwGenericParam(KType,TLiwVariant(KCpData_PubData))); |
|
58 inParamList->AppendL(TLiwGenericParam(KFilter ,TLiwVariant(aFilter))); |
|
59 |
|
60 iError = KErrNone; |
|
61 TRAP( iError, iInterface->ExecuteCmdL( |
|
62 KRequestNotification, |
|
63 *inParamList, |
|
64 *outParamList, |
|
65 0, |
|
66 this ) ); |
|
67 |
|
68 CleanupStack::PopAndDestroy( outParamList ); |
|
69 CleanupStack::PopAndDestroy( inParamList ); |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // Sing off to notification |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 void CWrtDataObserver ::ReleaseL() |
|
77 { |
|
78 if( iInterface ) |
|
79 { |
|
80 CLiwGenericParamList* inParamList = CLiwGenericParamList::NewL(); |
|
81 CleanupStack::PushL( inParamList ); |
|
82 CLiwGenericParamList* outParamList = CLiwGenericParamList::NewL(); |
|
83 CleanupStack::PushL( outParamList ); |
|
84 |
|
85 TInt err(KErrNone); |
|
86 TRAP(err, iInterface->ExecuteCmdL( |
|
87 KRequestNotification, |
|
88 *inParamList, |
|
89 *outParamList, |
|
90 KLiwOptCancel, |
|
91 this )); |
|
92 |
|
93 CleanupStack::PopAndDestroy( outParamList ); |
|
94 CleanupStack::PopAndDestroy( inParamList ); |
|
95 } |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // Factory method construction |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 CWrtDataObserver * CWrtDataObserver::NewL( MLiwInterface* aInterface, CWrtData* aData ) |
|
103 { |
|
104 CWrtDataObserver * self = new (ELeave) CWrtDataObserver(); |
|
105 CleanupStack::PushL( self ); |
|
106 self->ConstructL( aInterface, aData ); |
|
107 CleanupStack::Pop( self ); |
|
108 return self; |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // 2n phase constructor |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 void CWrtDataObserver::ConstructL( MLiwInterface* aInterface, CWrtData* aData ) |
|
116 { |
|
117 iData = aData; |
|
118 iInterface = aInterface; |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // Handles Published content notification |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 TInt CWrtDataObserver::HandleNotifyL( |
|
126 TInt aErrorCode, |
|
127 TInt /*aEventId*/, |
|
128 CLiwGenericParamList& aEventParamList, |
|
129 const CLiwGenericParamList& /*aInParamList*/ ) |
|
130 { |
|
131 |
|
132 // Is plugin active to refresh the published data |
|
133 iError = aErrorCode; |
|
134 TInt count(0); |
|
135 TInt pos(0); |
|
136 const TLiwGenericParam* param(NULL); |
|
137 CLiwDefaultList* listOfMaps = CLiwDefaultList::NewLC(); |
|
138 param = aEventParamList.FindFirst(pos,KChangeInfo); |
|
139 if( param ) |
|
140 { |
|
141 User::LeaveIfError( param->Value().Get( *listOfMaps ) ); |
|
142 count = listOfMaps->Count(); |
|
143 } |
|
144 TLiwVariant variant; |
|
145 // Extract the data from the map |
|
146 for(TInt i = 0;i < count; i++) |
|
147 { |
|
148 listOfMaps->AtL(i,variant); |
|
149 HBufC16* operation = NULL; |
|
150 |
|
151 CLiwDefaultMap *map = CLiwDefaultMap::NewLC(); |
|
152 variant.Get( *map ); |
|
153 TBool found; |
|
154 found = map->FindL( KOperation, variant ); |
|
155 if (found) |
|
156 { |
|
157 operation = variant.AsDes().AllocLC(); |
|
158 } |
|
159 variant.Reset(); |
|
160 if( operation->Des() != KOperationExecute ) |
|
161 { |
|
162 // Nothing to update for execute action |
|
163 HBufC16* publisher = NULL; |
|
164 HBufC16* contentType = NULL; |
|
165 HBufC16* contentId = NULL; |
|
166 found = map->FindL( KFLAG, variant ); |
|
167 if ( found) |
|
168 { |
|
169 // notification from publisher registry |
|
170 if ( operation->Des() != KOperationDelete ) |
|
171 { |
|
172 iData->UpdatePublisherStatusL(); |
|
173 } |
|
174 } |
|
175 // ignore update if plugin is in suspend mode |
|
176 else if ( iData->IsPluginActive() ) |
|
177 { |
|
178 // notification from content registry |
|
179 found = map->FindL( KPublisherId, variant ); |
|
180 if (found) |
|
181 { |
|
182 publisher = variant.AsDes().AllocLC(); |
|
183 } |
|
184 variant.Reset(); |
|
185 found = map->FindL( KContentType, variant ); |
|
186 if (found) |
|
187 { |
|
188 contentType = variant.AsDes().AllocLC(); |
|
189 } |
|
190 variant.Reset(); |
|
191 found = map->FindL( KContentId, variant ); |
|
192 if (found) |
|
193 { |
|
194 contentId = variant.AsDes().AllocLC(); |
|
195 } |
|
196 variant.Reset(); |
|
197 iData->RefreshL( *publisher, *contentType, *contentId, *operation ); |
|
198 |
|
199 if ( contentId ) |
|
200 { |
|
201 CleanupStack::PopAndDestroy( contentId ); |
|
202 } |
|
203 if ( contentType ) |
|
204 { |
|
205 CleanupStack::PopAndDestroy( contentType ); |
|
206 } |
|
207 if ( publisher ) |
|
208 { |
|
209 CleanupStack::PopAndDestroy( publisher ); |
|
210 } |
|
211 } |
|
212 variant.Reset(); |
|
213 } |
|
214 if ( operation ) |
|
215 { |
|
216 CleanupStack::PopAndDestroy( operation ); |
|
217 } |
|
218 CleanupStack::PopAndDestroy( map ); |
|
219 } |
|
220 CleanupStack::PopAndDestroy( listOfMaps ); |
|
221 |
|
222 return aErrorCode; |
|
223 } |
|
224 |