|
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: Presence Service Connection presence watcher list subscription implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <badesca.h> |
|
20 |
|
21 #include "watcherlistsubscriptionitem.h" |
|
22 #include "presenceinfofilterimp.h" |
|
23 #include "ximpitemparent.h" |
|
24 #include "ximppanics.h" |
|
25 #include "ximppsccontext.h" |
|
26 #include "documentutils.h" |
|
27 #include "presencewatcherlisteventimp.h" |
|
28 #include "ximpobjecthelpers.h" |
|
29 #include "presencetypehelpers.h" |
|
30 #include "presencewatcherinfoimp.h" |
|
31 #include "ximpidentityimp.h" |
|
32 #include "ximpdatasubscriptionstateimp.h" |
|
33 |
|
34 #include "ximptrace.h" |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CWatcherListSubscriptionItem::CWatcherListSubscriptionItem() |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CWatcherListSubscriptionItem::CWatcherListSubscriptionItem( MXIMPItemParentBase& aParent ) |
|
41 : CXIMPSubscriptionItemBase( aParent ) |
|
42 { |
|
43 } |
|
44 |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CWatcherListSubscriptionItem::ConstructL() |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 void CWatcherListSubscriptionItem::ConstructL() |
|
51 { |
|
52 BaseConstructL(); |
|
53 // empty lists must always exist |
|
54 iCurrentList = new ( ELeave) RPrWatLstInfoImpArray; |
|
55 iNewWatchers = new ( ELeave ) RPrWatLstInfoImpArray; |
|
56 iDisappeared = new ( ELeave ) RPrWatLstInfoImpArray; |
|
57 } |
|
58 |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // CWatcherListSubscriptionItem::NewL() |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 CWatcherListSubscriptionItem* CWatcherListSubscriptionItem::NewLC( MXIMPItemParentBase& aParent ) |
|
65 { |
|
66 CWatcherListSubscriptionItem* self = new( ELeave ) CWatcherListSubscriptionItem( aParent ); |
|
67 CleanupClosePushL( *self ); |
|
68 self->ConstructL(); |
|
69 return self; |
|
70 } |
|
71 |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // CWatcherListSubscriptionItem::~CWatcherListSubscriptionItem() |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 CWatcherListSubscriptionItem::~CWatcherListSubscriptionItem() |
|
78 { |
|
79 MXIMPItemParent* presCache = static_cast<MXIMPItemParent*>(iParent.GetInterface(PRESENCE_ITEM_PARENT)); |
|
80 presCache->RemoveMe( this ); |
|
81 |
|
82 |
|
83 if( iCurrentList ) |
|
84 { |
|
85 iCurrentList->Close(); |
|
86 } |
|
87 delete iCurrentList; |
|
88 |
|
89 Clean(); |
|
90 // just in case |
|
91 delete iNewWatchers; |
|
92 delete iDisappeared; |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // From MXIMPSubscriptionItem class. |
|
97 // CWatcherListSubscriptionItem::SynthesiseSubscriptionEventTo() |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 void CWatcherListSubscriptionItem::SynthesiseSubscriptionEventToL( |
|
101 MXIMPPscContext* aContext, TBool aForceEvent ) |
|
102 { |
|
103 TRACE_1( _L("CWatcherListSubscriptionItem::SynthesiseSubscriptionEventTo() aForce=%d"), aForceEvent ); |
|
104 CXIMPDataSubscriptionStateImp* status = StatusLC( aContext ); /// << status |
|
105 |
|
106 if( status->DataState() == MXIMPDataSubscriptionState::EDataAvailable || aForceEvent ) |
|
107 { |
|
108 CleanupStack::Pop( status ); // >> status |
|
109 CPresenceWatcherListEventImp* newEvent = CPresenceWatcherListEventImp::NewLC( |
|
110 iNewWatchers, |
|
111 aForceEvent ? iCurrentList : NULL, |
|
112 iDisappeared, |
|
113 status ); |
|
114 |
|
115 MXIMPItemParent* presCache = static_cast<MXIMPItemParent*>(iParent.GetInterface(PRESENCE_ITEM_PARENT)); |
|
116 presCache->AddEventL( *newEvent, aContext ); |
|
117 CleanupStack::PopAndDestroy(); // >>> newEvent |
|
118 } |
|
119 else |
|
120 { |
|
121 CleanupStack::PopAndDestroy(); // >>> status |
|
122 } |
|
123 } |
|
124 |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CWatcherListSubscriptionItem::SetNewListL() |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 EXPORT_C void CWatcherListSubscriptionItem::SetNewListL( |
|
131 RPrWatLstInfoImpArray* aList ) |
|
132 { |
|
133 TRACE_1( _L("CWatcherListSubscriptionItem::SetNewListL aList Count=%d"), aList->Count() ); |
|
134 RPrWatLstInfoImpArray* tmp = aList; |
|
135 CleanupDeletePushL( tmp ); |
|
136 |
|
137 TLinearOrder<CPresenceWatcherInfoImp> |
|
138 linearOrder( CPresenceWatcherInfoImp::IdLinearOrder ); |
|
139 |
|
140 for ( TInt i = 0; i < tmp->Count(); i++ ) |
|
141 { |
|
142 // compare against current list |
|
143 CPresenceWatcherInfoImp* info = (*tmp)[ i ]; |
|
144 TInt pos = iCurrentList->FindInOrder( info, linearOrder ); |
|
145 |
|
146 if ( pos == KErrNotFound ) |
|
147 { |
|
148 // not found in current list |
|
149 // so must be a fresh watcher |
|
150 iNewWatchers->InsertInOrderL( info, linearOrder ); |
|
151 } |
|
152 else |
|
153 { |
|
154 delete (*iCurrentList)[ pos ]; |
|
155 iCurrentList->Remove( pos ); |
|
156 |
|
157 // we must remove the found ones from iCurrentList, |
|
158 // otherwise we will not know what was left. and finding out |
|
159 // the deleted items will be difficult. |
|
160 } |
|
161 } |
|
162 |
|
163 // what's left in iCurrentList contains the deleted ones. |
|
164 delete iDisappeared; |
|
165 iDisappeared = iCurrentList; |
|
166 |
|
167 // the given list becomes the new list |
|
168 iCurrentList = tmp; |
|
169 CleanupStack::Pop( tmp ); |
|
170 iSubscriptionState->SetDataStateL( MXIMPDataSubscriptionState::EDataAvailable ); |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // CWatcherListSubscriptionItem::Clean() |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 EXPORT_C void CWatcherListSubscriptionItem::Clean() |
|
178 { |
|
179 TRACE( _L("CWatcherListSubscriptionItem::Clean") ); |
|
180 // empty the lists. |
|
181 // the lists must stay valid for use |
|
182 |
|
183 // iNewWatchers and iUpdated are collection from currentlist. Do not delete items. |
|
184 // iDisappeared is only place for items. Delete those. |
|
185 |
|
186 iNewWatchers->Reset(); |
|
187 iDisappeared->Close(); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // From CXIMPSubscriptionItemBase class. |
|
192 // CWatcherListSubscriptionItem::CleanExpired() |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 void CWatcherListSubscriptionItem::CleanExpired() |
|
196 { |
|
197 |
|
198 } |
|
199 |
|
200 // End of file |