|
1 /* |
|
2 * Copyright (c) 2008-2009 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 object class for interacting with servicetab for link and Display Name |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 |
|
20 #include "cimcvenginestoragelistener.h" |
|
21 #include "cimcvenginemessagehandler.h" |
|
22 #include "imcvlogger.h" |
|
23 |
|
24 //system includes |
|
25 |
|
26 // ================= MEMBER FUNCTIONS ======================= |
|
27 |
|
28 // -------------------------------------------------------------------------- |
|
29 // CIMCVEngineStorageListener::CIMCVEngineStorageListener |
|
30 // -------------------------------------------------------------------------- |
|
31 // |
|
32 CIMCVEngineStorageListener::CIMCVEngineStorageListener(MIMCVEngineStorageObserver& aObserver ) |
|
33 : CActive( CActive::EPriorityStandard ), |
|
34 iObserver( aObserver ) |
|
35 { |
|
36 CActiveScheduler::Add( this ); |
|
37 } |
|
38 |
|
39 |
|
40 // -------------------------------------------------------------------------- |
|
41 // CIMCVEngineStorageListener::ConstructL |
|
42 // -------------------------------------------------------------------------- |
|
43 // |
|
44 void CIMCVEngineStorageListener::ConstructL() |
|
45 { |
|
46 IM_CV_LOGS(TXT("CIMCVEngineStorageListener::ConstructL : start")); |
|
47 TInt err = RProperty::Define(KConvViewUID,KXspIdServiceIDKey,RProperty::EText); |
|
48 if(KErrAlreadyExists != err && KErrNone != err ) |
|
49 { |
|
50 User::LeaveIfError(err); |
|
51 } |
|
52 //define properties that engine will publish. |
|
53 err = RProperty::Define(KConvViewUID,KContactLinkDisplayNameKey,RProperty::ELargeText); |
|
54 if(KErrAlreadyExists != err && KErrNone != err ) |
|
55 { |
|
56 User::LeaveIfError(err); |
|
57 } |
|
58 //Attaching iProperty with the property published by engine to get contact link and display name. |
|
59 err = iProperty.Attach(KConvViewUID,KContactLinkDisplayNameKey); |
|
60 User::LeaveIfError(err); |
|
61 IM_CV_LOGS(TXT("CIMCVEngineStorageListener::ConstructL : end")); |
|
62 } |
|
63 // -------------------------------------------------------------------------- |
|
64 // CIMCVEngineStorageListener::NewL |
|
65 // -------------------------------------------------------------------------- |
|
66 // |
|
67 CIMCVEngineStorageListener* CIMCVEngineStorageListener::NewL(MIMCVEngineStorageObserver& aObserver) |
|
68 { |
|
69 CIMCVEngineStorageListener* self = new(ELeave) CIMCVEngineStorageListener( aObserver ); |
|
70 CleanupStack::PushL(self); |
|
71 self->ConstructL(); |
|
72 CleanupStack::Pop(self); |
|
73 return self; |
|
74 } |
|
75 // -------------------------------------------------------------------------- |
|
76 // CIMCVEngineStorageListener::GetContactLinkInfoL |
|
77 // -------------------------------------------------------------------------- |
|
78 // |
|
79 void CIMCVEngineStorageListener::GetContactLinkInfoL(TInt aServiceId, const TDesC& aXspID) |
|
80 { |
|
81 IM_CV_LOGS(TXT("CIMCVEngineStorageListener::GetContactLinkInfoL : start")); |
|
82 IM_CV_LOGS(TXT("CIMCVEngineStorageListener::GetContactLinkInfoL aServiceId= %d"),aServiceId ); |
|
83 IM_CV_LOGS(TXT("CIMCVEngineStorageListener::GetContactLinkInfoL aXspID= %S"),&aXspID ); |
|
84 StartListening(); |
|
85 |
|
86 TInt length = KMaxServiceIdLength + aXspID.Length() + KDelimiter().Length(); |
|
87 HBufC* userDetails = HBufC::NewLC(length); |
|
88 |
|
89 TPtr userDetailsPtr = userDetails->Des(); |
|
90 userDetailsPtr.Zero(); |
|
91 userDetailsPtr.AppendNum(aServiceId); |
|
92 userDetailsPtr.Append(KDelimiter()); |
|
93 userDetailsPtr.Append(aXspID); |
|
94 |
|
95 RProperty::Set(KConvViewUID,KXspIdServiceIDKey,userDetails->Des()); |
|
96 if( !iWait.IsStarted() ) |
|
97 { |
|
98 // codescanner warning can be ignored, we are not starting an active object but |
|
99 // CActiveSchedulerWait. |
|
100 iWait.Start(); |
|
101 } |
|
102 CleanupStack::PopAndDestroy(userDetails); |
|
103 IM_CV_LOGS(TXT("CIMCVEngineStorageListener::GetContactLinkInfoL : end")); |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------- |
|
107 // CIMCVEngineStorageListener::~CIMCVEngineStorageListener() |
|
108 // C++ Destructor |
|
109 // --------------------------------------------------------- |
|
110 // |
|
111 CIMCVEngineStorageListener::~CIMCVEngineStorageListener() |
|
112 { |
|
113 if( iWait.IsStarted() ) |
|
114 { |
|
115 // codescanner warning can be ignored, we are not starting an active object but |
|
116 // this is CActiveSchedulerWait. |
|
117 iWait.AsyncStop(); |
|
118 } |
|
119 StopListening(); // Cancel any request, if outstanding |
|
120 // delete the earlier defined property |
|
121 RProperty::Delete(KConvViewUID,KXspIdServiceIDKey); |
|
122 RProperty::Delete(KConvViewUID,KContactLinkDisplayNameKey); |
|
123 iProperty.Close(); // Destroy the property object |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------- |
|
127 // CIMCVEngineStorageListener::RunL() |
|
128 // --------------------------------------------------------- |
|
129 // |
|
130 void CIMCVEngineStorageListener::RunL() |
|
131 { |
|
132 IM_CV_LOGS(TXT("CIMCVEngineStorageListener::RunL : start")); |
|
133 if( iStatus.Int() == KErrNone ) |
|
134 { |
|
135 // TBuf <KMaxDisplayNameContactLinkLength> servId_usrId_name_link; |
|
136 HBufC16* servId_usrId_name_link = HBufC16::New(KMaxDisplayNameContactLinkLength); |
|
137 TPtr servId_usrId_name_linkPtr( servId_usrId_name_link->Des() ); |
|
138 //Get the property in "ServiceId:UserId:Name:ContactLink" formate |
|
139 iProperty.Get(KConvViewUID,KContactLinkDisplayNameKey,servId_usrId_name_linkPtr ); |
|
140 |
|
141 IM_CV_LOGS(TXT("CIMCVEngineStorageListener::RunL received property = %S"),&servId_usrId_name_linkPtr ); |
|
142 |
|
143 TInt posOfDelimiter = servId_usrId_name_link->Find(KDelimiter); |
|
144 if(KErrNotFound != posOfDelimiter ) |
|
145 { |
|
146 TInt serviceId; |
|
147 HBufC16* userID = NULL; |
|
148 HBufC16* contactLink = NULL; |
|
149 HBufC16* displayName = NULL; |
|
150 |
|
151 TBuf<KMaxServiceIdLength> serviceIdBuf; |
|
152 TPtrC ptr(servId_usrId_name_link->Left(posOfDelimiter)); |
|
153 serviceIdBuf = ptr; |
|
154 TLex16 lex(serviceIdBuf); |
|
155 lex.Val(serviceId); |
|
156 |
|
157 TPtrC usrId_name_link = servId_usrId_name_link->Right(servId_usrId_name_link->Length() - (posOfDelimiter+ 1) ); |
|
158 posOfDelimiter = usrId_name_link.Find(KDelimiter); |
|
159 //extracting user id |
|
160 if(KErrNotFound != posOfDelimiter ) |
|
161 { |
|
162 userID = (usrId_name_link.Left(posOfDelimiter)).AllocLC(); |
|
163 } |
|
164 |
|
165 //extracting display name. |
|
166 TPtrC name_link = usrId_name_link.Right(usrId_name_link.Length() - (posOfDelimiter+ 1) ); |
|
167 posOfDelimiter = name_link.Find(KDelimiter); |
|
168 if(KErrNotFound != posOfDelimiter ) |
|
169 { |
|
170 displayName = (name_link.Left(posOfDelimiter)).AllocLC(); |
|
171 } |
|
172 |
|
173 //extracting contact link |
|
174 TPtrC link = name_link.Right(name_link.Length() - (posOfDelimiter+ 1) ); |
|
175 contactLink = link.AllocLC(); |
|
176 |
|
177 HBufC8* convertedLink = NULL; |
|
178 |
|
179 if(contactLink) |
|
180 { |
|
181 convertedLink = HBufC8::NewLC(contactLink->Length()); |
|
182 TPtr8 convertedLinkPtr = convertedLink->Des(); |
|
183 convertedLinkPtr.Copy(*contactLink); |
|
184 } |
|
185 if( !convertedLink ) |
|
186 { |
|
187 convertedLink = KNullDesC8().AllocLC(); |
|
188 } |
|
189 |
|
190 if(convertedLink && userID && displayName) |
|
191 { |
|
192 iObserver.HandleServiceBuddyDetailsFetchedL( serviceId,*userID,*convertedLink,*displayName); |
|
193 |
|
194 IM_CV_LOGS(TXT("storage listener RunL userID = %S"),&(*userID) ); |
|
195 IM_CV_LOGS(TXT("storage listener RunL convertedLink = %S"),&(*convertedLink) ); |
|
196 IM_CV_LOGS(TXT("storage listener RunL displayName = %S"),&(*displayName) ); |
|
197 |
|
198 } |
|
199 delete (servId_usrId_name_link); |
|
200 //delete all alocated memory |
|
201 if(convertedLink) |
|
202 { |
|
203 CleanupStack::PopAndDestroy(convertedLink); |
|
204 } |
|
205 if(contactLink) |
|
206 { |
|
207 CleanupStack::PopAndDestroy(contactLink); |
|
208 } |
|
209 if(displayName) |
|
210 { |
|
211 CleanupStack::PopAndDestroy(displayName); |
|
212 } |
|
213 if(userID) |
|
214 { |
|
215 CleanupStack::PopAndDestroy(userID); |
|
216 } |
|
217 } |
|
218 } |
|
219 if( iWait.IsStarted() ) |
|
220 { |
|
221 // codescanner warning can be ignored, we are not starting an active object but |
|
222 // this is CActiveSchedulerWait. |
|
223 iWait.AsyncStop(); |
|
224 } |
|
225 |
|
226 IM_CV_LOGS(TXT("CIMCVEngineStorageListener::RunL : end")); |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------- |
|
230 // CIMCVEngineStorageListener::RunL() |
|
231 // --------------------------------------------------------- |
|
232 // |
|
233 void CIMCVEngineStorageListener::DoCancel() |
|
234 { |
|
235 iProperty.Cancel(); |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------- |
|
239 // CIMCVEngineStorageListener::StartListening() |
|
240 // --------------------------------------------------------- |
|
241 // |
|
242 void CIMCVEngineStorageListener::StartListening() |
|
243 { |
|
244 if( !IsActive() ) |
|
245 { |
|
246 iProperty.Subscribe(iStatus); |
|
247 SetActive(); // Tell scheduler a request is active |
|
248 } |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------- |
|
252 // CIMCVEngineStorageListener::StopListening() |
|
253 // --------------------------------------------------------- |
|
254 // |
|
255 void CIMCVEngineStorageListener::StopListening() |
|
256 { |
|
257 if( IsActive() ) |
|
258 { |
|
259 Cancel(); // Cancel any request, if outstanding |
|
260 } |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------- |
|
264 // CIMCVEngineStorageListener::StopListening() |
|
265 // --------------------------------------------------------- |
|
266 // |
|
267 TInt CIMCVEngineStorageListener::RunError( TInt aError ) |
|
268 { |
|
269 IM_CV_LOGS(TXT("CIMCVEngineStorageListener::RunError : start")); |
|
270 IM_CV_LOGS(TXT("CIMCVEngineStorageListener::RunError : end")); |
|
271 if( iWait.IsStarted() ) |
|
272 { |
|
273 // codescanner warning can be ignored, we are not starting an active object but |
|
274 // this is CActiveSchedulerWait. |
|
275 iWait.AsyncStop(); |
|
276 } |
|
277 return aError; |
|
278 } |
|
279 |
|
280 |
|
281 // End of File |
|
282 |