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: handles synchronisation of contacts |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ximpprotocolconnectionhost.h> |
|
20 |
|
21 #include <ximpobjectfactory.h> |
|
22 #include <protocolpresentitygroupsdatahost.h> |
|
23 #include <presentitygroupinfo.h> |
|
24 #include <presentitygroupmemberinfo.h> |
|
25 #include <ximpidentity.h> |
|
26 #include <protocolpresencedatahost.h> |
|
27 #include <presenceobjectfactory.h> |
|
28 |
|
29 #include <ximpcontext.h> |
|
30 |
|
31 #include <devicepresenceinfo.h> |
|
32 |
|
33 #include <e32des16.h> |
|
34 #include <string.h> |
|
35 #include <sys/types.h> |
|
36 #include <stdio.h> |
|
37 #include <stdlib.h> |
|
38 #include "msgliterals.h" |
|
39 |
|
40 #include "ccontactsynchandler.h" |
|
41 |
|
42 #include "mossprotocolconnectionmanager.h" |
|
43 #include "ossprotocolpluginlogger.h" |
|
44 #include "waittimer.h" |
|
45 #include "cossprotocolconnectionmanager.h" |
|
46 #include "ossprotocoladaptationuids.h" |
|
47 #include "ossprotocoladaptutils.h" |
|
48 |
|
49 // ======== MEMBER FUNCTIONS ======== |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CContactSyncHandler::CContactSyncHandler |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CContactSyncHandler::CContactSyncHandler ( |
|
56 MOSSProtocolConnectionManager& aConnMan ) : |
|
57 CActive ( EPriorityNormal ), |
|
58 iConnMan ( aConnMan ) |
|
59 { |
|
60 LOGGER ( TXT ( "CContactSyncHandler::CContactSyncHandler Start" ) ); |
|
61 CActiveScheduler::Add ( this ); |
|
62 |
|
63 LOGGER ( TXT ( "CContactSyncHandler::CContactSyncHandler End" ) ); |
|
64 } |
|
65 |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CContactSyncHandler::NewL |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 CContactSyncHandler* CContactSyncHandler::NewL ( |
|
72 MOSSProtocolConnectionManager& aConnMan ) |
|
73 { |
|
74 LOGGER ( TXT ( "CContactSyncHandler::NewL Start" ) ); |
|
75 |
|
76 CContactSyncHandler* self = new ( ELeave ) CContactSyncHandler ( aConnMan ); |
|
77 |
|
78 LOGGER ( TXT ( "CContactSyncHandler::NewL End" ) ); |
|
79 return self; |
|
80 } |
|
81 |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // CContactSyncHandler::~CContactSyncHandler |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 CContactSyncHandler::~CContactSyncHandler() |
|
88 { |
|
89 LOGGER ( TXT ( "::~CContactSyncHandler Start" ) ); |
|
90 |
|
91 Cancel(); |
|
92 |
|
93 LOGGER ( TXT ( "::~CContactSyncHandler End" ) ); |
|
94 } |
|
95 |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CContactSyncHandler::DoCancel() |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CContactSyncHandler::DoCancel() |
|
102 { |
|
103 LOGGER ( TXT ( "CContactSyncHandler::DoCancel Start" ) ); |
|
104 |
|
105 iConnMan.DataHandler().CancelContactsChangeListening(); |
|
106 |
|
107 LOGGER ( TXT ( "CContactSyncHandler::DoCancel End" ) ); |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CContactSyncHandler::RunL() |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 void CContactSyncHandler::RunL() |
|
115 { |
|
116 LOGGER ( TXT ( "CContactSyncHandler::RunL Start" ) ); |
|
117 |
|
118 // something is coming from the xmpp server |
|
119 User::LeaveIfError ( iStatus.Int() ); |
|
120 |
|
121 ProcessAndSendL(); |
|
122 StartListening(); |
|
123 |
|
124 LOGGER ( TXT ( "CContactSyncHandler::RunL End" ) ); |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CContactSyncHandler::ProcessAndSendL() |
|
129 // --------------------------------------------------------------------------- |
|
130 |
|
131 void CContactSyncHandler::ProcessAndSendL() |
|
132 { |
|
133 LOGGER ( TXT ( "CContactSyncHandler::ProcessIncomingDataL Start" ) ); |
|
134 char* pResponse = NULL, *pOrigResponse = NULL; |
|
135 message_hdr_resp* msg_struct = NULL; |
|
136 |
|
137 while( iConnMan.DataHandler().ContactsChangeResponseCount() ) // process all responses |
|
138 { |
|
139 pOrigResponse = pResponse = iConnMan.DataHandler().ResponseL (200 ); |
|
140 CleanupStack::PushL(pOrigResponse) ; |
|
141 |
|
142 msg_struct = ( message_hdr_resp* )pResponse; |
|
143 |
|
144 char* contact= pResponse + sizeof ( message_hdr_resp ); |
|
145 HBufC16* contactName = OssProtocolAdapUtils::ConvertCharToTUint16LC( contact ); |
|
146 switch ( msg_struct->hdr_req.message_type ) |
|
147 { |
|
148 case ESubscribe_Remote_Pending: |
|
149 { |
|
150 break; |
|
151 } |
|
152 case ETrying_To_Add_Contact_Known: |
|
153 { |
|
154 iConnMan.GetContactManager().AddContactToLocalL(*contactName); |
|
155 iConnMan.GetContactManager().RemoveInvitationFromLocalL(*contactName); |
|
156 break; |
|
157 } |
|
158 case ESubscribe_RP_Accepted: |
|
159 { |
|
160 break; |
|
161 } |
|
162 case EPublish_RP_Accepted: |
|
163 { |
|
164 break; |
|
165 } |
|
166 case ESubscribe_Removed_Or_Rejected: |
|
167 { |
|
168 //removing from the local copy of the contacts |
|
169 iConnMan.GetContactManager().RemoveContactFromLocalL(*contactName); |
|
170 break; |
|
171 } |
|
172 case EPublish_Removed_Or_Rejected: |
|
173 { |
|
174 iConnMan.GetContactManager().RemoveInvitationFromLocalL(*contactName); |
|
175 break; |
|
176 } |
|
177 } |
|
178 CleanupStack::PopAndDestroy ( 2 );//pOrigResponse, contactName |
|
179 } |
|
180 LOGGER ( TXT ( "CContactSyncHandler::ProcessIncomingDataL End" ) ); |
|
181 } |
|
182 |
|
183 |
|
184 // --------------------------------------------------------------------------- |
|
185 // CContactSyncHandler::RunError |
|
186 // --------------------------------------------------------------------------- |
|
187 // |
|
188 TInt CContactSyncHandler::RunError ( TInt aError ) |
|
189 { |
|
190 LOGGER ( TXT ( "CContactSyncHandler::RunError Start %d" ), aError ); |
|
191 |
|
192 LOGGER ( TXT ( "CContactSyncHandler::RunError End" ) ); |
|
193 return KErrNone; |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // CContactSyncHandler::StartListeningL |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 void CContactSyncHandler::StartListening() |
|
201 { |
|
202 LOGGER ( TXT ( "CContactSyncHandler::StartListeningL Start" ) ); |
|
203 |
|
204 if ( ! ( this->IsActive() ) ) |
|
205 { |
|
206 iConnMan.DataHandler().ListenContactsChange( iStatus ); |
|
207 SetActive(); |
|
208 } |
|
209 LOGGER ( TXT ( "CContactSyncHandler::StartListeningL End" ) ); |
|
210 } |
|
211 |
|
212 // End of file |
|