1 /* |
|
2 * Copyright (c) 2007-2008 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: Subscribe Presentity Group content request to the Network Server. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ximpprotocolconnectionhost.h> |
|
20 #include "csubscribepresentitygroupcontentrequest.h" |
|
21 #include "cossprotocolconnectionmanager.h" |
|
22 #include <ximpobjectfactory.h> |
|
23 #include <protocolpresencedatahost.h> |
|
24 #include <presenceobjectfactory.h> |
|
25 #include <ximpobjectcollection.h> |
|
26 #include <protocolpresentitygroupsdatahost.h> |
|
27 #include <presentitygroupinfo.h> |
|
28 #include <presentitygroupmemberinfo.h> |
|
29 #include <ximpidentity.h> |
|
30 #include <ximpdatasubscriptionstate.h> |
|
31 #include "ossprotocolpluginlogger.h" |
|
32 |
|
33 #include <glib/gstrfuncs.h> |
|
34 #include <gtypes.h> |
|
35 #include <stdlib.h> |
|
36 #include "stringutils.h" |
|
37 #include <string.h> |
|
38 #include <sys/types.h> |
|
39 #include <stdio.h> |
|
40 #include <glib/gprintf.h> |
|
41 #include "msgliterals.h" |
|
42 #include "msg_enums.h" |
|
43 #include "ossprotocoladaptutils.h" |
|
44 |
|
45 // ======== MEMBER FUNCTIONS ======== |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // CSubscribePresentityGroupContentRequest::CSubscribePresentityGroupContentRequest() |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CSubscribePresentityGroupContentRequest::CSubscribePresentityGroupContentRequest ( |
|
52 MOSSProtocolConnectionManager& aConnMan, |
|
53 TXIMPRequestId aRequestId ) : |
|
54 CActive ( EPriorityNormal ), |
|
55 iRequestId ( aRequestId ), |
|
56 iConnMan ( aConnMan ), |
|
57 iListcount ( 0 ) |
|
58 { |
|
59 LOGGER ( TXT ( "::CSubscribePresentityGroupContentRequest Start" ) ); |
|
60 CActiveScheduler::Add ( this ); |
|
61 LOGGER ( TXT ( "::CSubscribePresentityGroupContentRequest End" ) ); |
|
62 } |
|
63 |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CSubscribePresentityGroupContentRequest::ConstructL() |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 void CSubscribePresentityGroupContentRequest::ConstructL() |
|
70 { |
|
71 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::ConstructL Start-End" ) ); |
|
72 iGroupName = NULL; |
|
73 |
|
74 } |
|
75 |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CSubscribePresentityGroupContentRequest::NewL |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 CSubscribePresentityGroupContentRequest* CSubscribePresentityGroupContentRequest::NewL ( |
|
82 MOSSProtocolConnectionManager& aConnMan, |
|
83 TXIMPRequestId aRequestId ) |
|
84 { |
|
85 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::NewL Start" ) ); |
|
86 |
|
87 CSubscribePresentityGroupContentRequest* self = new ( ELeave ) |
|
88 CSubscribePresentityGroupContentRequest ( aConnMan, aRequestId ); |
|
89 CleanupStack::PushL ( self ); |
|
90 self->ConstructL(); |
|
91 CleanupStack::Pop ( self ); |
|
92 |
|
93 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::NewL End" ) ); |
|
94 return self; |
|
95 } |
|
96 |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // CSubscribePresentityGroupContentRequest::NewLC() |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 CSubscribePresentityGroupContentRequest* CSubscribePresentityGroupContentRequest::NewLC ( |
|
103 MOSSProtocolConnectionManager& aConnMan, |
|
104 TXIMPRequestId aRequestId ) |
|
105 { |
|
106 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::NewLC Start" ) ); |
|
107 |
|
108 CSubscribePresentityGroupContentRequest* self = |
|
109 CSubscribePresentityGroupContentRequest::NewL ( aConnMan, aRequestId ); |
|
110 CleanupStack::PushL ( self ); |
|
111 |
|
112 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::NewLC End" ) ); |
|
113 return self; |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // CSubscribePresentityGroupContentRequest::~CSubscribePresentityGroupContentRequest() |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 CSubscribePresentityGroupContentRequest::~CSubscribePresentityGroupContentRequest() |
|
121 { |
|
122 LOGGER ( TXT ( "::~CSubscribePresentityGroupContentRequest Start" ) ); |
|
123 delete iGroupName; |
|
124 iGroupName = NULL; |
|
125 Cancel(); |
|
126 //iContacts.ResetAndDestroy(); |
|
127 LOGGER ( TXT ( "::~CSubscribePresentityGroupContentRequest End" ) ); |
|
128 } |
|
129 |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // CSubscribePresentityGroupContentRequest::DoCancel() |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 void CSubscribePresentityGroupContentRequest::DoCancel() |
|
136 { |
|
137 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::DoCancel Start" ) ); |
|
138 iConnMan.DataHandler().CancelListening(); |
|
139 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::DoCancel End" ) ); |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CSubscribePresentityGroupContentRequest::RunL() |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CSubscribePresentityGroupContentRequest::RunL() |
|
147 { |
|
148 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::RunL Start" ) ); |
|
149 User::LeaveIfError( iStatus.Int() ); |
|
150 TRAPD( error, ProcessIncomingDataL( ) ); |
|
151 if ( error != KErrNone ) |
|
152 { |
|
153 Cancel(); |
|
154 } |
|
155 |
|
156 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::RunL End" ) ); |
|
157 } |
|
158 |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // CSubscribePresentityGroupContentRequest::RunError |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 TInt CSubscribePresentityGroupContentRequest::RunError ( TInt aError ) |
|
165 { |
|
166 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::RunError Start" ) ); |
|
167 |
|
168 iConnMan.HandleToHost().HandleRequestCompleted ( iRequestId, aError ); |
|
169 |
|
170 delete this; |
|
171 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::RunError End" ) ); |
|
172 return KErrNone; |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // CSubscribePresentityGroupContentRequest::SubscribePresentityGroupContentL |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 void CSubscribePresentityGroupContentRequest::SubscribePresentityGroupContentL ( |
|
180 const MXIMPIdentity& aIdentity ) |
|
181 { |
|
182 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::SubscribePresentityGroupContentL Start" ) ); |
|
183 if(iGroupName) |
|
184 { |
|
185 delete iGroupName; |
|
186 iGroupName = NULL; |
|
187 } |
|
188 iGroupName = aIdentity.Identity().AllocL(); |
|
189 iConnMan.SetGroupIDL( *iGroupName ); // this groupname is used by contactsync class for synchronisation |
|
190 |
|
191 if(iConnMan.DataHandler().IsFetchContactsCompleted()) |
|
192 { |
|
193 ProcessIncomingDataL( ); |
|
194 } |
|
195 else |
|
196 { |
|
197 if ( ! ( this->IsActive() ) ) |
|
198 { |
|
199 iConnMan.DataHandler().ListenIncomingData ( iStatus ); |
|
200 SetActive(); |
|
201 } |
|
202 } |
|
203 |
|
204 |
|
205 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::SubscribePresentityGroupContentL End" ) ); |
|
206 } |
|
207 |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // CSubscribePresentityGroupContentRequest::ProcessIncomingDataL() |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 void CSubscribePresentityGroupContentRequest::ProcessIncomingDataL() |
|
214 { |
|
215 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::ProcessIncomingDataL Start" ) ); |
|
216 |
|
217 PopulateDataL(); |
|
218 |
|
219 MXIMPObjectFactory& prfwObjFact = iConnMan.HandleToHost().ObjectFactory(); |
|
220 |
|
221 MPresenceObjectFactory& prObjFact = |
|
222 iConnMan.HandleToHost().ProtocolPresenceDataHost().PresenceObjectFactory(); |
|
223 |
|
224 MXIMPIdentity* contactIdentity = NULL; |
|
225 MPresentityGroupMemberInfo* groupMemberInfo = NULL; |
|
226 MXIMPObjectCollection* listOfContacts = prfwObjFact.NewObjectCollectionLC(); |
|
227 |
|
228 //get the ref to contacts which was already stored in PopulateDataL |
|
229 RPointerArray<HBufC>& contacts = iConnMan.GetContactManager().GetContactsListL(); |
|
230 |
|
231 for(TInt i = 0;i<contacts.Count();i++) |
|
232 { |
|
233 contactIdentity = prfwObjFact.NewIdentityLC(); |
|
234 groupMemberInfo = prObjFact.NewPresentityGroupMemberInfoLC(); |
|
235 contactIdentity->SetIdentityL ( *(contacts[ i ] )); |
|
236 groupMemberInfo->SetGroupMemberIdL ( contactIdentity ); |
|
237 groupMemberInfo->SetGroupMemberDisplayNameL ( *(contacts[ i ] ) ); |
|
238 listOfContacts->AddObjectL ( groupMemberInfo ); |
|
239 CleanupStack::Pop ( 2 );//groupMemberInfo, contactIdentity |
|
240 |
|
241 } |
|
242 |
|
243 MXIMPIdentity* groupIdentity = prfwObjFact.NewIdentityLC(); |
|
244 |
|
245 groupIdentity->SetIdentityL ( *iGroupName ); |
|
246 |
|
247 iConnMan.HandleToHost().ProtocolPresenceDataHost().GroupsDataHost().HandlePresentityGroupContentL ( |
|
248 groupIdentity, listOfContacts ); |
|
249 iConnMan.HandleToHost().HandleRequestCompleted ( iRequestId, KErrNone ); |
|
250 CleanupStack::Pop ( 2 );//groupIdentity,listOfContacts |
|
251 |
|
252 delete this; |
|
253 |
|
254 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::ProcessIncomingDataL End" ) ); |
|
255 |
|
256 } |
|
257 |
|
258 // --------------------------------------------------------------------------- |
|
259 // CSubscribePresentityGroupContentRequest::PopulateDataL |
|
260 // --------------------------------------------------------------------------- |
|
261 // |
|
262 void CSubscribePresentityGroupContentRequest::PopulateDataL() |
|
263 { |
|
264 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::PopulateDataL Start" ) ); |
|
265 |
|
266 int len = MAX_SIZE_DATA; |
|
267 char* pResponse = NULL, *pOrigResponse = NULL; |
|
268 |
|
269 TInt datacount = iConnMan.DataHandler().IncomingDataCount(); |
|
270 //to keep the local copy of contacts in adaptation till logout |
|
271 RPointerArray<HBufC>& contacts = iConnMan.GetContactManager().GetContactsListL(); |
|
272 |
|
273 while( datacount ) |
|
274 { |
|
275 // get the incoming response from the server with transaction id equals zero |
|
276 pOrigResponse = pResponse = iConnMan.DataHandler().ResponseL ( 0 ); |
|
277 CleanupStack::PushL(pOrigResponse) ; |
|
278 if( pResponse ) |
|
279 { |
|
280 pResponse += sizeof ( message_hdr_resp ); |
|
281 |
|
282 while(1) |
|
283 { |
|
284 len = strlen(pResponse) + 1; |
|
285 if (1 == len) |
|
286 { |
|
287 break; |
|
288 } |
|
289 char* contact = pResponse; |
|
290 pResponse += len; |
|
291 |
|
292 HBufC16 *contactName = OssProtocolAdapUtils::ConvertCharToTUint16LC( contact ); |
|
293 contacts.AppendL(contactName); |
|
294 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::PopulateDataL:ContactName:%S " ), contactName ); |
|
295 CleanupStack::Pop ( contactName ); |
|
296 } |
|
297 } |
|
298 |
|
299 CleanupStack::PopAndDestroy(pOrigResponse) ;//pOrigResponse |
|
300 |
|
301 datacount = iConnMan.DataHandler().IncomingDataCount(); |
|
302 } |
|
303 |
|
304 LOGGER ( TXT ( "CSubscribePresentityGroupContentRequest::PopulateDataL End" ) ); |
|
305 } |
|
306 |
|
307 |
|
308 |
|
309 // End of file |
|